Skip to content

Commit

Permalink
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
xjjiang authored Dec 17, 2024
2 parents d6fa153 + 7b2ef9f commit 6033e46
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 62 deletions.
3 changes: 2 additions & 1 deletion aviary/mission/gasp_based/ode/test/test_accel_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from aviary.utils.test_utils.default_subsystems import get_default_mission_subsystems
from aviary.utils.test_utils.IO_test_util import check_prob_outputs
from aviary.variable_info.options import get_option_defaults
from aviary.variable_info.variables import Dynamic
from aviary.variable_info.variables import Aircraft, Dynamic


class AccelerationODETestCase(unittest.TestCase):
Expand All @@ -21,6 +21,7 @@ def setUp(self):
self.prob = om.Problem()

aviary_options = get_option_defaults()
aviary_options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)
default_mission_subsystems = get_default_mission_subsystems(
'GASP', build_engine_deck(aviary_options))

Expand Down
3 changes: 2 additions & 1 deletion aviary/mission/gasp_based/ode/test/test_ascent_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from aviary.subsystems.propulsion.utils import build_engine_deck
from aviary.utils.test_utils.default_subsystems import get_default_mission_subsystems
from aviary.variable_info.options import get_option_defaults
from aviary.variable_info.variables import Dynamic
from aviary.variable_info.variables import Aircraft, Dynamic


class AscentODETestCase(unittest.TestCase):
def setUp(self):
self.prob = om.Problem()

aviary_options = get_option_defaults()
aviary_options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)
default_mission_subsystems = get_default_mission_subsystems(
'GASP', build_engine_deck(aviary_options))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from aviary.subsystems.propulsion.utils import build_engine_deck
from aviary.utils.test_utils.default_subsystems import get_default_mission_subsystems
from aviary.variable_info.options import get_option_defaults
from aviary.variable_info.variables import Dynamic
from aviary.variable_info.variables import Aircraft, Dynamic


class CruiseODETestCase(unittest.TestCase):
def setUp(self):
self.prob = om.Problem()

aviary_options = get_option_defaults()
aviary_options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)
default_mission_subsystems = get_default_mission_subsystems(
'GASP', build_engine_deck(aviary_options))

Expand Down
4 changes: 3 additions & 1 deletion aviary/mission/gasp_based/ode/test/test_climb_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ def setUp(self):
self.prob = om.Problem()

aviary_options = get_option_defaults()
aviary_options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)

default_mission_subsystems = get_default_mission_subsystems(
'GASP', build_engine_deck(aviary_options))

self.sys = self.prob.model = ClimbODE(
num_nodes=1,
EAS_target=250,
mach_cruise=0.8,
aviary_options=get_option_defaults(),
aviary_options=aviary_options,
core_subsystems=default_mission_subsystems
)

Expand Down
3 changes: 2 additions & 1 deletion aviary/mission/gasp_based/ode/test/test_flight_path_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aviary.utils.test_utils.default_subsystems import get_default_mission_subsystems
from aviary.utils.test_utils.IO_test_util import check_prob_outputs
from aviary.variable_info.options import get_option_defaults
from aviary.variable_info.variables import Dynamic
from aviary.variable_info.variables import Aircraft, Dynamic


class FlightPathODETestCase(unittest.TestCase):
Expand All @@ -22,6 +22,7 @@ def setUp(self):
self.prob = om.Problem()

aviary_options = get_option_defaults()
aviary_options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)
default_mission_subsystems = get_default_mission_subsystems(
'GASP', build_engine_deck(aviary_options))

Expand Down
3 changes: 2 additions & 1 deletion aviary/mission/gasp_based/ode/test/test_groundroll_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from aviary.utils.test_utils.default_subsystems import get_default_mission_subsystems
from aviary.utils.test_utils.IO_test_util import check_prob_outputs
from aviary.variable_info.options import get_option_defaults
from aviary.variable_info.variables import Dynamic
from aviary.variable_info.variables import Aircraft, Dynamic


class GroundrollODETestCase(unittest.TestCase):
Expand All @@ -21,6 +21,7 @@ def setUp(self):
self.prob = om.Problem()

aviary_options = get_option_defaults()
aviary_options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)
default_mission_subsystems = get_default_mission_subsystems(
'GASP', build_engine_deck(aviary_options))

Expand Down
1 change: 1 addition & 0 deletions aviary/mission/gasp_based/ode/test/test_rotation_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def setUp(self):
self.prob = om.Problem()

aviary_options = get_option_defaults()
aviary_options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)
default_mission_subsystems = get_default_mission_subsystems(
'GASP', build_engine_deck(aviary_options))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ aircraft:design:structural_mass_increment,0,lbm
aircraft:design:supercritical_drag_shift,0.033,unitless
aircraft:engine:additional_mass_fraction,0.14,unitless
aircraft:engine:data_file,models/engines/turbofan_23k_1.deck,unitless
aircraft:engine:global_throttle, True, unitless
aircraft:engine:mass_scaler,1,unitless
aircraft:engine:mass_specific,0.21366,lbm/lbf
aircraft:engine:num_engines,2,unitless
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ aircraft:design:structural_mass_increment,0,lbm
aircraft:design:supercritical_drag_shift,0.025,unitless
aircraft:engine:additional_mass_fraction,0.14,unitless
aircraft:engine:data_file,models/engines/turbofan_23k_1.deck,unitless
aircraft:engine:global_throttle, True, unitless
aircraft:engine:mass_scaler,1,unitless
aircraft:engine:mass_specific,0.2153,lbm/lbf
aircraft:engine:num_engines,2,unitless
Expand Down
1 change: 1 addition & 0 deletions aviary/models/test_aircraft/aircraft_for_bench_FwGm.csv
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ aircraft:design:structural_mass_increment,0,lbm
aircraft:design:supercritical_drag_shift,0.033,unitless
aircraft:engine:constant_fuel_consumption,0.,lbm/h
aircraft:engine:data_file,models/engines/turbofan_23k_1.deck,unitless
aircraft:engine:global_throttle, True, unitless
aircraft:engine:enable_sizing,False,unitless
aircraft:engine:mass_specific,0.21366,lbm/lbf
aircraft:engine:fuel_flow_scaler_constant_term,0.,unitless
Expand Down
1 change: 1 addition & 0 deletions aviary/models/test_aircraft/aircraft_for_bench_GwGm.csv
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ aircraft:design:structural_mass_increment,0,lbm
aircraft:design:supercritical_drag_shift,0.033,unitless
aircraft:engine:additional_mass_fraction,0.135,unitless
aircraft:engine:data_file,models/engines/turbofan_23k_1.deck,unitless
aircraft:engine:global_throttle, True, unitless
aircraft:engine:mass_scaler,1,unitless
aircraft:engine:mass_specific,0.21366,lbm/lbf
aircraft:engine:mass_scaler,1,unitless
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ aircraft:design:structural_mass_increment,0,lbm
aircraft:design:supercritical_drag_shift,0.033,unitless
aircraft:engine:additional_mass_fraction,0.135,unitless
aircraft:engine:data_file,models/engines/turbofan_23k_1_lbm_s.deck,unitless
aircraft:engine:global_throttle, True, unitless
aircraft:engine:mass_scaler,1,unitless
aircraft:engine:mass_specific,0.21366,lbm/lbf
aircraft:engine:mass_scaler,1,unitless
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ aircraft:design:structural_mass_increment,0,lbm
aircraft:design:supercritical_drag_shift,0.033,unitless
aircraft:engine:additional_mass_fraction,0.165,unitless
aircraft:engine:data_file,models/engines/turbofan_23k_1.deck,unitless
aircraft:engine:global_throttle,True
aircraft:engine:mass_scaler,1,unitless
aircraft:engine:mass_specific,0.21366,lbm/lbf
aircraft:engine:num_engines,2,unitless
Expand Down
44 changes: 28 additions & 16 deletions aviary/subsystems/propulsion/engine_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@

# EngineDecks internally require these options to have values. Input checks will set
# these options to default values in self.options if they are not provided
# TODO should this instead be a set to prevent duplicates?
required_options = (
Aircraft.Engine.SCALE_PERFORMANCE,
Aircraft.Engine.IGNORE_NEGATIVE_THRUST,
Expand All @@ -109,7 +108,7 @@
# TODO fuel flow scaler is required for the EngineScaling component but does not need
# to be defined on a per-engine basis, so it could exist only in the problem-
# level aviary_options without issue. Is this a propulsion_preprocessor task?
Mission.Summary.FUEL_FLOW_SCALER
Mission.Summary.FUEL_FLOW_SCALER,
)

# options that are only required based on the value of another option
Expand Down Expand Up @@ -146,17 +145,22 @@ class EngineDeck(EngineModel):
update
"""

def __init__(self, name='engine_deck', options: AviaryValues = None,
data: NamedValues = None,
required_variables: set = default_required_variables):
def __init__(
self,
name='engine_deck',
options: AviaryValues = None,
data: NamedValues = None,
required_variables: set = default_required_variables,
meta_data: dict = _MetaData,
):
if data is not None:
self.read_from_file = False
else:
self.read_from_file = True
# TODO update default name to be based on filename

# also calls _preprocess_inputs() as part of EngineModel __init__
super().__init__(name, options)
super().__init__(name, options, meta_data=meta_data)

# copy of raw data read from data_file or memory, never modified or used outside
# EngineDeck
Expand All @@ -180,12 +184,20 @@ def __init__(self, name='engine_deck', options: AviaryValues = None,
# Create dict for variables present in engine data with associated units
self.engine_variables = {}

# TODO make this an option - disabling global throttle ranges is better to
# prevent unintended extrapolation, but breaks missions using GASP-based
# engines that have uneven throttle ranges (need t4 constraint on mission
# to truly fix)
self.global_throttle = True
self.global_hybrid_throttle = True
if Aircraft.Engine.GLOBAL_THROTTLE in options:
self.global_throttle = self.options.get_val(Aircraft.Engine.GLOBAL_THROTTLE)
else:
default = meta_data[Aircraft.Engine.GLOBAL_THROTTLE]['default_value']
self.options.set_val(Aircraft.Engine.GLOBAL_THROTTLE, default)
self.global_throttle = default
if Aircraft.Engine.GLOBAL_HYBRID_THROTTLE in options:
self.global_hybrid_throttle = self.options.get_val(
Aircraft.Engine.GLOBAL_HYBRID_THROTTLE
)
else:
default = meta_data[Aircraft.Engine.GLOBAL_HYBRID_THROTTLE]['default_value']
self.options.set_val(Aircraft.Engine.GLOBAL_HYBRID_THROTTLE, default)
self.global_hybrid_throttle = default

# ensure required variables are a set
self.required_variables = {*required_variables}
Expand Down Expand Up @@ -216,8 +228,8 @@ def _preprocess_inputs(self):

for key in additional_options + required_options:
if key not in options:
val = _MetaData[key]['default_value']
units = _MetaData[key]['units']
val = self.meta_data[key]['default_value']
units = self.meta_data[key]['units']

if self.get_val(Settings.VERBOSITY) >= Verbosity.BRIEF:
warnings.warn(
Expand All @@ -232,8 +244,8 @@ def _preprocess_inputs(self):
if self.get_val(key):
for item in dependent_options[key]:
if item not in options:
val = _MetaData[item]['default_value']
units = _MetaData[item]['units']
val = self.meta_data[item]['default_value']
units = self.meta_data[item]['units']
self.set_val(item, val, units)

# LOGIC CHECKS
Expand Down
26 changes: 13 additions & 13 deletions aviary/subsystems/propulsion/engine_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ class EngineModel(SubsystemBuilderBase):

default_name = 'engine_model'

def __init__(
self, name: str = None, options: AviaryValues = None, meta_data: dict = None,
):
def __init__(self, name: str = None, options: AviaryValues = None,
meta_data: dict = None, **kwargs):
super().__init__(name, meta_data=meta_data)
if options is not None:
self.options = options.deepcopy()
Expand Down Expand Up @@ -146,27 +145,28 @@ def _preprocess_inputs(self):

# if val is multidimensional, raise error
if isinstance(val[0], (list, np.ndarray, tuple)):
raise UserWarning(f'Multidimensional {type(val)} was given '
f'for variable {key} in EngineModel '
f'<{self.name}>, but '
f"{type(self.meta_data[key]['default_value'])} "
'was expected.')
raise UserWarning(
f'Multidimensional {type(val)} was given for variable '
f'{key} in EngineModel <{self.name}>, but '
f"{type(self.meta_data[key]['default_value'])} "
'was expected.'
)
# use first item in val and warn user
if verbosity >= 1:
if len(val) > 1:
warnings.warn(
f'The value of {key} passed to EngineModel '
f'<{self.name}> is {type(val)}. Only the first entry in '
'this iterable will be used.')
f'<{self.name}> is {type(val)}. Only the first '
'entry in this iterable will be used.')

# if val is supposed to be an iterable...
else:
# but val is multidimensional, use first item and warn user
if isinstance(val[0], (list, np.ndarray, tuple)):
warnings.warn(
f'The value of {key} passed to EngineModel <{self.name}> '
f'is multidimensional {type(val)}. Only the first entry '
'in this iterable will be used.')
f'The value of {key} passed to EngineModel '
f'<{self.name}> is multidimensional {type(val)}. Only '
'the first entry in this iterable will be used.')
# and val is 1-D, then it is ok!
else:
continue
Expand Down
2 changes: 2 additions & 0 deletions aviary/subsystems/propulsion/test/test_data_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from aviary.validation_cases.validation_data.flops_data.FLOPS_Test_Data import \
FLOPS_Test_Data
from aviary.subsystems.propulsion.utils import build_engine_deck
from aviary.variable_info.variables import Aircraft


class DataInterpolationTest(unittest.TestCase):
def test_data_interpolation(self):
tol = 1e-6

aviary_values = FLOPS_Test_Data['LargeSingleAisle2FLOPS']['inputs']
aviary_values.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)

model = build_engine_deck(aviary_values)[0]

Expand Down
4 changes: 4 additions & 0 deletions aviary/subsystems/propulsion/test/test_engine_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
FLOPS_Test_Data
from aviary.subsystems.propulsion.utils import build_engine_deck

from aviary.variable_info.variables import Aircraft


class EngineDeckTest(unittest.TestCase):
def test_flight_idle(self):
tol = 1e-6

aviary_values = FLOPS_Test_Data['LargeSingleAisle2FLOPS']['inputs']
# Test data grabbed from LEAPS uses the global throttle approach
aviary_values.set_val(Aircraft.Engine.GLOBAL_THROTTLE, True)

model = build_engine_deck(aviary_values)[0]

Expand Down
Loading

0 comments on commit 6033e46

Please sign in to comment.