summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--creator.py99
-rw-r--r--evaluator.py (renamed from analysis.py)2
-rw-r--r--generator.py (renamed from genetic_algorithm.py)2
-rw-r--r--main.py34
4 files changed, 78 insertions, 59 deletions
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/analysis.py b/evaluator.py
index 8ea1579..6a87b7e 100644
--- a/analysis.py
+++ b/evaluator.py
@@ -13,4 +13,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-import airfoil as af
+import creator
diff --git a/genetic_algorithm.py b/generator.py
index 8ea1579..6a87b7e 100644
--- a/genetic_algorithm.py
+++ b/generator.py
@@ -13,4 +13,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-import airfoil as af
+import creator
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 <https://www.gnu.org/licenses/>.
-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)
Copyright 2019--2024 Marius PETER