[Python] Design & build airplanes from your specifications.
1
"""
2
The evaluator. module contains functions
3
that return calculated data for an aircraft.
4
Plotting aircraft components is also possible.
5
"""
6
7
import os.
8
import concurrent.
9
import matplotlib. as plt
10
11
from .import drag, inertia, lift, mass
12
13
14
def ():
15
"""Analyze a single aircraft."""
16
results = {
17
'Lift': lift.(),
18
'Drag': drag.(),
19
'Mass': mass.(),
20
'Centroid': inertia.()
21
}
22
aircraft. = results
23
return aircraft., results
24
25
26
def ():
27
"""Analyze all aircraft in a given population."""
28
# for aircraft in population.aircrafts:
29
# print(analyze(aircraft))
30
with concurrent..() as executor:
31
results = executor.(,.)
32
for result in results:
33
print()
34
return None
35
36
# def analysis(self, V_x, V_z):
37
# """Perform all analysis calculations and store in class instance."""
38
39
# self.drag = self.get_drag(10)
40
# self.lift_rectangular = self.get_lift_rectangular(13.7)
41
# self.lift_elliptical = self.get_lift_elliptical(15)
42
# self.lift_total = self.get_lift_total()
43
# self.mass_dist = self.get_mass_distribution(self.mass_total)
44
# self.centroid = self.get_centroid()
45
# self.I_['x'] = self.get_inertia_terms()[0]
46
# self.I_['z'] = self.get_inertia_terms()[1]
47
# self.I_['xz'] = self.get_inertia_terms()[2]
48
# spar_dx = self.get_dx(self.spar)
49
# spar_dz = self.get_dz(self.spar)
50
# self.spar.dP_x = self.get_dP(spar_dx, spar_dz, V_x, 0,
51
# self.spar.cap_area)
52
# self.spar.dP_z = self.get_dP(spar_dx, spar_dz, 0, V_z,
53
# self.spar.cap_area)
54
# print("yayyyyy")
55
# return None
56
57
# print(f"Analysis results for {aircraft.name}:\n", results)
58
# self.results = self.get_lift_total(aircraft)
59
60
# self.drag = self.get_drag(10)
61
# self.lift_rectangular = self.get_lift_rectangular(13.7)
62
# self.lift_elliptical = self.get_lift_elliptical(15)
63
# self.lift_total = self.get_lift_total()
64
# self.mass_dist = self.get_mass_distribution(self.mass_total)
65
# self.centroid = self.get_centroid()
66
# self.I_['x'] = self.get_inertia_terms()[0]
67
# self.I_['z'] = self.get_inertia_terms()[1]
68
# self.I_['xz'] = self.get_inertia_terms()[2]
69
# spar_dx = self.get_dx(self.spar)
70
# spar_dz = self.get_dz(self.spar)
71
# self.spar.dP_x = self.get_dP(spar_dx, spar_dz, V_x, 0,
72
# self.spar.cap_area)
73
# self.spar.dP_z = self.get_dP(spar_dx, spar_dz, 0, V_z,
74
# self.spar.cap_area)
75
# return None
76
77
deftree_print(self,population):
78
"""Print the list of subcomponents."""
79
name = f" TREE FOR {[.forin.]} IN {self.} "
80
num_of_dashes = len()
81
print(*'-')
82
print()
83
for aircraft in population:
84
print(".")
85
print(f"`-- {}")
86
print(f" |--{.}")
87
print(f" | |-- {..}")
88
for spar in aircraft..[:-1]:
89
print(f" | |-- {}")
90
print(f" | `-- {..[-1]}")
91
print(f" |-- {.}")
92
print(f" `-- {.}")
93
print(*'-')
94
return None
95
96
deftree_save(self,
97
population,
98
save_path='/home/blendux/Projects/Aircraft_Studio/save'):
99
"""Save the evaluator's tree to a file."""
100
for aircraft in population.:
101
file_name = f"{.}_tree.txt"
102
full_path = os..(,)
103
with open(,'w') as f:
104
try:
105
f.(".\n")
106
f.(f"`-- {}\n")
107
f.(f" |--{.}\n")
108
for spar in aircraft..[:-1]:
109
f.(f" | |-- {}\n")
110
f.(f" | `-- {..[-1]}\n")
111
f.(f" |-- {.}\n")
112
f.(f" `-- {.}\n")
113
logging.(f'Successfully wrote to file {}')
114
115
except IOError:
116
print(
117
f'Unable to write {} to specified directory.',
118
'Was the full path passed to the function?')
119
return None
120
121
122
defplot_geom(evaluator):
123
"""This function plots analysis results over the airfoil's geometry."""
124
# Plot chord
125
x_chord = [0, evaluator.]
126
y_chord = [0, 0]
127
plt.(,,linewidth='1')
128
# Plot quarter chord
129
plt.(./4,
130
0,
131
'.',
132
color='g',
133
markersize=24,
134
label='Quarter-chord')
135
# Plot airfoil surfaces
136
x = [0.98 * x for x in evaluator..]
137
y = [0.98 * z for z in evaluator..]
138
plt.(,,color='w',linewidth='1',fill=False)
139
x = [1.02 * x for x in evaluator..]
140
y = [1.02 * z for z in evaluator..]
141
plt.(,,color='b',linewidth='1',fill=False)
142
143
# Plot spars
144
try:
145
for _ in range(len(..)):
146
x = (evaluator..[])
147
y = (evaluator..[])
148
plt.(,,'-',color='b')
149
except AttributeError:
150
print('No spars to plot.')
151
# Plot stringers
152
try:
153
for _ in range(0,len(..)):
154
x = evaluator..[]
155
y = evaluator..[]
156
plt.(,,'.',color='y',markersize=12)
157
except AttributeError:
158
print('No stringers to plot.')
159
160
# Plot centroid
161
x = evaluator.[0]
162
y = evaluator.[1]
163
plt.(,,'.',color='r',markersize=24,label='centroid')
164
165
# Graph formatting
166
plt.('X axis')
167
plt.('Z axis')
168
169
plot_bound = max(..)
170
plt.(-0.10*,1.10*)
171
plt.(-(1.10*/2),(1.10*/2))
172
plt.().('equal',adjustable='box')
173
plt.().()
174
plt.(axis='both',linestyle=':',linewidth=1)
175
plt.()
176
return None
177
178
179
defplot_lift(evaluator):
180
x = range(.)
181
y_1 = evaluator.
182
y_2 = evaluator.
183
y_3 = evaluator.
184
plt.(,,'.',color='b',markersize=4,label='Rectangular lift')
185
plt.(,,'.',color='g',markersize=4,label='Elliptical lift')
186
plt.(,,'.',color='r',markersize=4,label='Total lift')
187
188
# Graph formatting
189
plt.('Semi-span location')
190
plt.('Lift')
191
192
plt.().()
193
plt.(axis='both',linestyle=':',linewidth=1)
194
plt.()
195
return None
196