Skip to content

Commit

Permalink
Merge pull request OpenMDAO#590 from xjjiang/test_mass_builders
Browse files Browse the repository at this point in the history
Test mass builders
  • Loading branch information
crecine authored Nov 1, 2024
2 parents a9516c2 + 9595e2d commit ddd8acc
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def setup(self):
add_aviary_input(self, Aircraft.Fuselage.PRESSURE_DIFFERENTIAL, val=7.5)
add_aviary_input(self, Aircraft.Fuselage.AVG_DIAMETER, val=13.1)
add_aviary_input(self, Aircraft.Engine.SCALED_SLS_THRUST,
val=np.full(num_engine_type, 28690))
val=np.full(num_engine_type, 4000), units="lbf")
add_aviary_input(self, Aircraft.Fuel.WING_FUEL_FRACTION, val=0.5)
add_aviary_input(self, Aircraft.Design.EXTERNAL_SUBSYSTEMS_MASS, val=0.)

Expand Down
14 changes: 8 additions & 6 deletions aviary/subsystems/mass/gasp_based/fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setup(self):
num_engine_type = len(self.options['aviary_options'].get_val(
Aircraft.Engine.NUM_ENGINES))

add_aviary_input(self, Aircraft.Wing.SWEEP, val=25)
add_aviary_input(self, Aircraft.Wing.SWEEP, val=0.436, units='rad')
add_aviary_input(self, Aircraft.Wing.TAPER_RATIO, val=0.33)
add_aviary_input(self, Aircraft.Wing.ASPECT_RATIO, val=10.13)
add_aviary_input(self, Aircraft.Wing.SPAN, val=117.8)
Expand Down Expand Up @@ -97,7 +97,7 @@ def setup(self):
)

self.declare_partials(
"c_gear_loc", Aircraft.LandingGear.MAIN_GEAR_LOCATION, val=0)
"c_gear_loc", Aircraft.LandingGear.MAIN_GEAR_LOCATION)

def compute(self, inputs, outputs):
aviary_options: AviaryValues = self.options['aviary_options']
Expand All @@ -113,7 +113,8 @@ def compute(self, inputs, outputs):
gear_location = inputs[Aircraft.LandingGear.MAIN_GEAR_LOCATION]

tan_half_sweep = \
np.tan(sweep_c4 * 0.017453) - (1.0 - taper_ratio) / (1.0 + taper_ratio) / AR
np.tan(sweep_c4) - \
(1.0 - taper_ratio) / (1.0 + taper_ratio) / AR

half_sweep = np.arctan(tan_half_sweep)
cos_half_sweep = np.cos(half_sweep)
Expand Down Expand Up @@ -168,7 +169,8 @@ def compute_partials(self, inputs, J):
gear_location = inputs[Aircraft.LandingGear.MAIN_GEAR_LOCATION]

tan_half_sweep = (
np.tan(sweep_c4 * 0.017453) - (1.0 - taper_ratio) / (1.0 + taper_ratio) / AR
np.tan(sweep_c4) -
(1.0 - taper_ratio) / (1.0 + taper_ratio) / AR
)
half_sweep = np.arctan(tan_half_sweep)
cos_half_sweep = np.cos(half_sweep)
Expand All @@ -178,7 +180,7 @@ def compute_partials(self, inputs, J):
not_fuselage_mounted = self.options["aviary_options"].get_val(
Aircraft.Engine.NUM_FUSELAGE_ENGINES) == 0

dTanHS_dSC4 = (1 / np.cos(sweep_c4 * 0.017453) ** 2) * 0.017453
dTanHS_dSC4 = (1 / np.cos(sweep_c4) ** 2)
dTanHS_TR = (
-(1 / AR)
* ((1 + taper_ratio) * (-1) - (1 - taper_ratio))
Expand Down Expand Up @@ -608,7 +610,7 @@ def setup(self):
add_aviary_input(self, Aircraft.Engine.MASS_SPECIFIC,
val=np.full(num_engine_type, 0.21366))
add_aviary_input(self, Aircraft.Engine.SCALED_SLS_THRUST,
val=np.full(num_engine_type, 4000))
val=np.full(num_engine_type, 4000), units="lbf")
add_aviary_input(self, Aircraft.Nacelle.MASS_SPECIFIC,
val=np.full(num_engine_type, 3))
add_aviary_input(self, Aircraft.Nacelle.SURFACE_AREA,
Expand Down
52 changes: 52 additions & 0 deletions aviary/subsystems/mass/test/test_flops_mass_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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.mass.mass_builder import CoreMassBuilder
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 TestFLOPSMassBuilder(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 = CoreMassBuilder(
'test_core_mass', meta_data=BaseMetaData, code_origin=FLOPS)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(Aircraft.Design.USE_ALT_MASS, False, units='unitless')
self.aviary_values.set_val(Aircraft.Engine.NUM_ENGINES, [1], units='unitless')
self.aviary_values.set_val(
Aircraft.Engine.NUM_WING_ENGINES, [2], units='unitless')


class TestFLOPSMassBuilderAltMass(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 = CoreMassBuilder(
'test_core_mass', meta_data=BaseMetaData, code_origin=FLOPS)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(Aircraft.Design.USE_ALT_MASS, True, units='unitless')
self.aviary_values.set_val(Aircraft.Engine.NUM_ENGINES, [1], units='unitless')
self.aviary_values.set_val(
Aircraft.Engine.NUM_WING_ENGINES, [2], units='unitless')


if __name__ == '__main__':
unittest.main()
63 changes: 63 additions & 0 deletions aviary/subsystems/mass/test/test_gasp_mass_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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.mass.mass_builder import CoreMassBuilder

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 TestGASPMassBuilderHybrid(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 = CoreMassBuilder(
'test_core_mass', meta_data=BaseMetaData, code_origin=GASP)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(
Aircraft.Design.PART25_STRUCTURAL_CATEGORY, 3, units='unitless')
self.aviary_values.set_val(
Aircraft.Propulsion.TOTAL_NUM_ENGINES, 2, 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.Engine.NUM_ENGINES, [1], units='unitless')


class TestGASPMassBuilder(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 = CoreMassBuilder(
'test_core_mass', meta_data=BaseMetaData, code_origin=GASP)
self.aviary_values = av.AviaryValues()
self.aviary_values.set_val(
Aircraft.Design.PART25_STRUCTURAL_CATEGORY, 3, units='unitless')
self.aviary_values.set_val(
Aircraft.Propulsion.TOTAL_NUM_ENGINES, 2, 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.Engine.NUM_ENGINES, [1], units='unitless')


if __name__ == '__main__':
unittest.main()

0 comments on commit ddd8acc

Please sign in to comment.