-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenAeroData.py
115 lines (93 loc) · 3.44 KB
/
GenAeroData.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from datetime import datetime as dt
from HorizonAircraft import scene, sceneDict, updateControls, updateState, bw, cbar, forcesOptions
from multiprocessing import Pool, cpu_count
import numpy as np
import matplotlib.pyplot as plt
import ZachsModules as zm
import polyFits as pf
import machupX as mx
import sys
forcesOptions = {'body_frame':True, 'stab_frame':False, 'wind_frame':False,
'dimensional':False}#, 'verbose':True}
pbar2p = 2. * 54. / bw
qbar2q = 2. * 54. / cbar
def horizonForcesMoments(j):
## unpack inputs
n = pf.decompose_j(j, Nvec)
## update the aircraft state
updateState(54., AOA[n[14]], BETA[n[15]], [ PBAR[n[11]]*pbar2p,
QBAR[n[12]]*qbar2q,
RBAR[n[13]]*pbar2p], scene)
r = [DEFL[i] for i in n[1: 6]]
l = [DEFL[i] for i in n[6:11]]
s = [(r[i]+l[i])/2. for i in range(5)]
a = [(r[i]-l[i])/2. for i in range(5)]
updateControls([DEFL[n[0]]]+s, a, scene)
try:
x = scene.solve_forces(**forcesOptions)['Horizon']['total']
fm = [ x['Cx'], x['Cy'], x['Cz'], x['Cl'], x['Cm'], x['Cn'] ]
except mx.exceptions.SolverNotConvergedError:
fm = [None] * 6
return (j, *fm)
def initializeCases(j):
n = pf.decompose_j(j, Nvec)
vals = [None] * 16
for i in range(dofs):
if i < 11:
vals[i] = DEFL[n[i]]
else:
vals[i] = data[i-11][n[i]]
i = -1
while None in vals:
vals[i] = 0.
i -= 1
return vals #.append(mx.Scene(sceneDict)))
N = 3
d = 20
DEFL = np.linspace(-d,d,N)
PBAR = np.linspace(-.2,.2,N)
QBAR = np.linspace(-.02,.02,N)
RBAR = np.linspace(-.15,.15,N)
AOA = np.linspace(-30,30,N)
BETA = np.linspace(-30,30,N)
data = [PBAR, QBAR, RBAR, AOA, BETA]
dofs = 16
J = N ** dofs
Nvec = [N-1] * dofs
if __name__ == '__main__':
start = int(sys.argv[1])
end = int(sys.argv[2])
it = list(range(start,end+1))
jid = str(dt.now()).replace(':','_').replace(' ','__')
fn = 'LinearHorizonAerodynamicDatabase_start{}_end{}.csv'.format(start, end)
f = open(fn, 'w')
f.write(zm.io.csvLineWrite( 'J',
'Center',
'R0',
'R1',
'R2',
'R3',
'R4',
'L0',
'L1',
'L2',
'L3',
'L4',
'PBAR',
'QBAR',
'RBAR',
'AOA',
'BETA' ) )
f.write(zm.io.csvLineWrite( J, *[N]*16) )
f.write('\n')
f.write(zm.io.csvLineWrite( 'j',
'Cx',
'Cy',
'Cz',
'Cl',
'Cm',
'Cn' ) )
f.close()
bat = int(sys.argv[3])
chu = int(sys.argv[4])
zm.nm.runCases(horizonForcesMoments, it, fn, nBatch=bat, chunkSize=chu, progKW={'title':'Running Cases: {}/batch, {}/chunck'.format(bat,chu)})