Skip to content

Commit

Permalink
Added error when IVC iterable doesn't contain a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjasa committed Apr 18, 2024
1 parent 907137d commit 09fd833
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openmdao/core/indepvarcomp.py
Expand Up @@ -41,6 +41,8 @@ def __init__(self, name=None, val=1.0, **kwargs):

elif isinstance(name, (list, tuple)):
for tup in name:
if not isinstance(tup, tuple):
raise TypeError("Each entry in the list of tuples must be of type tuple.")
if len(tup) == 2:
super().add_output(tup[0], tup[1], **kwargs)
elif len(tup) == 3:
Expand Down
12 changes: 12 additions & 0 deletions openmdao/core/tests/test_indep_var_comp.py
Expand Up @@ -139,6 +139,18 @@ def test_tuple_ivc_kwargs(self):
assert_near_equal(prob.get_val('indep_var', units='m'), 1.0)
assert_near_equal(prob.get_val('indep_var2', units='m'), 2.0)

def test_tuple_error(self):
"""Test to see if the objects in the list are actually tuples."""

ivcs = ['indep_var', 'indep_var2']

try:
om.IndepVarComp(ivcs)
except TypeError as err:
self.assertEqual(str(err), "Each entry in the list of tuples must be of type tuple.")
else:
self.fail('Exception expected.')

def test_promote_glob_no_inputs(self):
p = om.Problem()
p.model.add_subsystem('indep',
Expand Down

0 comments on commit 09fd833

Please sign in to comment.