77This is a submodule for the genetic algorithm that is explained in
88https://docs.google.com/presentation/d/1_78ilFL-nbuN5KB5FmNeo-EIZly1PjqxqIB-ant-GfM/edit?usp=sharing
99
10- This script is the main program. It will call the different submodules
11- and manage the data transfer between them in order to achieve the
12- genetic optimization of the profile.
13-
14- '''
15-
10+ This script is the ambient subprogram. Its objective is to calculate the
11+ Mach and Reynolds numbers that XFoil uses to calculate the
12+ aerodynamics of airfoils.
1613
1714
15+ This subprogram consist mainly in models for the International Standard Atmosphere
16+ and an equivalent atmosphere model for Mars.
17+ '''
1818
1919import numpy as np
2020
2121
2222
23-
24-
25- def ventana ( x , inicio = 0 , fin = 1 , f = 1. ):
26- _1 = (np .sign (x - inicio ))
27- _2 = (np .sign (- x + fin ))
23+ def window ( x , start = 0 , end = 1 , f = 1. ):
24+ '''Returns a function f between 'start' and 'endn'.
25+ Returns 0 outside this interval'''
26+ _1 = (np .sign (x - start ))
27+ _2 = (np .sign (- x + end ))
2828 return 0.25 * (_1 + 1 ) * (_2 + 1 ) * f
2929
30- def etc (x , inicio = 0 , f = 1. ):
31- _1 = (np .sign (x - inicio ))
30+ def etc (x , start = 0 , f = 1. ):
31+ '''Returns 0 until 'start', returns 'f' after.
32+ '''
33+ _1 = (np .sign (x - start ))
3234 return 0.5 * (_1 + 1 ) * f
3335
3436def earth_conditions ():
37+
38+ '''Returns an array of atmospheric and physical data from which the complete
39+ model of the atmosphere can be built.
40+ '''
3541 heights = np .array ([- 1.000 ,
3642 11.019 ,
3743 20.063 ,
@@ -43,7 +49,7 @@ def earth_conditions():
4349 90.000 ])
4450
4551
46- # an es el gradiente válido entre H(n-1) y H(n)
52+
4753 temp_gradient = np .array ([- 6.49 ,
4854 0 ,
4955 0.99 ,
@@ -72,8 +78,8 @@ def earth_conditions():
7278 return conditions
7379
7480
75- def temperatura (h , conditions , dT = 0 ):
76- '''Calcula la temperatura a una altura h en Km sobre el nivel del mar '''
81+ def temperature (h , conditions , dT = 0 ):
82+ '''Calculates the value for temperature in Kelvin at a certain altitude '''
7783 grad = 0
7884 heights = conditions [0 ]
7985 gradient = conditions [1 ]
@@ -84,50 +90,48 @@ def temperatura(h, conditions, dT = 0):
8490
8591 for layer in np .arange (0 , atm_layer - 1 ,1 ):
8692 increase = temp_points [layer ] + gradient [layer ] * (h - heights [layer ])
87- grad = grad + ventana (h , heights [layer ],heights [layer + 1 ], increase )
93+ grad = grad + window (h , heights [layer ],heights [layer + 1 ], increase )
8894 grad = grad + etc (h , heights [atm_layer - 1 ],temp_points [atm_layer - 1 ] + gradient [atm_layer - 1 ]* (h - heights [atm_layer - 1 ]))
8995 return grad + dT
9096
9197
92- def segmento_presion_1 (z , pi , z0 , dT , conditions ):
93- '''calcula la presión en un segmento de atmósfera de temperatura constante '''
98+ def pressure_segment_1 (z , pi , z0 , dT , conditions ):
99+ '''Calculates pressure throught a constant temperature segment of the atmosphere '''
94100 g = conditions [3 ]
95101 R = conditions [4 ]
96102 radius = conditions [5 ]
97103 h = (radius * z ) / (radius + z )
98104 h0 = (radius * z0 )/ (radius + z0 )
99- _ = 1000 * (h - h0 ) * g / (R * temperatura (z , conditions , dT ))
105+ _ = 1000 * (h - h0 ) * g / (R * temperature (z , conditions , dT ))
100106 return pi * np .e ** - _
101107
102- def segmento_presion_2 (z , pi , Ti , a , dT , conditions ):
103- '''calcula la presión en un segmento de atmósfera con gradiente de temperatura "a" '''
108+ def pressure_segment_2 (z , pi , Ti , a , dT , conditions ):
109+ '''Calculates pressure throught a variant temperature segment of the atmosphere '''
104110 g = conditions [3 ]
105111 R = conditions [4 ]
106112 _ = g / (a * R / 1000 )
107- return pi * (temperatura (z , conditions , dT )/ (Ti + dT )) ** - _
113+ return pi * (temperature (z , conditions , dT )/ (Ti + dT )) ** - _
108114
109- def presion (h , conditions , dT = 0 ):
110- '''Calcula la presion en Pa a una altura h en m sobre el nivel del mar '''
115+ def pressure (h , conditions , dT = 0 ):
116+ '''Calculates the value for pressure in Pascal at a certain altitude '''
111117
112118 heights = conditions [0 ]
113119 gradient = conditions [1 ]
114120 temp_points = conditions [2 ]
115121 atm_layer = gradient .shape [0 ]
116- #Primero, calculamos la presion de cada punto de cambio de capa para la condición de dT pedida
117- #Suponemos que la presión es siempre constante a 101325 Pa a nivel del mar
118122
119123
120124 pressure_points = np .zeros ([atm_layer ])
121125 pressure_points [0 ] = conditions [6 ]
122126
123127 for layer in np .arange (1 , atm_layer , 1 ):
124128 if (abs (gradient [layer - 1 ]) < 1e-8 ):
125- pressure_points [layer ] = segmento_presion_1 (heights [layer ],
129+ pressure_points [layer ] = pressure_segment_1 (heights [layer ],
126130 pressure_points [layer - 1 ],
127131 heights [layer - 1 ],
128132 dT , conditions )
129133 else :
130- pressure_points [layer ] = segmento_presion_2 (heights [layer ],
134+ pressure_points [layer ] = pressure_segment_2 (heights [layer ],
131135 pressure_points [layer - 1 ],
132136 temp_points [layer - 1 ],
133137 gradient [layer - 1 ],
@@ -139,24 +143,24 @@ def presion (h, conditions, dT = 0):
139143 grad = 0
140144 for layer in np .arange (1 , atm_layer , 1 ):
141145 if (abs (gradient [layer - 1 ]) < 1e-8 ):
142- funcion = segmento_presion_1 (h ,
146+ funcion = pressure_segment_1 (h ,
143147 pressure_points [layer - 1 ],
144148 heights [layer - 1 ],
145149 dT , conditions )
146150 else :
147- funcion = segmento_presion_2 (h ,
151+ funcion = pressure_segment_2 (h ,
148152 pressure_points [layer - 1 ],
149153 temp_points [layer - 1 ],
150154 gradient [layer - 1 ],
151155 dT , conditions )
152- grad = grad + ventana (h , heights [layer - 1 ], heights [layer ], funcion )
156+ grad = grad + window (h , heights [layer - 1 ], heights [layer ], funcion )
153157 if (abs (gradient [layer - 1 ])< 10e-8 ):
154- funcion = segmento_presion_1 (h ,
158+ funcion = pressure_segment_1 (h ,
155159 pressure_points [layer - 1 ],
156160 heights [layer - 1 ],
157161 dT , conditions )
158162 else :
159- funcion = segmento_presion_2 (h ,
163+ funcion = pressure_segment_2 (h ,
160164 pressure_points [layer - 1 ],
161165 temp_points [layer - 1 ],
162166 gradient [layer - 1 ],
@@ -166,13 +170,16 @@ def presion (h, conditions, dT = 0):
166170 return grad
167171
168172
169- def densidad (h , conditions , dT = 0 ):
170- '''Calcula la densidad a una altura h en m sobre el nivel del mar '''
173+ def density (h , conditions , dT = 0 ):
174+ '''Calculates the value for density in Kg/m3 at a certain altitude '''
171175 R = conditions [4 ]
172- return presion (h , conditions , dT )/ (R * temperatura (h , conditions , dT ))
176+ return pressure (h , conditions , dT )/ (R * temperature (h , conditions , dT ))
173177
174178
175179def mars_conditions ():
180+ '''Returns an array of atmospheric and physical data from which the complete
181+ model of the atmosphere can be built.
182+ '''
176183 heights = np .array ([- 8.3 ,
177184 8.85 ,
178185 30 ])
@@ -200,7 +207,10 @@ def mars_conditions():
200207
201208
202209
203- def viscosidad (temp , planet ):
210+ def viscosity (temp , planet ):
211+ '''Calculates the value for viscosity in microPascal*second
212+ for a certain temperature'''
213+
204214 if (planet == 'Earth' ):
205215 c = 120
206216 lamb = 1.512041288
@@ -213,16 +223,20 @@ def viscosidad(temp, planet):
213223
214224
215225def Reynolds (dens , longitud , vel , visc ):
226+ '''Calculates the Reynolds number'''
216227 re = 1000000 * dens * longitud * vel / visc
217228 return re
218229
219230
220231def aero_conditions (ambient_data ):
232+ '''Given a certain conditions, return the value of the Mach and Reynolds
233+ numbers, in that order.
234+ '''
221235 (planet , chord , height , speed_type , speed ) = ambient_data
222236 planet_dic = {'Mars' :mars_conditions (), 'Earth' :earth_conditions ()}
223237
224238
225- sound = (1.4 * presion (height , planet_dic [planet ]) / densidad (height ,planet_dic [planet ]))** 0.5
239+ sound = (1.4 * pressure (height , planet_dic [planet ]) / density (height ,planet_dic [planet ]))** 0.5
226240
227241 if (speed_type == 'mach' ):
228242 mach = speed
@@ -234,14 +248,9 @@ def aero_conditions(ambient_data):
234248 print ('error in the data, invalid speed parameter' )
235249
236250
237-
238- re = Reynolds (densidad (height , planet_dic [planet ]), chord , vel , viscosidad ( temperatura ( height , planet_dic [ planet ]), planet ) )
251+ visc = viscosity ( temperature ( height , planet_dic [ planet ]), planet )
252+ re = Reynolds (density (height , planet_dic [planet ]), chord , vel , visc )
239253
240254
241255
242256 return [mach , re ]
243- #
244- #ambient_data = ('Earth', 03.0003, 11, 'speed', 30.1)
245- #
246- #result = aero_conditions(('Earth', 0.03, 11, 'mach', 0.1))
247- #print(result)
0 commit comments