Skip to content

Commit

Permalink
Merge 43dc32d into ee17269
Browse files Browse the repository at this point in the history
  • Loading branch information
swryan committed Aug 17, 2020
2 parents ee17269 + 43dc32d commit 9967d79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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

0 comments on commit 9967d79

Please sign in to comment.