Skip to content

Commit

Permalink
Merge pull request #6 from szoppelt/new-mass-branch
Browse files Browse the repository at this point in the history
New mass branch
  • Loading branch information
szoppelt authored Mar 5, 2025
2 parents 5080065 + d079930 commit 4bb9b25
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 13 deletions.
54 changes: 54 additions & 0 deletions aviary/subsystems/mass/simple_mass/test_fuselage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import unittest

import openmdao.api as om
from openmdao.utils.assert_utils import assert_check_partials, assert_near_equal

from aviary.subsystems.mass.simple_mass.fuselage import FuselageMassAndCOG

class FuselageMassTestCase(unittest.TestCase):
"""
Fuselage mass test case.
"""

def setUp(self):

self.prob = om.Problem()
self.prob.model.add_subsystem(
"fuselage",
FuselageMassAndCOG(),
promotes_inputs=["*"],
promotes_outputs=["*"],
)

self.prob.model.set_input_defaults(
"fuselage_mass",
val=10,
units="kg")

self.prob.setup(
check=False,
force_alloc_complex=True)

def test_case(self):

self.prob.run_model()

tol=1e-10

assert_near_equal(
self.prob["fuselage_mass"],
100, # filler value for now
tol)

partial_data = self.prob.check_partials(
out_stream=None,
method="fd") # fd for now since cs is used in the fuselage mass calculation right now

assert_check_partials(
partial_data,
atol=1e-15,
rtol=1e-15)

if __name__ == "__main__":
unittest.main()
54 changes: 54 additions & 0 deletions aviary/subsystems/mass/simple_mass/test_tail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import unittest

import openmdao.api as om
from openmdao.utils.assert_utils import assert_check_partials, assert_near_equal

from aviary.subsystems.mass.simple_mass.tail import TailMassAndCOG

class TailMassTestCase(unittest.TestCase):
"""
Tail mass test case.
"""

def setUp(self):

self.prob = om.Problem()
self.prob.model.add_subsystem(
"Tail",
TailMassAndCOG(),
promotes_inputs=["*"],
promotes_outputs=["*"],
)

self.prob.model.set_input_defaults(
"tail_mass",
val=10,
units="kg")

self.prob.setup(
check=False,
force_alloc_complex=True)

def test_case(self):

self.prob.run_model()

tol = 1e-10

assert_near_equal(
self.prob["tail_mass"],
100, # still need to calculate by hand
tol)

partial_data = self.prob.check_partials(
out_stream=None,
method="fd") # Finite difference because cs is used in tail mass calculation right now

assert_check_partials(
partial_data,
atol=1e-15,
rtol=1e-15)

if __name__ == "__main__":
unittest.main()
38 changes: 25 additions & 13 deletions aviary/subsystems/mass/simple_mass/test_wing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,51 @@
import openmdao.api as om
from openmdao.utils.assert_utils import assert_check_partials, assert_near_equal


from aviary.subsystems.mass.simple_mass.wing import WingMassAndCOG

class WingMassTestCase(unittest.TestCase):
"""
Wing mass test case
Wing mass test case.
"""

def setUp(self):

self.prob = om.Problem()
#self.prob.model.add_subsystem(
# "wing",
# WingMassAndCOG(),
# promotes_inputs=["*"],
# promotes_outputs=['*'],
#)
self.prob.model.add_subsystem(
"wing",
WingMassAndCOG(),
promotes_inputs=["*"],
promotes_outputs=['*'],
)

self.prob.model.set_input_defaults(
"wing_mass", val=10, units="kg"
"wing_mass",
val=10,
units="kg"
)

self.prob.setup(check=False, force_alloc_complex=True)
self.prob.setup(
check=False,
force_alloc_complex=True
)

def test_case(self):

self.prob.run_model()

tol = 1e-10
assert_near_equal(self.prob["wing_mass"], 100, tol) # Need to calculate first -- filler value for now
assert_near_equal(self.prob["wing_mass"],
100, # Need to calculate first -- filler value for now
tol)

partial_data = self.prob.check_partials(out_stream=None, method="fd") # finite difference used because cs is used in wing.py calculation
assert_check_partials(partial_data, atol=1e-15, rtol=1e-15)
partial_data = self.prob.check_partials(
out_stream=None,
method="fd") # finite difference used because cs is used in wing.py calculation
assert_check_partials(
partial_data,
atol=1e-15,
rtol=1e-15)


if __name__ == "__main__":
Expand Down

0 comments on commit 4bb9b25

Please sign in to comment.