summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--creator.py147
-rw-r--r--evaluator.py52
2 files changed, 98 insertions, 101 deletions
diff --git a/creator.py b/creator.py
index 78c537d..d75661f 100644
--- a/creator.py
+++ b/creator.py
@@ -53,14 +53,9 @@ class Coordinates:
self.area = float()
# Component material
self.material = str()
- # Upper coordinates
- self.x_u = []
- self.z_u = []
- # Lower coordinates
- self.x_l = []
- self.z_l = []
- # Coordinates x_u, z_u, x_l, z_l packed in single list
- self.coord = []
+ # Coordinates
+ self.x = []
+ self.z = []
# The airfoil components know the Coordinates instance's coords
global parent
@@ -85,10 +80,8 @@ class Coordinates:
print('Semi-span:', self.semi_span)
print('Mass:', self.mass)
print(num_of_dashes * '-')
- print('x_u the upper x-coordinates:\n', np.around(self.x_u, round))
- print('z_u the upper z-coordinates:\n', np.around(self.z_u, round))
- print('x_l the lower x-coordinates:\n', np.around(self.x_l, round))
- print('z_l the lower z-coordinates:\n', np.around(self.z_l, round))
+ print('x-coordinates:\n', np.around(self.x, round))
+ print('z-coordinates:\n', np.around(self.z, round))
return None
def info_save(self, save_path, number):
@@ -182,14 +175,14 @@ class Airfoil(Coordinates):
return theta
def get_upper_coord(x):
- x_u = x - get_thickness(x) * sin(get_theta(x))
- z_u = get_camber(x) + get_thickness(x) * cos(get_theta(x))
- return (x_u, z_u)
+ x = x - get_thickness(x) * sin(get_theta(x))
+ z = get_camber(x) + get_thickness(x) * cos(get_theta(x))
+ return (x, z)
def get_lower_coord(x):
- x_l = x + get_thickness(x) * sin(get_theta(x))
- z_l = get_camber(x) - get_thickness(x) * cos(get_theta(x))
- return (x_l, z_l)
+ x = x + get_thickness(x) * sin(get_theta(x))
+ z = get_camber(x) - get_thickness(x) * cos(get_theta(x))
+ return (x, z)
# Densify x-coordinates 10 times for first 1/4 chord length
x_chord_25_percent = round(self.chord / 4)
@@ -200,10 +193,13 @@ class Airfoil(Coordinates):
for x in x_chord:
self.x_c.append(x)
self.y_c.append(get_camber(x))
- self.x_u.append(get_upper_coord(x)[0])
- self.z_u.append(get_upper_coord(x)[1])
- self.x_l.append(get_lower_coord(x)[0])
- self.z_l.append(get_lower_coord(x)[1])
+ self.x.append(get_upper_coord(x)[0])
+ self.z.append(get_upper_coord(x)[1])
+ # Behold the true power of Python list slicing!
+ # (This special list index reverses the list.)
+ for x in x_chord[::-1]:
+ self.x.append(get_lower_coord(x)[0])
+ self.z.append(get_lower_coord(x)[1])
return None
def add_mass(self, mass):
@@ -211,8 +207,8 @@ class Airfoil(Coordinates):
def info_print(self, round):
super().info_print(round)
- print('x_c the camber x-coordinates:\n', np.around(self.x_u, round))
- print('z_c the camber z-coordinates:\n', np.around(self.x_u, round))
+ print('x_c the camber x-coordinates:\n', np.around(self.x, round))
+ print('z_c the camber z-coordinates:\n', np.around(self.x, round))
return None
@@ -223,12 +219,12 @@ class Spar(Coordinates):
def __init__(self):
super().__init__(parent.chord, parent.semi_span)
- def add_coord(self, airfoil, spar_x):
+ def add_coord(self, airfoil, x_loc_percent):
'''
Add a single spar at the % chord location given to function.
Parameters:
- coordinates: provided by Airfoil.coordinates[x_u, z_u, x_l, z_l].
+ coordinates: provided by Airfoil.coordinates[x, z, x, z].
material: spar's material. Assumes homogeneous material.
spar_x: spar's location as a % of total chord length.
@@ -237,21 +233,22 @@ class Spar(Coordinates):
'''
# Airfoil surface coordinates
# unpacked from 'coordinates' (list of lists in 'Coordinates').
- x_u = airfoil.x_u
- z_u = airfoil.z_u
- x_l = airfoil.x_l
- z_l = airfoil.z_l
+ x = airfoil.x
+ z = airfoil.z
# Scaled spar location with regards to chord
- loc = spar_x * self.chord
- # bisect_left: returns index of first value in x_u > loc.
- # Ensures that the spar coordinates intersect with airfoil surface.
- spar_x_u = bi.bisect_left(x_u, loc) # index of spar's x_u
- spar_x_l = bi.bisect_left(x_l, loc) # index of spar's x_l
+ loc = x_loc_percent * self.chord
+ # bisect_left: returns index of first value in x > loc
+ # starting from [0]
+ # bisect_right: returns index of first value in x > loc
+ # starting from [-1] (last list element).
+ # This ensures that the spar geom intersects with airfoil geom.
+ spar_x = bi.bisect_left(x, loc) # index of spar's x
+ spar_x = bi.bisect_left(x, loc) # index of spar's x
# These x and y coordinates are assigned to the spar, NOT airfoil.
- self.x_u.append(x_u[spar_x_u])
- self.z_u.append(z_u[spar_x_u])
- self.x_l.append(x_l[spar_x_l])
- self.z_l.append(z_l[spar_x_l])
+ self.x.append(x[spar_x])
+ self.z.append(z[spar_x])
+ self.x.append(x[spar_x])
+ self.z.append(z[spar_x])
return None
def add_spar_caps(self, spar_cap_area):
@@ -259,7 +256,7 @@ class Spar(Coordinates):
return None
def add_mass(self, mass):
- self.mass = len(self.x_u) * mass
+ self.mass = len(self.x) * mass
return None
@@ -291,44 +288,44 @@ class Stringer(Coordinates):
'''
# Find distance between leading edge and first upper stringer
- interval = airfoil.spar.x_u[0] / (stringer_u_1 + 1)
- # initialise first self.stringer_x_u at first interval
+ interval = airfoil.spar.x[0] / (stringer_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):
- # Index of the first value of airfoil_x_u > x
- index = bi.bisect_left(airfoil.x_u, x)
- self.x_u.append(airfoil.x_u[index])
- self.z_u.append(airfoil.z_u[index])
+ # Index of the first value of airfoil_x > x
+ index = bi.bisect_left(airfoil.x, x)
+ self.x.append(airfoil.x[index])
+ self.z.append(airfoil.z[index])
x += interval
# Add upper stringers from first spar until last spar
# TODO: stringer placement if only one spar is created
- interval = (airfoil.spar.x_u[-1]
- - airfoil.spar.x_u[0]) / (stringer_u_2 + 1)
- x = interval + airfoil.spar.x_u[0]
+ interval = (airfoil.spar.x[-1]
+ - airfoil.spar.x[0]) / (stringer_u_2 + 1)
+ x = interval + airfoil.spar.x[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.z_u.append(airfoil.z_u[index])
+ index = bi.bisect_left(airfoil.x, x)
+ self.x.append(airfoil.x[index])
+ self.z.append(airfoil.z[index])
x += interval
# Find distance between leading edge and first lower stringer
- interval = airfoil.spar.x_l[0] / (stringer_l_1 + 1)
+ interval = airfoil.spar.x[0] / (stringer_l_1 + 1)
x = interval
# 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_l.append(airfoil.x_l[index])
- self.z_l.append(airfoil.z_l[index])
+ index = bi.bisect_left(airfoil.x, x)
+ self.x.append(airfoil.x[index])
+ self.z.append(airfoil.z[index])
x += interval
# Add lower stringers from first spar until last spar
- interval = (airfoil.spar.x_l[-1]
- - airfoil.spar.x_l[0]) / (stringer_l_2 + 1)
- x = interval + airfoil.spar.x_l[0]
+ interval = (airfoil.spar.x[-1]
+ - airfoil.spar.x[0]) / (stringer_l_2 + 1)
+ x = interval + airfoil.spar.x[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.z_l.append(airfoil.z_l[index])
+ index = bi.bisect_left(airfoil.x, x)
+ self.x.append(airfoil.x[index])
+ self.z.append(airfoil.z[index])
x += interval
return None
@@ -337,7 +334,7 @@ class Stringer(Coordinates):
return None
def add_mass(self, mass):
- self.mass = len(self.x_u) * mass + len(self.x_l) * mass
+ self.mass = len(self.x) * mass + len(self.x) * mass
return None
def info_print(self, round):
@@ -361,34 +358,34 @@ def plot_geom(airfoil):
'-.', color='r', linewidth='2',
label='Mean camber line')
# Plot upper surface
- plt.plot(airfoil.x_u, airfoil.z_u,
+ plt.plot(airfoil.x, airfoil.z,
'', color='b', linewidth='1')
# Plot lower surface
- plt.plot(airfoil.x_l, airfoil.z_l,
+ plt.plot(airfoil.x, airfoil.z,
'', color='b', linewidth='1')
# Plot spars
- for _ in range(0, len(airfoil.spar.x_u)):
- x = (airfoil.spar.x_u[_], airfoil.spar.x_l[_])
- y = (airfoil.spar.z_u[_], airfoil.spar.z_l[_])
+ for _ in range(0, len(airfoil.spar.x)):
+ x = (airfoil.spar.x[_], airfoil.spar.x[_])
+ y = (airfoil.spar.z[_], airfoil.spar.z[_])
plt.plot(x, y, '.-', color='b')
# Plot upper stringers
- for _ in range(0, len(airfoil.stringer.x_u)):
- x = airfoil.stringer.x_u[_]
- y = airfoil.stringer.z_u[_]
+ for _ in range(0, len(airfoil.stringer.x)):
+ x = airfoil.stringer.x[_]
+ y = airfoil.stringer.z[_]
plt.plot(x, y, '.', color='y', markersize=12)
# Plot lower stringers
- for _ in range(0, len(airfoil.stringer.x_l)):
- x = airfoil.stringer.x_l[_]
- y = airfoil.stringer.z_l[_]
+ for _ in range(0, len(airfoil.stringer.x)):
+ x = airfoil.stringer.x[_]
+ y = airfoil.stringer.z[_]
plt.plot(x, y, '.', color='y', markersize=12)
# Graph formatting
plt.xlabel('X axis')
plt.ylabel('Z axis')
- plot_bound = airfoil.x_u[-1]
+ plot_bound = airfoil.x[-1]
plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound)
plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2))
plt.gca().set_aspect('equal', adjustable='box')
diff --git a/evaluator.py b/evaluator.py
index 5710522..801c5ae 100644
--- a/evaluator.py
+++ b/evaluator.py
@@ -39,11 +39,11 @@ class Evaluator:
+ airfoil.stringer.mass)
self.mass_dist = []
# Upper coordinates
- self.x_u = airfoil.x_u
- self.z_u = airfoil.z_u
+ self.x = airfoil.x
+ self.z = airfoil.z
# Lower coordinates
- self.x_l = airfoil.x_l
- self.z_l = airfoil.z_l
+ self.x = airfoil.x
+ self.z = airfoil.z
self.lift_rectangular = []
self.lift_elliptical = []
self.lift_total = []
@@ -140,15 +140,15 @@ class Evaluator:
stringer_area = self.stringer.area
caps_area = self.spar.cap_area
- x_spars = self.spar.x_u + self.spar.x_l
- x_stringers = self.stringer.x_u + self.stringer.x_l
- z_stringers = self.stringer.z_u + self.stringer.z_l
+ x_spars = self.spar.x + self.spar.x
+ x_stringers = self.stringer.x + self.stringer.x
+ z_stringers = self.stringer.z + self.stringer.z
denom = float(len(x_spars) * caps_area
+ len(x_stringers) * stringer_area)
- x_ctr = (sum([i * caps_area for i in self.spar.x_u])
+ x_ctr = (sum([i * caps_area for i in self.spar.x])
+ sum([i * stringer_area for i in x_stringers])) / denom
- z_ctr = (sum([i * caps_area for i in self.spar.z_u])
+ z_ctr = (sum([i * caps_area for i in self.spar.z])
+ sum([i * stringer_area for i in z_stringers])) / denom
return(x_ctr, z_ctr)
@@ -159,12 +159,12 @@ class Evaluator:
caps_area = self.spar.cap_area
# Adds upper and lower components' coordinates to list
- x_stringers = self.stringer.x_u + self.stringer.x_l
- z_stringers = self.stringer.z_u + self.stringer.z_l
- x_spars = self.spar.x_u + self.spar.x_l
- z_spars = self.spar.z_u + self.spar.z_l
+ x_stringers = self.stringer.x + self.stringer.x
+ z_stringers = self.stringer.z + self.stringer.z
+ x_spars = self.spar.x + self.spar.x
+ z_spars = self.spar.z + self.spar.z
stringer_count = range(len(x_stringers))
- spar_count = range(len(self.spar.x_u))
+ spar_count = range(len(self.spar.x))
# I_x is the sum of the contributions of the spar caps and stringers
I_x = (sum([caps_area * (z_spars[i] - self.centroid[1]) ** 2
@@ -212,27 +212,27 @@ def plot_geom(evaluator):
q = evaluator.chord / 4
plt.plot(q, 0, '.', color='g', markersize=24, label='Quarter-chord')
# Plot upper surface
- plt.plot(evaluator.x_u, evaluator.z_u,
+ plt.plot(evaluator.x, evaluator.z,
'', color='b', linewidth='1')
# Plot lower surface
- plt.plot(evaluator.x_l, evaluator.z_l,
+ plt.plot(evaluator.x, evaluator.z,
'', color='b', linewidth='1')
# Plot spars
- for _ in range(0, len(evaluator.spar.x_u)):
- x = (evaluator.spar.x_u[_], evaluator.spar.x_l[_])
- y = (evaluator.spar.z_u[_], evaluator.spar.z_l[_])
+ for _ in range(0, len(evaluator.spar.x)):
+ x = (evaluator.spar.x[_], evaluator.spar.x[_])
+ y = (evaluator.spar.z[_], evaluator.spar.z[_])
plt.plot(x, y, '.-', color='b')
# Plot upper stringers
- for _ in range(0, len(evaluator.stringer.x_u)):
- x = evaluator.stringer.x_u[_]
- y = evaluator.stringer.z_u[_]
+ for _ in range(0, len(evaluator.stringer.x)):
+ x = evaluator.stringer.x[_]
+ y = evaluator.stringer.z[_]
plt.plot(x, y, '.', color='y', markersize=12)
# Plot lower stringers
- for _ in range(0, len(evaluator.stringer.x_l)):
- x = evaluator.stringer.x_l[_]
- y = evaluator.stringer.z_l[_]
+ for _ in range(0, len(evaluator.stringer.x)):
+ x = evaluator.stringer.x[_]
+ y = evaluator.stringer.z[_]
plt.plot(x, y, '.', color='y', markersize=12)
# Plot centroid
@@ -244,7 +244,7 @@ def plot_geom(evaluator):
plt.xlabel('X axis')
plt.ylabel('Z axis')
- plot_bound = evaluator.x_u[-1]
+ plot_bound = evaluator.x[-1]
plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound)
plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2))
plt.gca().set_aspect('equal', adjustable='box')
Copyright 2019--2024 Marius PETER