Skip to content

Commit 02780d0

Browse files
committed
Merge branch 'develop' of https://github.com/suavecode/Tutorials into develop
2 parents 42365d0 + 9157fdf commit 02780d0

File tree

8 files changed

+1774
-1
lines changed

8 files changed

+1774
-1
lines changed

Solar_UAV_Optimization/Analyses.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Analyses.py
2+
#
3+
# Created: Feb 2015, E. Botero
4+
# Modified:
5+
6+
# ----------------------------------------------------------------------
7+
# Imports
8+
# ----------------------------------------------------------------------
9+
10+
import SUAVE
11+
12+
# ----------------------------------------------------------------------
13+
# Setup Analyses
14+
# ----------------------------------------------------------------------
15+
16+
def setup(configs):
17+
18+
analyses = SUAVE.Analyses.Analysis.Container()
19+
20+
# build a base analysis for each config
21+
for tag,config in configs.items():
22+
analysis = base(config)
23+
analyses[tag] = analysis
24+
25+
return analyses
26+
27+
# ----------------------------------------------------------------------
28+
# Define Base Analysis
29+
# ----------------------------------------------------------------------
30+
31+
def base(vehicle):
32+
33+
# ------------------------------------------------------------------
34+
# Initialize the Analyses
35+
# ------------------------------------------------------------------
36+
analyses = SUAVE.Analyses.Vehicle()
37+
38+
# ------------------------------------------------------------------
39+
# Basic Geometry Relations
40+
sizing = SUAVE.Analyses.Sizing.Sizing()
41+
sizing.features.vehicle = vehicle
42+
analyses.append(sizing)
43+
44+
# ------------------------------------------------------------------
45+
# Weights
46+
# ------------------------------------------------------------------
47+
weights = SUAVE.Analyses.Weights.Weights()
48+
weights.settings.empty_weight_method = SUAVE.Methods.Weights.Correlations.UAV.Empty
49+
weights.vehicle = vehicle
50+
analyses.append(weights)
51+
52+
# ------------------------------------------------------------------
53+
# Aerodynamics Analysis
54+
# ------------------------------------------------------------------
55+
aerodynamics = SUAVE.Analyses.Aerodynamics.Fidelity_Zero()
56+
aerodynamics.geometry = vehicle
57+
analyses.append(aerodynamics)
58+
59+
# ------------------------------------------------------------------
60+
# Energy
61+
# ------------------------------------------------------------------
62+
energy = SUAVE.Analyses.Energy.Energy()
63+
energy.network = vehicle.propulsors
64+
analyses.append(energy)
65+
66+
# ------------------------------------------------------------------
67+
# Planet Analysis
68+
# ------------------------------------------------------------------
69+
planet = SUAVE.Analyses.Planets.Planet()
70+
analyses.append(planet)
71+
72+
# ------------------------------------------------------------------
73+
# Atmosphere Analysis
74+
# ------------------------------------------------------------------
75+
atmosphere = SUAVE.Analyses.Atmospheric.US_Standard_1976()
76+
atmosphere.features.planet = planet.features
77+
analyses.append(atmosphere)
78+
79+
return analyses

Solar_UAV_Optimization/Missions.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Missions.py
2+
#
3+
# Created: Feb 2016, E. Botero
4+
# Modified:
5+
6+
# ----------------------------------------------------------------------
7+
# Imports
8+
# ----------------------------------------------------------------------
9+
10+
import SUAVE
11+
from SUAVE.Core import Units
12+
import time
13+
14+
import numpy as np
15+
16+
# ----------------------------------------------------------------------
17+
# Define the Mission
18+
# ----------------------------------------------------------------------
19+
20+
def setup(analyses):
21+
22+
# the mission container
23+
missions = SUAVE.Analyses.Mission.Mission.Container()
24+
missions.mission = mission(analyses)
25+
26+
return missions
27+
28+
def mission(analyses):
29+
30+
# ------------------------------------------------------------------
31+
# Initialize the Mission
32+
# ------------------------------------------------------------------
33+
34+
mission = SUAVE.Analyses.Mission.Sequential_Segments()
35+
mission.tag = 'mission'
36+
37+
mission.atmosphere = SUAVE.Attributes.Atmospheres.Earth.US_Standard_1976()
38+
mission.planet = SUAVE.Attributes.Planets.Earth()
39+
40+
# unpack Segments module
41+
Segments = SUAVE.Analyses.Mission.Segments
42+
43+
# base segment
44+
base_segment = Segments.Segment()
45+
base_segment.process.iterate.initials.initialize_battery = SUAVE.Methods.Missions.Segments.Common.Energy.initialize_battery
46+
47+
# ------------------------------------------------------------------
48+
# Cruise Segment: Constant Dynamic Pressure, Constant Altitude
49+
# ------------------------------------------------------------------
50+
51+
segment = SUAVE.Analyses.Mission.Segments.Cruise.Constant_Dynamic_Pressure_Constant_Altitude(base_segment)
52+
segment.tag = "cruise"
53+
54+
# connect vehicle configuration
55+
segment.analyses.extend(analyses.base)
56+
57+
# segment attributes
58+
segment.state.numerics.number_control_points = 50
59+
segment.dynamic_pressure = 115.0 * Units.pascals
60+
segment.start_time = time.strptime("Tue, Jun 21 11:00:00 2016", "%a, %b %d %H:%M:%S %Y",)
61+
segment.altitude = 1000.0 * Units.feet
62+
segment.distance = 1000.0 * Units.km
63+
segment.charge_ratio = 1.0
64+
segment.latitude = 37.4
65+
segment.longitude = -122.15
66+
segment.state.conditions.frames.wind.body_rotations[:,2] = 125.* Units.degrees
67+
68+
mission.append_segment(segment)
69+
70+
return mission

Solar_UAV_Optimization/Optimize.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Optimize.py
2+
#
3+
# Created: Feb 2016, E. Botero
4+
# Modified:
5+
6+
# ----------------------------------------------------------------------
7+
# Imports
8+
# ----------------------------------------------------------------------
9+
10+
from SUAVE.Core import Units, Data
11+
import numpy as np
12+
import Vehicles
13+
import Analyses
14+
import Missions
15+
import Procedure
16+
import Plot_Mission
17+
import SUAVE.Optimization.Package_Setups.scipy_setup as scipy_setup
18+
import SUAVE.Optimization.Package_Setups.pyopt_setup as pyopt_setup
19+
from SUAVE.Optimization.Nexus import Nexus
20+
21+
# ----------------------------------------------------------------------
22+
# Run the whole thing
23+
# ----------------------------------------------------------------------
24+
def main():
25+
26+
problem = setup()
27+
output = scipy_setup.SciPy_Solve(problem)
28+
29+
problem.translate(output)
30+
31+
Plot_Mission.plot_mission(problem.results.mission)
32+
33+
return
34+
35+
# ----------------------------------------------------------------------
36+
# Inputs, Objective, & Constraints
37+
# ----------------------------------------------------------------------
38+
39+
def setup():
40+
41+
nexus = Nexus()
42+
problem = Data()
43+
nexus.optimization_problem = problem
44+
45+
# -------------------------------------------------------------------
46+
# Inputs
47+
# -------------------------------------------------------------------
48+
49+
# [ tag , initial, [lb,ub], scaling, units ]
50+
problem.inputs = np.array([
51+
[ 'wing_area' , 0.5, ( 0.1, 1.5 ), 0.5, Units.meter ],
52+
[ 'aspect_ratio' , 10.0, ( 5.0, 20.0 ), 10.0, Units.less ],
53+
[ 'dynamic_pressure', 125.0, ( 1.0, 2000.0 ), 125.0, Units.pascals ],
54+
[ 'solar_ratio' , 0.0, ( 0.0, 0.97), 1.0, Units.less ],
55+
[ 'kv' , 800.0, ( 10.0, 1500.0 ), 800.0, Units['rpm/volt']],
56+
])
57+
58+
# -------------------------------------------------------------------
59+
# Objective
60+
# -------------------------------------------------------------------
61+
62+
# [ tag, scaling, units ]
63+
problem.objective = np.array([
64+
[ 'Nothing', 1. , Units.kg],####Optimize.py:
65+
])
66+
67+
# -------------------------------------------------------------------
68+
# Constraints
69+
# -------------------------------------------------------------------
70+
71+
# [ tag, sense, edge, scaling, units ]
72+
problem.constraints = np.array([
73+
[ 'energy_constraint', '=', 0.0, 1.0, Units.less],
74+
[ 'battery_mass' , '>', 0.0, 1.0, Units.kg ],
75+
[ 'CL' , '>', 0.0, 1.0, Units.less],
76+
[ 'Throttle_min' , '>', 0.0, 1.0, Units.less],
77+
[ 'Throttle_max' , '>', 0.0, 1.0, Units.less],
78+
])
79+
80+
# -------------------------------------------------------------------
81+
# Aliases
82+
# -------------------------------------------------------------------
83+
84+
# [ 'alias' , ['data.path1.name','data.path2.name'] ]
85+
problem.aliases = [
86+
[ 'wing_area' ,['vehicle_configurations.*.wings.main_wing.areas.reference',
87+
'vehicle_configurations.base.reference_area'] ],
88+
[ 'aspect_ratio' , 'vehicle_configurations.*.wings.main_wing.aspect_ratio' ],
89+
[ 'kv' , 'vehicle_configurations.*.propulsors.network.motor.speed_constant' ],
90+
[ 'battery_mass' , 'vehicle_configurations.base.propulsors.network.battery.mass_properties.mass'],
91+
[ 'solar_ratio' , 'vehicle_configurations.*.propulsors.network.solar_panel.ratio' ],
92+
[ 'dynamic_pressure' , 'missions.mission.segments.cruise.dynamic_pressure' ],
93+
[ 'Nothing' , 'summary.nothing' ],
94+
[ 'energy_constraint', 'summary.energy_constraint' ],
95+
[ 'CL' , 'summary.CL' ],
96+
[ 'Throttle_min' , 'summary.throttle_min' ],
97+
[ 'Throttle_max' , 'summary.throttle_max' ],
98+
]
99+
100+
# -------------------------------------------------------------------
101+
# Vehicles
102+
# -------------------------------------------------------------------
103+
nexus.vehicle_configurations = Vehicles.setup()
104+
105+
# -------------------------------------------------------------------
106+
# Analyses
107+
# -------------------------------------------------------------------
108+
nexus.analyses = Analyses.setup(nexus.vehicle_configurations)
109+
110+
# -------------------------------------------------------------------
111+
# Missions
112+
# -------------------------------------------------------------------
113+
nexus.missions = Missions.setup(nexus.analyses)
114+
115+
# -------------------------------------------------------------------
116+
# Procedure
117+
# -------------------------------------------------------------------
118+
nexus.procedure = Procedure.setup()
119+
120+
return nexus
121+
122+
if __name__ == '__main__':
123+
main()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Plot_Mission.py
2+
#
3+
# Created: Feb 2016, E. Botero
4+
# Modified:
5+
6+
# ----------------------------------------------------------------------
7+
# Imports
8+
# ----------------------------------------------------------------------
9+
10+
from SUAVE.Core import Units
11+
import pylab as plt
12+
13+
# ----------------------------------------------------------------------
14+
# Plot Mission
15+
# ----------------------------------------------------------------------
16+
def plot_mission(results,line_style='bo-'):
17+
18+
axis_font = {'fontname':'Arial', 'size':'14'}
19+
20+
# ------------------------------------------------------------------
21+
# Battery Energy
22+
# ------------------------------------------------------------------
23+
plt.figure("Battery Energy")
24+
axes = plt.gca()
25+
for i in range(len(results.segments)):
26+
time = results.segments[i].conditions.frames.inertial.time[:,0] / Units.min
27+
energy = results.segments[i].conditions.propulsion.battery_energy[:,0]
28+
axes.plot(time, energy, 'bo-')
29+
axes.set_xlabel('Time (mins)')
30+
axes.set_ylabel('Battery Energy (J)')
31+
axes.get_yaxis().get_major_formatter().set_scientific(False)
32+
axes.get_yaxis().get_major_formatter().set_useOffset(False)
33+
axes.grid(True)
34+
plt.savefig("opt_battery_energy.png")
35+
36+
# ------------------------------------------------------------------
37+
# Solar Flux
38+
# ------------------------------------------------------------------
39+
plt.figure("Solar Flux")
40+
axes = plt.gca()
41+
for i in range(len(results.segments)):
42+
time = results.segments[i].conditions.frames.inertial.time[:,0] / Units.min
43+
energy = results.segments[i].conditions.propulsion.solar_flux[:,0]
44+
axes.plot(time, energy, 'bo-')
45+
axes.set_xlabel('Time (mins)')
46+
axes.set_ylabel('Solar Flux ($W/m^{2}$)')
47+
axes.get_yaxis().get_major_formatter().set_scientific(False)
48+
axes.get_yaxis().get_major_formatter().set_useOffset(False)
49+
axes.grid(True)
50+
plt.savefig("opt_solar_flux.png")
51+
52+
# ------------------------------------------------------------------
53+
# Battery Draw
54+
# ------------------------------------------------------------------
55+
plt.figure("Battery Charging")
56+
axes = plt.gca()
57+
for i in range(len(results.segments)):
58+
time = results.segments[i].conditions.frames.inertial.time[:,0] / Units.min
59+
energy = results.segments[i].conditions.propulsion.battery_draw[:,0]
60+
axes.plot(time, energy, 'bo-')
61+
axes.set_xlabel('Time (mins)')
62+
axes.set_ylabel('Battery Charging (Watts)')
63+
axes.get_yaxis().get_major_formatter().set_scientific(False)
64+
axes.get_yaxis().get_major_formatter().set_useOffset(False)
65+
axes.grid(True)
66+
plt.savefig("opt_battery_draw.png")
67+
68+
plt.show()
69+
70+
return
71+
72+
if __name__ == '__main__':
73+
main()
74+
plt.show()

0 commit comments

Comments
 (0)