Skip to content

Commit

Permalink
Merge branch 'OpenMDAO:main' into dynamic_option
Browse files Browse the repository at this point in the history
  • Loading branch information
xjjiang authored May 28, 2024
2 parents 427888b + 14c0a6d commit dfb7241
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 47 deletions.
10 changes: 10 additions & 0 deletions aviary/interface/methods_for_level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
This file contains functions needed to run Aviary using the Level 1 interface.
"""
import os
from importlib.machinery import SourceFileLoader
from pathlib import Path

import openmdao.api as om
from aviary.variable_info.enums import AnalysisScheme, Verbosity
from aviary.interface.methods_for_level2 import AviaryProblem
from aviary.utils.functions import get_path


def run_aviary(aircraft_filename, phase_info, optimizer=None,
Expand Down Expand Up @@ -122,6 +124,14 @@ def run_level_1(
# else:
kwargs['optimizer'] = optimizer

if isinstance(phase_info, str):
phase_info_path = get_path(phase_info)
phase_info_file = SourceFileLoader(
"phase_info_file", str(phase_info_path)).load_module()
phase_info = getattr(phase_info_file, 'phase_info')
kwargs['phase_info_parameterization'] = getattr(
phase_info_file, 'phase_info_parameterization', None)

prob = run_aviary(input_deck, phase_info, **kwargs)

if n2:
Expand Down
6 changes: 6 additions & 0 deletions aviary/interface/test/test_cmd_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def bench_test_IPOPT_cmd(self):
' --optimizer IPOPT --max_iter 1 --shooting'
self.run_and_test_cmd(cmd)

@require_pyoptsparse(optimizer="IPOPT")
def bench_test_phase_info_cmd(self):
cmd = 'aviary run_mission models/test_aircraft/aircraft_for_bench_GwGm.csv --optimizer IPOPT --max_iter 1' \
' --phase_info interface/default_phase_info/two_dof.py'
self.run_and_test_cmd(cmd)

def test_diff_configuration_conversion(self):
filepath = pkg_resources.resource_filename('aviary',
'models/test_aircraft/converter_configuration_test_data_GwGm.dat')
Expand Down
9 changes: 1 addition & 8 deletions aviary/mission/gasp_based/ode/climb_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def initialize(self):
)

def setup(self):
self.options['auto_order'] = True
nn = self.options["num_nodes"]
analysis_scheme = self.options["analysis_scheme"]
aviary_options = self.options['aviary_options']
Expand Down Expand Up @@ -148,7 +149,6 @@ def setup(self):
kwargs = {'num_nodes': nn, 'aviary_inputs': aviary_options,
'method': 'cruise'}
# collect the propulsion group names for later use with
prop_groups = []
for subsystem in core_subsystems:
system = subsystem.build_mission(**kwargs)
if system is not None:
Expand All @@ -159,9 +159,6 @@ def setup(self):
**kwargs),
promotes_outputs=subsystem.mission_outputs(**kwargs))
else:
if isinstance(subsystem, PropulsionBuilderBase):
prop_groups.append(subsystem.name)

self.add_subsystem(subsystem.name,
system,
promotes_inputs=subsystem.mission_inputs(
Expand Down Expand Up @@ -221,10 +218,6 @@ def setup(self):
# the last two subsystems will also be used for constraints
self.add_excess_rate_comps(nn)

if analysis_scheme is AnalysisScheme.COLLOCATION:
self.set_order(['params', 'USatm', 'mach_balance_group'] + prop_groups +
['lift_balance_group', 'constraints', 'SPECIFIC_ENERGY_RATE_EXCESS', 'ALTITUDE_RATE_MAX'])

ParamPort.set_default_vals(self)
self.set_input_defaults("CL_max", val=5 * np.ones(nn), units="unitless")
self.set_input_defaults(Dynamic.Mission.ALTITUDE,
Expand Down
21 changes: 2 additions & 19 deletions aviary/mission/gasp_based/ode/descent_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def initialize(self):
)

def setup(self):
self.options['auto_order'] = True
nn = self.options["num_nodes"]
analysis_scheme = self.options["analysis_scheme"]
aviary_options = self.options['aviary_options']
Expand Down Expand Up @@ -94,6 +95,7 @@ def setup(self):
"mach_balance_group", subsys=om.Group(), promotes=["*"]
)

mach_balance_group.options['auto_order'] = True
mach_balance_group.nonlinear_solver = om.NewtonSolver()
mach_balance_group.nonlinear_solver.options["solve_subsystems"] = True
mach_balance_group.nonlinear_solver.options["iprint"] = 0
Expand Down Expand Up @@ -205,7 +207,6 @@ def setup(self):
kwargs = {'num_nodes': nn, 'aviary_inputs': aviary_options,
'method': 'cruise'}
# collect the propulsion group names for later use
prop_groups = []
for subsystem in core_subsystems:
system = subsystem.build_mission(**kwargs)
if system is not None:
Expand All @@ -216,9 +217,6 @@ def setup(self):
**kwargs),
promotes_outputs=subsystem.mission_outputs(**kwargs))
else:
if isinstance(subsystem, PropulsionBuilderBase):
prop_groups.append(subsystem.name)

self.add_subsystem(subsystem.name,
system,
promotes_inputs=subsystem.mission_inputs(
Expand All @@ -234,21 +232,6 @@ def setup(self):
# the last two subsystems will also be used for constraints
self.add_excess_rate_comps(nn)

if analysis_scheme is AnalysisScheme.COLLOCATION:
fc_loc = ['fc']
if input_speed_type is SpeedType.MACH:
mach_balance_group.set_order(['speed_bal', 'fc', 'speeds', 'ks'])
fc_loc = ['mach_balance_group']
# TODO this assumes the name of propulsion subsystem, need to pull from
# the subsystem itself
self.set_order(['params',
'USatm',] +
fc_loc+prop_groups +
['lift_balance_group',
'constraints',
'SPECIFIC_ENERGY_RATE_EXCESS',
'ALTITUDE_RATE_MAX'])

ParamPort.set_default_vals(self)
self.set_input_defaults(Dynamic.Mission.ALTITUDE,
val=37500 * np.ones(nn), units="ft")
Expand Down
16 changes: 1 addition & 15 deletions aviary/mission/gasp_based/ode/flight_path_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def initialize(self):
desc="If true then no flaps or gear are included. Useful for high-speed flight phases.")

def setup(self):
self.options['auto_order'] = True
nn = self.options["num_nodes"]
aviary_options = self.options['aviary_options']
alpha_mode = self.options['alpha_mode']
Expand Down Expand Up @@ -109,7 +110,6 @@ def setup(self):
promotes_outputs=[Dynamic.Mission.DYNAMIC_PRESSURE,] + speed_outputs,
)

lift_comp = []
if alpha_mode is AlphaModes.DEFAULT:
# alpha as input
pass
Expand Down Expand Up @@ -141,7 +141,6 @@ def setup(self):
],
promotes_outputs=['required_lift']
)
lift_comp = ['calc_weight', 'calc_lift']
self.AddAlphaControl(alpha_mode=alpha_mode, target_load_factor=1,
atol=1e-6, rtol=1e-12, num_nodes=nn, print_level=print_level)

Expand Down Expand Up @@ -211,7 +210,6 @@ def setup(self):
self.add_excess_rate_comps(nn)

# Example of how to use a print_comp
debug_comp = []
if False:
from aviary.utils.functions import create_printcomp
dummy_comp = create_printcomp(
Expand Down Expand Up @@ -253,18 +251,6 @@ def setup(self):
],
)

self.set_order(['params', 'USatm', 'fc',
] + lift_comp + [
'core_aerodynamics',
'alpha_comp',
'prop_group',
'flight_path_eom',
'mass_trigger',
'SPECIFIC_ENERGY_RATE_EXCESS',
'ALTITUDE_RATE_MAX',
] +
debug_comp)

ParamPort.set_default_vals(self)
if not self.options["clean"]:
self.set_input_defaults("t_init_flaps", val=47.5)
Expand Down
13 changes: 8 additions & 5 deletions aviary/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,14 @@ def get_path(path: [str, Path], verbose: bool = False) -> Path:

# If the path still doesn't exist, attempt to find it in the models directory.
if not path.exists():
hangar_based_path = get_model(original_path)
if verbose:
print(
f"Unable to locate '{aviary_based_path}' as an Aviary package path, checking built-in models")
path = hangar_based_path
try:
hangar_based_path = get_model(original_path)
if verbose:
print(
f"Unable to locate '{aviary_based_path}' as an Aviary package path, checking built-in models")
path = hangar_based_path
except FileNotFoundError:
pass

# If the path still doesn't exist in any of the prioritized locations, raise an error.
if not path.exists():
Expand Down

0 comments on commit dfb7241

Please sign in to comment.