From 97a837f74c7ca5c53bae48364398b09d15b1509e Mon Sep 17 00:00:00 2001 From: blendoit Date: Thu, 17 Oct 2019 22:24:21 -0700 Subject: refactor stringer generating function --- creator/wing.py | 94 ++++++++++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 55 deletions(-) (limited to 'creator/wing.py') diff --git a/creator/wing.py b/creator/wing.py index 7bf0b23..8257d63 100644 --- a/creator/wing.py +++ b/creator/wing.py @@ -170,17 +170,9 @@ class Spar(base.Component): class Stringer(base.Component): """Contains the coordinates of all stringers.""" - def __init__(self, parent, name, den_u, den_l, den_un, den_ul): - """ - parameters: - - den_u: upper stringer density - den_l: lower stringer density - den_un: upper nose stringer density - den_ul: upper nose stringer density - """ - super().__init__() - parent.stringers.append(self) + def __init__(self, parent, name): + super().__init__(parent, name) + parent.stringers = self self.x_start = [] self.x_end = [] self.z_start = [] @@ -188,62 +180,61 @@ class Stringer(base.Component): self.diameter = float() self.area = float() - def add_coord(self, airfoil, spars, stringer_u_1, stringer_u_2, - stringer_l_1, stringer_l_2): + def add_coord(self, airfoil, den_u_1=4, den_u_2=4, den_l_1=4, den_l_2=4): """Add equally distributed stringers to four airfoil locations (upper nose, lower nose, upper surface, lower surface). Parameters: airfoil_coord: packed airfoil coordinates spar_coord: packed spar coordinates - stringer_u_1: upper nose number of stringers - stringer_u_2: upper surface number of stringers - stringer_l_1: lower nose number of stringers - stringer_l_2: lower surface number of stringers + den_u_1: upper nose number of stringers + den_u_2: upper surface number of stringers + den_l_1: lower nose number of stringers + den_l_2: lower surface number of stringers Returns: None """ # Find distance between leading edge and first upper stringer - interval = spars.x[0][0] / (stringer_u_1 + 1) + interval = airfoil.spars[0].x[0] / (den_u_1 + 1) # initialise first self.stringer_x at first interval x = interval # Add upper stringers from leading edge until first spar. - for _ in range(0, stringer_u_1): + for _ in range(0, den_u_1): # Index of the first value of airfoil.x > x i = bi.bisect_left(airfoil.x, x) - self.x.append(airfoil.x[i]) - self.z.append(airfoil.z[i]) + self.x = np.append(self.x, airfoil.x[i]) + self.z = np.append(self.z, airfoil.z[i]) x += interval # Add upper stringers from first spar until last spar # TODO: stringer placement if only one spar is created - interval = (airfoil.spar.x[-1][0] - - airfoil.spar.x[0][0]) / (stringer_u_2 + 1) - x = interval + airfoil.spar.x[0][0] - for _ in range(0, stringer_u_2): + interval = (airfoil.spars[-1].x[0] - + airfoil.spars[0].x[0]) / (den_u_2 + 1) + x = interval + airfoil.spars[0].x[0] + for _ in range(0, den_u_2): i = bi.bisect_left(airfoil.x, x) - self.x.append(airfoil.x[i]) - self.z.append(airfoil.z[i]) + self.x = np.append(self.x, airfoil.x[i]) + self.z = np.append(self.z, airfoil.z[i]) x += interval # Find distance between leading edge and first lower stringer - interval = airfoil.spar.x[0][1] / (stringer_l_1 + 1) + interval = airfoil.spars[0].x[1] / (den_l_1 + 1) x = interval # Add lower stringers from leading edge until first spar. - for _ in range(0, stringer_l_1): + for _ in range(0, den_l_1): i = bi.bisect_left(airfoil.x[::-1], x) - self.x.append(airfoil.x[-i]) - self.z.append(airfoil.z[-i]) + self.x = np.append(self.x, airfoil.x[-i]) + self.z = np.append(self.z, airfoil.z[-i]) x += interval # Add lower stringers from first spar until last spar - interval = (airfoil.spar.x[-1][1] - - airfoil.spar.x[0][1]) / (stringer_l_2 + 1) - x = interval + airfoil.spar.x[0][1] - for _ in range(0, stringer_l_2): + interval = (airfoil.spars[-1].x[1] - + airfoil.spars[0].x[1]) / (den_l_2 + 1) + x = interval + airfoil.spars[0].x[1] + for _ in range(0, den_l_2): i = bi.bisect_left(airfoil.x[::-1], x) - self.x.append(airfoil.x[-i]) - self.z.append(airfoil.z[-i]) + self.x = np.append(self.x, airfoil.x[-i]) + self.z = np.append(self.z, airfoil.z[-i]) x += interval return None @@ -265,13 +256,13 @@ class Stringer(base.Component): self.thickness = thickness return None - def info_print(self, round): + def info_print(self, round=2): super().info_print(round) print('Stringer Area:\n', np.around(self.area, round)) return None -def plot_geom(airfoil, spars, stringers): +def plot_geom(airfoil): """This function plots the airfoil's + sub-components' geometry.""" fig, ax = plt.subplots() @@ -296,31 +287,24 @@ def plot_geom(airfoil, spars, stringers): # Plot airfoil surfaces ax.plot(airfoil.x, airfoil.z, color='b', linewidth='1') - # Plot spars - try: - for spar in spars: + try: # Plot spars + for spar in airfoil.spars: x = (spar.x) y = (spar.z) ax.plot(x, y, '-', color='y', linewidth='4') except AttributeError: print('No spars to plot.') - # Plot stringers - try: - for _ in range(0, len(airfoil.stringer.x)): - x = airfoil.stringer.x[_] - y = airfoil.stringer.z[_] + try: # Plot stringers + for i in range(len(airfoil.stringers.x)): + x = airfoil.stringers.x[i] + y = airfoil.stringers.z[i] ax.plot(x, y, '.', color='y', markersize=12) except AttributeError: print('No stringers to plot.') - # Graph formatting - # plot_bound = np.amax(airfoil.x) - ax.set( - title='NACA ' + str(airfoil.naca_num) + ' airfoil', - xlabel='X axis', - # xlim=[-0.10 * plot_bound, 1.10 * plot_bound], - ylabel='Z axis') - # ylim=[-(1.10 * plot_bound / 2), (1.10 * plot_bound / 2)]) + ax.set(title='NACA ' + str(airfoil.naca_num) + ' airfoil', + xlabel='X axis', + ylabel='Z axis') plt.grid(axis='both', linestyle=':', linewidth=1) plt.gca().set_aspect('equal', adjustable='box') -- cgit v1.2.3