turn plot() function into Airfoil class method

Commit
ed394647e3c5101255a1bcbb023e78ed768d30e0
Author
Marius Peter <blendoit@gmail.com>
Author date
Committer
Marius Peter <blendoit@gmail.com>
Committer date
Changed files
creator.py
index a4f67ad5..fb6e4e15 100644..100644
@@ -221,7 +221,57 @@
221 221 print('z_c the camber z-coordinates:\n', np.around(self.x_u, round))
222 222 return None
223 223
224 Added: def plot(self):
225 Added: '''This function plots the elements passed as arguments.'''
224 226
227 Added: # Plot chord
228 Added: x_chord = [0, self.chord]
229 Added: y_chord = [0, 0]
230 Added: plt.plot(x_chord, y_chord, linewidth='1')
231 Added: # Plot quarter chord
232 Added: plt.plot(self.chord / 4, 0, '.', color='g')
233 Added: # Plot mean camber line
234 Added: plt.plot(self.x_c, self.y_c,
235 Added: '-.', color='r', linewidth='2',
236 Added: label='mean camber line')
237 Added: # Plot upper surface
238 Added: plt.plot(self.x_u, self.z_u,
239 Added: '', color='b', linewidth='1')
240 Added: # Plot lower surface
241 Added: plt.plot(self.x_l, self.z_l,
242 Added: '', color='b', linewidth='1')
243 Added:
244 Added: # Plot spars
245 Added: for _ in range(0, len(self.spar.x_u)):
246 Added: x = (self.spar.x_u[_], self.spar.x_l[_])
247 Added: y = (self.spar.z_u[_], self.spar.z_l[_])
248 Added: plt.plot(x, y, '.-', color='b')
249 Added:
250 Added: # Plot stringers
251 Added: # Upper stringers
252 Added: for _ in range(0, len(self.stringer.x_u)):
253 Added: x = self.stringer.x_u[_]
254 Added: y = self.stringer.z_u[_]
255 Added: plt.plot(x, y, '.', color='y')
256 Added: # Lower stringers
257 Added: for _ in range(0, len(self.stringer.x_l)):
258 Added: x = self.stringer.x_l[_]
259 Added: y = self.stringer.z_l[_]
260 Added: plt.plot(x, y, '.', color='y')
261 Added:
262 Added: # Graph formatting
263 Added: plt.xlabel('X axis')
264 Added: plt.ylabel('Z axis')
265 Added:
266 Added: plot_bound = self.x_u[-1]
267 Added: plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound)
268 Added: plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2))
269 Added: plt.gca().set_aspect('equal', adjustable='box')
270 Added: plt.grid(axis='both', linestyle=':', linewidth=1)
271 Added: plt.show()
272 Added: return None
273 Added:
274 Added:
225 275 class Spar(Coordinates):
226 276 '''Contains a single spar's location.'''
227 277 global parent
@@ -357,57 +407,6 @@
357 407 super().print_info(round)
358 408 print('Stringer Area:\n', np.around(self.area, round))
359 409 return None
360 Removed:
361 Removed:
362 Removed: def plot(airfoil, spar, stringer):
363 Removed: '''This function plots the elements passed as arguments.'''
364 Removed:
365 Removed: # Plot chord
366 Removed: x_chord = [0, airfoil.chord]
367 Removed: y_chord = [0, 0]
368 Removed: plt.plot(x_chord, y_chord, linewidth='1')
369 Removed: # Plot quarter chord
370 Removed: plt.plot(airfoil.chord / 4, 0, '.', color='g')
371 Removed: # Plot mean camber line
372 Removed: plt.plot(airfoil.x_c, airfoil.y_c,
373 Removed: '-.', color='r', linewidth='2',
374 Removed: label='mean camber line')
375 Removed: # Plot upper surface
376 Removed: plt.plot(airfoil.x_u, airfoil.z_u,
377 Removed: '', color='b', linewidth='1')
378 Removed: # Plot lower surface
379 Removed: plt.plot(airfoil.x_l, airfoil.z_l,
380 Removed: '', color='b', linewidth='1')
381 Removed:
382 Removed: # Plot spars
383 Removed: for _ in range(0, len(spar.x_u)):
384 Removed: x = (spar.x_u[_], spar.x_l[_])
385 Removed: y = (spar.z_u[_], spar.z_l[_])
386 Removed: plt.plot(x, y, '.-', color='b')
387 Removed:
388 Removed: # Plot stringers
389 Removed: # Upper stringers
390 Removed: for _ in range(0, len(stringer.x_u)):
391 Removed: x = stringer.x_u[_]
392 Removed: y = stringer.z_u[_]
393 Removed: plt.plot(x, y, '.', color='y')
394 Removed: # Lower stringers
395 Removed: for _ in range(0, len(stringer.x_l)):
396 Removed: x = stringer.x_l[_]
397 Removed: y = stringer.z_l[_]
398 Removed: plt.plot(x, y, '.', color='y')
399 Removed:
400 Removed: # Graph formatting
401 Removed: plt.xlabel('X axis')
402 Removed: plt.ylabel('Z axis')
403 Removed:
404 Removed: plot_bound = airfoil.x_u[-1]
405 Removed: plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound)
406 Removed: plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2))
407 Removed: plt.gca().set_aspect('equal', adjustable='box')
408 Removed: plt.grid(axis='both', linestyle=':', linewidth=1)
409 Removed: plt.show()
410 Removed: return None
411 410
412 411
413 412 def main():
evaluator.py
index 59d233ae..489b3465 100644..100644
@@ -20,16 +20,19 @@
20 20 from math import sin, cos, atan, sqrt
21 21
22 22
23 Removed: class Evaluator:
23 Added: class Airfoil:
24 24 '''Performs structural evaluations for the airfoil passed as argument.'''
25 25
26 26 def __init__(self, airfoil):
27 27 self.airfoil = airfoil
28 Added: print(self.airfoil)
28 29 # Global dimensions
29 30 self.chord = airfoil.chord
30 31 self.semi_span = airfoil.semi_span
31 32 # mass and area
32 Removed: self.mass_total = airfoil.mass + airfoil.spar.mass + airfoil.stringer.mass
33 Added: self.mass_total = float(airfoil.mass
34 Added: + airfoil.spar.mass
35 Added: + airfoil.stringer.mass)
33 36 self.mass_dist = []
34 37
35 38 self.lift_rectangular = []
@@ -51,6 +54,7 @@
51 54 print('Chord length:', self.chord)
52 55 print('Semi-span:', self.semi_span)
53 56 print('Total airfoil mass:', self.mass_total)
57 Added: print('Centroid location:', np.around(self.centroid, round + 1))
54 58 print(22 * '-')
55 59 print('Rectangular lift:\n', np.around(self.lift_rectangular, round))
56 60 print('Elliptical lift:\n', np.around(self.lift_elliptical, round))
@@ -114,10 +118,19 @@
114 118 F_x.extend([1.25 * drag for x in semi_span[cutoff:]])
115 119 return F_x
116 120
121 Added: def get_centroid(self):
122 Added: area = self.airfoil.stringer.area
123 Added: x_stringers = self.airfoil.stringer.x_u + self.airfoil.stringer.x_l
124 Added: x_centroid = sum([x * area for x in x_stringers]) / \
125 Added: (len(x_stringers) * area)
126 Added:
127 Added: z_stringers = self.airfoil.stringer.z_u + self.airfoil.stringer.z_l
128 Added: z_centroid = sum([x * area for x in z_stringers]) / \
129 Added: (len(x_stringers) * area)
130 Added: return(x_centroid, z_centroid)
131 Added:
117 132 def analysis(self):
118 Removed: '''
119 Removed: Perform all analysis calculations and store in class instance.
120 Removed: '''
133 Added: '''Perform all analysis calculations and store in class instance.'''
121 134
122 135 self.drag = self.get_drag(10)
123 136
@@ -125,18 +138,9 @@
125 138 self.lift_elliptical = self.get_lift_elliptical(15)
126 139 self.lift = self.get_lift_total()
127 140
128 Removed: # self.mass_total = self.get_mass_total()
129 141 self.mass_dist = self.get_mass_distribution(self.mass_total)
142 Added: self.centroid = self.get_centroid()
130 143 return None
131 Removed:
132 Removed: # def get_centroid(airfoil):
133 Removed: # area = airfoil.stringer.area
134 Removed: # top_stringers = airfoil.stringer
135 Removed: # bottom_stringers =
136 Removed: # nose_top_stringers =
137 Removed: # nose_bottom_stringers =
138 Removed: # for _ in airfoil.stringer[1]:
139 Removed: # centroid.x +=
140 144
141 145 # denominator
142 146 # z_c =
main.py
index 821bbb6e..6d9fa9af 100644..100644
@@ -23,8 +23,8 @@
23 23
24 24 # Airfoil dimensions
25 25 NACA_NUM = 2412
26 Removed: CHORD_LENGTH = 40
27 Removed: SEMI_SPAN = 200
26 Added: CHORD_LENGTH = 20
27 Added: SEMI_SPAN = 20
28 28
29 29 # Component masses
30 30 AIRFOIL_MASS = 10 # lbs
@@ -77,15 +77,15 @@
77 77 # af.stringer.print_info(2)
78 78
79 79 # Plot components with matplotlib
80 Removed: # creator.plot(af, af.spar, af.stringer)
80 Added: af.plot()
81 81
82 82 # Save component info
83 Removed: af.save_info(SAVE_PATH, _)
84 Removed: af.spar.save_info(SAVE_PATH, _)
85 Removed: af.stringer.save_info(SAVE_PATH, _)
83 Added: # af.save_info(SAVE_PATH, _)
84 Added: # af.spar.save_info(SAVE_PATH, _)
85 Added: # af.stringer.save_info(SAVE_PATH, _)
86 86
87 87 # evaluator.Evaluator instance contains airfoil analysis results.
88 Removed: eval = evaluator.Evaluator(af)
88 Added: eval = evaluator.Airfoil(af)
89 89 # The analysis is performed in the evaluator.py module.
90 90 eval.analysis()
91 91 eval.print_info(2)