Andrew
Andrew

Reputation: 175

Is there a way to expand groups with the XDSM diagram creation in OpenMDAO?

Most of my test files involve the creation of an IndepVarComp that gets connected to a group. When I go to create an XDSM from the test file, it only shows the IndepVarComp Box and the Group Box. Is there a way to get it to expand the group and show what's inside?

This would also be useful when dealing with a top level model that contains many levels of groups where I want to expand one or two levels and leave the rest closed.

Upvotes: 0

Views: 210

Answers (1)

onodip
onodip

Reputation: 655

There is a recurse option, which controls if groups are expanded or not. Here is a small example with the Sellar problem to explore this option. The disciplines d1 and d2 are part of a Group called cycle.

import numpy as np
import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarNoDerivatives

from omxdsm import write_xdsm

prob = om.Problem()
prob.model = model = SellarNoDerivatives()
model.add_design_var('z', lower=np.array([-10.0, 0.0]),
                     upper=np.array([10.0, 10.0]), indices=np.arange(2, dtype=int))
model.add_design_var('x', lower=0.0, upper=10.0)
model.add_objective('obj')
model.add_constraint('con1', equals=np.zeros(1))
model.add_constraint('con2', upper=0.0)

prob.setup()
prob.final_setup()

# Write output. PDF will only be created, if pdflatex is installed
write_xdsm(prob, filename='sellar_pyxdsm', out_format='pdf', show_browser=True,
           quiet=False, output_side='left', recurse=True)

XDSM with recurse set to True

The same code with recurse=False (d1 and d2 are not shown, instead their Group cycle):

XDSM with recurse set to False

To enable the recursion from the command line, use the --recurse flag:

openmdao xdsm sellar_pyxdsm.py -f pdf --recurse

With the function it is turned on by default, in the command line you have to include the flag. If this does not work as expected for you, please provide an example.

You can find a lot of examples with different options in the tests of the XDSM plugin. Some of the options, like recurse, include_indepvarcomps, include_solver and model_path control what is included in the XDSM.

Upvotes: 2

Related Questions