View Connections of a Model#
View Connections from Command Line#
The openmdao view_connections
command generates a table of connection information for all input and
output variables in the model. For more in-depth documentation, see openmdao view_connections.
View Connections from Script#
You can also generate a display of model connections from within a script by calling the function view_connections
.
- openmdao.visualization.connection_viewer.viewconns.view_connections(root, outfile='connections.html', show_browser=True, show_values=True, precision=6, title=None)[source]
Generate an html or csv file containing a detailed connection viewer.
Optionally pops up a web browser to view the file.
- Parameters:
- rootSystem or Problem
The root for the desired tree.
- outfilestr, optional
The name of the output file. Defaults to ‘connections.html’. The extension specified in the file name will determine the output file format.
- show_browserbool, optional
If True, pop up a browser to view the generated html file. Defaults to True.
- show_valuesbool, optional
If True, retrieve the values and display them.
- precisionint, optional
Sets the precision for displaying array values.
- titlestr, optional
Sets the title of the web page.
Here is an example of how this function can be used.
SellarNoDerivatives
class definition
class SellarNoDerivatives(om.Group):
"""
Group containing the Sellar MDA. This version uses the disciplines without derivatives.
"""
def initialize(self):
self.options.declare('nonlinear_solver', default=None,
desc='Nonlinear solver for Sellar MDA')
self.options.declare('nl_atol', default=None,
desc='User-specified atol for nonlinear solver.')
self.options.declare('nl_maxiter', default=None,
desc='Iteration limit for nonlinear solver.')
self.options.declare('linear_solver', default=None,
desc='Linear solver')
self.options.declare('ln_atol', default=None,
desc='User-specified atol for linear solver.')
self.options.declare('ln_maxiter', default=None,
desc='Iteration limit for linear solver.')
def setup(self):
cycle = self.add_subsystem('cycle', om.Group(), promotes=['x', 'z', 'y1', 'y2'])
cycle.add_subsystem('d1', SellarDis1(), promotes=['x', 'z', 'y1', 'y2'])
cycle.add_subsystem('d2', SellarDis2(), promotes=['z', 'y1', 'y2'])
self.add_subsystem('obj_cmp', om.ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
z=np.array([0.0, 0.0]), x=0.0),
promotes=['x', 'z', 'y1', 'y2', 'obj'])
self.add_subsystem('con_cmp1', om.ExecComp('con1 = 3.16 - y1'), promotes=['con1', 'y1'])
self.add_subsystem('con_cmp2', om.ExecComp('con2 = y2 - 24.0'), promotes=['con2', 'y2'])
self.set_input_defaults('x', 1.0)
self.set_input_defaults('z', np.array([5.0, 2.0]))
nl = self.options['nonlinear_solver']
if nl:
self.nonlinear_solver = nl() if inspect.isclass(nl) else nl
if self.options['nl_atol']:
self.nonlinear_solver.options['atol'] = self.options['nl_atol']
if self.options['nl_maxiter']:
self.nonlinear_solver.options['maxiter'] = self.options['nl_maxiter']
def configure(self):
ln = self.options['linear_solver']
if ln:
self.cycle.linear_solver = ln() if inspect.isclass(ln) else ln
if self.options['ln_atol']:
self.cycle.linear_solver.options['atol'] = self.options['ln_atol']
if self.options['ln_maxiter']:
self.cycle.linear_solver.options['maxiter'] = self.options['ln_maxiter']
import openmdao.api as om
from openmdao.test_suite.components.sellar import SellarNoDerivatives
prob = om.Problem()
prob.model = SellarNoDerivatives()
prob.setup()
prob.final_setup()
om.view_connections(prob, outfile= "sellar_connections.html", show_browser=False)
In this example, an HTML file named sellar_connections.html
is created. This file can then be opened using using your browser. The page will look like this.