*ARCHIVED* development moved to aircraft-studio.
use subplots in creator.py for tkinter in gui.py
Changed files
creator.py
@@ -32,7 +32,6 @@
32
32
from math import sin, cos, atan, sqrt
33
33
import bisect as bi
34
34
import matplotlib.pyplot as plt
35
Removed:
from matplotlib.figure import Figure
36
35
37
36
38
37
class Airfoil:
@@ -359,29 +358,34 @@
359
358
return None
360
359
361
360
362
Removed:
def plot_geom(airfoil):
361
Added:
def plot_geom(airfoil, view: False):
363
362
"""This function plots the airfoil's + sub-components' geometry."""
364
363
365
Removed:
fig = Figure()
364
Added:
fig, ax = plt.subplots()
365
Added:
ax.axis('off')
366
Added:
366
367
# Plot chord
367
Removed:
x_chord = [0, airfoil.chord]
368
Removed:
y_chord = [0, 0]
369
Removed:
plt.plot(x_chord, y_chord, linewidth='1')
368
Added:
x = [0, airfoil.chord]
369
Added:
y = [0, 0]
370
Added:
fig.add_subplot(111).plot(x, y, linewidth='1')
370
371
# Plot quarter chord
371
Removed:
plt.plot(airfoil.chord / 4, 0, '.', color='g',
372
Removed:
markersize=24, label='Quarter-chord')
372
Added:
fig.add_subplot(111).plot(airfoil.chord / 4, 0,
373
Added:
'.', color='g', markersize=24,
374
Added:
label='Quarter-chord')
373
375
# Plot mean camber line
374
Removed:
plt.plot(airfoil.x_c, airfoil.z_c, '-.', color='r', linewidth='2',
375
Removed:
label='Mean camber line')
376
Added:
fig.add_subplot(111).plot(airfoil.x_c, airfoil.z_c,
377
Added:
'-.', color='r', linewidth='2',
378
Added:
label='Mean camber line')
376
379
# Plot airfoil surfaces
377
Removed:
plt.fill(airfoil.x, airfoil.z, color='b', linewidth='1', fill=False)
380
Added:
fig.add_subplot(111).plot(airfoil.x, airfoil.z,
381
Added:
color='b', linewidth='1')
378
382
379
383
# Plot spars
380
384
try:
381
385
for _ in range(len(airfoil.spar.x)):
382
386
x = (airfoil.spar.x[_])
383
387
y = (airfoil.spar.z[_])
384
Removed:
plt.plot(x, y, '-', color='y', linewidth='4')
388
Added:
fig.add_subplot(111).plot(x, y, '-', color='y', linewidth='4')
385
389
except AttributeError:
386
390
print('No spars to plot.')
387
391
# Plot stringers
@@ -389,21 +393,22 @@
389
393
for _ in range(0, len(airfoil.stringer.x)):
390
394
x = airfoil.stringer.x[_]
391
395
y = airfoil.stringer.z[_]
392
Removed:
plt.plot(x, y, '.', color='y', markersize=12)
396
Added:
fig.add_subplot(111).plot(x, y, '.', color='y', markersize=12)
393
397
except AttributeError:
394
398
print('No stringers to plot.')
395
399
396
400
# Graph formatting
397
Removed:
plt.xlabel('X axis')
398
Removed:
plt.ylabel('Z axis')
399
Removed:
plot_bound = max(airfoil.x)
400
Removed:
plt.xlim(- 0.10 * plot_bound, 1.10 * plot_bound)
401
Removed:
plt.ylim(- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2))
401
Added:
ax.set(title='NACA ' + str(airfoil.naca_num) + ' airfoil',
402
Added:
xlabel='X axis',
403
Added:
ylabel='Z axis')
404
Added:
plt.grid(axis='both', linestyle=':', linewidth=1)
402
405
plt.gca().set_aspect('equal', adjustable='box')
403
406
plt.gca().legend()
404
Removed:
plt.grid(axis='both', linestyle=':', linewidth=1)
405
Removed:
plt.show()
406
Removed:
return None
407
Added:
if view == True:
408
Added:
plt.show()
409
Added:
else:
410
Added:
pass
411
Added:
return fig, ax
407
412
408
413
409
414
def main():
gui.py
@@ -19,39 +19,65 @@
19
19
20
20
from matplotlib.backends.backend_tkagg import (
21
21
FigureCanvasTkAgg, NavigationToolbar2Tk)
22
Removed:
from matplotlib.figure import Figure
23
22
24
Removed:
import numpy as np
25
23
24
Added:
def make_airfoil():
25
Added:
"""Create airfoil instance."""
26
26
27
Removed:
root = tk.Tk()
28
Removed:
root.wm_title('MAE 154B - Airfoil Design, Evaluation, Optimization')
29
Removed:
# root.geometry('1000x400')
27
Added:
airfoil = creator.Airfoil.from_dimensions(100, 200)
28
Added:
airfoil.add_naca(2412)
29
Added:
airfoil.add_mass(10)
30
30
31
Removed:
# # User inputs
32
Removed:
# l_naca = ttk.Label(root, text='NACA Number')
33
Removed:
# e_naca = ttk.Entry(root)
34
Removed:
# l_chord = ttk.Label(root, text='Chord Length')
35
Removed:
# e_chord = ttk.Entry(root)
36
Removed:
# # Graph window
31
Added:
airfoil.spar = creator.Spar()
32
Added:
airfoil.spar.add_coord(airfoil, 0.23)
33
Added:
airfoil.spar.add_coord(airfoil, 0.57)
34
Added:
airfoil.spar.add_spar_caps(0.3)
35
Added:
airfoil.spar.add_mass(10)
36
Added:
airfoil.spar.add_webs(0.4)
37
37
38
Removed:
fig = Figure()
39
Removed:
t = np.arange(0, 3, .01)
40
Removed:
fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t))
38
Added:
airfoil.stringer = creator.Stringer()
39
Added:
airfoil.stringer.add_coord(airfoil,
40
Added:
3,
41
Added:
6,
42
Added:
5,
43
Added:
4)
44
Added:
airfoil.stringer.add_area(0.1)
45
Added:
airfoil.stringer.add_mass(5)
46
Added:
airfoil.stringer.add_webs(0.1)
47
Added:
return airfoil
41
48
42
Removed:
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
43
Removed:
canvas.draw()
44
Removed:
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
45
49
46
Removed:
toolbar = NavigationToolbar2Tk(canvas, root)
47
Removed:
toolbar.update()
48
Removed:
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
50
Added:
def main():
51
Added:
root = tk.Tk()
52
Added:
root.wm_title('MAE 154B - Airfoil Design, Evaluation, Optimization')
53
Added:
# root.geometry('1000x400')
49
54
55
Added:
# # User inputs
56
Added:
l_naca = ttk.Label(root, text='NACA Number')
57
Added:
e_naca = ttk.Entry(root)
58
Added:
l_chord = ttk.Label(root, text='Chord Length')
59
Added:
e_chord = ttk.Entry(root)
60
Added:
af = make_airfoil()
50
61
51
Removed:
# # Layout
52
Removed:
# l_naca.grid(row=0, sticky='W')
53
Removed:
# e_naca.grid(row=0, column=1)
54
Removed:
# l_chord.grid(row=1, sticky='W')
55
Removed:
# e_chord.grid(row=1, column=1)
62
Added:
# # Graph window
63
Added:
fig, ax = creator.plot_geom(af, False)
56
64
57
Removed:
root.mainloop()
65
Added:
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
66
Added:
canvas.draw()
67
Added:
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
68
Added:
69
Added:
toolbar = NavigationToolbar2Tk(canvas, root)
70
Added:
toolbar.update()
71
Added:
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
72
Added:
73
Added:
# # Layout
74
Added:
l_naca.pack()
75
Added:
e_naca.pack()
76
Added:
l_chord.pack()
77
Added:
e_chord.pack()
78
Added:
79
Added:
root.mainloop()
80
Added:
81
Added:
82
Added:
if __name__ == '__main__':
83
Added:
main()
main.py
@@ -66,20 +66,20 @@
66
66
# Define NACA airfoil coordinates and mass
67
67
af.add_naca(NACA_NUM)
68
68
af.add_mass(AIRFOIL_MASS)
69
Removed:
af.info_print(2)
70
Removed:
af.info_save(SAVE_PATH, _)
69
Added:
# af.info_print(2)
70
Added:
# af.info_save(SAVE_PATH, _)
71
71
72
72
# Create spar instance
73
73
af.spar = creator.Spar()
74
74
# Define the spar coordinates and mass, stored in single spar object
75
75
af.spar.add_coord(af, 0.23)
76
76
af.spar.add_coord(af, 0.57)
77
Removed:
# Automatically adds spar caps for every previously defined
77
Added:
# Automatically adds spar caps for each spar defined previously
78
78
af.spar.add_spar_caps(SPAR_CAP_AREA)
79
79
af.spar.add_mass(SPAR_MASS)
80
80
af.spar.add_webs(SPAR_THICKNESS)
81
Removed:
af.spar.info_print(2)
82
Removed:
af.spar.info_save(SAVE_PATH, _)
81
Added:
# af.spar.info_print(2)
82
Added:
# af.spar.info_save(SAVE_PATH, _)
83
83
84
84
# Create stringer instance
85
85
af.stringer = creator.Stringer()
@@ -92,24 +92,24 @@
92
92
af.stringer.add_area(STRINGER_AREA)
93
93
af.stringer.add_mass(STRINGER_MASS)
94
94
af.stringer.add_webs(SKIN_THICKNESS)
95
Removed:
af.stringer.info_print(2)
96
Removed:
af.stringer.info_save(SAVE_PATH, _)
95
Added:
# af.stringer.info_print(2)
96
Added:
# af.stringer.info_save(SAVE_PATH, _)
97
97
98
98
# Plot components with matplotlib
99
Removed:
creator.plot_geom(af)
99
Added:
creator.plot_geom(af, True)
100
100
101
101
# Evaluator object contains airfoil analysis results.
102
102
eval = evaluator.Evaluator(af)
103
103
# The analysis is performed in the evaluator.py module.
104
104
eval.analysis(1, 1)
105
Removed:
eval.info_print(2)
106
Removed:
eval.info_save(SAVE_PATH, _)
105
Added:
# eval.info_print(2)
106
Added:
# eval.info_save(SAVE_PATH, _)
107
107
# evaluator.plot_geom(eval)
108
108
# evaluator.plot_lift(eval)
109
109
110
110
pop = generator.Population(10)
111
111
112
Removed:
print(help(creator))
112
Added:
# print(help(creator))
113
113
# print(help(evaluator))
114
114
# print(help(generator))
115
115