Skip to content
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

Test FLOPS Aero Builder #619

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4c62481
commment out lines of total_num_engines that are never used in landin…
xjjiang Dec 5, 2024
14ef4df
add detail of key in assertIn() in subsystem_tester.py
xjjiang Dec 5, 2024
499dca3
update aerodynamics_builder.py to pass unit test
xjjiang Dec 5, 2024
0de5a9d
add test_flops_aero_builder.py
xjjiang Dec 5, 2024
e15ee37
Merge branch 'main' into test_flops_aero_builder
xjjiang Dec 5, 2024
233c1d0
add numpy back
xjjiang Dec 5, 2024
dd58f50
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Dec 6, 2024
15ca235
update phase_info in get_parameters() call
xjjiang Dec 6, 2024
8457556
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Dec 6, 2024
0a2d82c
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Dec 6, 2024
f68bc73
user must specify a method to build aerodynamics. Otherwise, an excep…
xjjiang Dec 11, 2024
d6fa153
allow list in get_bus_variables
xjjiang Dec 12, 2024
6033e46
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Dec 17, 2024
5c9b82d
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Dec 18, 2024
791d910
add a note for add_aviary_input/add_aviary_output
xjjiang Dec 31, 2024
28a9b4a
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Dec 31, 2024
8f743d7
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Jan 7, 2025
6f880ef
Merge branch 'main' into test_flops_aero_builder
jkirk5 Jan 8, 2025
f8e83b2
Merge branch 'OpenMDAO:main' into test_flops_aero_builder
xjjiang Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,9 @@
"# Need to declare dymos parameters for every input that is promoted out of the missions.\n",
"external_parameters = {'climb': {}, 'cruise': {}, 'descent': {}}\n",
"for default_subsys in default_mission_subsystems:\n",
" params = default_subsys.get_parameters(aviary_inputs=aviary_inputs,\n",
" phase_info={})\n",
" params = default_subsys.get_parameters(\n",
" aviary_inputs=aviary_inputs,\n",
" phase_info={\"subsystem_options\": {\"core_aerodynamics\": {\"method\": \"computed\"}}})\n",
" for key, val in params.items():\n",
" for phname in external_parameters:\n",
" external_parameters[phname][key] = val\n",
Expand Down
7 changes: 7 additions & 0 deletions aviary/docs/user_guide/variable_hierarchy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@
" av.add_aviary_output(self, Aircraft.VerticalTail.SPAN, val=0, units='ft', desc='span of the vertical tail')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If `units` is not provided, it assumes the `units` in the metadata."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
4 changes: 2 additions & 2 deletions aviary/mission/flops_based/ode/landing_eom.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):

alpha0 = aviary_options.get_val(Mission.Takeoff.ANGLE_OF_ATTACK_RUNWAY, 'rad')
t_inc = aviary_options.get_val(Mission.Takeoff.THRUST_INCIDENCE, 'rad')
total_num_engines = aviary_options.get_val(Aircraft.Propulsion.TOTAL_NUM_ENGINES)
# total_num_engines = aviary_options.get_val(Aircraft.Propulsion.TOTAL_NUM_ENGINES)

mass = inputs[Dynamic.Vehicle.MASS]
lift = inputs[Dynamic.Vehicle.LIFT]
Expand Down Expand Up @@ -234,7 +234,7 @@ def compute_partials(self, inputs, J, discrete_inputs=None):

alpha0 = aviary_options.get_val(Mission.Takeoff.ANGLE_OF_ATTACK_RUNWAY, 'rad')
t_inc = aviary_options.get_val(Mission.Takeoff.THRUST_INCIDENCE, 'rad')
total_num_engines = aviary_options.get_val(Aircraft.Propulsion.TOTAL_NUM_ENGINES)
# total_num_engines = aviary_options.get_val(Aircraft.Propulsion.TOTAL_NUM_ENGINES)

mass = inputs[Dynamic.Vehicle.MASS]
lift = inputs[Dynamic.Vehicle.LIFT]
Expand Down
26 changes: 14 additions & 12 deletions aviary/subsystems/aerodynamics/aerodynamics_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

CoreAerodynamicsBuilder : the interface for Aviary's core aerodynamics subsystem builder
"""
from itertools import chain

import numpy as np
from itertools import chain

import openmdao.api as om
from dymos.utils.misc import _unspecified
# from dymos.utils.misc import _unspecified

from aviary.subsystems.aerodynamics.flops_based.computed_aero_group import \
ComputedAeroGroup
Expand All @@ -39,7 +37,7 @@
GASP = LegacyCode.GASP
FLOPS = LegacyCode.FLOPS

_default_name = 'aerodynamics'
default_name = 'aerodynamics'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep the old name - it marks default_name as a variable intended as private to this file, so other devs know they shouldn't try from aerodynamics_builder import default_name

It's unlikely anyone would ever even want that, but it's good practice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required by unittest because TestSubsystemBuilderBase has an attribute default_name.



class AerodynamicsBuilderBase(SubsystemBuilderBase):
Expand All @@ -58,7 +56,7 @@ class AerodynamicsBuilderBase(SubsystemBuilderBase):

def __init__(self, name=None, meta_data=None):
if name is None:
name = _default_name
name = default_name

super().__init__(name=name, meta_data=meta_data)

Expand Down Expand Up @@ -337,7 +335,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):
aero_opt = phase_info['subsystem_options'][self.name]
method = aero_opt['method']
except KeyError:
method = 'computed'
method = None

if phase_info is not None:
# Only solved_alpha has connectable inputs.
Expand Down Expand Up @@ -387,7 +385,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):

val = meta['default_value']
if val is None:
val = _unspecified
val = 0.0 # _unspecified
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_unspecified might actually be useful here? If used consistently throughout the code it could provide a valid use of None as a default, although I'm unsure where that would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unittest does not like it.

units = meta['units']

if var in aviary_inputs:
Expand All @@ -397,6 +395,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):
val = aviary_inputs.get_val(var)

params[var] = {'val': val,
'units': units,
'static_target': True}

for var in ENGINE_SIZED_INPUTS:
Expand All @@ -410,7 +409,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):

val = meta['default_value']
if val is None:
val = _unspecified
val = 0.0 # _unspecified
units = meta['units']

if var in aviary_inputs:
Expand All @@ -420,6 +419,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):
val = aviary_inputs.get_val(var)

params[var] = {'val': val,
'units': units,
'static_target': True}

elif method == "low_speed":
Expand All @@ -430,7 +430,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):

val = meta['default_value']
if val is None:
val = _unspecified
val = 0.0 # _unspecified
units = meta['units']

if var in aviary_inputs:
Expand All @@ -440,14 +440,15 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):
val = aviary_inputs.get_val(var)

params[var] = {'val': val,
'units': units,
'static_target': True}

else:

# TODO: 2DOF/Gasp decided on phases based on phase names. We used
# a saved phase_name to determine the correct aero variables to
# promote. Ideally, this should all be refactored.
if phase_info['phase_type'] in ['ascent', 'groundroll', 'rotation']:
if bool(phase_info) and phase_info['phase_type'] in ['ascent', 'groundroll', 'rotation']:
all_vars = (AERO_2DOF_INPUTS, AERO_LS_2DOF_INPUTS)
else:
all_vars = (AERO_2DOF_INPUTS, AERO_CLEAN_2DOF_INPUTS)
Expand All @@ -458,7 +459,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):

val = meta['default_value']
if val is None:
val = _unspecified
val = 0.0 # _unspecified
units = meta['units']

if var in aviary_inputs:
Expand All @@ -468,6 +469,7 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):
val = aviary_inputs.get_val(var)

params[var] = {'val': val,
'units': units,
'static_target': True}

return params
Expand Down
27 changes: 27 additions & 0 deletions aviary/subsystems/aerodynamics/test/test_flops_aero_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from aviary.subsystems.aerodynamics.aerodynamics_builder import CoreAerodynamicsBuilder
from aviary.variable_info.enums import LegacyCode
from aviary.variable_info.variables import Aircraft
from aviary.variable_info.variable_meta_data import _MetaData as BaseMetaData
import aviary.api as av

FLOPS = LegacyCode.FLOPS


class TestAeroBuilder(av.TestSubsystemBuilderBase):
"""
That class inherits from TestSubsystemBuilder. So all the test functions are
within that inherited class. The setUp() method prepares the class and is run
before the test methods; then the test methods are run.
"""

def setUp(self):
self.subsystem_builder = CoreAerodynamicsBuilder(
'core_aerodynamics', BaseMetaData, FLOPS)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(Aircraft.Engine.NUM_ENGINES, [1], units='unitless')


if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions aviary/subsystems/test/subsystem_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ def test_get_parameters(self):
val, dict, "The values in the dictionary returned by get_parameters() should be dictionaries")

# Verify that the dictionaries have the correct keys
for val in parameters.values():
for key, val in parameters.items():
self.assertIn(
'val', val, "The dictionaries returned by get_parameters() should have a 'val' key")
'val', val, f"The dictionaries returned by get_parameters() should have a 'val' key for {key}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wording
---> should have a 'val' for key '{key}'."

self.assertIn(
'units', val, "The dictionaries returned by get_parameters() should have a 'units' key")
'units', val, f"The dictionaries returned by get_parameters() should have a 'units' key for {key}")

def test_get_initial_guesses(self):
initial_guesses = self.subsystem_builder.get_initial_guesses()
Expand Down
Loading