*ARCHIVED* development moved to aircraft-studio.
Merge pull request #5 from Blendoit/inherit_airfoil
Inherit airfoil
Changed files
creator.py
@@ -12,8 +12,9 @@
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program. If not, see <https://www.gnu.org/licenses/>.
15
Added:
15
16
"""
16
Removed:
The 'creator' module contains class definitions for coordinates
17
Added:
The creator.py module contains class definitions for coordinates
17
18
and various components we add to an airfoil (spars, stringers, and ribs.)
18
19
19
20
Classes:
@@ -25,6 +26,7 @@
25
26
Functions:
26
27
plot_geom(airfoil): generates a 2D plot of the airfoil & any components.
27
28
"""
29
Added:
28
30
import sys
29
31
import os.path
30
32
import numpy as np
@@ -33,13 +35,6 @@
33
35
import matplotlib.pyplot as plt
34
36
35
37
36
Removed:
# This variable is required for main.py constant wing dimensions
37
Removed:
# to be passed to inheriting classes (Airfoil, Spar, Stringer, Rib).
38
Removed:
# This way, we don't have to redeclare our coordinates as parameters for
39
Removed:
# our spars, stringers and ribs. This makes for more elegant code.
40
Removed:
global parent
41
Removed:
42
Removed:
43
38
class Coordinates:
44
39
"""
45
40
All airfoil components need the following:
@@ -55,10 +50,10 @@
55
50
So, all component classes inherit from class Coordinates.
56
51
"""
57
52
58
Removed:
def __init__(self, chord, semi_span):
59
Removed:
# Global dimensions
60
Removed:
self.chord = chord if chord > 40 else 40
61
Removed:
self.semi_span = semi_span
53
Added:
chord = 100
54
Added:
semi_span = 200
55
Added:
56
Added:
def __init__(self):
62
57
# mass and area
63
58
self.mass = float()
64
59
self.area = float()
@@ -68,9 +63,11 @@
68
63
self.x = []
69
64
self.z = []
70
65
71
Removed:
# The airfoil components know the Coordinates instance's coords
72
Removed:
global parent
73
Removed:
parent = self
66
Added:
@classmethod
67
Added:
def from_chord(cls, chord, semi_span):
68
Added:
cls.chord = chord
69
Added:
cls.semi_span = semi_span
70
Added:
return None
74
71
75
72
def __str__(self):
76
73
return type(self).__name__
@@ -81,6 +78,7 @@
81
78
82
79
This function's output is piped to the 'save_coord' function below.
83
80
"""
81
Added:
84
82
name = ' CREATOR DATA '
85
83
num_of_dashes = len(name)
86
84
@@ -99,6 +97,7 @@
99
97
"""
100
98
Save all the object's coordinates (must be full path).
101
99
"""
100
Added:
102
101
file_name = '{}_{}.txt'.format(str(self).lower(), number)
103
102
full_path = os.path.join(save_path, file_name)
104
103
try:
@@ -129,9 +128,10 @@
129
128
"""
130
129
131
130
def __init__(self):
132
Removed:
global parent
133
131
# Run 'Coordinates' super class init method with same chord & 1/2 span.
134
Removed:
super().__init__(parent.chord, parent.semi_span)
132
Added:
super().__init__()
133
Added:
self.chord = Coordinates.chord
134
Added:
self.semi_span = Coordinates.semi_span
135
135
# NACA number
136
136
self.naca_num = int()
137
137
# Mean camber line
@@ -236,10 +236,9 @@
236
236
237
237
class Spar(Coordinates):
238
238
"""Contains a single spar's location."""
239
Removed:
global parent
240
239
241
240
def __init__(self):
242
Removed:
super().__init__(parent.chord, parent.semi_span)
241
Added:
super().__init__()
243
242
self.x_start = []
244
243
self.x_end = []
245
244
self.thickness = float()
@@ -261,6 +260,7 @@
261
260
Return:
262
261
None
263
262
"""
263
Added:
264
264
# Scaled spar location with regards to chord
265
265
loc = x_loc_percent * self.chord
266
266
# bi.bisect_left: returns index of first value in airfoil.x > loc
@@ -298,10 +298,9 @@
298
298
299
299
class Stringer(Coordinates):
300
300
"""Contains the coordinates of all stringers."""
301
Removed:
global parent
302
301
303
302
def __init__(self):
304
Removed:
super().__init__(parent.chord, parent.semi_span)
303
Added:
super().__init__()
305
304
self.x_start = []
306
305
self.x_end = []
307
306
self.thickness = float()
@@ -331,6 +330,7 @@
331
330
Returns:
332
331
None
333
332
"""
333
Added:
334
334
# Find distance between leading edge and first upper stringer
335
335
interval = airfoil.spar.x[0][0] / (stringer_u_1 + 1)
336
336
# initialise first self.stringer_x at first interval
@@ -399,6 +399,7 @@
399
399
400
400
def plot_geom(airfoil):
401
401
"""This function plots the airfoil's + sub-components' geometry."""
402
Added:
402
403
# Plot chord
403
404
x_chord = [0, airfoil.chord]
404
405
y_chord = [0, 0]
@@ -432,7 +433,6 @@
432
433
# Graph formatting
433
434
plt.xlabel('X axis')
434
435
plt.ylabel('Z axis')
435
Removed:
436
436
plot_bound = max(airfoil.x)
437
437
plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound)
438
438
plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2))
main.py
@@ -59,7 +59,7 @@
59
59
"""
60
60
# Create coordinate system specific to our airfoil dimensions.
61
61
# TODO: imperial + metric unit setting
62
Removed:
creator.Coordinates(CHORD_LENGTH, SEMI_SPAN)
62
Added:
creator.Coordinates.from_chord(CHORD_LENGTH, SEMI_SPAN)
63
63
64
64
# Interate through all wings in population, creating and evaluating them.
65
65
for _ in range(1, POP_SIZE + 1):