diff options
author | Blendoit <51464356+Blendoit@users.noreply.github.com> | 2019-06-23 12:32:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-23 12:32:30 -0700 |
commit | f3c4b943012397cf085a67580acf660fe9ef7df5 (patch) | |
tree | 83285d0a2806d1cafe6552bfc03069b0d0633f47 /evaluator.py | |
parent | 4fdb14b652ea2a1f13b0ea0b1daaa5b59d8b9f33 (diff) | |
parent | c9dde0aa778331bc110dc1e223cb76816847a08c (diff) |
Merge pull request #4 from Blendoit/2_coord_vs_4
2 coord vs 4
Diffstat (limited to 'evaluator.py')
-rw-r--r-- | evaluator.py | 95 |
1 files changed, 51 insertions, 44 deletions
diff --git a/evaluator.py b/evaluator.py index 5710522..046d4dd 100644 --- a/evaluator.py +++ b/evaluator.py @@ -38,17 +38,17 @@ class Evaluator: + airfoil.spar.mass + airfoil.stringer.mass) self.mass_dist = [] - # Upper coordinates - self.x_u = airfoil.x_u - self.z_u = airfoil.z_u - # Lower coordinates - self.x_l = airfoil.x_l - self.z_l = airfoil.z_l + # Coordinates + self.x = airfoil.x + self.z = airfoil.z + # Lift self.lift_rectangular = [] self.lift_elliptical = [] self.lift_total = [] # Drag self.drag = [] + # centroid + self.centroid = [] # Inertia terms: # I_x = self.I_[0] # I_z = self.I_[1] @@ -137,20 +137,26 @@ class Evaluator: def get_centroid(self): '''Return the coordinates of the centroid.''' + stringer_area = self.stringer.area caps_area = self.spar.cap_area - x_spars = self.spar.x_u + self.spar.x_l - x_stringers = self.stringer.x_u + self.stringer.x_l - z_stringers = self.stringer.z_u + self.stringer.z_l - denom = float(len(x_spars) * caps_area - + len(x_stringers) * stringer_area) + caps_x = [value for spar in self.spar.x for value in spar] + caps_z = [value for spar in self.spar.z for value in spar] + stringers_x = self.stringer.x + stringers_z = self.stringer.z + + denominator = float(len(caps_x) * caps_area + + len(stringers_x) * stringer_area) - x_ctr = (sum([i * caps_area for i in self.spar.x_u]) - + sum([i * stringer_area for i in x_stringers])) / denom - z_ctr = (sum([i * caps_area for i in self.spar.z_u]) - + sum([i * stringer_area for i in z_stringers])) / denom - return(x_ctr, z_ctr) + centroid_x = float(sum([x * caps_area for x in caps_x]) + + sum([x * stringer_area for x in stringers_x])) + centroid_x = centroid_x / denominator + + centroid_z = float(sum([z * caps_area for z in caps_z]) + + sum([z * stringer_area for z in stringers_z])) + centroid_z = centroid_z / denominator + return(centroid_x, centroid_z) def get_inertia_terms(self): '''Obtain all inertia terms.''' @@ -159,12 +165,12 @@ class Evaluator: caps_area = self.spar.cap_area # Adds upper and lower components' coordinates to list - x_stringers = self.stringer.x_u + self.stringer.x_l - z_stringers = self.stringer.z_u + self.stringer.z_l - x_spars = self.spar.x_u + self.spar.x_l - z_spars = self.spar.z_u + self.spar.z_l + x_stringers = self.stringer.x + z_stringers = self.stringer.z + x_spars = self.spar.x[:][0] + self.spar.x[:][1] + z_spars = self.spar.z[:][0] + self.spar.z[:][1] stringer_count = range(len(x_stringers)) - spar_count = range(len(self.spar.x_u)) + spar_count = range(len(self.spar.x)) # I_x is the sum of the contributions of the spar caps and stringers I_x = (sum([caps_area * (z_spars[i] - self.centroid[1]) ** 2 @@ -209,31 +215,32 @@ def plot_geom(evaluator): y_chord = [0, 0] plt.plot(x_chord, y_chord, linewidth='1') # Plot quarter chord - q = evaluator.chord / 4 - plt.plot(q, 0, '.', color='g', markersize=24, label='Quarter-chord') - # Plot upper surface - plt.plot(evaluator.x_u, evaluator.z_u, - '', color='b', linewidth='1') - # Plot lower surface - plt.plot(evaluator.x_l, evaluator.z_l, - '', color='b', linewidth='1') + plt.plot(evaluator.chord / 4, 0, '.', color='g', + markersize=24, label='Quarter-chord') + # Plot airfoil surfaces + plt.fill(evaluator.x, evaluator.z, color='b', linewidth='1', fill=False) # Plot spars - for _ in range(0, len(evaluator.spar.x_u)): - x = (evaluator.spar.x_u[_], evaluator.spar.x_l[_]) - y = (evaluator.spar.z_u[_], evaluator.spar.z_l[_]) - plt.plot(x, y, '.-', color='b') - + try: + for _ in range(len(evaluator.spar.x)): + x = (evaluator.spar.x[_]) + y = (evaluator.spar.z[_]) + plt.plot(x, y, '-', color='b') + except AttributeError: + print('No spars to plot.') # Plot upper stringers - for _ in range(0, len(evaluator.stringer.x_u)): - x = evaluator.stringer.x_u[_] - y = evaluator.stringer.z_u[_] - plt.plot(x, y, '.', color='y', markersize=12) - # Plot lower stringers - for _ in range(0, len(evaluator.stringer.x_l)): - x = evaluator.stringer.x_l[_] - y = evaluator.stringer.z_l[_] - plt.plot(x, y, '.', color='y', markersize=12) + try: + for _ in range(0, len(evaluator.stringer.x)): + x = evaluator.stringer.x[_] + y = evaluator.stringer.z[_] + plt.plot(x, y, '.', color='y', markersize=12) + except AttributeError: + print('No stringers to plot.') + # # Plot lower stringers + # for _ in range(0, len(evaluator.stringer.x)): + # x = evaluator.stringer.x[_] + # y = evaluator.stringer.z[_] + # plt.plot(x, y, '.', color='y', markersize=12) # Plot centroid x = evaluator.centroid[0] @@ -244,7 +251,7 @@ def plot_geom(evaluator): plt.xlabel('X axis') plt.ylabel('Z axis') - plot_bound = evaluator.x_u[-1] + plot_bound = max(evaluator.x) 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') |