Skip to content

Commit

Permalink
Merge pull request OpenMDAO#597 from xjjiang/test_geom_builders
Browse files Browse the repository at this point in the history
Test geom builders
  • Loading branch information
jkirk5 authored Nov 13, 2024
2 parents e769e7d + 449f79a commit 07ca01e
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup(self):
add_aviary_input(self, Aircraft.Fuselage.LENGTH, 0.0)

add_aviary_input(self, Aircraft.HorizontalTail.AREA, 0.0)
add_aviary_input(self, Aircraft.HorizontalTail.ASPECT_RATIO, 0.0)
add_aviary_input(self, Aircraft.HorizontalTail.ASPECT_RATIO, 4.75)
# add_aviary_input(self, Aircraft.HorizontalTail.LAMINAR_FLOW_LOWER, 0.0)
# add_aviary_input(self, Aircraft.HorizontalTail.LAMINAR_FLOW_UPPER, 0.0)
add_aviary_input(self, Aircraft.HorizontalTail.THICKNESS_TO_CHORD, 0.0)
Expand Down
6 changes: 4 additions & 2 deletions aviary/subsystems/geometry/flops_based/prep_geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ def setup(self):
add_aviary_input(self, Aircraft.Fuselage.MAX_WIDTH, 0.0)

add_aviary_input(self, Aircraft.HorizontalTail.AREA, 0.0)
add_aviary_input(self, Aircraft.HorizontalTail.ASPECT_RATIO, 0.0)
add_aviary_input(self, Aircraft.HorizontalTail.TAPER_RATIO, 0.0)
add_aviary_input(self, Aircraft.HorizontalTail.ASPECT_RATIO,
4.75, units="unitless")
add_aviary_input(self, Aircraft.HorizontalTail.TAPER_RATIO,
0.352, units="unitless")
add_aviary_input(self, Aircraft.HorizontalTail.THICKNESS_TO_CHORD, 0.0)

add_aviary_input(self, Aircraft.VerticalTail.AREA, 0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def setup(self):
add_aviary_input(self, Aircraft.Wing.SPAN, val=0)

if self.options["aviary_options"].get_val(Aircraft.Wing.FOLD_DIMENSIONAL_LOCATION_SPECIFIED, units='unitless'):
add_aviary_input(self, Aircraft.Wing.FOLDED_SPAN, val=0)
add_aviary_input(self, Aircraft.Wing.FOLDED_SPAN, val=25)
add_aviary_output(self, Aircraft.Wing.FOLDED_SPAN_DIMENSIONLESS, val=0)
else:
add_aviary_input(self, Aircraft.Wing.FOLDED_SPAN_DIMENSIONLESS, val=0)
Expand Down
9 changes: 5 additions & 4 deletions aviary/subsystems/geometry/geometry_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ def get_parameters(self, aviary_inputs=None, phase_info=None):
params = {}

for entry in Aircraft.Nacelle.__dict__:
var = getattr(Aircraft.Nacelle, entry)
if var in aviary_inputs:
if 'total' not in var:
params[var] = {'shape': (num_engine_type), 'static_target': True}
if entry != "__dict__": # cannot get attribute from mappingproxy
var = getattr(Aircraft.Nacelle, entry)
if var in aviary_inputs:
if 'total' not in var:
params[var] = {'shape': (num_engine_type), 'static_target': True}

return params

Expand Down
88 changes: 88 additions & 0 deletions aviary/subsystems/geometry/test/test_flops_geom_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import unittest

import numpy as np
import openmdao.api as om

from openmdao.utils.assert_utils import assert_check_partials, assert_near_equal

from aviary.subsystems.geometry.geometry_builder import CoreGeometryBuilder
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 TestFLOPSGeomBuilder(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 = CoreGeometryBuilder(
'core_geometry',
BaseMetaData,
use_both_geometries=False,
code_origin=FLOPS,
code_origin_to_prioritize=FLOPS)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(Aircraft.Engine.NUM_ENGINES, [1], units='unitless')
self.aviary_values.set_val(
Aircraft.Electrical.HAS_HYBRID_SYSTEM, False, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_FOLD, True, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_STRUT, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_HTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_VTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.SPAN_EFFICIENCY_REDUCTION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.CHOOSE_FOLD_LOCATION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.FOLD_DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Strut.DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')


class TestFLOPSGeomBuilderHybrid(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 = CoreGeometryBuilder(
'core_geometry',
BaseMetaData,
use_both_geometries=False,
code_origin=FLOPS,
code_origin_to_prioritize=FLOPS)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(Aircraft.Engine.NUM_ENGINES, [1], units='unitless')
self.aviary_values.set_val(
Aircraft.Electrical.HAS_HYBRID_SYSTEM, True, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_FOLD, True, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_STRUT, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_HTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_VTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.SPAN_EFFICIENCY_REDUCTION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.CHOOSE_FOLD_LOCATION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.FOLD_DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Strut.DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Propulsion.TOTAL_NUM_WING_ENGINES, 2, units='unitless')


if __name__ == '__main__':
unittest.main()
88 changes: 88 additions & 0 deletions aviary/subsystems/geometry/test/test_gasp_geom_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import unittest

import numpy as np
import openmdao.api as om

from openmdao.utils.assert_utils import assert_check_partials, assert_near_equal

from aviary.subsystems.geometry.geometry_builder import CoreGeometryBuilder
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

GASP = LegacyCode.GASP


class TestGASPGeomBuilder(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 = CoreGeometryBuilder(
'core_geometry',
BaseMetaData,
use_both_geometries=False,
code_origin=GASP,
code_origin_to_prioritize=GASP)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(Aircraft.Engine.NUM_ENGINES, [1], units='unitless')
self.aviary_values.set_val(
Aircraft.Electrical.HAS_HYBRID_SYSTEM, False, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_FOLD, True, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_STRUT, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_HTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_VTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.SPAN_EFFICIENCY_REDUCTION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.CHOOSE_FOLD_LOCATION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.FOLD_DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Strut.DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')


class TestGASPGeomBuilderHybrid(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 = CoreGeometryBuilder(
'core_geometry',
BaseMetaData,
use_both_geometries=False,
code_origin=GASP,
code_origin_to_prioritize=GASP)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(Aircraft.Engine.NUM_ENGINES, [1], units='unitless')
self.aviary_values.set_val(
Aircraft.Electrical.HAS_HYBRID_SYSTEM, True, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_FOLD, True, units='unitless')
self.aviary_values.set_val(Aircraft.Wing.HAS_STRUT, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_HTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Design.COMPUTE_VTAIL_VOLUME_COEFF, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.SPAN_EFFICIENCY_REDUCTION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.CHOOSE_FOLD_LOCATION, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Wing.FOLD_DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Strut.DIMENSIONAL_LOCATION_SPECIFIED, True, units='unitless')
self.aviary_values.set_val(
Aircraft.Propulsion.TOTAL_NUM_WING_ENGINES, 2, units='unitless')


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion aviary/subsystems/mass/flops_based/horizontal_tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(self):
def setup(self):
add_aviary_input(self, Aircraft.HorizontalTail.AREA, val=0.0)

add_aviary_input(self, Aircraft.HorizontalTail.TAPER_RATIO, val=0.0)
add_aviary_input(self, Aircraft.HorizontalTail.TAPER_RATIO, val=0.352)

add_aviary_input(self, Mission.Design.GROSS_MASS, val=0.0)

Expand Down

0 comments on commit 07ca01e

Please sign in to comment.