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

add test, set_val/get_val on simple component model with units #1626

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion openmdao/core/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4526,7 +4526,7 @@ def convert_from_units(self, name, val, units):

def convert_units(self, name, val, units_from, units_to):
"""
Wrap the utilty convert_units and give a good error message.
Wrap the utility convert_units and give a good error message.

Parameters
----------
Expand Down
25 changes: 25 additions & 0 deletions openmdao/core/tests/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import openmdao.utils.hooks as hooks
from openmdao.test_suite.components.paraboloid import Paraboloid
from openmdao.test_suite.components.sellar import SellarDerivatives
from openmdao.utils.units import convert_units

try:
from parameterized import parameterized
Expand Down Expand Up @@ -117,6 +118,29 @@ def solve_nonlinear(self, inputs, outputs):

class TestProblem(unittest.TestCase):

def test_simple_component_model_with_units(self):
class TestComp(om.ExplicitComponent):
def setup(self):
self.add_input('foo', units='N')
self.add_output('bar', units='N')
self.declare_partials('bar', 'foo')

def compute(self, inputs, outputs):
outputs['bar'] = inputs['foo']

def compute_partials(self, inputs, J):
J['bar', 'foo'] = 1.

p = om.Problem(model=TestComp())
p.setup()

p.set_val('foo', 5, units='lbf')
p.run_model()

lbf_val = convert_units(5, 'lbf', 'N')
self.assertEqual(p.get_val('foo'), lbf_val)
self.assertEqual(p.get_val('bar'), lbf_val)

def test_feature_simple_run_once_no_promote(self):
import openmdao.api as om
from openmdao.test_suite.components.paraboloid import Paraboloid
Expand Down Expand Up @@ -2053,6 +2077,7 @@ def test_error_msg_set_val_before_setup(self):
prob.set_val('x', 0.)
self.assertEqual(str(cm.exception), "Problem: 'x' Cannot call set_val before setup.")


class NestedProblemTestCase(unittest.TestCase):

def test_nested_prob(self):
Expand Down