Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
DKilkenny committed May 12, 2020
1 parent d45cb80 commit 8a44765
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions openmdao/core/tests/test_expl_comp.py
Expand Up @@ -166,6 +166,118 @@ def test_compute_and_list(self):
with self.assertRaisesRegex(RuntimeError, msg):
prob.model.list_outputs(explicit=False, implicit=False)

def test_list_inputs_outputs_with_parallel_comps(self):
class TestComp(om.ExplicitComponent):

def initialize(self):
self.options['distributed'] = False

def setup(self):
self.add_input('x', shape=1)
self.add_output('y', shape=1)
self.declare_partials('y', 'x')

def compute(self, inputs, outputs):
outputs['y'] = inputs['x'] ** 2

def compute_partials(self, inputs, J):
J['y', 'x'] = 2 * inputs['x']


class TestComp2(om.ExplicitComponent):

def initialize(self):
self.options['distributed'] = False

def setup(self):
self.add_input('x', shape=1)
self.add_output('y', shape=1)
self.declare_partials('y', 'x')

def compute(self, inputs, outputs):
print(self.comm.rank)
outputs['y'] = inputs['x'] ** 2

def compute_partials(self, inputs, J):
J['y', 'x'] = 2 * inputs['x']

prob = om.Problem()
model = prob.model

model.add_subsystem('p1', om.IndepVarComp('x', 1.0))
model.add_subsystem('p2', om.IndepVarComp('x', 1.0))

parallel = model.add_subsystem('parallel', om.ParallelGroup())
parallel.add_subsystem('c1', TestComp())
parallel.add_subsystem('c2', TestComp2())

model.add_subsystem('c3', om.ExecComp(['y=3.0*x1+7.0*x2']))

model.connect("parallel.c1.y", "c3.x1")
model.connect("parallel.c2.y", "c3.x2")

model.connect("p1.x", "parallel.c1.x")
model.connect("p2.x", "parallel.c2.x")

prob.setup(check=False, mode='fwd')
prob.run_model()

stream = StringIO()
prob.model.list_outputs(out_stream=stream)

text = stream.getvalue().split('\n')
expected_text = [
"5 Explicit Output(s) in 'model'",
"-------------------------------",
"",
"varname value",
"---------- -----",
"model",
"p1",
" x [1.]",
"p2",
" x [1.]",
"parallel",
" c1",
" y [1.]",
" c2",
" y [1.]",
"c3",
" y [10.]",
"",
"",
"0 Implicit Output(s) in 'model'",
"-------------------------------",
]
for i, line in enumerate(expected_text):
if line and not line.startswith('-'):
self.assertEqual(remove_whitespace(text[i]), remove_whitespace(line))

stream = StringIO()
prob.model.list_inputs(out_stream=stream)

text = stream.getvalue().split('\n')
expected_text = [
"4 Input(s) in 'model'",
"---------------------",
"",
"varname value",
"---------- -----",
"model",
"parallel",
" c1",
" x [1.]",
" c2",
" x [1.]",
"c3",
" x1 [1.]",
" x2 [1.]",
]

for i, line in enumerate(expected_text):
if line and not line.startswith('-'):
self.assertEqual(remove_whitespace(text[i]), remove_whitespace(line))

def test_simple_list_vars_options(self):

import openmdao.api as om
Expand Down

0 comments on commit 8a44765

Please sign in to comment.