From 4baa99bcf568f91ffe9ce961e86185cf42a75a4b Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 9 Jun 2019 11:50:49 -0700 Subject: class Stringer --- creator.py | 16 ++++++---------- main.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/creator.py b/creator.py index b1a58a9..953f088 100644 --- a/creator.py +++ b/creator.py @@ -236,7 +236,7 @@ class Airfoil(Coordinates): class Spar(Coordinates): - """Contains a single spar's location and material.""" + """Contains a single spar's location.""" global parent def __init__(self): @@ -275,17 +275,13 @@ class Spar(Coordinates): class Stringer(): - """Contains the coordinates of stringer(s) location and material.""" + """Contains the coordinates of stringer(s).""" + global parent def __init__(self): - # Stringer attributes - self.stringer_x_u = [] - self.stringer_y_u = [] - self.stringer_x_l = [] - self.stringer_y_l = [] - self.stringer_mat = [] - - def add_stringers(self, *density): + super().__init__(parent.chord, parent.semi_span) + + def add_stringer(self, *density): """ Add stringers to the wing from their distribution density between spars. First half of density[] concerns stringer distribution on diff --git a/main.py b/main.py index f62a88a..4bbd7a9 100644 --- a/main.py +++ b/main.py @@ -38,6 +38,7 @@ def main(): af.naca(2412) # Print coordinates of af to terminal af.print_coord(4) + # Create spar instance af.spar = creator.Spar() # Define the spar coordinates @@ -45,8 +46,17 @@ def main(): af.spar.add_spar(af.coordinates, 0.55) # Print coordinates of af.spar to terminal af.spar.print_coord(4) + + # Create stringer instance + af.stringer = creator.Stringer() + # Define the stringer coordinates + af.stringer.add_stringer(af.coordinates, 0.15) + af.stringer.add_stringer(af.coordinates, 0.55) + # Print coordinates of af.stringer to terminal + af.stringer.print_coord(4) + # Plot components with matplotlib - creator.plot(af, af.spar) + creator.plot(af, af.spar, af.stringer) # Save component coordinates af.save_coord(SAVE_PATH) -- cgit v1.2.3 From e5610a86d65615a91a89205b3ae4ee559a37d751 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 9 Jun 2019 12:15:41 -0700 Subject: pack_coord method in Coordinates --- creator.py | 39 ++++++++++++++++++++++++++------------- main.py | 33 ++++++++++++++++----------------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/creator.py b/creator.py index 953f088..673cfe9 100644 --- a/creator.py +++ b/creator.py @@ -59,11 +59,12 @@ class Coordinates: self.x_l = [] self.y_l = [] # Coordinates x_u, y_u, x_l, y_l packed in single list - self.coordinates = [] + self.coord = [] + # The airfoil components know the Coordinates instance's coords global parent parent = self - def print_coord(self, round): + def print_component(self, round): """ Print all the component's coordinates to the terminal. @@ -100,6 +101,12 @@ class Coordinates: self.print_coord(4) return None + def pack_coord(self): + self.coord.append(self.x_u) + self.coord.append(self.y_u) + self.coord.append(self.x_l) + self.coord.append(self.y_l) + class Airfoil(Coordinates): """This class enables the creation of a single NACA airfoil.""" @@ -227,11 +234,7 @@ class Airfoil(Coordinates): self.x_l.append(get_lower_coordinates(x)[0]) self.y_l.append(get_lower_coordinates(x)[1]) - self.coordinates.append(self.x_u) - self.coordinates.append(self.y_u) - self.coordinates.append(self.x_l) - self.coordinates.append(self.y_l) - + super().pack_coord() return None @@ -271,6 +274,8 @@ class Spar(Coordinates): self.y_u.append(y_u[spar_x_u]) self.x_l.append(x_l[spar_x_l]) self.y_l.append(y_l[spar_x_l]) + + super().pack_coord() return None @@ -281,17 +286,25 @@ class Stringer(): def __init__(self): super().__init__(parent.chord, parent.semi_span) - def add_stringer(self, *density): + def add_stringer(self, coordinates, den_u_1, den_u_2, den_l_1, den_l_2): """ - Add stringers to the wing from their distribution density between spars. - First half of density[] concerns stringer distribution on + Add stringers to the wing from their density distribution. Parameters: - material: stringer material - *density: + den_u_1: upper nose stringer density (until first spar) + den_u_2: upper surface stringer density + den_l_1: lower nose stringer density (until first spar) + den_l_2: lower surface stringer density + Returns: + None """ - + # Airfoil surface coordinates + # unpacked from 'coordinates' (list of lists in 'Airfoil'). + x_u = coordinates[0] + y_u = coordinates[1] + x_l = coordinates[2] + y_l = coordinates[3] # Find interval between leading edge and first upper stringer, # from density parameter den_u_1. interval = self.spar_x_u[0] / (den_u_1 * self.spar_x_u[0]) diff --git a/main.py b/main.py index 4bbd7a9..bba67ce 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ import random import time start_time = time.time() -CHORD_LENGTH = 100 +CHORD_LENGTH = 10 SEMI_SPAN = 200 POP_SIZE = 1 @@ -36,31 +36,30 @@ def main(): af = creator.Airfoil() # Define NACA airfoil coordinates af.naca(2412) - # Print coordinates of af to terminal - af.print_coord(4) + + print(af.coord) # Create spar instance af.spar = creator.Spar() # Define the spar coordinates - af.spar.add_spar(af.coordinates, 0.15) - af.spar.add_spar(af.coordinates, 0.55) + af.spar.add_spar(af.coord, 0.15) + af.spar.add_spar(af.coord, 0.55) # Print coordinates of af.spar to terminal - af.spar.print_coord(4) - # Create stringer instance - af.stringer = creator.Stringer() - # Define the stringer coordinates - af.stringer.add_stringer(af.coordinates, 0.15) - af.stringer.add_stringer(af.coordinates, 0.55) - # Print coordinates of af.stringer to terminal - af.stringer.print_coord(4) + # # Create stringer instance + # af.stringer = creator.Stringer() + # # Define the stringer coordinates + # af.stringer.add_stringer(af.coordinates, 0.15) + # af.stringer.add_stringer(af.coordinates, 0.55) + # # Print coordinates of af.stringer to terminal + # af.stringer.print_coord(4) # Plot components with matplotlib - creator.plot(af, af.spar, af.stringer) + creator.plot(af, af.spar) - # Save component coordinates - af.save_coord(SAVE_PATH) - af.spar.save_coord(SAVE_PATH) + # # Save component coordinates + # af.save_coord(SAVE_PATH) + # af.spar.save_coord(SAVE_PATH) # Print final execution time print("--- %s seconds ---" % (time.time() - start_time)) -- cgit v1.2.3 From 6e03a7184120cee7a4d3713936c97d64244c482a Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Mon, 10 Jun 2019 21:34:22 -0700 Subject: Stringer plotting & Coordinates __str__ method --- analysis.py | 16 --------- creator.py | 99 +++++++++++++++++++++++++++++++--------------------- evaluator.py | 16 +++++++++ generator.py | 16 +++++++++ genetic_algorithm.py | 16 --------- main.py | 34 +++++++++--------- 6 files changed, 108 insertions(+), 89 deletions(-) delete mode 100644 analysis.py create mode 100644 evaluator.py create mode 100644 generator.py delete mode 100644 genetic_algorithm.py diff --git a/analysis.py b/analysis.py deleted file mode 100644 index 8ea1579..0000000 --- a/analysis.py +++ /dev/null @@ -1,16 +0,0 @@ -# This file is part of Marius Peter's airfoil analysis package (this program). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import airfoil as af diff --git a/creator.py b/creator.py index 673cfe9..5ac4c06 100644 --- a/creator.py +++ b/creator.py @@ -64,14 +64,17 @@ class Coordinates: global parent parent = self - def print_component(self, round): + def __str__(self): + return type(self).__name__ + + def print_coord(self, round): """ Print all the component's coordinates to the terminal. This function's output is piped to the 'save_coord' function below. """ print('============================') - print('Component:', type(self).__name__) + print('Component:', str(self)) print('Chord length:', self.chord) print('Semi-span:', self.semi_span) print('============================') @@ -94,7 +97,8 @@ class Coordinates: """ Save all the object's coordinates (must be full path). """ - file_name = str(type(self).__name__) + + file_name = str(self) full_path = os.path.join(save_dir_path, file_name + '.txt') file = open(full_path, 'w') sys.stdout = file @@ -127,11 +131,11 @@ class Airfoil(Coordinates): # Theta self.theta = [] - def naca(self, naca_num): + def add_naca(self, naca_num): """ - This function generates geometry for our chosen NACA airfoil shape.\ - The nested functions perform the required steps to generate geometry,\ - and can be called to solve the geometry y-coordinate for any 'x' input.\ + This function generates geometry for our chosen NACA airfoil shape. + The nested functions perform the required steps to generate geometry, + and can be called to solve the geometry y-coordinate for any 'x' input. Equation coefficients were retrieved from Wikipedia.org. Parameters: @@ -245,7 +249,7 @@ class Spar(Coordinates): def __init__(self): super().__init__(parent.chord, parent.semi_span) - def add_spar(self, coordinates, spar_x): + def add(self, airfoil_coord, spar_x): """ Add a single spar at the % chord location given to function. @@ -258,11 +262,11 @@ class Spar(Coordinates): None """ # Airfoil surface coordinates - # unpacked from 'coordinates' (list of lists in 'Airfoil'). - x_u = coordinates[0] - y_u = coordinates[1] - x_l = coordinates[2] - y_l = coordinates[3] + # unpacked from 'coordinates' (list of lists in 'Coordinates'). + x_u = airfoil_coord[0] + y_u = airfoil_coord[1] + x_l = airfoil_coord[2] + y_l = airfoil_coord[3] # Scaled spar location with regards to chord loc = spar_x * self.chord # bisect_left: returns index of first value in x_u > loc. @@ -279,14 +283,15 @@ class Spar(Coordinates): return None -class Stringer(): +class Stringer(Coordinates): """Contains the coordinates of stringer(s).""" global parent def __init__(self): super().__init__(parent.chord, parent.semi_span) - def add_stringer(self, coordinates, den_u_1, den_u_2, den_l_1, den_l_2): + def add(self, airfoil_coord, spar_coord, den_u_1, den_u_2, den_l_1, + den_l_2): """ Add stringers to the wing from their density distribution. @@ -299,41 +304,53 @@ class Stringer(): Returns: None """ + # Airfoil surface coordinates - # unpacked from 'coordinates' (list of lists in 'Airfoil'). - x_u = coordinates[0] - y_u = coordinates[1] - x_l = coordinates[2] - y_l = coordinates[3] - # Find interval between leading edge and first upper stringer, + # unpacked from 'coordinates' (list of lists in 'Coordinates'). + airfoil_x_u = airfoil_coord[0] + airfoil_y_u = airfoil_coord[1] + airfoil_x_l = airfoil_coord[2] + airfoil_y_l = airfoil_coord[3] + + # Spar coordinates + # unpacked from 'coordinates' (list of lists in 'Coordinates'). + spar_x_u = spar_coord[0] + spar_y_u = spar_coord[1] + spar_x_l = spar_coord[2] + spar_y_l = spar_coord[3] + + # Find distance between leading edge and first upper stringer, # from density parameter den_u_1. - interval = self.spar_x_u[0] / (den_u_1 * self.spar_x_u[0]) + interval = den_u_1 * spar_x_u[0] # initialise first self.stringer_x_u at first interval. x = interval # Add upper stringers until first spar. - while x < self.spar_x_u[0]: - # Index of the first value of self.x_u > x - x_u = bi.bisect_left(self.x_u, x) - self.stringer_x_u.append(self.x_u[x_u]) - self.stringer_y_u.append(self.y_u[x_u]) + while x < spar_x_u[0]: + # Index of the first value of airfoil_x_u > x + index = bi.bisect_left(airfoil_x_u, x) + # Append the value of airfoil_x_u at index to stringer's coordinates + self.x_u.append(airfoil_x_u[index]) + self.y_u.append(airfoil_y_u[index]) x += interval # Find interval between leading edge and first lower stringer, # from density parameter den_l_1. - interval = self.spar_x_u[0] / (den_l_1 * self.spar_x_u[0]) + interval = den_l_1 * spar_x_u[0] # initialise first self.stringer_x_l at first interval. x = interval # Add lower stringers until first spar. - while x < self.spar_x_l[0]: + while x < spar_x_l[0]: # Index of the first value of self.x_l > x - x_u = bi.bisect_left(self.x_l, x) - self.stringer_x_l.append(self.x_l[x_u]) - self.stringer_y_l.append(self.y_l[x_u]) + index = bi.bisect_left(airfoil_x_l, x) + self.x_u.append(airfoil_x_u[index]) + self.y_u.append(airfoil_y_u[index]) x += interval + + super().pack_coord() return None -def plot(airfoil, spar): +def plot(airfoil, spar, stringer): """This function plots the elements passed as arguments.""" print('Plotting airfoil.') @@ -352,6 +369,7 @@ def plot(airfoil, spar): plt.plot(airfoil.x_u, airfoil.y_u, '', color='b', linewidth='1') # Plot lower surface plt.plot(airfoil.x_l, airfoil.y_l, '', color='b', linewidth='1') + # Plot spars try: for _ in range(0, len(spar.x_u)): @@ -361,14 +379,15 @@ def plot(airfoil, spar): plt.legend() except: print('Did not plot spars. Were they added?') + # Plot stringers - # if len(self.spar_x) != 0: - # for _ in range(0, len(self.stringer_x)): - # x = (self.stringer_x[_], self.stringer_x[_]) - # y = (self.stringer_y_u[_], self.stringer_y_l[_]) - # plt.scatter(x, y, color='y', linewidth='1', - # else: - # print('Unable to plot stringers. Were they created?') + try: + for _ in range(0, len(stringer.x_u)): + x = (spar.x_u[_], spar.x_l[_]) + y = (spar.y_u[_], spar.y_l[_]) + except: + print('Unable to plot stringers. Were they created?') + # Graph formatting plt.gcf().set_size_inches(9, 2.2) plt.xlabel('X axis') diff --git a/evaluator.py b/evaluator.py new file mode 100644 index 0000000..6a87b7e --- /dev/null +++ b/evaluator.py @@ -0,0 +1,16 @@ +# This file is part of Marius Peter's airfoil analysis package (this program). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import creator diff --git a/generator.py b/generator.py new file mode 100644 index 0000000..6a87b7e --- /dev/null +++ b/generator.py @@ -0,0 +1,16 @@ +# This file is part of Marius Peter's airfoil analysis package (this program). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import creator diff --git a/genetic_algorithm.py b/genetic_algorithm.py deleted file mode 100644 index 8ea1579..0000000 --- a/genetic_algorithm.py +++ /dev/null @@ -1,16 +0,0 @@ -# This file is part of Marius Peter's airfoil analysis package (this program). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import airfoil as af diff --git a/main.py b/main.py index bba67ce..17d081a 100644 --- a/main.py +++ b/main.py @@ -13,13 +13,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import creator +import creator # Create geometry +import evaluator # Evaluate geometry +import generator # Iteratevely evaluate instances of geometry import random import time start_time = time.time() -CHORD_LENGTH = 10 +CHORD_LENGTH = 40 SEMI_SPAN = 200 POP_SIZE = 1 @@ -27,7 +29,7 @@ SAVE_PATH = 'C:/Users/blend/github/UCLA_MAE_154B/save' def main(): - # Create coordinate system specific to airfoil dimensions. + # Create coordinate system specific to our airfoil dimensions. creator.Coordinates(CHORD_LENGTH, SEMI_SPAN) # Interate through all wings in population. @@ -35,27 +37,25 @@ def main(): # Create airfoil instance af = creator.Airfoil() # Define NACA airfoil coordinates - af.naca(2412) - - print(af.coord) + af.add_naca(2412) # Create spar instance af.spar = creator.Spar() - # Define the spar coordinates - af.spar.add_spar(af.coord, 0.15) - af.spar.add_spar(af.coord, 0.55) + # Define the spar coordinates, stored in single spar object + af.spar.add(af.coord, 0.15) + af.spar.add(af.coord, 0.55) # Print coordinates of af.spar to terminal - # # Create stringer instance - # af.stringer = creator.Stringer() - # # Define the stringer coordinates - # af.stringer.add_stringer(af.coordinates, 0.15) - # af.stringer.add_stringer(af.coordinates, 0.55) - # # Print coordinates of af.stringer to terminal - # af.stringer.print_coord(4) + # Create stringer instance + af.stringer = creator.Stringer() + # Define the stringer coordinates from airfoil's and spars' + af.stringer.add(af.coord, af.spar.coord, 0.2, 0.2, 0.2, 0.2) + # Print coordinates of af.stringer to terminal + # af.stringer.print_coord(2) + print(af.stringer.coord) # Plot components with matplotlib - creator.plot(af, af.spar) + creator.plot(af, af.spar, af.stringer) # # Save component coordinates # af.save_coord(SAVE_PATH) -- cgit v1.2.3 From 8bbc799672b95d71ff80759c0f8bf30bc11f9c19 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Tue, 11 Jun 2019 13:15:23 -0700 Subject: Final Stringer.add implementation --- creator.py | 105 ++++++++++++++++++++++++++++++++++--------------------------- main.py | 14 ++++----- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/creator.py b/creator.py index 5ac4c06..c6cae4e 100644 --- a/creator.py +++ b/creator.py @@ -78,19 +78,11 @@ class Coordinates: print('Chord length:', self.chord) print('Semi-span:', self.semi_span) print('============================') - print('x_u the upper x-coordinates:', - np.around(self.x_u, round), - sep='\n') - print('y_u the upper y-coordinates:', - np.around(self.y_u, round), - sep='\n') - print('x_l the lower x-coordinates:', - np.around(self.x_l, round), - sep='\n') - print('y_l the lower y-coordinates:', - np.around(self.y_l, round), - sep='\n') - print('\n') + print('x_u the upper x-coordinates:\n', np.around(self.x_u, round)) + print('y_u the upper y-coordinates:\n', np.around(self.y_u, round)) + print('x_l the lower x-coordinates:\n', np.around(self.x_l, round)) + print('y_l the lower y-coordinates:\n', np.around(self.y_l, round)) + # print('\n') return None def save_coord(self, save_dir_path): @@ -140,7 +132,6 @@ class Airfoil(Coordinates): Parameters: naca_num: 4-digit NACA wing - chord: wing chord length, in any unit Return: None @@ -284,22 +275,23 @@ class Spar(Coordinates): class Stringer(Coordinates): - """Contains the coordinates of stringer(s).""" + """Contains the coordinates of all stringers.""" global parent def __init__(self): super().__init__(parent.chord, parent.semi_span) - def add(self, airfoil_coord, spar_coord, den_u_1, den_u_2, den_l_1, - den_l_2): + def add(self, airfoil_coord, spar_coord, stringer_u_1, stringer_u_2, + stringer_l_1, stringer_l_2): """ - Add stringers to the wing from their density distribution. + Add equally distributed stringers to four airfoil locations + (upper nose, lower nose, upper surface, lower surface). Parameters: - den_u_1: upper nose stringer density (until first spar) - den_u_2: upper surface stringer density - den_l_1: lower nose stringer density (until first spar) - den_l_2: lower surface stringer density + 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 Returns: None @@ -311,39 +303,51 @@ class Stringer(Coordinates): airfoil_y_u = airfoil_coord[1] airfoil_x_l = airfoil_coord[2] airfoil_y_l = airfoil_coord[3] - # Spar coordinates # unpacked from 'coordinates' (list of lists in 'Coordinates'). - spar_x_u = spar_coord[0] - spar_y_u = spar_coord[1] - spar_x_l = spar_coord[2] - spar_y_l = spar_coord[3] - - # Find distance between leading edge and first upper stringer, - # from density parameter den_u_1. - interval = den_u_1 * spar_x_u[0] - # initialise first self.stringer_x_u at first interval. + try: + spar_x_u = spar_coord[0] + spar_y_u = spar_coord[1] + spar_x_l = spar_coord[2] + spar_y_l = spar_coord[3] + except: + print('Unable to initialize stringers. Were spars created?') + # Find distance between leading edge and first upper stringer + interval = spar_x_u[0] / (stringer_u_1 + 1) + # initialise first self.stringer_x_u at first interval x = interval - # Add upper stringers until first spar. - while x < spar_x_u[0]: + # Add upper stringers from leading edge until first spar. + for _ in range(0, stringer_u_1): # Index of the first value of airfoil_x_u > x index = bi.bisect_left(airfoil_x_u, x) - # Append the value of airfoil_x_u at index to stringer's coordinates + self.x_u.append(airfoil_x_u[index]) + self.y_u.append(airfoil_y_u[index]) + x += interval + # Add upper stringers from first spar until last spar + interval = (spar_x_u[-1] - spar_x_u[0]) / (stringer_u_2 + 1) + x = interval + spar_x_u[0] + for _ in range(0, stringer_u_2): + index = bi.bisect_left(airfoil_x_u, x) self.x_u.append(airfoil_x_u[index]) self.y_u.append(airfoil_y_u[index]) x += interval - # Find interval between leading edge and first lower stringer, - # from density parameter den_l_1. - interval = den_l_1 * spar_x_u[0] - # initialise first self.stringer_x_l at first interval. + # Find distance between leading edge and first lower stringer + interval = spar_x_l[0] / (stringer_l_1 + 1) x = interval - # Add lower stringers until first spar. - while x < spar_x_l[0]: - # Index of the first value of self.x_l > x + # Add lower stringers from leading edge until first spar. + for _ in range(0, stringer_l_1): index = bi.bisect_left(airfoil_x_l, x) - self.x_u.append(airfoil_x_u[index]) - self.y_u.append(airfoil_y_u[index]) + self.x_l.append(airfoil_x_l[index]) + self.y_l.append(airfoil_y_l[index]) + x += interval + # Add lower stringers from first spar until last spar + interval = (spar_x_l[-1] - spar_x_l[0]) / (stringer_l_2 + 1) + x = interval + spar_x_l[0] + for _ in range(0, stringer_l_2): + index = bi.bisect_left(airfoil_x_l, x) + self.x_l.append(airfoil_x_l[index]) + self.y_l.append(airfoil_y_l[index]) x += interval super().pack_coord() @@ -375,16 +379,23 @@ def plot(airfoil, spar, stringer): for _ in range(0, len(spar.x_u)): x = (spar.x_u[_], spar.x_l[_]) y = (spar.y_u[_], spar.y_l[_]) - plt.plot(x, y, '.-', color='b', label='spar') + plt.plot(x, y, '.-', color='b') plt.legend() except: print('Did not plot spars. Were they added?') # Plot stringers try: + # Upper stringers for _ in range(0, len(stringer.x_u)): - x = (spar.x_u[_], spar.x_l[_]) - y = (spar.y_u[_], spar.y_l[_]) + x = stringer.x_u[_] + y = stringer.y_u[_] + plt.plot(x, y, '.', color='y') + # Lower stringers + for _ in range(0, len(stringer.x_l)): + x = stringer.x_l[_] + y = stringer.y_l[_] + plt.plot(x, y, '.', color='y') except: print('Unable to plot stringers. Were they created?') diff --git a/main.py b/main.py index 17d081a..909547e 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,7 @@ import random import time start_time = time.time() -CHORD_LENGTH = 40 +CHORD_LENGTH = 100 SEMI_SPAN = 200 POP_SIZE = 1 @@ -38,26 +38,26 @@ def main(): af = creator.Airfoil() # Define NACA airfoil coordinates af.add_naca(2412) + af.print_coord(2) # Create spar instance af.spar = creator.Spar() # Define the spar coordinates, stored in single spar object af.spar.add(af.coord, 0.15) af.spar.add(af.coord, 0.55) - # Print coordinates of af.spar to terminal + af.spar.print_coord(2) # Create stringer instance af.stringer = creator.Stringer() - # Define the stringer coordinates from airfoil's and spars' - af.stringer.add(af.coord, af.spar.coord, 0.2, 0.2, 0.2, 0.2) + # Define the stringer coordinates from their amount + af.stringer.add(af.coord, af.spar.coord, 10, 7, 5, 6) # Print coordinates of af.stringer to terminal - # af.stringer.print_coord(2) + af.stringer.print_coord(2) - print(af.stringer.coord) # Plot components with matplotlib creator.plot(af, af.spar, af.stringer) - # # Save component coordinates + # Save component coordinates # af.save_coord(SAVE_PATH) # af.spar.save_coord(SAVE_PATH) -- cgit v1.2.3