From dbaeb7d1f1f062a8639f87ed4dfb2eb11d856f10 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sat, 29 Jun 2019 13:24:27 -0700 Subject: start --- creator.py | 38 +++++++++++++++++--------------------- main.py | 2 +- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/creator.py b/creator.py index 3e36036..1431e11 100644 --- a/creator.py +++ b/creator.py @@ -12,8 +12,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + """ -The 'creator' module contains class definitions for coordinates +The creator.py module contains class definitions for coordinates and various components we add to an airfoil (spars, stringers, and ribs.) Classes: @@ -25,6 +26,7 @@ Classes: Functions: plot_geom(airfoil): generates a 2D plot of the airfoil & any components. """ + import sys import os.path import numpy as np @@ -33,13 +35,6 @@ import bisect as bi import matplotlib.pyplot as plt -# This variable is required for main.py constant wing dimensions -# to be passed to inheriting classes (Airfoil, Spar, Stringer, Rib). -# This way, we don't have to redeclare our coordinates as parameters for -# our spars, stringers and ribs. This makes for more elegant code. -global parent - - class Coordinates: """ All airfoil components need the following: @@ -55,10 +50,10 @@ class Coordinates: So, all component classes inherit from class Coordinates. """ - def __init__(self, chord, semi_span): - # Global dimensions - self.chord = chord if chord > 40 else 40 - self.semi_span = semi_span + chord = 100 + semi_span = 200 + + def __init__(self): # mass and area self.mass = float() self.area = float() @@ -68,9 +63,11 @@ class Coordinates: self.x = [] self.z = [] - # The airfoil components know the Coordinates instance's coords - global parent - parent = self + @classmethod + def from_chord(cls, chord, semi_span): + cls.chord = chord + cls.semi_span = semi_span + return None def __str__(self): return type(self).__name__ @@ -131,7 +128,9 @@ class Airfoil(Coordinates): def __init__(self): global parent # Run 'Coordinates' super class init method with same chord & 1/2 span. - super().__init__(parent.chord, parent.semi_span) + super().__init__() + self.chord = Coordinates.chord + self.semi_span = Coordinates.semi_span # NACA number self.naca_num = int() # Mean camber line @@ -236,10 +235,9 @@ class Airfoil(Coordinates): class Spar(Coordinates): """Contains a single spar's location.""" - global parent def __init__(self): - super().__init__(parent.chord, parent.semi_span) + super().__init__() self.x_start = [] self.x_end = [] self.thickness = float() @@ -298,10 +296,9 @@ class Spar(Coordinates): class Stringer(Coordinates): """Contains the coordinates of all stringers.""" - global parent def __init__(self): - super().__init__(parent.chord, parent.semi_span) + super().__init__() self.x_start = [] self.x_end = [] self.thickness = float() @@ -432,7 +429,6 @@ def plot_geom(airfoil): # Graph formatting plt.xlabel('X axis') plt.ylabel('Z axis') - plot_bound = max(airfoil.x) plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound) plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2)) diff --git a/main.py b/main.py index f816c4b..8eb652c 100644 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ def main(): """ # Create coordinate system specific to our airfoil dimensions. # TODO: imperial + metric unit setting - creator.Coordinates(CHORD_LENGTH, SEMI_SPAN) + creator.Coordinates.from_chord(CHORD_LENGTH, SEMI_SPAN) # Interate through all wings in population, creating and evaluating them. for _ in range(1, POP_SIZE + 1): -- cgit v1.2.3 From 2bd4de876393f45d701c849d47db0542b4509962 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sat, 29 Jun 2019 14:05:04 -0700 Subject: remove global variable in creator.py --- creator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/creator.py b/creator.py index 1431e11..4368400 100644 --- a/creator.py +++ b/creator.py @@ -78,6 +78,7 @@ class Coordinates: This function's output is piped to the 'save_coord' function below. """ + name = ' CREATOR DATA ' num_of_dashes = len(name) @@ -96,6 +97,7 @@ class Coordinates: """ Save all the object's coordinates (must be full path). """ + file_name = '{}_{}.txt'.format(str(self).lower(), number) full_path = os.path.join(save_path, file_name) try: @@ -126,7 +128,6 @@ class Airfoil(Coordinates): """ def __init__(self): - global parent # Run 'Coordinates' super class init method with same chord & 1/2 span. super().__init__() self.chord = Coordinates.chord @@ -259,6 +260,7 @@ class Spar(Coordinates): Return: None """ + # Scaled spar location with regards to chord loc = x_loc_percent * self.chord # bi.bisect_left: returns index of first value in airfoil.x > loc @@ -328,6 +330,7 @@ class Stringer(Coordinates): Returns: None """ + # Find distance between leading edge and first upper stringer interval = airfoil.spar.x[0][0] / (stringer_u_1 + 1) # initialise first self.stringer_x at first interval @@ -396,6 +399,7 @@ class Stringer(Coordinates): def plot_geom(airfoil): """This function plots the airfoil's + sub-components' geometry.""" + # Plot chord x_chord = [0, airfoil.chord] y_chord = [0, 0] -- cgit v1.2.3