# common.py import numpy as np from Bar import Bar def fdm_heat_extraction(t_0, t_1, dx, bar:'Bar', order=2): '''Get the heat conduction at the point t_1 using Taylor series''' if order == 1: return -1 * bar.k * bar.area * (t_1 - t_0) / dx elif order == 2: return -1 * bar.k * bar.area * (((t_1 - t_0) / dx) + (bar.alpha**2 * dx * t_1 / 2)) def fem_heat_extraction(t_0, t_1, dx, bar:'Bar'): '''Get the heat conduction at the point t_1 using FEM equation''' term_1 = (-1/dx + bar.alpha**2*dx/6) * t_0 term_2 = (1/dx + 2*bar.alpha**2*dx/6) * t_1 return -1 * bar.k * bar.area * (term_1 + term_2) def calc_error(exact, q_1): return np.abs((exact - q_1) / exact) def calc_beta(exact, q_1, q_2, dx_1, dx_2): return np.log(np.abs((exact - q_1)/(exact - q_2))) / np.log(dx_1 / dx_2) def calc_extrapolated(q1, q2, q3): '''Calcs the Richardson Extrapolation value based on 3 different meshes. Assumes that q3 is 2x finer than q2 is 2x finer than q1''' numerator = q1*q3 - q2**2 denominator = q1 + q3 - 2*q2 return numerator / denominator