From ed394647e3c5101255a1bcbb023e78ed768d30e0 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Fri, 21 Jun 2019 18:06:35 -0700 Subject: turn plot() function into Airfoil class method --- creator.py | 101 +++++++++++++++++++++++++++++------------------------------ evaluator.py | 34 +++++++++++--------- main.py | 14 ++++----- 3 files changed, 76 insertions(+), 73 deletions(-) diff --git a/creator.py b/creator.py index a4f67ad..fb6e4e1 100644 --- a/creator.py +++ b/creator.py @@ -221,6 +221,56 @@ class Airfoil(Coordinates): print('z_c the camber z-coordinates:\n', np.around(self.x_u, round)) return None + def plot(self): + '''This function plots the elements passed as arguments.''' + + # Plot chord + x_chord = [0, self.chord] + y_chord = [0, 0] + plt.plot(x_chord, y_chord, linewidth='1') + # Plot quarter chord + plt.plot(self.chord / 4, 0, '.', color='g') + # Plot mean camber line + plt.plot(self.x_c, self.y_c, + '-.', color='r', linewidth='2', + label='mean camber line') + # Plot upper surface + plt.plot(self.x_u, self.z_u, + '', color='b', linewidth='1') + # Plot lower surface + plt.plot(self.x_l, self.z_l, + '', color='b', linewidth='1') + + # Plot spars + for _ in range(0, len(self.spar.x_u)): + x = (self.spar.x_u[_], self.spar.x_l[_]) + y = (self.spar.z_u[_], self.spar.z_l[_]) + plt.plot(x, y, '.-', color='b') + + # Plot stringers + # Upper stringers + for _ in range(0, len(self.stringer.x_u)): + x = self.stringer.x_u[_] + y = self.stringer.z_u[_] + plt.plot(x, y, '.', color='y') + # Lower stringers + for _ in range(0, len(self.stringer.x_l)): + x = self.stringer.x_l[_] + y = self.stringer.z_l[_] + plt.plot(x, y, '.', color='y') + + # Graph formatting + plt.xlabel('X axis') + plt.ylabel('Z axis') + + plot_bound = self.x_u[-1] + plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound) + plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2)) + plt.gca().set_aspect('equal', adjustable='box') + plt.grid(axis='both', linestyle=':', linewidth=1) + plt.show() + return None + class Spar(Coordinates): '''Contains a single spar's location.''' @@ -359,57 +409,6 @@ class Stringer(Coordinates): return None -def plot(airfoil, spar, stringer): - '''This function plots the elements passed as arguments.''' - - # Plot chord - x_chord = [0, airfoil.chord] - y_chord = [0, 0] - plt.plot(x_chord, y_chord, linewidth='1') - # Plot quarter chord - plt.plot(airfoil.chord / 4, 0, '.', color='g') - # Plot mean camber line - plt.plot(airfoil.x_c, airfoil.y_c, - '-.', color='r', linewidth='2', - label='mean camber line') - # Plot upper surface - plt.plot(airfoil.x_u, airfoil.z_u, - '', color='b', linewidth='1') - # Plot lower surface - plt.plot(airfoil.x_l, airfoil.z_l, - '', color='b', linewidth='1') - - # Plot spars - for _ in range(0, len(spar.x_u)): - x = (spar.x_u[_], spar.x_l[_]) - y = (spar.z_u[_], spar.z_l[_]) - plt.plot(x, y, '.-', color='b') - - # Plot stringers - # Upper stringers - for _ in range(0, len(stringer.x_u)): - x = stringer.x_u[_] - y = stringer.z_u[_] - plt.plot(x, y, '.', color='y') - # Lower stringers - for _ in range(0, len(stringer.x_l)): - x = stringer.x_l[_] - y = stringer.z_l[_] - plt.plot(x, y, '.', color='y') - - # Graph formatting - plt.xlabel('X axis') - plt.ylabel('Z axis') - - plot_bound = airfoil.x_u[-1] - plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound) - plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2)) - plt.gca().set_aspect('equal', adjustable='box') - plt.grid(axis='both', linestyle=':', linewidth=1) - plt.show() - return None - - def main(): return None diff --git a/evaluator.py b/evaluator.py index 59d233a..489b346 100644 --- a/evaluator.py +++ b/evaluator.py @@ -20,16 +20,19 @@ import numpy as np from math import sin, cos, atan, sqrt -class Evaluator: +class Airfoil: '''Performs structural evaluations for the airfoil passed as argument.''' def __init__(self, airfoil): self.airfoil = airfoil + print(self.airfoil) # Global dimensions self.chord = airfoil.chord self.semi_span = airfoil.semi_span # mass and area - self.mass_total = airfoil.mass + airfoil.spar.mass + airfoil.stringer.mass + self.mass_total = float(airfoil.mass + + airfoil.spar.mass + + airfoil.stringer.mass) self.mass_dist = [] self.lift_rectangular = [] @@ -51,6 +54,7 @@ class Evaluator: print('Chord length:', self.chord) print('Semi-span:', self.semi_span) print('Total airfoil mass:', self.mass_total) + print('Centroid location:', np.around(self.centroid, round + 1)) print(22 * '-') print('Rectangular lift:\n', np.around(self.lift_rectangular, round)) print('Elliptical lift:\n', np.around(self.lift_elliptical, round)) @@ -114,10 +118,19 @@ class Evaluator: F_x.extend([1.25 * drag for x in semi_span[cutoff:]]) return F_x + def get_centroid(self): + area = self.airfoil.stringer.area + x_stringers = self.airfoil.stringer.x_u + self.airfoil.stringer.x_l + x_centroid = sum([x * area for x in x_stringers]) / \ + (len(x_stringers) * area) + + z_stringers = self.airfoil.stringer.z_u + self.airfoil.stringer.z_l + z_centroid = sum([x * area for x in z_stringers]) / \ + (len(x_stringers) * area) + return(x_centroid, z_centroid) + def analysis(self): - ''' - Perform all analysis calculations and store in class instance. - ''' + '''Perform all analysis calculations and store in class instance.''' self.drag = self.get_drag(10) @@ -125,18 +138,9 @@ class Evaluator: self.lift_elliptical = self.get_lift_elliptical(15) self.lift = self.get_lift_total() - # self.mass_total = self.get_mass_total() self.mass_dist = self.get_mass_distribution(self.mass_total) + self.centroid = self.get_centroid() return None -# def get_centroid(airfoil): -# area = airfoil.stringer.area -# top_stringers = airfoil.stringer -# bottom_stringers = -# nose_top_stringers = -# nose_bottom_stringers = -# for _ in airfoil.stringer[1]: -# centroid.x += - # denominator # z_c = diff --git a/main.py b/main.py index 821bbb6..6d9fa9a 100644 --- a/main.py +++ b/main.py @@ -23,8 +23,8 @@ start_time = time.time() # Airfoil dimensions NACA_NUM = 2412 -CHORD_LENGTH = 40 -SEMI_SPAN = 200 +CHORD_LENGTH = 20 +SEMI_SPAN = 20 # Component masses AIRFOIL_MASS = 10 # lbs @@ -77,15 +77,15 @@ def main(): # af.stringer.print_info(2) # Plot components with matplotlib - # creator.plot(af, af.spar, af.stringer) + af.plot() # Save component info - af.save_info(SAVE_PATH, _) - af.spar.save_info(SAVE_PATH, _) - af.stringer.save_info(SAVE_PATH, _) + # af.save_info(SAVE_PATH, _) + # af.spar.save_info(SAVE_PATH, _) + # af.stringer.save_info(SAVE_PATH, _) # evaluator.Evaluator instance contains airfoil analysis results. - eval = evaluator.Evaluator(af) + eval = evaluator.Airfoil(af) # The analysis is performed in the evaluator.py module. eval.analysis() eval.print_info(2) -- cgit v1.2.3