-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
85 lines (64 loc) · 2.37 KB
/
utils.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
80
81
82
83
84
85
from scipy.interpolate import splev,splprep
from scipy import optimize
import numpy as np
class Fit_airfoil():
def __init__(self,airfoil,iLE=128):
self.iLE = iLE
self.tck, self.u = splprep(airfoil.T,s=0)
# parsec features
rle = self.get_rle()
xup, yup, yxxup = self.get_up()
xlo, ylo, yxxlo = self.get_lo()
yteup = airfoil[0,1]
ytelo = airfoil[-1,1]
alphate, betate = self.get_te_angle()
self.parsec_features = np.array([rle,xup,yup,yxxup,xlo,ylo,yxxlo,
yteup,ytelo,alphate,betate])
xaft, yaft, yxxaft = self.get_aftload()
def get_rle(self):
uLE = self.u[self.iLE]
xu,yu = splev(uLE, self.tck,der=1)
xuu,yuu = splev(uLE, self.tck,der=2)
K = abs(xu*yuu-xuu*yu)/(xu**2+yu**2)**1.5
return 1/K
def get_up(self):
def f(u_tmp):
x_tmp,y_tmp = splev(u_tmp, self.tck)
return -y_tmp
res = optimize.minimize_scalar(f,bounds=(0,self.u[self.iLE]),method='bounded')
uup = res.x
xup ,yup = splev(uup, self.tck)
xu,yu = splev(uup, self.tck, der=1)
xuu,yuu = splev(uup, self.tck, der=2)
yxx = (yuu*xu-xuu*yu)/xu**3
return xup, yup, yxx
def get_lo(self):
def f(u_tmp):
x_tmp,y_tmp = splev(u_tmp, self.tck)
return y_tmp
res = optimize.minimize_scalar(f,bounds=(self.u[self.iLE],1),method='bounded')
ulo = res.x
xlo ,ylo = splev(ulo, self.tck)
xu,yu = splev(ulo, self.tck, der=1)
xuu,yuu = splev(ulo, self.tck, der=2)
yxx = (yuu*xu-xuu*yu)/xu**3
return xlo, ylo, yxx
def get_te_angle(self):
xu,yu = splev(0, self.tck, der=1)
yx = yu/xu
alphate = np.arctan(yx)
xu,yu = splev(1, self.tck, der=1)
yx = yu/xu
betate = np.arctan(yx)
return alphate, betate
def get_aftload(self):
def f(u_tmp):
x_tmp,y_tmp = splev(u_tmp, self.tck)
return -y_tmp
res = optimize.minimize_scalar(f,bounds=(0.75,1),method='bounded')
ulo = res.x
xlo ,ylo = splev(ulo, self.tck)
xu,yu = splev(ulo, self.tck, der=1)
xuu,yuu = splev(ulo, self.tck, der=2)
yxx = (yuu*xu-xuu*yu)/xu**3
return xlo, ylo, yxx