-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_tools.py
79 lines (63 loc) · 1.93 KB
/
math_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
#Theo_a_python
A simple tool for analysis of 2D airfoils using potential flow theory
Methodology: Linear vorticity distribution
Version: Python prepro, solver & postpro
@author: Rodrigo R. Velazquez
AUG 2023
#Module
Math_tools
- General purpose numeric tools. POT_FLOW solver needs this module.
"""
#Imports
import numpy as np
#Funcs
def LST_ARR(tent_lst):
if isinstance(tent_lst, list):
return np.array(tent_lst)
else:
return tent_lst
def checkabs(*vals):
ret = []
for loc in vals:
if abs(loc) < 1e-10:
loc = 0
ret.append(loc)
return(ret)
def checkarr(gamma_1, gamma_2):
if isinstance(gamma_1, np.ndarray):
gamma_1 = gamma_1[0]
if isinstance(gamma_2,np.ndarray):
gamma_2 = gamma_2[0]
return gamma_1, gamma_2
def QUAD_GRID(coords, size):
x = np.linspace(*coords[0:2], size)
y = np.linspace(*coords[1:-1], size)
return np.meshgrid(x,y)
def MAT_G2L(beta):
return np.array([[np.cos(beta), np.sin(beta)],[-np.sin(beta), np.cos(beta)]])
def MAT_L2G(beta):
return np.array([[np.cos(beta), -np.sin(beta)],[np.sin(beta), np.cos(beta)]])
def RGLOB_LOC(P, r0, beta):
r_g = P - r0
r_l = np.matmul(MAT_G2L(beta), r_g)
return r_l
def RLOC_GLOB(P_l, r0, beta):
r_g = r0 + np.matmul(MAT_L2G(beta), P_l)
return r_g
def appnd_last(arr):
return np.append(arr, arr[0])
def rot_vect(matrx, vec):
return np.matmul(matrx, vec)
def gen_norm(theta, v0, scale=1, supress_print = True):
probe_t = rot_vect(MAT_L2G(theta), np.array([1,0])*scale)
probe_n = rot_vect(MAT_L2G(theta), np.array([0,1])*scale)
p_1x = probe_t + v0
p_1y = probe_n + v0
if not supress_print:
print(probe_n)
print(v0)
print(np.dot(probe_t, probe_n))
print(p_1x, p_1y)
print(np.dot(p_1x, p_1y))
return(v0, p_1x, p_1y)