Skip to content

Commit

Permalink
Merge pull request OpenMDAO#268 from xjjiang/dynamic_option
Browse files Browse the repository at this point in the history
Move Dynamic Options
  • Loading branch information
jkirk5 authored May 29, 2024
2 parents 14c0a6d + dfb7241 commit dec6d7f
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 80 deletions.
16 changes: 12 additions & 4 deletions aviary/docs/user_guide/external_aero.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"id": "technological-compatibility",
"metadata": {},
"source": [
"Next, the existing mission phases need to be given the information they need to set up our aerodynamics analysis using `phase_info`. We use the `solved_alpha` method of Aviary's included aerodynamics for this, which can accept the input passed from our external subsystem. Since we are using Aviary's built-in aerodynamics methods, we use the default name \"core_aerodynamics\". Don't forget to update the `subsystem_options` for each phase. We must specify the `method`, the `aero_data` that contains our altitude, Mach, and angle of attack data, as well as the `training_data` flag to denote we are passing our drag polars via openMDAO connections."
"Next, the existing mission phases need to be given the information they need to set up our aerodynamics analysis using `phase_info`. We use the `solved_alpha` method of Aviary's included aerodynamics for this, which can accept the input passed from our external subsystem. Since we are using Aviary's built-in aerodynamics methods, we use the default name \"core_aerodynamics\". Don't forget to update the `subsystem_options` for each phase. We must specify the `method`, the `aero_data` that contains our altitude, Mach, and angle of attack data, as well as the `connect_training_data` flag to denote we are passing our drag polars via openMDAO connections."
]
},
{
Expand All @@ -189,7 +189,7 @@
"source": [
"subsystem_options = {'method': 'solved_alpha',\n",
" 'aero_data': aero_data,\n",
" 'training_data': True}\n",
" 'connect_training_data': True}\n",
"\n",
"phase_info['climb']['subsystem_options'] = {'core_aerodynamics': subsystem_options}\n",
"phase_info['cruise']['subsystem_options'] = {'core_aerodynamics': subsystem_options}\n",
Expand Down Expand Up @@ -252,12 +252,20 @@
"prob.add_objective(objective_type=\"mass\", ref=-1e5)\n",
"prob.setup()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9ed7c42",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -271,7 +279,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.9.18"
},
"orphan": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from aviary.mission.gasp_based.ode.unsteady_solved.unsteady_solved_flight_conditions import \
UnsteadySolvedFlightConditions
from aviary.variable_info.enums import SpeedType
from aviary.variable_info.options import get_option_defaults
from aviary.variable_info.variables import Aircraft, Dynamic, Mission


Expand All @@ -38,6 +39,7 @@ def _test_unsteady_alpha_thrust_iter_group(self, ground_roll=False):
g = UnsteadyControlIterGroup(num_nodes=nn,
ground_roll=ground_roll,
clean=True,
aviary_options=get_option_defaults(),
core_subsystems=[aero])

p.model.add_subsystem("iter_group",
Expand Down
6 changes: 4 additions & 2 deletions aviary/mission/gasp_based/phases/landing_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aviary.subsystems.aerodynamics.gasp_based.gaspaero import LowSpeedAero
from aviary.subsystems.propulsion.propulsion_mission import PropulsionMission
from aviary.variable_info.enums import SpeedType
from aviary.variable_info.options import get_option_defaults
from aviary.variable_info.variables import Aircraft, Dynamic, Mission


Expand Down Expand Up @@ -64,7 +65,7 @@ def setup(self):
# alpha input not needed, only used for CL_max
self.add_subsystem(
"aero_app",
LowSpeedAero(num_nodes=1),
LowSpeedAero(num_nodes=1, aviary_options=get_option_defaults()),
promotes_inputs=[
"*",
(Dynamic.Mission.ALTITUDE, Mission.Landing.INITIAL_ALTITUDE),
Expand Down Expand Up @@ -144,7 +145,8 @@ def setup(self):

self.add_subsystem(
"aero_td",
LowSpeedAero(num_nodes=1, retract_flaps=True, retract_gear=False),
LowSpeedAero(num_nodes=1, retract_flaps=True, retract_gear=False,
aviary_options=get_option_defaults()),
promotes_inputs=[
"*",
(Dynamic.Mission.ALTITUDE, Mission.Landing.AIRPORT_ALTITUDE),
Expand Down
12 changes: 7 additions & 5 deletions aviary/subsystems/aerodynamics/aerodynamics_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from aviary.subsystems.aerodynamics.gasp_based.premission_aero import PreMissionAero
from aviary.subsystems.aerodynamics.gasp_based.gaspaero import CruiseAero
from aviary.subsystems.aerodynamics.gasp_based.gaspaero import LowSpeedAero
from aviary.subsystems.aerodynamics.gasp_based.table_based import CruiseAero as TabularCruiseAero
from aviary.subsystems.aerodynamics.gasp_based.table_based import LowSpeedAero as TabularLowSpeedAero
from aviary.subsystems.aerodynamics.gasp_based.table_based import TabularCruiseAero
from aviary.subsystems.aerodynamics.gasp_based.table_based import TabularLowSpeedAero as TabularLowSpeedAero
from aviary.subsystems.aerodynamics.flops_based.computed_aero_group import \
ComputedAeroGroup
from aviary.subsystems.aerodynamics.flops_based.takeoff_aero_group import \
Expand Down Expand Up @@ -122,15 +122,17 @@ def build_mission(self, num_nodes, aviary_inputs, **kwargs):

elif self.code_origin is GASP:
if method is None:
aero_group = CruiseAero(num_nodes=num_nodes)
aero_group = CruiseAero(num_nodes=num_nodes,
aviary_options=aviary_inputs)

elif method == 'cruise':
if 'aero_data' in kwargs:
aero_group = TabularCruiseAero(num_nodes=num_nodes,
aviary_options=aviary_inputs,
aero_data=kwargs.pop('aero_data'),
**kwargs)
else:
aero_group = CruiseAero(num_nodes=num_nodes,
aero_group = CruiseAero(num_nodes=num_nodes, aviary_options=aviary_inputs,
**kwargs)

elif method == 'low_speed':
Expand All @@ -147,7 +149,7 @@ def build_mission(self, num_nodes, aviary_inputs, **kwargs):
**kwargs)

else:
aero_group = LowSpeedAero(num_nodes=num_nodes,
aero_group = LowSpeedAero(num_nodes=num_nodes, aviary_options=aviary_inputs,
**kwargs)

else:
Expand Down
10 changes: 5 additions & 5 deletions aviary/subsystems/aerodynamics/flops_based/solved_alpha_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import aviary.constants as constants
from aviary.subsystems.aerodynamics.aero_common import DynamicPressure
from aviary.subsystems.aerodynamics.gasp_based.table_based import CruiseAero as TabularCruiseAero
from aviary.subsystems.aerodynamics.gasp_based.table_based import TabularCruiseAero
from aviary.utils.named_values import NamedValues
from aviary.variable_info.variables import Aircraft, Dynamic

Expand Down Expand Up @@ -33,7 +33,7 @@ def initialize(self):
'drag coefficient table as a function of altitude, '
'Mach, and angle of attack')

self.options.declare('training_data', default=False,
self.options.declare('connect_training_data', default=False,
desc='When True, the aero tables will be passed as '
'OpenMDAO variables')

Expand All @@ -47,7 +47,7 @@ def setup(self):
options = self.options
nn = options['num_nodes']
aero_data = options['aero_data']
training_data = options['training_data']
connect_training_data = options['connect_training_data']
structured = options['structured']
extrapolate = options['extrapolate']

Expand All @@ -58,11 +58,11 @@ def setup(self):

aero = TabularCruiseAero(num_nodes=nn,
aero_data=aero_data,
training_data=training_data,
connect_training_data=connect_training_data,
structured=structured,
extrapolate=extrapolate)

if training_data:
if connect_training_data:
extra_promotes = [Aircraft.Design.DRAG_POLAR,
Aircraft.Design.LIFT_POLAR]
else:
Expand Down
10 changes: 5 additions & 5 deletions aviary/subsystems/aerodynamics/flops_based/tabular_aero_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def initialize(self):
options.declare('structured', types=bool, default=True,
desc='Flag that sets if data is a structured grid.')

options.declare('training_data', types=bool, default=False,
options.declare('connect_training_data', types=bool, default=False,
desc='Flag that sets if drag data for interpolation will be '
'passed via openMDAO connections. If True, provided values '
'for drag coefficients in data will be ignored.')
Expand All @@ -55,7 +55,7 @@ def setup(self):
CDI_table = options['CDI_data']
CD0_table = options['CD0_data']
structured = options['structured']
training_data = options['training_data']
connect_training_data = options['connect_training_data']

# if data is from file, read data using alias dict
if isinstance(CDI_table, str):
Expand All @@ -67,7 +67,7 @@ def setup(self):
if isinstance(CD0_table, Path):
CD0_table = read_data_file(CD0_table, aliases=aliases)

if training_data or not structured:
if connect_training_data or not structured:
method = 'lagrange3'
else:
method = '2D-lagrange3'
Expand All @@ -76,13 +76,13 @@ def setup(self):
interpolator_outputs={'zero_lift_drag_coefficient':
'unitless'},
method=method, structured=structured,
training_data=training_data)
connect_training_data=connect_training_data)

CDI_interp = build_data_interpolator(nn, interpolator_data=CDI_table,
interpolator_outputs={'lift_dependent_drag_coefficient':
'unitless'},
method=method, structured=structured,
training_data=training_data)
connect_training_data=connect_training_data)

# add subsystems
self.add_subsystem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_solved_aero_pass_polar(self):

subsystem_options = {'method': 'solved_alpha',
'aero_data': aero_data,
'training_data': True}
'connect_training_data': True}
ph_in['pre_mission']['external_subsystems'] = [polar_builder]

ph_in['cruise']['subsystem_options'] = {'core_aerodynamics': subsystem_options}
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_solved_aero_pass_polar_unique_abscissa(self):

subsystem_options = {'method': 'solved_alpha',
'aero_data': aero_data,
'training_data': True}
'connect_training_data': True}
ph_in['pre_mission']['external_subsystems'] = [polar_builder]

ph_in['cruise']['subsystem_options'] = {'core_aerodynamics': subsystem_options}
Expand Down
36 changes: 27 additions & 9 deletions aviary/subsystems/aerodynamics/gasp_based/gaspaero.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
TanhRampComp)
from aviary.variable_info.functions import add_aviary_input
from aviary.variable_info.variables import Aircraft, Dynamic, Mission
from aviary.utils.aviary_values import AviaryValues

#
# data from INTERFERENCE - polynomial coefficients
Expand Down Expand Up @@ -377,10 +378,8 @@ class AeroGeom(om.ExplicitComponent):
def initialize(self):
self.options.declare("num_nodes", default=1, types=int)
self.options.declare(
"include_strut",
default=False,
types=bool,
desc="Whether the aircraft has a strut or not",
'aviary_options', types=AviaryValues,
desc='collection of Aircraft/Mission specific options'
)

def setup(self):
Expand Down Expand Up @@ -667,7 +666,9 @@ def compute(self, inputs, outputs):
fnre[good_mask] = (np.log10(reli[good_mask] * nac_len) / 7) ** -2.6
fvtre[good_mask] = (np.log10(reli[good_mask] * vtail_chord) / 7) ** -2.6
fhtre[good_mask] = (np.log10(reli[good_mask] * htail_chord) / 7) ** -2.6
if self.options["include_strut"]:
include_strut = self.options["aviary_options"].get_val(
Aircraft.Wing.HAS_STRUT, units='unitless')
if include_strut:
fstrtre = (np.log10(reli[good_mask] * strut_chord) / 7) ** -2.6

# fuselage form drag factor
Expand Down Expand Up @@ -781,9 +782,14 @@ def initialize(self):
desc="Directly input speed of sound and kinematic viscosity instead of "
"computing them with an atmospherics component. For testing.",
)
self.options.declare(
'aviary_options', types=AviaryValues,
desc='collection of Aircraft/Mission specific options'
)

def setup(self):
nn = self.options["num_nodes"]
aviary_options = self.options['aviary_options']

self.add_subsystem("ratios", WingTailRatios(), promotes=["*"])
self.add_subsystem("xlifts", Xlifts(num_nodes=nn), promotes=["*"])
Expand Down Expand Up @@ -829,7 +835,8 @@ def setup(self):
promotes=["*"],
)

self.add_subsystem("geom", AeroGeom(num_nodes=nn), promotes=["*"])
self.add_subsystem("geom", AeroGeom(
num_nodes=nn, aviary_options=aviary_options), promotes=["*"])


class DragCoef(om.ExplicitComponent):
Expand Down Expand Up @@ -1282,12 +1289,18 @@ def initialize(self):
desc="Directly input speed of sound and kinematic viscosity instead of "
"computing them with an atmospherics component. For testing.",
)
self.options.declare(
'aviary_options', types=AviaryValues,
desc='collection of Aircraft/Mission specific options'
)

def setup(self):
nn = self.options["num_nodes"]
aviary_options = self.options["aviary_options"]
self.add_subsystem(
"aero_setup",
AeroSetup(num_nodes=nn, input_atmos=self.options["input_atmos"]),
AeroSetup(num_nodes=nn, aviary_options=aviary_options,
input_atmos=self.options["input_atmos"]),
promotes=["*"],
)
if self.options["output_alpha"]:
Expand Down Expand Up @@ -1332,14 +1345,19 @@ def initialize(self):
desc="Directly input speed of sound and kinematic viscosity instead of "
"computing them with an atmospherics component. For testing.",
)
self.options.declare(
'aviary_options', types=AviaryValues,
desc='collection of Aircraft/Mission specific options'
)

def setup(self):
nn = self.options["num_nodes"]
output_alpha = self.options["output_alpha"]

aviary_options = self.options["aviary_options"]
self.add_subsystem(
"aero_setup",
AeroSetup(num_nodes=nn, input_atmos=self.options["input_atmos"]),
AeroSetup(num_nodes=nn, aviary_options=aviary_options,
input_atmos=self.options["input_atmos"]),
promotes=["*"],
)

Expand Down
Loading

0 comments on commit dec6d7f

Please sign in to comment.