/
Airfoil_Plots.py
408 lines (309 loc) · 14.5 KB
/
Airfoil_Plots.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
## @ingroup Plots
# Airfoil_Plots.py
#
# Created: Mar 2021, M. Clarke
# Modified: Feb 2022, M. Clarke
# ----------------------------------------------------------------------
# Imports
# ----------------------------------------------------------------------
import SUAVE
from SUAVE.Core import Units
from SUAVE.Methods.Geometry.Two_Dimensional.Cross_Section.Airfoil.import_airfoil_polars \
import import_airfoil_polars
from SUAVE.Methods.Geometry.Two_Dimensional.Cross_Section.Airfoil.compute_airfoil_polars \
import compute_airfoil_polars
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import os
## @ingroup Plots
def plot_airfoil_analysis_boundary_layer_properties(ap,show_legend = True ):
""" This plots the boundary layer properties of an airfoil
or group of airfoils
Assumptions:
None
Inputs:
ap - data stucture of airfoil boundary layer properties
Outputs:
None
Properties Used:
N/A
"""
# determine dimension of angle of attack and reynolds number
nAoA = len(ap.AoA)
nRe = len(ap.Re)
# create array of colors for difference reynolds numbers
colors = cm.rainbow(np.linspace(0, 1,nAoA))
markers = ['o','v','s','P','p','^','D','X','*']
fig1 = plt.figure('Airfoil Geometry',figsize=(8,6))
axis1 = fig1.add_subplot(1,1,1)
axis1.set_xlabel('x')
axis1.set_ylabel('y')
axis1.set_ylim(-0.2, 0.2)
fig2 = plt.figure('Airfoil Boundary Layer Properties',figsize=(12,8))
axis2 = fig2.add_subplot(2,3,1)
axis2.set_ylabel('$Ue/V_{inf}$')
axis3 = fig2.add_subplot(2,3,2)
axis3.set_ylabel('$dV_e/dx$')
axis3.set_ylim(-1, 10)
axis4 = fig2.add_subplot(2,3,3)
axis4.set_ylabel(r'$\theta$')
axis5 = fig2.add_subplot(2,3,4)
axis5.set_xlabel('x')
axis5.set_ylabel('$H$')
axis6 = fig2.add_subplot(2,3,5)
axis6.set_xlabel('x')
axis6.set_ylabel(r'$\delta$*')
axis7 = fig2.add_subplot(2,3,6)
axis7.set_xlabel('x')
axis7.set_ylabel(r'$\delta$')
fig3 = plt.figure('Airfoil Cp',figsize=(8,6))
axis8 = fig3.add_subplot(1,1,1)
axis8.set_ylabel('$C_p$')
axis8.set_ylim(1.2,-7)
mid = int(len(ap.x)/2)
for i in range(nAoA):
for j in range(nRe):
tag = 'AoA: ' + str(round(ap.AoA[i][0]/Units.degrees,2)) + '$\degree$, Re: ' + str(round(ap.Re[j][0]/1000000,2)) + 'E6'
axis1.plot(ap.x[:,j,i], ap.y[:,j,i],'k-')
axis1.plot(ap.x_bl[:,j,i],ap.y_bl[:,j,i],color = colors[j], linestyle = '-' ,marker = markers[j%9] , label = tag)
axis2.plot(ap.x[:mid,j,i], abs(ap.Ue_Vinf)[:mid,j,i],color = colors[j], linestyle = '-' ,marker = markers[j%9] , label= tag )
axis2.plot(ap.x[mid:,j,i], abs(ap.Ue_Vinf)[mid:,j,i],color = colors[j], linestyle = '--' ,marker = markers[j%9])
axis3.plot(ap.x[:mid,j,i], abs(ap.dVe)[:mid,j,i],color = colors[j], linestyle = '-' ,marker = markers[j%9] )
axis3.plot(ap.x[mid:,j,i], abs(ap.dVe)[mid:,j,i],color = colors[j], linestyle = '--' ,marker = markers[j%9])
axis4.plot(ap.x[:mid,j,i], ap.theta[:mid,j,i],color = colors[j], linestyle = '-' ,marker = markers[j%9] )
axis4.plot(ap.x[mid:,j,i], ap.theta[mid:,j,i],color = colors[j], linestyle = '--' ,marker = markers[j%9])
axis5.plot(ap.x[:mid,j,i], ap.H[:mid,j,i],color = colors[j], linestyle = '-' ,marker = markers[j%9] )
axis5.plot(ap.x[mid:,j,i], ap.H[mid:,j,i],color = colors[j], linestyle = '--' ,marker = markers[j%9] )
axis6.plot(ap.x[:mid,j,i],ap.delta_star[:mid,j,i],color = colors[j], linestyle = '-' ,marker = markers[j%9] )
axis6.plot(ap.x[mid:,j,i],ap.delta_star[mid:,j,i],color = colors[j], linestyle = '--' ,marker = markers[j%9])
axis7.plot(ap.x[:mid,j,i],ap.delta[:mid,j,i],color = colors[j], linestyle = '-' ,marker = markers[j%9] )
axis7.plot(ap.x[mid:,j,i],ap.delta[mid:,j,i],color = colors[j], linestyle = '--' ,marker = markers[j%9])
axis8.plot(ap.x[:mid,j,i], ap.Cp[:mid,j,i] ,color = colors[j], linestyle = '-' ,marker = markers[j%9] , label= tag)
axis8.plot(ap.x[mid:,j,i], ap.Cp[ mid:,j,i],color = colors[j], linestyle = '--' ,marker = markers[j%9])
# add legends for plotting
plt.tight_layout()
if show_legend:
lines1, labels1 = fig2.axes[0].get_legend_handles_labels()
fig2.legend(lines1, labels1, loc='upper center', ncol=5)
plt.tight_layout()
axis8.legend(loc='upper right')
return
## @ingroup Plots
def plot_airfoil_analysis_polars(ap,show_legend = True):
""" This plots the polars of an airfoil or group of airfoils
Assumptions:
None
Inputs:
ap - data stucture of airfoil boundary layer properties and polars
Outputs:
None
Properties Used:
N/A
"""
# determine dimension of angle of attack and reynolds number
nAoA = len(ap.AoA)
nRe = len(ap.Re)
# create array of colors for difference reynolds numbers
colors = cm.rainbow(np.linspace(0, 1,nAoA))
markers = ['o','v','s','P','p','^','D','X','*']
fig1 = plt.figure('Airfoil Geometry',figsize=(8,6))
axis1 = fig1.add_subplot(1,1,1)
axis1.set_xlabel('x')
axis1.set_ylabel('y')
axis1.set_ylim(-0.2, 0.2)
fig4 = plt.figure('Airfoil Polars',figsize=(12,5))
axis12 = fig4.add_subplot(1,3,1)
axis12.set_title('Lift Coefficients')
axis12.set_xlabel('AoA')
axis12.set_ylabel(r'$C_l$')
axis12.set_ylim(-1,2)
axis13 = fig4.add_subplot(1,3,2)
axis13.set_title('Drag Coefficient')
axis13.set_xlabel('AoA')
axis13.set_ylabel(r'$C_d$')
axis13.set_ylim(0,0.1)
axis14 = fig4.add_subplot(1,3,3)
axis14.set_title('Moment Coefficient')
axis14.set_xlabel('AoA')
axis14.set_ylabel(r'$C_m$')
axis14.set_ylim(-0.1,0.1)
for i in range(nRe):
Re_tag = 'Re: ' + str(round(ap.Re[i][0]/1000000,2)) + 'E6'
# Lift Coefficient
axis12.plot(ap.AoA[:,0]/Units.degrees,ap.Cl[:,i],color = colors[i], linestyle = '-' ,marker = markers[i], label= Re_tag )
# Drag Coefficient
axis13.plot(ap.AoA[:,0]/Units.degrees,ap.Cd[:,i],color = colors[i], linestyle = '-',marker = markers[i], label = Re_tag)
# Moment Coefficient
axis14.plot(ap.AoA[:,0]/Units.degrees, ap.Cm[:,i],color = colors[i], linestyle = '-',marker = markers[i], label = Re_tag)
plt.tight_layout()
# add legends for plotting
if show_legend:
axis12.legend(loc='upper left')
axis13.legend(loc='upper left')
axis14.legend(loc='upper left')
return
## @ingroup Plots
def plot_airfoil_analysis_surface_forces(ap,show_legend= True,arrow_color = 'r'):
""" This plots the forces on an airfoil surface
Assumptions:
None
Inputs:
ap - data stucture of airfoil boundary layer properties and polars
Outputs:
None
Properties Used:
N/A
"""
# determine dimension of angle of attack and reynolds number
nAoA = len(ap.AoA)
nRe = len(ap.Re)
n_cpts = len(ap.x[0,0,:])
for i in range(nAoA):
for j in range(nRe):
label = '_AoA_' + str(round(ap.AoA[i][0]/Units.degrees,2)) + '_deg_Re_' + str(round(ap.Re[j][0]/1000000,2)) + 'E6'
fig = plt.figure('Airfoil_Pressure_Normals' + label )
axis = fig.add_subplot(1,1,1)
axis.plot(ap.x[0,0,:], ap.y[0,0,:],'k-')
for k in range(n_cpts):
dx_val = ap.normals[i,j,k,0]*abs(ap.Cp[i,j,k])*0.1
dy_val = ap.normals[i,j,k,1]*abs(ap.Cp[i,j,k])*0.1
if ap.Cp[i,j,k] < 0:
plt.arrow(x= ap.x[i,j,k], y=ap.y[i,j,k] , dx= dx_val , dy = dy_val ,
fc=arrow_color, ec=arrow_color,head_width=0.005, head_length=0.01 )
else:
plt.arrow(x= ap.x[i,j,k]+dx_val , y= ap.y[i,j,k]+dy_val , dx= -dx_val , dy = -dy_val ,
fc=arrow_color, ec=arrow_color,head_width=0.005, head_length=0.01 )
return
def plot_airfoil_polar_files(airfoil_path, airfoil_polar_paths, line_color = 'k-', use_surrogate = False,
display_plot = False, save_figure = False, save_filename = "Airfoil_Polars", file_type = ".png"):
"""This plots all airfoil polars in the list "airfoil_polar_paths"
Assumptions:
None
Source:
None
Inputs:
airfoil_polar_paths [list of strings]
Outputs:
Plots
Properties Used:
N/A
"""
shape = np.shape(airfoil_polar_paths)
n_airfoils = shape[0]
n_Re = shape[1]
if use_surrogate:
# Compute airfoil surrogates
a_data = compute_airfoil_polars(airfoil_path, airfoil_polar_paths,npoints = 200, use_pre_stall_data=False)
CL_sur = a_data.lift_coefficient_surrogates
CD_sur = a_data.drag_coefficient_surrogates
alpha = np.asarray(a_data.aoa_from_polar)
n_alpha = len(alpha.T)
alpha = np.reshape(alpha,(n_airfoils,1,n_alpha))
alpha = np.repeat(alpha, n_Re, axis=1)
Re = a_data.re_from_polar
Re = np.reshape(Re,(n_airfoils,n_Re,1))
Re = np.repeat(Re, n_alpha, axis=2)
CL = np.zeros_like(Re)
CD = np.zeros_like(Re)
else:
# Use the raw data polars
airfoil_polar_data = import_airfoil_polars(airfoil_polar_paths)
CL = airfoil_polar_data.lift_coefficients
CD = airfoil_polar_data.drag_coefficients
n_alpha = np.shape(CL)[2]
Re = airfoil_polar_data.reynolds_number
Re = np.reshape(Re, (n_airfoils,n_Re,1))
Re = np.repeat(Re, n_alpha, axis=2)
for i in range(n_airfoils):
airfoil_name = os.path.basename(airfoil_path[i][0])
if use_surrogate:
CL[i,:,:] = CL_sur[airfoil_path[i]](Re[i,:,:],alpha[i,:,:],grid=False)
CD[i,:,:] = CD_sur[airfoil_path[i]](Re[i,:,:],alpha[i,:,:],grid=False)
# plot all Reynolds number polars for ith airfoil
fig = plt.figure(save_filename +'_'+ str(i))
fig.set_size_inches(10, 4)
axes = fig.add_subplot(1,1,1)
axes.set_title(airfoil_name)
for j in range(n_Re):
Re_val = str(round(Re[i,j,0]))
axes.plot(CD[i,j,:], CL[i,j,:], label='Re='+Re_val)
axes.set_xlabel('$C_D$')
axes.set_ylabel('$C_L$')
axes.legend(bbox_to_anchor=(1,1), loc='upper left', ncol=1)
if save_figure:
plt.savefig(save_filename +'_' + str(i) + file_type)
if display_plot:
plt.show()
return
def plot_airfoil_aerodynamic_coefficients(airfoil_path, airfoil_polar_paths, line_color = 'k-', use_surrogate = True,
display_plot = False, save_figure = False, save_filename = "Airfoil_Polars", file_type = ".png"):
"""This plots all airfoil polars in the list "airfoil_polar_paths"
Assumptions:
None
Source:
None
Inputs:
airfoil_polar_paths [list of strings]
Outputs:
Plots
Properties Used:
N/A
"""
shape = np.shape(airfoil_polar_paths)
n_airfoils = shape[0]
n_Re = shape[1]
col_raw = ['m-', 'b-', 'r-', 'g-', 'o-','p-']
if use_surrogate:
col_sur = ['m--', 'b--', 'r--', 'g--', 'o--','p--']
# Compute airfoil surrogates
a_data = compute_airfoil_polars(airfoil_path, airfoil_polar_paths,npoints = 200, use_pre_stall_data=False)
CL_sur = a_data.lift_coefficient_surrogates
CD_sur = a_data.drag_coefficient_surrogates
alpha = np.linspace(-16,16,100)
n_alpha = len(alpha.T)
alpha = np.reshape(alpha,(n_airfoils,1,n_alpha))
alpha = np.repeat(alpha, n_Re, axis=1)
Re = a_data.re_from_polar
Re = np.reshape(Re,(n_airfoils,n_Re,1))
Re = np.repeat(Re, n_alpha, axis=2)
CL = np.zeros_like(Re)
CD = np.zeros_like(Re)
for i in range(n_airfoils):
CL[i,:,:] = CL_sur[airfoil_path[i]](Re[i,:,:],alpha[i,:,:]* Units.deg,grid=False)
CD[i,:,:] = CD_sur[airfoil_path[i]](Re[i,:,:],alpha[i,:,:]* Units.deg,grid=False)
# Get raw data polars
airfoil_polar_data = import_airfoil_polars(airfoil_polar_paths)
CL_raw = airfoil_polar_data.lift_coefficients
CD_raw = airfoil_polar_data.drag_coefficients
alpha_raw = airfoil_polar_data.angle_of_attacks
n_alpha_raw = len(alpha_raw)
# reshape into Re and n_airfoils
alpha_raw = np.tile(alpha_raw, (n_airfoils,n_Re,1))
Re = airfoil_polar_data.reynolds_number
Re = np.reshape(Re, (n_airfoils,n_Re,1))
Re = np.repeat(Re, n_alpha_raw, axis=2)
for i in range(n_airfoils):
airfoil_name = os.path.basename(airfoil_path[i])
# plot all Reynolds number polars for ith airfoil
fig = plt.figure(airfoil_name[:-4], figsize=(8,2*n_Re))
for j in range(n_Re):
ax1 = fig.add_subplot(n_Re,2,1+2*j)
ax2 = fig.add_subplot(n_Re,2,2+2*j)
Re_val = str(round(Re[i,j,0])/1e6)+'e6'
ax1.plot(alpha_raw[i,j,:], CL_raw[i,j,:], col_raw[j], label='Re='+Re_val)
ax2.plot(alpha_raw[i,j,:], CD_raw[i,j,:], col_raw[j], label='Re='+Re_val)
if use_surrogate:
ax1.plot(alpha[i,j,:], CL[i,j,:], col_sur[j])
ax2.plot(alpha[i,j,:], CD[i,j,:], col_sur[j])
ax1.set_ylabel('$C_l$')
ax2.set_ylabel('$C_d$')
ax1.legend(loc='best')
ax1.set_xlabel('AoA [deg]')
ax2.set_xlabel('AoA [deg]')
fig.tight_layout()
if save_figure:
plt.savefig(save_filename +'_' + str(i) + file_type)
if display_plot:
plt.show()
return