Numerical-Simulation/HW1/common.py

20 lines
545 B
Python

# common.py
import numpy as np
k = 0.5 # W / (cm K)
area = np.pi / 100 # cm^2
def taylor_extraction(t_0, t_1, dx, a=0, order=1):
if order == 1:
return -1 * k * area * (t_1 - t_0) / dx
elif order == 2:
return -1 * k * area * (((t_1 - t_0) / dx) + (a**2 * dx * t_1 / 2))
def calc_error(q_exact, q_1):
return np.abs((q_exact - q_1) / q_exact)
def calc_beta(q_exact, q_1, q_2, dx_1, dx_2):
return np.log(np.abs((q_exact - q_1)/(q_exact - q_2))) / np.log(dx_1 / dx_2)