I am attempting to utilize numba.njit()/numba.jit() on my code to speed up my mathematical operations. I want to NJIT/JIT compile the following type of function, which I call repeatedly.
class MeshPoint():
# @numba.njit()
def internal(p1data, p2data, p3data):
# p1 is below, p2 is above
x1, x2 = p1data[0], p2data[0]
y1, y2 = p1data[1], p2data[1]
M1, M2 = p1data[2], p2data[2]
theta1, theta2 = p1data[3], p2data[3]
mu1, mu2 = AeroFunc.M2mu(M1), AeroFunc.M2mu(M2)
nu1, nu2 = AeroFunc.M2nu(M1), AeroFunc.M2nu(M2)
nu3 = (nu1 + nu2)/2 - (theta1 - theta2)/2
theta3 = (theta1 + theta2)/2 - (nu1 - nu2)/2
M3 = AeroFunc.nu2M(nu3)
mu3 = AeroFunc.M2mu(M3)
phi1 = (theta1 + theta3 + mu1 + mu3)/2
phi2 = (theta2 + theta3 - mu2 - mu3)/2
x3 = x1 * math.tan(phi1) - x2 * math.tan(phi2) + y2 - y1
x3 /= math.tan(phi1) - math.tan(phi2)
y3 = y1 + math.tan(phi1) * (x3 - x1)
p3data[0] = x3
p3data[1] = y3
p3data[2] = M3
p3data[3] = theta3
return p3data
However, within this function, I am utilizing other aerodynamic functions, which are contained within AeroFunc():
class AeroFunc():
@numba.njit()
def M2nu(M): # Prandtl-Meyer Function
# https://en.wikipedia.org/wiki/Prandtl-Meyer_function
A = np.sqrt((gamma + 1)/(gamma - 1))
B = np.sqrt(M**2 - 1)
return A * np.arctan(B/A) - np.arctan(B)
@numba.jit()
def nu2M(nu): # Inverse Prandtl-Meyer Function
# https://en.wikipedia.org/wiki/Prandtl-Meyer_function
return root_scalar(lambda M: nu - AeroFunc.M2nu(M), x0 = M_inl, x1 = M_exi).root
@numba.njit()
def M2mu(M): # Mach Angle Function
# https://en.wikipedia.org/wiki/Mach_wave
return np.arcsin(1/M)