Skip to content

Commit

Permalink
Merge pull request OpenMDAO#280 from jkirk5/external_engine
Browse files Browse the repository at this point in the history
Fixes to allow use of external engine models & multiple engines using L2 interface
  • Loading branch information
jkirk5 authored Jun 18, 2024
2 parents ec4f212 + 9e0057a commit 9c83a46
Show file tree
Hide file tree
Showing 87 changed files with 1,049 additions and 767 deletions.
2 changes: 1 addition & 1 deletion aviary/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from aviary.utils.options import list_options
from aviary.constants import GRAV_METRIC_GASP, GRAV_ENGLISH_GASP, GRAV_METRIC_FLOPS, GRAV_ENGLISH_FLOPS, GRAV_ENGLISH_LBM, RHO_SEA_LEVEL_ENGLISH, RHO_SEA_LEVEL_METRIC, MU_TAKEOFF, MU_LANDING, PSLS_PSF, TSLS_DEGR, RADIUS_EARTH_METRIC
from aviary.subsystems.test.subsystem_tester import TestSubsystemBuilderBase, skipIfMissingDependencies
from aviary.interface.default_phase_info.height_energy import default_premission_subsystems, default_mission_subsystems
from aviary.subsystems.propulsion.utils import build_engine_deck

###################
# Level 3 Imports #
Expand Down
2 changes: 1 addition & 1 deletion aviary/docs/getting_started/onboarding_ext_subsystem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions aviary/docs/getting_started/onboarding_level2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -764,7 +764,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
52 changes: 31 additions & 21 deletions aviary/docs/getting_started/onboarding_level3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
"driver.opt_settings[\"tol\"] = 1e-3\n",
"driver.opt_settings['print_level'] = 4\n",
"\n",
"##########################################\n",
"# Aircraft Input Variables and Options #\n",
"##########################################\n",
"########################################\n",
"# Aircraft Input Variables and Options #\n",
"########################################\n",
"\n",
"aviary_inputs = get_flops_inputs('N3CC')\n",
"\n",
Expand Down Expand Up @@ -154,9 +154,21 @@
"t_f_descent = 461.62*_units.minute\n",
"t_duration_descent = t_f_descent - t_i_descent\n",
"\n",
"##########################\n",
"# Design Variables #\n",
"##########################\n",
"engine = av.build_engine_deck(aviary_inputs)\n",
"av.preprocess_options(aviary_inputs, engine_models=engine)\n",
"\n",
"# define subsystems\n",
"aero = av.CoreAerodynamicsBuilder(code_origin=av.LegacyCode('FLOPS'))\n",
"geom = av.CoreGeometryBuilder(code_origin=av.LegacyCode('FLOPS'))\n",
"mass = av.CoreMassBuilder(code_origin=av.LegacyCode('FLOPS'))\n",
"prop = av.CorePropulsionBuilder(engine_models=engine)\n",
"\n",
"premission_subsystems = [prop, geom, aero, mass]\n",
"mission_subsystems = [aero, prop]\n",
"\n",
"####################\n",
"# Design Variables #\n",
"####################\n",
"\n",
"# Nudge it a bit off the correct answer to verify that the optimize takes us there.\n",
"aviary_inputs.set_val(av.Mission.Design.GROSS_MASS, 135000.0, units='lbm')\n",
Expand All @@ -170,9 +182,9 @@
" num_engines=aviary_inputs.get_val(av.Aircraft.Engine.NUM_ENGINES)\n",
")\n",
"\n",
"##################\n",
"# Define Phases #\n",
"##################\n",
"#################\n",
"# Define Phases #\n",
"#################\n",
"num_segments_climb = 6\n",
"num_segments_cruise = 1\n",
"num_segments_descent = 5\n",
Expand Down Expand Up @@ -200,7 +212,7 @@
" 'input_initial': (True, 'unitless'),\n",
" 'use_polynomial_control': (False, 'unitless'),\n",
" }),\n",
" core_subsystems=av.default_mission_subsystems,\n",
" core_subsystems=mission_subsystems,\n",
" subsystem_options={'core_aerodynamics': {'method': 'computed'}},\n",
" transcription=transcription_climb,\n",
")\n",
Expand All @@ -215,7 +227,7 @@
" 'required_available_climb_rate': (300, 'ft/min'),\n",
" 'fix_initial': (False, 'unitless'),\n",
" }),\n",
" core_subsystems=av.default_mission_subsystems,\n",
" core_subsystems=mission_subsystems,\n",
" subsystem_options={'core_aerodynamics': {'method': 'computed'}},\n",
" transcription=transcription_cruise,\n",
")\n",
Expand All @@ -230,7 +242,7 @@
" 'fix_initial': (False, 'unitless'),\n",
" 'use_polynomial_control': (False, 'unitless'),\n",
" }),\n",
" core_subsystems=av.default_mission_subsystems,\n",
" core_subsystems=mission_subsystems,\n",
" subsystem_options={'core_aerodynamics': {'method': 'computed'}},\n",
" transcription=transcription_descent,\n",
")\n",
Expand All @@ -241,13 +253,11 @@
" av.Mission.Landing.LIFT_COEFFICIENT_MAX) # no units\n",
")\n",
"\n",
"av.preprocess_crewpayload(aviary_inputs)\n",
"\n",
"# Upstream static analysis for aero\n",
"prob.model.add_subsystem(\n",
" 'pre_mission',\n",
" av.CorePreMission(aviary_options=aviary_inputs,\n",
" subsystems=av.default_premission_subsystems),\n",
" subsystems=premission_subsystems),\n",
" promotes_inputs=['aircraft:*', 'mission:*'],\n",
" promotes_outputs=['aircraft:*', 'mission:*'])\n",
"\n",
Expand Down Expand Up @@ -298,9 +308,9 @@
" 'landing', landing, promotes_inputs=['aircraft:*', 'mission:*'],\n",
" promotes_outputs=['mission:*'])\n",
"\n",
"##########################################\n",
"# link phases #\n",
"##########################################\n",
"###############\n",
"# link phases #\n",
"###############\n",
"\n",
"traj.link_phases([\"climb\", \"cruise\", \"descent\"], [\"time\", av.Dynamic.Mission.MASS, av.Dynamic.Mission.DISTANCE], connected=strong_couple)\n",
"\n",
Expand Down Expand Up @@ -336,9 +346,9 @@
"prob.model.connect('traj.descent.control_values:altitude', av.Mission.Landing.INITIAL_ALTITUDE,\n",
" src_indices=[-1])\n",
"\n",
"##########################\n",
"# Constraints #\n",
"##########################\n",
"###############\n",
"# Constraints #\n",
"###############\n",
"\n",
"ecomp = om.ExecComp('fuel_burned = initial_mass - descent_mass_final',\n",
" initial_mass={'units': 'lbm', 'shape': 1},\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"\n",
"from aviary.models.N3CC.N3CC_data import inputs\n",
"\n",
"aviary_options = inputs.deepcopy()\n",
"\n",
"# This builder can be used for both takeoff and landing phases\n",
"aero_builder = av.CoreAerodynamicsBuilder(\n",
" name='low_speed_aero',\n",
Expand Down Expand Up @@ -79,7 +81,8 @@
"\n",
"# We also need propulsion analysis for takeoff and landing. No additional configuration\n",
"# is needed for this builder\n",
"prop_builder = av.CorePropulsionBuilder()"
"engine = av.build_engine_deck(aviary_options)\n",
"prop_builder = av.CorePropulsionBuilder(engine_models=engine)"
]
},
{
Expand Down Expand Up @@ -254,10 +257,9 @@
" takeoff_mic_p2_builder, takeoff_mic_p2_to_engine_cutback_builder,\n",
" takeoff_engine_cutback_builder, takeoff_engine_cutback_to_mic_p1_builder,\n",
" takeoff_mic_p1_to_climb_builder, takeoff_liftoff_user_options)\n",
"from aviary.utils.test_utils.default_subsystems import get_default_premission_subsystems\n",
"\n",
"\n",
"aviary_options = inputs.deepcopy()\n",
"\n",
"takeoff_trajectory_builder = av.DetailedTakeoffTrajectoryBuilder('detailed_takeoff')\n",
"\n",
"takeoff_trajectory_builder.set_brake_release_to_decision_speed(\n",
Expand All @@ -283,12 +285,15 @@
"\n",
"takeoff = om.Problem()\n",
"\n",
"# default subsystems\n",
"default_premission_subsystems = get_default_premission_subsystems('FLOPS', engine)\n",
" \n",
"# Upstream pre-mission analysis for aero\n",
"takeoff.model.add_subsystem(\n",
" 'core_subsystems',\n",
" av.CorePreMission(\n",
" aviary_options=aviary_options,\n",
" subsystems=av.default_premission_subsystems,\n",
" subsystems=default_premission_subsystems,\n",
" ),\n",
" promotes_inputs=['*'],\n",
" promotes_outputs=['*'])\n",
Expand Down Expand Up @@ -541,7 +546,7 @@
" 'core_subsystems',\n",
" av.CorePreMission(\n",
" aviary_options=aviary_options,\n",
" subsystems=av.default_premission_subsystems,\n",
" subsystems=default_premission_subsystems,\n",
" ),\n",
" promotes_inputs=['*'],\n",
" promotes_outputs=['*'])\n",
Expand Down Expand Up @@ -581,7 +586,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -595,7 +600,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,24 @@
"import dymos as dm\n",
"\n",
"import aviary.api as av\n",
"from aviary.utils.test_utils.default_subsystems import get_default_mission_subsystems\n",
"\n",
"\n",
"prob = om.Problem(model=om.Group())\n",
"driver = prob.driver = om.ScipyOptimizeDriver()\n",
"driver.options[\"optimizer\"] = \"SLSQP\"\n",
"driver.options[\"maxiter\"] = 1\n",
"\n",
"##########################################\n",
"# Aircraft Input Variables and Options #\n",
"##########################################\n",
"########################################\n",
"# Aircraft Input Variables and Options #\n",
"########################################\n",
"\n",
"csv_path = \"models/test_aircraft/aircraft_for_bench_FwFm.csv\"\n",
"\n",
"aviary_inputs, _ = av.create_vehicle('models/test_aircraft/aircraft_for_bench_FwFm.csv')\n",
"\n",
"engine = av.EngineDeck(options=aviary_inputs)\n",
"av.preprocess_propulsion(aviary_inputs, [engine])\n",
"engine = av.build_engine_deck(aviary_inputs)\n",
"av.preprocess_options(aviary_inputs, engine_models=engine)\n",
"\n",
"alt_airport = 0 # ft\n",
"\n",
Expand Down Expand Up @@ -250,19 +251,33 @@
"t_f_descent = 299. * _units.minute\n",
"t_duration_descent = t_f_descent - t_i_descent\n",
"\n",
"##########################\n",
"# Design Variables #\n",
"##########################\n",
"####################\n",
"# Build Subsystems #\n",
"####################\n",
"aero = av.CoreAerodynamicsBuilder(code_origin=av.LegacyCode('FLOPS'))\n",
"geom = av.CoreGeometryBuilder(code_origin=av.LegacyCode('FLOPS'))\n",
"mass = av.CoreMassBuilder(code_origin=av.LegacyCode('FLOPS'))\n",
"prop = av.CorePropulsionBuilder(engine_models=engine)\n",
"\n",
"premission_subsystems = [prop, geom, aero, mass]\n",
"mission_subsystems = [aero, prop]\n",
"\n",
"####################\n",
"# Design Variables #\n",
"####################\n",
"\n",
"# Nudge it a bit off the correct answer to verify that the optimize takes us there.\n",
"aviary_inputs.set_val(av.Mission.Design.GROSS_MASS, 135000.0, units='lbm')\n",
"\n",
"prob.model.add_design_var(av.Mission.Design.GROSS_MASS, units='lbm',\n",
" lower=100000.0, upper=200000.0, ref=135000)\n",
"\n",
"##################\n",
"# Define Phases #\n",
"##################\n",
"# default subsystems\n",
"default_mission_subsystems = get_default_mission_subsystems('FLOPS', engine)\n",
"\n",
"#################\n",
"# Define Phases #\n",
"#################\n",
"num_segments_climb = 6\n",
"num_segments_cruise = 1\n",
"num_segments_descent = 5\n",
Expand All @@ -289,7 +304,7 @@
" 'fix_initial': (True, 'unitless'),\n",
" 'use_polynomial_control': (False, 'unitless'),\n",
" }),\n",
" core_subsystems=av.default_mission_subsystems,\n",
" core_subsystems=default_mission_subsystems,\n",
" subsystem_options={'core_aerodynamics': {'method': 'computed'}},\n",
" transcription=transcription_climb,\n",
")\n",
Expand All @@ -304,7 +319,7 @@
" 'required_available_climb_rate': (300, 'ft/min'),\n",
" 'fix_initial': (False, 'unitless'),\n",
" }),\n",
" core_subsystems=av.default_mission_subsystems,\n",
" core_subsystems=default_mission_subsystems,\n",
" subsystem_options={'core_aerodynamics': {'method': 'computed'}},\n",
" transcription=transcription_cruise,\n",
")\n",
Expand All @@ -319,7 +334,7 @@
" 'fix_initial': (False, 'unitless'),\n",
" 'use_polynomial_control': (False, 'unitless'),\n",
" }),\n",
" core_subsystems=av.default_mission_subsystems,\n",
" core_subsystems=default_mission_subsystems,\n",
" subsystem_options={'core_aerodynamics': {'method': 'computed'}},\n",
" transcription=transcription_descent,\n",
")\n",
Expand All @@ -330,7 +345,7 @@
"prob.model.add_subsystem(\n",
" 'pre_mission',\n",
" av.CorePreMission(aviary_options=aviary_inputs,\n",
" subsystems=av.default_premission_subsystems),\n",
" subsystems=premission_subsystems),\n",
" promotes_inputs=['aircraft:*', 'mission:*'],\n",
" promotes_outputs=['aircraft:*', 'mission:*'])\n",
"\n",
Expand Down Expand Up @@ -390,9 +405,9 @@
"traj = av.setup_trajectory_params(prob.model, traj, aviary_inputs, \n",
" external_parameters=external_parameters)\n",
"\n",
"##########################\n",
"# Constraints #\n",
"##########################\n",
"###############\n",
"# Constraints #\n",
"###############\n",
"\n",
"ecomp = om.ExecComp('fuel_burned = initial_mass - descent_mass_final',\n",
" initial_mass={'units': 'lbm', 'shape': 1},\n",
Expand Down Expand Up @@ -425,9 +440,9 @@
"\n",
"prob.setup(force_alloc_complex=True)\n",
"\n",
"###########################################\n",
"############################################\n",
"# Initial Settings for States and Controls #\n",
"###########################################\n",
"############################################\n",
"\n",
"prob.set_val('traj.climb.t_initial', t_i_climb, units='s')\n",
"prob.set_val('traj.climb.t_duration', t_duration_climb, units='s')\n",
Expand Down
18 changes: 1 addition & 17 deletions aviary/interface/default_phase_info/height_energy.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
from aviary.subsystems.propulsion.propulsion_builder import CorePropulsionBuilder
from aviary.subsystems.geometry.geometry_builder import CoreGeometryBuilder
from aviary.subsystems.mass.mass_builder import CoreMassBuilder
from aviary.subsystems.aerodynamics.aerodynamics_builder import CoreAerodynamicsBuilder
from aviary.variable_info.variable_meta_data import _MetaData as BaseMetaData
from aviary.variable_info.variables import Dynamic, Mission
from aviary.variable_info.enums import LegacyCode

FLOPS = LegacyCode.FLOPS

prop = CorePropulsionBuilder('core_propulsion', BaseMetaData)
mass = CoreMassBuilder('core_mass', BaseMetaData, FLOPS)
aero = CoreAerodynamicsBuilder('core_aerodynamics', BaseMetaData, FLOPS)
geom = CoreGeometryBuilder('core_geometry', BaseMetaData, FLOPS)

default_premission_subsystems = [prop, geom, mass, aero]
default_mission_subsystems = [aero, prop]
from aviary.variable_info.variables import Mission


phase_info = {
Expand Down
Loading

0 comments on commit 9c83a46

Please sign in to comment.