-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Implementation of Height Energy in SGM #97
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
d4fd2ac
Initial commit for Height Energy SGM phase
crecine ca34560
moved empty execcomp into a function to be shared amongst ODEs
crecine a7c18fc
Converted takeoff and landing ODEs to be compatible with SGM
crecine 27d6c12
Updated variable pass through from outer problem to SimuPy problem Ad…
crecine f3b8fcd
temp for debugging
crecine 7d3b46e
temp commit for debugging
crecine 2c4701f
Reduced usage of blocked_state_names by specifying states in more phases
crecine 2285655
Added ability to auto-promote all auto_ivs variables
crecine 5fc9c65
Added debug prints
crecine 4676eab
added more prints
crecine 6a6f5a6
Remove debug prints
crecine 0e6f3fc
Added SGM phases for detailed takeoff and landing
crecine 27490e8
Merge branch 'main' into flops_sgm
crecine 7349550
Switched from mission_ODE to simple_mission_ODE
crecine f4c7017
Converting simple_mission to SGM
crecine c53993d
Merge branch 'sgm-update' into flops_sgm
crecine 218e803
prepared for testing detailed takeoff and landing
crecine f5fff48
Merge branch 'main' into flops_sgm
crecine c999f70
Merge branch 'main' into flops_sgm
johnjasa f8596a1
Merge branch 'main' into flops_sgm
crecine f2fb553
cleaned up comments and removed unused values
crecine 62c1d20
Adding flexible triggers and removing unused trajectories
crecine a9e8b68
Using flexible triggers
crecine 28f9a78
fixed missing squeeze
crecine abd6143
Merge branch 'main' into flops_sgm
crecine 52ea87e
fixing units and type hint
crecine abd99f7
Merge branch 'main' into flops_sgm
crecine 6042876
Added some temporary debugging statements and tweaked triggers
crecine 8335270
added debug environment files to gitignore
crecine 33c0e8b
fixed typo
crecine 35bc9dd
adding phase names to ascent subphases and adding states to phases
crecine edec537
restoring descent estimation
crecine 546f1fa
reverted temporary debugging
crecine 104f765
Merge branch 'main' into flops_sgm
crecine 3ec4f9b
updated debug to verbosity
crecine 0856940
added a bench test for SGM and add some key to list conversion
crecine 6a9a2e3
Merge branch 'main' into flops_sgm
crecine afd6e8d
Merge branch 'main' into flops_sgm
crecine cfdb0da
moving HE SGM example to test case and minor refactoring
crecine ee630fe
Merge branch 'flops_sgm' of https://github.com/crecine/om-Aviary into…
crecine 5e912d0
adding skip for missing pyoptsparse
crecine 591a671
reverted test values
crecine 7b09c6e
minor changes to tests
crecine a4f04ed
fixed value when clearing triggers
crecine d5a24eb
PR feedback
crecine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ venv/ | |
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
.github/*_environment.yml | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
aviary/mission/flops_based/phases/test/test_time_integration_phases.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
import openmdao.api as om | ||
from openmdao.utils.assert_utils import assert_near_equal | ||
|
||
from aviary.interface.methods_for_level2 import AviaryGroup | ||
from aviary.mission.gasp_based.phases.time_integration_traj import FlexibleTraj | ||
from aviary.mission.flops_based.phases.time_integration_phases import \ | ||
SGMHeightEnergy, SGMDetailedTakeoff, SGMDetailedLanding | ||
from aviary.subsystems.premission import CorePreMission | ||
from aviary.utils.functions import set_aviary_initial_values | ||
from aviary.variable_info.enums import Verbosity | ||
from aviary.variable_info.variables import Aircraft, Dynamic, Mission | ||
from aviary.variable_info.variables_in import VariablesIn | ||
|
||
from aviary.interface.default_phase_info.height_energy import aero, prop, geom | ||
from aviary.subsystems.propulsion.engine_deck import EngineDeck | ||
from aviary.utils.process_input_decks import create_vehicle | ||
from aviary.utils.preprocessors import preprocess_propulsion | ||
from aviary.variable_info.variable_meta_data import _MetaData as BaseMetaData | ||
|
||
import warnings | ||
import unittest | ||
import importlib | ||
|
||
|
||
@unittest.skipUnless(importlib.util.find_spec("pyoptsparse") is not None, "pyoptsparse is not installed") | ||
class HE_SGMDescentTestCase(unittest.TestCase): | ||
def setUp(self): | ||
aviary_inputs, initial_guesses = create_vehicle( | ||
'models/test_aircraft/aircraft_for_bench_FwFm.csv') | ||
aviary_inputs.set_val(Aircraft.Engine.SCALED_SLS_THRUST, val=28690, units="lbf") | ||
aviary_inputs.set_val(Dynamic.Mission.THROTTLE, val=0, units="unitless") | ||
aviary_inputs.set_val(Mission.Takeoff.ROLLING_FRICTION_COEFFICIENT, | ||
val=0.0175, units="unitless") | ||
aviary_inputs.set_val(Mission.Takeoff.BRAKING_FRICTION_COEFFICIENT, | ||
val=0.35, units="unitless") | ||
ode_args = dict(aviary_options=aviary_inputs, core_subsystems=[prop, geom, aero]) | ||
preprocess_propulsion(aviary_inputs, [EngineDeck(options=aviary_inputs)]) | ||
|
||
ode_args['num_nodes'] = 1 | ||
ode_args['subsystem_options'] = {'core_aerodynamics': {'method': 'computed'}} | ||
|
||
self.ode_args = ode_args | ||
self.aviary_inputs = aviary_inputs | ||
self.tol = 1e-5 | ||
|
||
def setup_prob(self, phases) -> om.Problem: | ||
prob = om.Problem() | ||
prob.driver = om.pyOptSparseDriver() | ||
prob.driver.options["optimizer"] = 'IPOPT' | ||
prob.driver.opt_settings['tol'] = 1.0E-6 | ||
prob.driver.opt_settings['mu_init'] = 1e-5 | ||
prob.driver.opt_settings['max_iter'] = 50 | ||
prob.driver.opt_settings['print_level'] = 5 | ||
|
||
aviary_options = self.ode_args['aviary_options'] | ||
subsystems = self.ode_args['core_subsystems'] | ||
|
||
traj = FlexibleTraj( | ||
Phases=phases, | ||
promote_all_auto_ivc=True, | ||
traj_final_state_output=[Dynamic.Mission.MASS, | ||
Dynamic.Mission.DISTANCE, | ||
Dynamic.Mission.ALTITUDE], | ||
traj_initial_state_input=[ | ||
Dynamic.Mission.MASS, | ||
Dynamic.Mission.DISTANCE, | ||
Dynamic.Mission.ALTITUDE, | ||
], | ||
) | ||
prob.model = AviaryGroup(aviary_options=aviary_options, | ||
aviary_metadata=BaseMetaData) | ||
prob.model.add_subsystem( | ||
'pre_mission', | ||
CorePreMission(aviary_options=aviary_options, | ||
subsystems=subsystems), | ||
promotes_inputs=['aircraft:*', 'mission:*'], | ||
promotes_outputs=['aircraft:*', 'mission:*'] | ||
) | ||
prob.model.add_subsystem('traj', traj, | ||
promotes=['aircraft:*', 'mission:*'] | ||
) | ||
|
||
prob.model.add_subsystem( | ||
"fuel_obj", | ||
om.ExecComp( | ||
"reg_objective = overall_fuel/10000", | ||
reg_objective={"val": 0.0, "units": "unitless"}, | ||
overall_fuel={"units": "lbm"}, | ||
), | ||
promotes_inputs=[ | ||
("overall_fuel", Mission.Summary.TOTAL_FUEL_MASS), | ||
], | ||
promotes_outputs=[("reg_objective", Mission.Objectives.FUEL)], | ||
) | ||
|
||
prob.model.add_objective(Mission.Objectives.FUEL, ref=1e4) | ||
|
||
prob.model.add_subsystem( | ||
'input_sink', | ||
VariablesIn(aviary_options=self.aviary_inputs, | ||
meta_data=BaseMetaData), | ||
promotes_inputs=['*'], | ||
promotes_outputs=['*']) | ||
|
||
with warnings.catch_warnings(): | ||
|
||
# Set initial default values for all LEAPS aircraft variables. | ||
set_aviary_initial_values( | ||
prob.model, self.aviary_inputs, meta_data=BaseMetaData) | ||
|
||
warnings.simplefilter("ignore", om.PromotionWarning) | ||
|
||
prob.setup() | ||
|
||
return prob | ||
|
||
def run_simulation(self, phases, initial_values: dict): | ||
prob = self.setup_prob(phases) | ||
|
||
for key, val in initial_values.items(): | ||
prob.set_val(key, **val) | ||
|
||
prob.run_model() | ||
|
||
distance = prob.get_val('traj.distance_final', units='NM')[0] | ||
mass = prob.get_val('traj.mass_final', units='lbm')[0] | ||
alt = prob.get_val('traj.altitude_final', units='ft')[0] | ||
|
||
final_states = {'distance': distance, 'mass': mass, 'altitude': alt} | ||
return final_states | ||
|
||
# def test_takeoff(self): | ||
# initial_values_takeoff = { | ||
# "traj.altitude_initial": {'val': 0, 'units': "ft"}, | ||
# "traj.mass_initial": {'val': 171000, 'units': "lbm"}, | ||
# "traj.distance_initial": {'val': 0, 'units': "NM"}, | ||
# "traj.velocity": {'val': .1, 'units': "m/s"}, | ||
# } | ||
|
||
# ode_args = self.ode_args | ||
# ode_args['friction_key'] = Mission.Takeoff.ROLLING_FRICTION_COEFFICIENT | ||
# brake_release_to_decision = SGMDetailedTakeoff( | ||
# ode_args, | ||
# simupy_args=dict(verbosity=Verbosity.DEBUG,) | ||
# ) | ||
# brake_release_to_decision.clear_triggers() | ||
# brake_release_to_decision.add_trigger(Dynamic.Mission.VELOCITY, value=167.85, units='kn') | ||
|
||
# phases = {'HE': { | ||
# 'ode': brake_release_to_decision, | ||
# 'vals_to_set': {} | ||
# }} | ||
|
||
# final_states = self.run_simulation(phases, initial_values_takeoff) | ||
# # assert_near_equal(final_states['altitude'], 500, self.tol) | ||
# assert_near_equal(final_states['velocity'], 167.85, self.tol) | ||
|
||
def test_cruise(self): | ||
initial_values_cruise = { | ||
"traj.altitude_initial": {'val': 35000, 'units': "ft"}, | ||
"traj.mass_initial": {'val': 171000, 'units': "lbm"}, | ||
"traj.distance_initial": {'val': 0, 'units': "NM"}, | ||
"traj.mach": {'val': .8, 'units': "unitless"}, | ||
} | ||
|
||
SGMCruise = SGMHeightEnergy( | ||
self.ode_args, | ||
phase_name='cruise', | ||
simupy_args=dict(verbosity=Verbosity.QUIET,) | ||
) | ||
SGMCruise.triggers[0].value = 160000 | ||
|
||
phases = {'HE': { | ||
'ode': SGMCruise, | ||
'vals_to_set': {} | ||
}} | ||
|
||
final_states = self.run_simulation(phases, initial_values_cruise) | ||
assert_near_equal(final_states['mass'], 160000, self.tol) | ||
|
||
# def test_landing(self): | ||
# initial_values_landing = { | ||
# "traj.altitude_initial": {'val': 35000, 'units': "ft"}, | ||
# "traj.mass_initial": {'val': 171000, 'units': "lbm"}, | ||
# "traj.distance_initial": {'val': 0, 'units': "NM"}, | ||
# "traj.velocity": {'val': 300, 'units': "m/s"}, | ||
# } | ||
|
||
# ode_args = self.ode_args | ||
# ode_args['friction_key'] = Mission.Takeoff.BRAKING_FRICTION_COEFFICIENT | ||
# phases = {'HE': { | ||
# 'ode': SGMDetailedLanding( | ||
# ode_args, | ||
# simupy_args=dict(verbosity=Verbosity.QUIET,) | ||
# ), | ||
# 'vals_to_set': {} | ||
# }} | ||
|
||
# final_states = self.run_simulation(phases, initial_values_landing) | ||
# assert_near_equal(final_states['altitude'], 0, self.tol) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of wonder why the default is 2 for colocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's what it was on line 208, so I didn't want to change it.