summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Peter <51464356+Blendoit@users.noreply.github.com>2019-06-29 14:13:33 -0700
committerGitHub <noreply@github.com>2019-06-29 14:13:33 -0700
commit8a48e962ab9f89233aabd682e88a608f83a61e43 (patch)
tree994d8a088cff860abb28a8635fa70012bd39d3cc
parent1a75e9a544ae0d11e723e60ecc40d53f09c6a2d4 (diff)
parent2bd4de876393f45d701c849d47db0542b4509962 (diff)
Merge pull request #5 from Blendoit/inherit_airfoil
Inherit airfoil
-rw-r--r--creator.py44
-rw-r--r--main.py2
2 files changed, 23 insertions, 23 deletions
diff --git a/creator.py b/creator.py
index 3e36036..4368400 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 <https://www.gnu.org/licenses/>.
+
"""
-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__
@@ -81,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)
@@ -99,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:
@@ -129,9 +128,10 @@ 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 +236,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()
@@ -261,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
@@ -298,10 +298,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()
@@ -331,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
@@ -399,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]
@@ -432,7 +433,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):
Copyright 2019--2024 Marius PETER