start work on evaluator for real though

Commit
99362c09681f5382470f36fed4a6caf6948a84e1
Author
Marius Peter <blendoit@gmail.com>
Author date
Committer
Marius Peter <blendoit@gmail.com>
Committer date
Changed files
creator.py
index 3cc10d18..138fffbd 100644..100644
@@ -19,8 +19,6 @@
19 19 from math import sin, cos, tan, atan, sqrt, ceil
20 20 import bisect as bi
21 21 import matplotlib.pyplot as plt
22 Removed: import matplotlib as mpl
23 Removed: from mpl_toolkits.mplot3d import Axes3D
24 22
25 23 # This variable is required for main.py constant wing dimensions
26 24 # to be passed to inheriting classes (Airfoil, Spar, Stringer, Rib).
@@ -50,17 +48,18 @@
50 48 if chord < 10:
51 49 self.chord = 10
52 50 self.semi_span = semi_span
53 Removed: # mass
51 Added: # mass and area
54 52 self.mass = float()
53 Added: self.area = float()
55 54 # Component material
56 55 self.material = str()
57 56 # Upper coordinates
58 57 self.x_u = []
59 Removed: self.y_u = []
58 Added: self.z_u = []
60 59 # Lower coordinates
61 60 self.x_l = []
62 Removed: self.y_l = []
63 Removed: # Coordinates x_u, y_u, x_l, y_l packed in single list
61 Added: self.z_l = []
62 Added: # Coordinates x_u, z_u, x_l, z_l packed in single list
64 63 self.coord = []
65 64
66 65 # The airfoil components know the Coordinates instance's coords
@@ -70,6 +69,10 @@
70 69 def __str__(self):
71 70 return type(self).__name__
72 71
72 Added: def add_area(self, area):
73 Added: self.area = area
74 Added: return None
75 Added:
73 76 def print_info(self, round):
74 77 """
75 78 Print all the component's coordinates to the terminal.
@@ -83,9 +86,9 @@
83 86 print('Mass:', self.mass)
84 87 print('============================')
85 88 print('x_u the upper x-coordinates:\n', np.around(self.x_u, round))
86 Removed: print('y_u the upper y-coordinates:\n', np.around(self.y_u, round))
89 Added: print('z_u the upper y-coordinates:\n', np.around(self.z_u, round))
87 90 print('x_l the lower x-coordinates:\n', np.around(self.x_l, round))
88 Removed: print('y_l the lower y-coordinates:\n', np.around(self.y_l, round))
91 Added: print('z_l the lower y-coordinates:\n', np.around(self.z_l, round))
89 92 return None
90 93
91 94 def save_info(self, save_dir_path, number):
@@ -106,14 +109,14 @@
106 109 .format(file_name),
107 110 'Was the full path passed to the function?')
108 111 # It is cleaner to use this context guard to ensure file is closed
109 Removed:
110 112 return None
111 113
112 114 def pack_info(self):
113 115 self.coord.append(self.x_u)
114 Removed: self.coord.append(self.y_u)
116 Added: self.coord.append(self.z_u)
115 117 self.coord.append(self.x_l)
116 Removed: self.coord.append(self.y_l)
118 Added: self.coord.append(self.z_l)
119 Added: return None
117 120
118 121
119 122 class Airfoil(Coordinates):
@@ -209,25 +212,25 @@
209 212
210 213 def get_upper_coordinates(x):
211 214 x_u = float()
212 Removed: y_u = float()
215 Added: z_u = float()
213 216 if 0 <= x < self.chord:
214 217 x_u = x - self.y_t[x] * sin(self.theta[x])
215 Removed: y_u = self.y_c[x] + self.y_t[x] * cos(self.theta[x])
218 Added: z_u = self.y_c[x] + self.y_t[x] * cos(self.theta[x])
216 219 elif x == self.chord:
217 220 x_u = x - self.y_t[x] * sin(self.theta[x])
218 Removed: y_u = 0 # Make upper curve finish at y = 0
219 Removed: return (x_u, y_u)
221 Added: z_u = 0 # Make upper curve finish at y = 0
222 Added: return (x_u, z_u)
220 223
221 224 def get_lower_coordinates(x):
222 225 x_l = float()
223 Removed: y_l = float()
226 Added: z_l = float()
224 227 if 0 <= x < self.chord:
225 228 x_l = (x + self.y_t[x] * sin(self.theta[x]))
226 Removed: y_l = (self.y_c[x] - self.y_t[x] * cos(self.theta[x]))
229 Added: z_l = (self.y_c[x] - self.y_t[x] * cos(self.theta[x]))
227 230 elif x == self.chord:
228 231 x_l = (x + self.y_t[x] * sin(self.theta[x]))
229 Removed: y_l = 0 # Make lower curve finish at y = 0
230 Removed: return (x_l, y_l)
232 Added: z_l = 0 # Make lower curve finish at y = 0
233 Added: return (x_l, z_l)
231 234
232 235 # Generate all our wing geometries from previous sub-functions
233 236 for x in range(0, self.chord + 1):
@@ -237,9 +240,9 @@
237 240 self.dy_c.append(get_dy_c(x))
238 241 self.theta.append(get_theta(self.dy_c[x]))
239 242 self.x_u.append(get_upper_coordinates(x)[0])
240 Removed: self.y_u.append(get_upper_coordinates(x)[1])
243 Added: self.z_u.append(get_upper_coordinates(x)[1])
241 244 self.x_l.append(get_lower_coordinates(x)[0])
242 Removed: self.y_l.append(get_lower_coordinates(x)[1])
245 Added: self.z_l.append(get_lower_coordinates(x)[1])
243 246
244 247 super().pack_info()
245 248 return None
@@ -260,7 +263,7 @@
260 263 Add a single spar at the % chord location given to function.
261 264
262 265 Parameters:
263 Removed: coordinates: provided by Airfoil.coordinates[x_u, y_u, x_l, y_l].
266 Added: coordinates: provided by Airfoil.coordinates[x_u, z_u, x_l, z_l].
264 267 material: spar's material. Assumes homogeneous material.
265 268 spar_x: spar's location as a % of total chord length.
266 269
@@ -270,9 +273,9 @@
270 273 # Airfoil surface coordinates
271 274 # unpacked from 'coordinates' (list of lists in 'Coordinates').
272 275 x_u = airfoil_coord[0]
273 Removed: y_u = airfoil_coord[1]
276 Added: z_u = airfoil_coord[1]
274 277 x_l = airfoil_coord[2]
275 Removed: y_l = airfoil_coord[3]
278 Added: z_l = airfoil_coord[3]
276 279 # Scaled spar location with regards to chord
277 280 loc = spar_x * self.chord
278 281 # bisect_left: returns index of first value in x_u > loc.
@@ -281,9 +284,9 @@
281 284 spar_x_l = bi.bisect_left(x_l, loc) # index of spar's x_l
282 285 # These x and y coordinates are assigned to the spar, NOT airfoil.
283 286 self.x_u.append(x_u[spar_x_u])
284 Removed: self.y_u.append(y_u[spar_x_u])
287 Added: self.z_u.append(z_u[spar_x_u])
285 288 self.x_l.append(x_l[spar_x_l])
286 Removed: self.y_l.append(y_l[spar_x_l])
289 Added: self.z_l.append(z_l[spar_x_l])
287 290
288 291 super().pack_info()
289 292 return None
@@ -318,16 +321,16 @@
318 321 # Airfoil surface coordinates
319 322 # unpacked from 'coordinates' (list of lists in 'Coordinates').
320 323 airfoil_x_u = airfoil_coord[0]
321 Removed: airfoil_y_u = airfoil_coord[1]
324 Added: airfoil_z_u = airfoil_coord[1]
322 325 airfoil_x_l = airfoil_coord[2]
323 Removed: airfoil_y_l = airfoil_coord[3]
326 Added: airfoil_z_l = airfoil_coord[3]
324 327 # Spar coordinates
325 328 # unpacked from 'coordinates' (list of lists in 'Coordinates').
326 329 try:
327 330 spar_x_u = spar_coord[0]
328 Removed: spar_y_u = spar_coord[1]
331 Added: spar_z_u = spar_coord[1]
329 332 spar_x_l = spar_coord[2]
330 Removed: spar_y_l = spar_coord[3]
333 Added: spar_z_l = spar_coord[3]
331 334 except:
332 335 print('Unable to initialize stringers. Were spars created?')
333 336 # Find distance between leading edge and first upper stringer
@@ -339,7 +342,7 @@
339 342 # Index of the first value of airfoil_x_u > x
340 343 index = bi.bisect_left(airfoil_x_u, x)
341 344 self.x_u.append(airfoil_x_u[index])
342 Removed: self.y_u.append(airfoil_y_u[index])
345 Added: self.z_u.append(airfoil_z_u[index])
343 346 x += interval
344 347 # Add upper stringers from first spar until last spar
345 348 interval = (spar_x_u[-1] - spar_x_u[0]) / (stringer_u_2 + 1)
@@ -347,7 +350,7 @@
347 350 for _ in range(0, stringer_u_2):
348 351 index = bi.bisect_left(airfoil_x_u, x)
349 352 self.x_u.append(airfoil_x_u[index])
350 Removed: self.y_u.append(airfoil_y_u[index])
353 Added: self.z_u.append(airfoil_z_u[index])
351 354 x += interval
352 355
353 356 # Find distance between leading edge and first lower stringer
@@ -357,7 +360,7 @@
357 360 for _ in range(0, stringer_l_1):
358 361 index = bi.bisect_left(airfoil_x_l, x)
359 362 self.x_l.append(airfoil_x_l[index])
360 Removed: self.y_l.append(airfoil_y_l[index])
363 Added: self.z_l.append(airfoil_z_l[index])
361 364 x += interval
362 365 # Add lower stringers from first spar until last spar
363 366 interval = (spar_x_l[-1] - spar_x_l[0]) / (stringer_l_2 + 1)
@@ -365,7 +368,7 @@
365 368 for _ in range(0, stringer_l_2):
366 369 index = bi.bisect_left(airfoil_x_l, x)
367 370 self.x_l.append(airfoil_x_l[index])
368 Removed: self.y_l.append(airfoil_y_l[index])
371 Added: self.z_l.append(airfoil_z_l[index])
369 372 x += interval
370 373
371 374 super().pack_info()
@@ -391,15 +394,15 @@
391 394 linewidth='2')
392 395 # label='mean camber line')
393 396 # Plot upper surface
394 Removed: plt.plot(airfoil.x_u, airfoil.y_u, '', color='b', linewidth='1')
397 Added: plt.plot(airfoil.x_u, airfoil.z_u, '', color='b', linewidth='1')
395 398 # Plot lower surface
396 Removed: plt.plot(airfoil.x_l, airfoil.y_l, '', color='b', linewidth='1')
399 Added: plt.plot(airfoil.x_l, airfoil.z_l, '', color='b', linewidth='1')
397 400
398 401 # Plot spars
399 402 try:
400 403 for _ in range(0, len(spar.x_u)):
401 404 x = (spar.x_u[_], spar.x_l[_])
402 Removed: y = (spar.y_u[_], spar.y_l[_])
405 Added: y = (spar.z_u[_], spar.z_l[_])
403 406 plt.plot(x, y, '.-', color='b')
404 407 # plt.legend()
405 408 except:
@@ -410,12 +413,12 @@
410 413 # Upper stringers
411 414 for _ in range(0, len(stringer.x_u)):
412 415 x = stringer.x_u[_]
413 Removed: y = stringer.y_u[_]
416 Added: y = stringer.z_u[_]
414 417 plt.plot(x, y, '.', color='y')
415 418 # Lower stringers
416 419 for _ in range(0, len(stringer.x_l)):
417 420 x = stringer.x_l[_]
418 Removed: y = stringer.y_l[_]
421 Added: y = stringer.z_l[_]
419 422 plt.plot(x, y, '.', color='y')
420 423 except:
421 424 print('Unable to plot stringers. Were they created?')
@@ -423,7 +426,7 @@
423 426 # Graph formatting
424 427 plt.gca().set_aspect('equal', adjustable='box')
425 428 plt.xlabel('X axis')
426 Removed: plt.ylabel('Y axis')
429 Added: plt.ylabel('Z axis')
427 430 plt.grid(axis='both', linestyle=':', linewidth=1)
428 431 plt.show()
429 432 return None
evaluator.py
index 6a87b7ef..180d49ac 100644..100644
@@ -13,4 +13,8 @@
13 13 # You should have received a copy of the GNU General Public License
14 14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15 15
16 Removed: import creator
16 Added: # F_z =
17 Added:
18 Added:
19 Added: def get_centroid(airfoil):
20 Added: pass
main.py
index a5307304..e0921c20 100644..100644
@@ -35,6 +35,7 @@
35 35
36 36 def main():
37 37 # Create coordinate system specific to our airfoil dimensions.
38 Added: # TODO: imperial + metric unit setting
38 39 creator.Coordinates(CHORD_LENGTH, SEMI_SPAN)
39 40
40 41 # Interate through all wings in population.
@@ -63,7 +64,7 @@
63 64 af.stringer.print_info(2)
64 65
65 66 # Plot components with matplotlib
66 Removed: # creator.plot(af, af.spar, af.stringer)
67 Added: creator.plot(af, af.spar, af.stringer)
67 68
68 69 # Save component info
69 70 af.save_info(SAVE_PATH, _)