-
Notifications
You must be signed in to change notification settings - Fork 17
/
TASOPT_c_series_airfoil_fits.py
373 lines (348 loc) · 15.2 KB
/
TASOPT_c_series_airfoil_fits.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
"TASOPT c series airfoil fits"
from __future__ import print_function
from builtins import zip
from builtins import range
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from gpfit.fit import fit
plt.rcParams.update({'font.size':15})
def text_to_df(filename):
"parse XFOIL polars and concatente data in DataFrame"
lines = list(open(filename))
for i, l in enumerate(lines):
lines[i] = l.split("\n")[0]
for j in 10-np.arange(9):
if " "*j in lines[i]:
lines[i] = lines[i].replace(" "*j, " ")
if "---" in lines[i]:
start = i
data = {}
titles = lines[start-1].split(" ")[1:]
for t in titles:
data[t] = []
for l in lines[start+1:]:
for i, v in enumerate(l.split(" ")[1:]):
data[titles[i]].append(v)
df = pd.DataFrame(data)
df = df.astype(float)
return df
def fit_setup(thick_range, re_range, M_range):
"set up x and y parameters for gp fitting"
cd = []
tau = []
mach = []
re = []
cl = []
for m in M_range:
for n in thick_range:
for r in re_range:
dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
for i in range(len(dataf["CD"])):
if dataf["CD"][i] and dataf["CL"][i] != 0:
cd.append(dataf["CD"][i])
cl.append(dataf["CL"][i])
re.append(r)
tau.append(float(n)/1000)
mach.append(m)
u1 = np.hstack(re)
print(u1)
u2 = np.hstack(tau)
print(u2)
u3 = np.hstack(mach)
u4 = np.hstack(cl)
## print len(u1)
## print len(u2)
## print len(u3)
## print len(u4)
w = np.hstack(cd)
## print len(w)
u1 = u1.astype(np.float)
u2 = u2.astype(np.float)
u3 = u3.astype(np.float)
w = w.astype(np.float)
u = [u1, u2, u3, u4]
x = np.log(u)
y = np.log(w)
return x, y
def return_fit(u_1, u_2, u_3, u_4):
"c series airfoil tau, M, cl, and reynolds fit"
"""returned 4 term SMA fit w/RMS of 0.0517691407091:
w**1.65625 = 191.003 * (u_1)**-0.219123 * (u_2)**3.95226 * (u_3)**19.2722 * (u_4)**1.15491
+ 0.046236 * (u_1)**-0.390044 * (u_2)**0.78635 * (u_3)**-0.340387 * (u_4)**0.953522
+ 2.72291e-12 * (u_1)**1.18241 * (u_2)**-1.75793 * (u_3)**0.10586 * (u_4)**-1.44159
+ 1.60657 * (u_1)**-0.551398 * (u_2)**1.29389 * (u_3)**3.0428 * (u_4)**1.78078
returned 3 term SMA fir w/RMS of 0.0524738754518 is
w**0.238549 = 1.05729 * (u_1)**-0.0897274 * (u_2)**0.165956 * (u_3)**0.0331981 * (u_4)**0.208971
+ 1.11829e-06 * (u_1)**0.701152 * (u_2)**-1.09254 * (u_3)**-0.192159 * (u_4)**-1.08356
+ 42.2841 * (u_1)**-0.0792097 * (u_2)**2.09529 * (u_3)**11.7479 * (u_4)**0.480427
u1 = Re
u2 = tau
u3 = M
u4 = cl
fitted ranges are defined by:
Re = range(10000, 35000, 5000)
thick = ["100", "110", "120", "130", "140", "145"]
M = [0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
cl = np.linspace(0.35, 0.70, 8)
"""
w = (1.05729 * (u_1)**-0.0897274 * (u_2)**0.165956 * (u_3)**0.0331981 * (u_4)**0.208971
+ 1.11829e-06 * (u_1)**0.701152 * (u_2)**-1.09254 * (u_3)**-0.192159 * (u_4)**-1.08356
+ 42.2841 * (u_1)**-0.0792097 * (u_2)**2.09529 * (u_3)**11.7479 * (u_4)**0.480427)**(1/0.238549)
return w
def make_fit(thick_range, re_range, M_range):
#call the fit setup function
x, y = fit_setup(thick_range, re_range, M_range)
cstrt, rms = fit(x, y, 4, 'SMA')
print("RMS")
print(rms)
def plot_fits(thick_range, re_range, M_range, cl_range):
"plot fit compared to data"
## colors = ["k", "m", "b", "g", "y"]#, "r"]#, "c", "m", "k"]
## res = np.linspace(re_range[0], re_range[-1], 50)
## for m in M_range:
## for n in thick_range:
## i = 0
## fig, ax = plt.subplots()
## for i in range(len(re_range)):
## cd = []
## cl = []
##
## r = re_range[i]
## dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
## if len(dataf["CL"]) != 0:
## cd.append(dataf["CD"])
## cl.append(dataf["CL"])
## ax.plot(cl, cd, "o", mec=colors[i], c="None", mew=1.5)
## i = i+1
## ax.set_xlabel("$C_{l}$")
## ax.set_ylabel("$c_{dp}$")
## ax.grid()
## ax.set_title('NC%s Drag Polar for M=%s and Re of %sk' % (n, m, r))
## fig.savefig("wing__data_fits/tasopt_c_series_data_M%s_Re%s.pdf" % (m, r), bbox_inches="tight")
##
## for m in M_range:
## for n in thick_range:
## i = 0
## fig, ax = plt.subplots()
## for i in range(len(re_range)):
## cd = []
## cl = []
##
## r = re_range[i]
## dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
## if len(dataf["CL"]) != 0:
## cd.append(dataf["CD"])
## cl.append(dataf["CL"])
## ax.plot(np.log(cl), np.log(cd), "o", mec=colors[i], c="None", mew=1.5)
## i = i+1
## ax.set_xlabel("Log of $C_{l}$")
## ax.set_ylabel("Log of $c_{dp}$")
## ax.grid()
## ax.set_title('NC%s Drag Polar for M=%s and Re of %sk' % (n, m, r))
## fig.savefig("wing_data_fits/log_tasopt_c_series_data_M%s_Re%s.pdf" % (m, r), bbox_inches="tight")
##
## colors = ["k", "m", "b", "g", "y", "r", "c", "m", "k"]
## for r in re_range:
## fig, ax = plt.subplots()
## for n, col in zip(thick_range, colors):
## i = 0
## for i in range(len(cl_range)):
## cd = []
## m_vec = []
## cl = []
## for m in M_range:
## dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
## for j in range(len(dataf["CL"])):
## if dataf["CL"][j] <= cl_range[i]+0.01 and dataf["CL"][j] >= cl_range[i]-0.01:
## cd.append(dataf["CD"][j])
## m_vec.append(m)
## cl.append(dataf["CL"][j])
## ax.plot(m_vec, cd, "o", mec=colors[i], c="None", mew=1.5)
## i = i+1
## ax.legend(cl_range, loc=2, fontsize=15)
## ax.set_xlabel("M")
## ax.set_ylabel("$c_{dp}$")
## ax.grid()
## ax.set_title('NC%s Drag Rise for Re of %sk' % (n, r))
## fig.savefig("m_fits/tasopt_NC%s_Re%s_drag_rise.pdf" % (n, r), bbox_inches="tight")
colors = ["k", "m", "b", "g", "y", "r", "c", "m", "k"]
res = np.linspace(re_range[0], re_range[-1], 50)
for r in re_range:
for n, col in zip(thick_range, colors):
i = 0
fig, ax = plt.subplots()
for i in range(len(cl_range)):
cd = []
m_vec = []
cl = []
refit = []
w = []
for m in M_range:
ms = res = np.linspace(M_range[0], M_range[-1], len(res))
dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
for j in range(len(dataf["CL"])):
if dataf["CL"][j] <= cl_range[i]+0.01 and dataf["CL"][j] >= cl_range[i]-0.01:
cd.append(dataf["CD"][j])
m_vec.append(m)
cl.append(dataf["CL"][j])
refit.append(r)
ax.plot(m_vec, cd, "o", mec=colors[i], c="None", mew=1.5)
for h in range(len(refit)):
w.append(return_fit(refit[h], float(n)/1000., m_vec[h], cl[h]))
h = h+1
ax.plot(m_vec, w, c=colors[i], label="NC%s" % n, lw=2)
i = i+1
## ax.legend(cl_range, loc=2, fontsize=15)
ax.set_xlabel("Log of M")
ax.set_ylabel("Log of $c_{dp}$")
ax.grid()
ax.set_title('NC%s Drag Rise for Re of %sk' % (n, r))
fig.savefig("m_fits/log_tasopt_NC%s_Re%s_drag_rise.pdf" % (n, r), bbox_inches="tight")
#plot fixed cl diff curves based off of mach number cd vs re
## colors = ["k", "m", "b", "g", "y"]#, "r"]#, "c", "m", "k"]
## for m in M_range:
## fig, ax = plt.subplots()
## for n, col in zip(thick_range, colors):
## i = 0
##
## for i in range(len(cl_range)):
## cd = []
## cl = []
## re_plot = []
## for r in re_range:
## dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
## for j in range(len(dataf["CL"])):
## if dataf["CL"][j] <= cl_range[i]+0.01 and dataf["CL"][j] >= cl_range[i]-0.01:
## cd.append(dataf["CD"][j])
## re_plot.append(r)
## ax.plot(re_plot, cd, "o", mec='k', c="None", mew=1.5)
## i = i+1
#### ax.legend(cl_range, loc=2, fontsize=15)
## ax.set_xlabel("Log of M")
## ax.set_ylabel("Log of $c_{dp}$")
## ax.grid()
## ax.set_title('NC%s Drag Rise for Re of %sk' % (n, r))
## fig.savefig("re_fits/log_tasopt_NC%s_Re%s_drag_rise.pdf" % (n, r), bbox_inches="tight")
def plot_data(thick_range, re_range, M_range, cl_range):
"plot x foil data"
colors = ["k", "m", "b", "g", "y"]#, "r"]#, "c", "m", "k"]
res = np.linspace(re_range[0], re_range[-1], 50)
for m in M_range:
for n in thick_range:
i = 0
fig, ax = plt.subplots()
for i in range(len(re_range)):
cd = []
cl = []
r = re_range[i]
dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
if len(dataf["CL"]) != 0:
cd.append(dataf["CD"])
cl.append(dataf["CL"])
ax.plot(cl, cd, "o", mec=colors[i], c="None", mew=1.5)
i = i+1
ax.set_xlabel("$C_{l}$")
ax.set_ylabel("$c_{dp}$")
ax.grid()
ax.set_title('NC%s Drag Polar for M=%s and Re of %sk' % (n, m, r))
fig.savefig("wing_data/tasopt_c_series_data_M%s_Re%s.pdf" % (m, r), bbox_inches="tight")
for m in M_range:
for n in thick_range:
i = 0
fig, ax = plt.subplots()
for i in range(len(re_range)):
cd = []
cl = []
r = re_range[i]
dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
if len(dataf["CL"]) != 0:
cd.append(dataf["CD"])
cl.append(dataf["CL"])
ax.plot(np.log(cl), np.log(cd), "o", mec=colors[i], c="None", mew=1.5)
i = i+1
ax.set_xlabel("Log of $C_{l}$")
ax.set_ylabel("Log of $c_{dp}$")
ax.grid()
ax.set_title('NC%s Drag Polar for M=%s and Re of %sk' % (n, m, r))
fig.savefig("wing_data/log_tasopt_c_series_data_M%s_Re%s.pdf" % (m, r), bbox_inches="tight")
colors = ["k", "m", "b", "g", "y", "r", "c", "m", "k"]
for r in re_range:
fig, ax = plt.subplots()
for n, col in zip(thick_range, colors):
i = 0
for i in range(len(cl_range)):
cd = []
m_vec = []
cl = []
for m in M_range:
dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
for j in range(len(dataf["CL"])):
if dataf["CL"][j] <= cl_range[i]+0.01 and dataf["CL"][j] >= cl_range[i]-0.01:
cd.append(dataf["CD"][j])
m_vec.append(m)
cl.append(dataf["CL"][j])
ax.plot(m_vec, cd, "o", mec=colors[i], c="None", mew=1.5)
i = i+1
ax.legend(cl_range, loc=2, fontsize=15)
ax.set_xlabel("M")
ax.set_ylabel("$c_{dp}$")
ax.grid()
ax.set_title('NC%s Drag Rise for Re of %sk' % (n, r))
fig.savefig("m_data/tasopt_NC%s_Re%s_drag_rise.pdf" % (n, r), bbox_inches="tight")
for r in re_range:
fig, ax = plt.subplots()
for n, col in zip(thick_range, colors):
i = 0
for i in range(len(cl_range)):
cd = []
m_vec = []
cl = []
for m in M_range:
dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
for j in range(len(dataf["CL"])):
if dataf["CL"][j] <= cl_range[i]+0.01 and dataf["CL"][j] >= cl_range[i]-0.01:
cd.append(dataf["CD"][j])
m_vec.append(m)
cl.append(dataf["CL"][j])
ax.plot(np.log(m_vec), np.log(cd), "o", mec=colors[i], c="None", mew=1.5)
i = i+1
## ax.legend(cl_range, loc=2, fontsize=15)
ax.set_xlabel("Log of M")
ax.set_ylabel("Log of $c_{dp}$")
ax.grid()
ax.set_title('NC%s Drag Rise for Re of %sk' % (n, r))
fig.savefig("m_data/log_tasopt_NC%s_Re%s_drag_rise.pdf" % (n, r), bbox_inches="tight")
#plot fixed cl diff curves based off of mach number cd vs re
colors = ["k", "m", "b", "g", "y"]#, "r"]#, "c", "m", "k"]
for m in M_range:
fig, ax = plt.subplots()
for n, col in zip(thick_range, colors):
i = 0
for i in range(len(cl_range)):
cd = []
cl = []
re_plot = []
for r in re_range:
dataf = text_to_df("blade.c%s.Re%dk.M%s.pol" % (n, r, m))
for j in range(len(dataf["CL"])):
if dataf["CL"][j] <= cl_range[i]+0.01 and dataf["CL"][j] >= cl_range[i]-0.01:
cd.append(dataf["CD"][j])
re_plot.append(r)
ax.plot(re_plot, cd, "o", mec='k', c="None", mew=1.5)
i = i+1
## ax.legend(cl_range, loc=2, fontsize=15)
ax.set_xlabel("Log of M")
ax.set_ylabel("Log of $c_{dp}$")
ax.grid()
ax.set_title('NC%s Drag Rise for Re of %sk' % (n, r))
fig.savefig("re_data/log_tasopt_NC%s_Re%s_drag_rise.pdf" % (n, r), bbox_inches="tight")
if __name__ == "__main__":
Re = list(range(10000, 35000, 5000))
thick = ["100", "110", "120", "130", "140", "145"]
M = [0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
cl = np.linspace(0.35, 0.70, 8)
## X, Y = fit_setup(thick, Re, M) # call fit(X, Y, 4, "SMA") to get fit
## make_fit(thick, Re, M)
## plot_data(thick, Re, M, cl)
plot_fits(thick, Re, M, cl)