forked from suavecode/Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut_C172.py
528 lines (414 loc) · 23.7 KB
/
tut_C172.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# Cessna_172.py
#
# Created: Feb 2022, E. Botero
# ----------------------------------------------------------------------
# Imports
# ----------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
import SUAVE
assert SUAVE.__version__=='2.5.2', 'These tutorials only work with the SUAVE 2.5.2 release'
from SUAVE.Core import Units
from SUAVE.Methods.Propulsion import propeller_design
from SUAVE.Methods.Geometry.Two_Dimensional.Planform import segment_properties
from SUAVE.Plots.Performance import *
#from SUAVE.Input_Output.OpenVSP import write
# ----------------------------------------------------------------------
# Main
# ----------------------------------------------------------------------
def main():
# Define internal combustion engine from Cessna Regression Aircraft
vehicle = vehicle_setup()
#write(vehicle,'C172')
# Setup analyses and mission
analyses = base_analysis(vehicle)
analyses.finalize()
mission = mission_setup(analyses,vehicle)
# evaluate
results = mission.evaluate()
plot_mission(results)
def vehicle_setup():
# ------------------------------------------------------------------
# Initialize the Vehicle
# ------------------------------------------------------------------
vehicle = SUAVE.Vehicle()
vehicle.tag = 'Cessna_172_SP'
# ------------------------------------------------------------------
# Vehicle-level Properties
# ------------------------------------------------------------------
# mass properties
vehicle.mass_properties.max_takeoff = 2550. * Units.pounds
vehicle.mass_properties.takeoff = 2550. * Units.pounds
vehicle.mass_properties.max_zero_fuel = 2555. * Units.pounds
# envelope properties
vehicle.envelope.ultimate_load = 5.7
vehicle.envelope.limit_load = 3.8
# basic parameters
vehicle.reference_area = 174. * Units.feet**2
vehicle.passengers = 4
# ------------------------------------------------------------------
# Main Wing
# ------------------------------------------------------------------
wing = SUAVE.Components.Wings.Main_Wing()
wing.tag = 'main_wing'
wing.sweeps.quarter_chord = 0.0 * Units.deg
wing.thickness_to_chord = 0.12
wing.areas.reference = 174. * Units.feet**2
wing.spans.projected = 36. * Units.feet + 1. * Units.inches
wing.chords.root = 66. * Units.inches
wing.chords.tip = 45. * Units.inches
wing.taper = wing.chords.tip/wing.chords.root
wing.aspect_ratio = wing.spans.projected**2. / wing.areas.reference
wing.twists.root = 0.0 * Units.degrees
wing.twists.tip = 0.0 * Units.degrees
wing.origin = [[80.* Units.inches,0,36.75* Units.inches]]
wing.vertical = False
wing.symmetric = True
wing.high_lift = False
wing.dynamic_pressure_ratio = 1.0
# Wing Segments
segment = SUAVE.Components.Wings.Segment()
segment.tag = 'Root'
segment.percent_span_location = 0.0
segment.twist = 3. * Units.deg
segment.root_chord_percent = 1.
segment.thickness_to_chord = 0.12
segment.dihedral_outboard = 2.5 * Units.degrees
segment.sweeps.quarter_chord = 0
wing.append_segment(segment)
segment = SUAVE.Components.Wings.Segment()
segment.tag = 'Break'
segment.percent_span_location = 0.531177829
segment.twist = 2. * Units.deg
segment.root_chord_percent = 1.0
segment.thickness_to_chord = 0.12
segment.dihedral_outboard = 5 * Units.degrees
segment.sweeps.quarter_chord = -3. * Units.degrees
wing.append_segment(segment)
segment = SUAVE.Components.Wings.Segment()
segment.tag = 'Tip'
segment.percent_span_location = 1.
segment.twist = 1. * Units.degrees
segment.root_chord_percent = 0.67
segment.thickness_to_chord = 0.12
segment.dihedral_outboard = 0.
segment.sweeps.quarter_chord = 0.
wing.append_segment(segment)
# Fill out more segment properties automatically
wing = segment_properties(wing)
wing = SUAVE.Methods.Geometry.Two_Dimensional.Planform.wing_planform(wing)
# add to vehicle
vehicle.append_component(wing)
# ------------------------------------------------------------------
# Horizontal Stabilizer
# ------------------------------------------------------------------
wing = SUAVE.Components.Wings.Horizontal_Tail()
wing.tag = 'horizontal_stabilizer'
wing.sweeps.quarter_chord = 19.5 * Units.deg
wing.thickness_to_chord = 0.12
wing.spans.projected = 135. * Units.inches
wing.areas.reference = 5500 * Units.inches**2
wing.chords.root = 55. * Units.inches
wing.chords.tip = 28. * Units.inches
wing.taper = wing.chords.tip/wing.chords.root
wing.aspect_ratio = (wing.spans.projected**2)/ wing.areas.reference
wing.twists.root = 0.0 * Units.degrees
wing.twists.tip = 0.0 * Units.degrees
wing.origin = [[253.* Units.inches,0,0]]
wing.vertical = False
wing.symmetric = True
wing.high_lift = False
wing.dynamic_pressure_ratio = 0.9
wing = SUAVE.Methods.Geometry.Two_Dimensional.Planform.wing_planform(wing)
vehicle.append_component(wing)
# ------------------------------------------------------------------
# Vertical Stabilizer
# ------------------------------------------------------------------
wing = SUAVE.Components.Wings.Vertical_Tail()
wing.tag = 'vertical_stabilizer'
wing.sweeps.quarter_chord = 48. * Units.deg
wing.thickness_to_chord = 0.12
wing.areas.reference = 3500. * Units.inches**2
wing.spans.projected = 56. * Units.inches
wing.chords.root = 64. * Units.inches
wing.chords.tip = 30. * Units.inches
wing.taper = wing.chords.tip/wing.chords.root
wing.aspect_ratio = wing.spans.projected**2. / wing.areas.reference
wing.twists.root = 0.0 * Units.degrees
wing.twists.tip = 0.0 * Units.degrees
wing.origin = [[240.* Units.inches,0,0]]
wing.vertical = True
wing.symmetric = False
wing.t_tail = False
wing.dynamic_pressure_ratio = 1.0
wing = SUAVE.Methods.Geometry.Two_Dimensional.Planform.wing_planform(wing)
vehicle.append_component(wing)
# ------------------------------------------------------------------
# Strut
# ------------------------------------------------------------------
wing = SUAVE.Components.Wings.Wing()
wing.tag = 'strut'
wing.sweeps.quarter_chord = 0. * Units.deg
wing.thickness_to_chord = 0.4
wing.areas.reference = 660. * Units.inches**2
wing.spans.projected = 200. * Units.inches
wing.chords.root = 6. * Units.inches
wing.chords.tip = 6. * Units.inches
wing.chords.mean_aerodynamic = 6. * Units.inches
wing.taper = wing.chords.tip/wing.chords.root
wing.aspect_ratio = wing.spans.projected**2. / wing.areas.reference
wing.twists.root = 0.0 * Units.degrees
wing.twists.tip = 0.0 * Units.degrees
wing.origin = [[80.* Units.inches,20.* Units.inches,-17.* Units.inches]]
wing.dihedral = 30.0 * Units.degrees
wing.vertical = False
wing.symmetric = True
wing.t_tail = False
wing.dynamic_pressure_ratio = 1.0
# add to vehicle
vehicle.append_component(wing)
# ------------------------------------------------------------------
# Fuselage
# ------------------------------------------------------------------
fuselage = SUAVE.Components.Fuselages.Fuselage()
fuselage.tag = 'fuselage'
fuselage.number_coach_seats = 4.
fuselage.tag = 'fuselage'
fuselage.differential_pressure = 0.
fuselage.width = 42. * Units.inches
fuselage.heights.maximum = 62. * Units.inches
fuselage.lengths.total = 326. * Units.inches
fuselage.lengths.empennage = 161. * Units.inches
fuselage.lengths.cabin = 105. * Units.inches
fuselage.lengths.structure = fuselage.lengths.total-fuselage.lengths.empennage
fuselage.mass_properties.volume = .4*fuselage.lengths.total*(np.pi/4.)*(fuselage.heights.maximum**2.) #try this as approximation
fuselage.mass_properties.internal_volume = .3*fuselage.lengths.total*(np.pi/4.)*(fuselage.heights.maximum**2.)
fuselage.areas.wetted = 20.396
fuselage.seats_abreast = 2.
fuselage.fineness.nose = 1.6
fuselage.fineness.tail = 2.
fuselage.lengths.nose = 60. * Units.inches
fuselage.heights.at_quarter_length = 62. * Units.inches
fuselage.heights.at_three_quarters_length = 62. * Units.inches
fuselage.heights.at_wing_root_quarter_chord = 23. * Units.inches
fuselage.areas.front_projected = fuselage.width* fuselage.heights.maximum
fuselage.effective_diameter = 50. * Units.inches
# Segment
segment = SUAVE.Components.Lofted_Body_Segment.Segment()
segment.tag = 'segment_0'
segment.percent_x_location = 0.
segment.percent_z_location = 16.75 /326.
segment.height = 0. * Units.inches
segment.width = 0. * Units.inches
fuselage.Segments.append(segment)
# Segment
segment = SUAVE.Components.Lofted_Body_Segment.Segment()
segment.tag = 'segment_1'
segment.percent_x_location = 0.070433529
segment.percent_z_location = 0.023187437
segment.height = 28.089241 * Units.inches
segment.width = 40. * Units.inches
fuselage.Segments.append(segment)
# Segment
segment = SUAVE.Components.Lofted_Body_Segment.Segment()
segment.tag = 'segment_2'
segment.percent_x_location = 0.16766091
segment.percent_z_location = 0.014375532
segment.height = 38.872257 * Units.inches
segment.width = 42. * Units.inches
fuselage.Segments.append(segment)
# Segment
segment = SUAVE.Components.Lofted_Body_Segment.Segment()
segment.tag = 'segment_3'
segment.percent_x_location = 0.243802224
segment.percent_z_location = 0.026573779
segment.height = 56.19732 * Units.inches
segment.width = 42. * Units.inches
fuselage.Segments.append(segment)
# Segment
segment = SUAVE.Components.Lofted_Body_Segment.Segment()
segment.tag = 'segment_4'
segment.percent_x_location = 0.443495521
segment.percent_z_location = 0.015
segment.height = 46 * Units.inches
segment.width = 42. * Units.inches
fuselage.Segments.append(segment)
# Segment
segment = SUAVE.Components.Lofted_Body_Segment.Segment()
segment.tag = 'segment_5'
segment.percent_x_location = 0.508342393
segment.percent_z_location = -0.000878305
segment.height = 34.067009 * Units.inches
segment.width = 42. * Units.inches
fuselage.Segments.append(segment)
# Segment
segment = SUAVE.Components.Lofted_Body_Segment.Segment()
segment.tag = 'segment_6'
segment.percent_x_location = 0.857801856
segment.percent_z_location = -0.022517885
segment.height = 15.538013 * Units.inches
segment.width = 10 * Units.inches
fuselage.Segments.append(segment)
# add to vehicle
vehicle.append_component(fuselage)
# ------------------------------------------------------------------
# Piston Propeller Network
# ------------------------------------------------------------------
# build network
net = SUAVE.Components.Energy.Networks.Internal_Combustion_Propeller()
net.tag = 'internal_combustion'
net.number_of_engines = 1.
net.identical_propellers = True
# the engine
engine = SUAVE.Components.Energy.Converters.Internal_Combustion_Engine()
engine.sea_level_power = 180. * Units.horsepower
engine.flat_rate_altitude = 0.0
engine.rated_speed = 2700. * Units.rpm
engine.power_specific_fuel_consumption = 0.52
net.engines.append(engine)
# the prop
prop = SUAVE.Components.Energy.Converters.Propeller()
prop.number_of_blades = 2.0
prop.origin = [[0.0,0.0,16.75 * Units.inches]]
prop.freestream_velocity = 119. * Units.knots
prop.angular_velocity = 2650. * Units.rpm
prop.tip_radius = 76./2. * Units.inches
prop.hub_radius = 8. * Units.inches
prop.design_Cl = 0.8
prop.design_altitude = 12000. * Units.feet
prop.design_power = .64 * 180. * Units.horsepower
prop.variable_pitch = False
prop.airfoil_geometry = ['./Airfoils/NACA_4412.txt']
prop.airfoil_polars = [['./Airfoils/Polars/NACA_4412_polar_Re_50000.txt' ,
'./Airfoils/Polars/NACA_4412_polar_Re_100000.txt' ,
'./Airfoils/Polars/NACA_4412_polar_Re_200000.txt' ,
'./Airfoils/Polars/NACA_4412_polar_Re_500000.txt' ,
'./Airfoils/Polars/NACA_4412_polar_Re_1000000.txt' ]]
prop.airfoil_polar_stations = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
prop = propeller_design(prop)
net.propellers.append(prop)
# add the network to the vehicle
vehicle.append_component(net)
# ------------------------------------------------------------------
# Vehicle Definition Complete
# ------------------------------------------------------------------
return vehicle
def configs_setup(vehicle):
# ------------------------------------------------------------------
# Initialize Configurations
# ------------------------------------------------------------------
configs = SUAVE.Components.Configs.Config.Container()
base_config = SUAVE.Components.Configs.Config(vehicle)
base_config.tag = 'base'
configs.append(base_config)
# ------------------------------------------------------------------
# Cruise Configuration
# ------------------------------------------------------------------
config = SUAVE.Components.Configs.Config(base_config)
config.tag = 'cruise'
configs.append(config)
return configs
# ----------------------------------------------------------------------
# Define the Mission
# ----------------------------------------------------------------------
def mission_setup(analyses,vehicle):
# ------------------------------------------------------------------
# Initialize the Mission
# ------------------------------------------------------------------
mission = SUAVE.Analyses.Mission.Sequential_Segments()
mission.tag = 'the_mission'
# unpack Segments module
Segments = SUAVE.Analyses.Mission.Segments
# base segment
base_segment = Segments.Segment()
# ------------------------------------------------------------------
# Cruise Segment: Constant Speed Constant Altitude
# ------------------------------------------------------------------
segment = Segments.Cruise.Constant_Speed_Constant_Altitude(base_segment)
segment.tag = "cruise"
segment.analyses.extend( analyses )
segment.altitude = 12000. * Units.feet
segment.air_speed = 116. * Units.knots
segment.distance = 100 * Units.nautical_mile
ones_row = segment.state.ones_row
segment.state.numerics.number_control_points = 16
segment.state.unknowns.throttle = 1.0 * ones_row(1)
segment = vehicle.networks.internal_combustion.add_unknowns_and_residuals_to_segment(segment,rpm=2600)
segment.process.iterate.conditions.stability = SUAVE.Methods.skip
segment.process.finalize.post_process.stability = SUAVE.Methods.skip
# add to mission
mission.append_segment(segment)
return mission
def base_analysis(vehicle):
# ------------------------------------------------------------------
# Initialize the Analyses
# ------------------------------------------------------------------
analyses = SUAVE.Analyses.Vehicle()
## ------------------------------------------------------------------
## Basic Geometry Relations
#sizing = SUAVE.Analyses.Sizing.Sizing()
#sizing.features.vehicle = vehicle
#analyses.append(sizing)
# ------------------------------------------------------------------
# Weights
weights = SUAVE.Analyses.Weights.Weights_Transport()
weights.vehicle = vehicle
analyses.append(weights)
# ------------------------------------------------------------------
# Aerodynamics Analysis
# Calculate extra drag from landing gear:
main_wheel_width = 4. * Units.inches
main_wheel_height = 12. * Units.inches
nose_gear_height = 10. * Units.inches
nose_gear_width = 4. * Units.inches
total_wheel = 2*main_wheel_width*main_wheel_height + nose_gear_width*nose_gear_height
main_gear_strut_height = 2. * Units.inches
main_gear_strut_length = 24. * Units.inches
nose_gear_strut_height = 12. * Units.inches
nose_gear_strut_width = 2. * Units.inches
total_strut = 2*main_gear_strut_height*main_gear_strut_length + nose_gear_strut_height*nose_gear_strut_width
# total drag increment area
drag_area = 1.4*( total_wheel + total_strut)
aerodynamics = SUAVE.Analyses.Aerodynamics.Fidelity_Zero()
aerodynamics.geometry = vehicle
aerodynamics.settings.drag_coefficient_increment = 1.0*drag_area/vehicle.reference_area
analyses.append(aerodynamics)
# ------------------------------------------------------------------
# Energy
energy= SUAVE.Analyses.Energy.Energy()
energy.network = vehicle.networks #what is called throughout the mission (at every time step))
analyses.append(energy)
# ------------------------------------------------------------------
# Planet Analysis
planet = SUAVE.Analyses.Planets.Planet()
analyses.append(planet)
# ------------------------------------------------------------------
# Atmosphere Analysis
atmosphere = SUAVE.Analyses.Atmospheric.US_Standard_1976()
atmosphere.features.planet = planet.features
analyses.append(atmosphere)
# done!
return analyses
# ----------------------------------------------------------------------
# Plot Mission
# ----------------------------------------------------------------------
def plot_mission(results,line_style='bo-'):
# Plot Flight Conditions
plot_flight_conditions(results, line_style)
# Plot Aerodynamic Forces
plot_aerodynamic_forces(results, line_style)
# Plot Aerodynamic Coefficients
plot_aerodynamic_coefficients(results, line_style)
# Drag Components
plot_drag_components(results, line_style)
# Plot Altitude, sfc, vehicle weight
plot_altitude_sfc_weight(results, line_style)
# Plot Velocities
plot_aircraft_velocities(results, line_style)
return
# ----------------------------------------------------------------------
# Call Main
# ----------------------------------------------------------------------
if __name__ == '__main__':
main()
plt.show()