group.py

Defines the base class for a Group in OpenMDAO.

class openmdao.core.group.Group[source]

Bases: openmdao.core.system.System

A system that contains other systems.

Options:

deriv_options[‘type’] : str(‘user’)

Derivative calculation type (‘user’, ‘fd’, ‘cs’) Default is ‘user’, where derivative is calculated from user-supplied derivatives. Set to ‘fd’ to finite difference this system. Set to ‘cs’ to perform the complex step if your components support it.

deriv_options[‘form’] : str(‘forward’)

Finite difference mode. (forward, backward, central)

deriv_options[‘step_size’] : float(1e-06)

Default finite difference stepsize

deriv_options[‘step_calc’] : str(‘absolute’)

Set to absolute, relative

deriv_options[‘check_type’] : str(‘fd’)

Type of derivative check for check_partial_derivatives. Set to ‘fd’ to finite difference this system. Set to ‘cs’ to perform the complex step method if your components support it.

deriv_options[‘check_form’] : str(‘forward’)

Finite difference mode: (“forward”, “backward”, “central”) During check_partial_derivatives, the difference form that is used for the check.

deriv_options[‘check_step_calc’] : str(‘absolute’,)

Set to ‘absolute’ or ‘relative’. Default finite difference step calculation for the finite difference check in check_partial_derivatives.

deriv_options[‘check_step_size’] : float(1e-06)

Default finite difference stepsize for the finite difference check in check_partial_derivatives”

deriv_options[‘linearize’] : bool(False)

Set to True if you want linearize to be called even though you are using FD.

add(name, system, promotes=None)[source]

Add a subsystem to this group, specifying its name and any variables that it promotes to the parent level.

Args:

name : str

The name by which the subsystem is to be known.

system : System

The subsystem to be added.

promotes : tuple, optional

The names of variables in the subsystem which are to be promoted.

apply_nonlinear(params, unknowns, resids, metadata=None)[source]

Evaluates the residuals of our children systems.

Args:

params : VecWrapper

VecWrapper containing parameters. (p)

unknowns : VecWrapper

VecWrapper containing outputs and states. (u)

resids : VecWrapper

VecWrapper containing residuals. (r)

metadata : dict, optional

Dictionary containing execution metadata (e.g. iteration coordinate).

assemble_jacobian(mode='fwd', method='assemble', mult=None)[source]

Assemble and return an ndarray containing the Jacobian for this Group.

Args:

system : System

Parent System object.

mode : string(‘fwd’)

Derivative mode, can be ‘fwd’ or ‘rev’.

method : string(‘assemble’)

Method to assemble the jacobian to solve. Select ‘MVP’ to build the Jacobian by calling apply_linear with columns of identity. Select ‘assemble’ to build the Jacobian by taking the calculated Jacobians in each component and placing them directly into a clean identity matrix.

mult : function(None)

Solver mult function to coordinate the matrix vector product

Returns:

ndarray : Jacobian Matrix. Note: if mode is ‘rev’, then the transpose

Jacobian is returned.

dict of tuples : Contains the location of each derivative in the Jacobian. The

key is a tuple containing the component name string, and a tuple with the output

(derivative of) and param (derivative with respect to) variable names. The value

is a tuple of 4 indices: starting row, ending row, starting column, ending column.

Note, if mode is ‘rev’, then rows and columns are swapped.

children_solve_nonlinear(metadata)[source]

Loops over our children systems and asks them to solve.

Args:

metadata : dict

Dictionary containing execution metadata (e.g. iteration coordinate).

cleanup()[source]

Clean up resources prior to exit.

clear_dparams()[source]

Zeros out the dparams (dp) vector.

components(local=False, recurse=False, include_self=False)[source]
Returns:

iterator

Iterator over sub-Components.

connect(source, targets, src_indices=None)[source]

Connect the given source variable to the given target variable.

Args:

source : source

The name of the source variable.

targets : str OR iterable

The name of one or more target variables.

src_indices : index array, optional

If specified, connect the specified entries of the full distributed source value to the target.

dump(nest=0, out_stream=<open file '<stdout>', mode 'w'>, verbose=False, dvecs=False, sizes=False)[source]

Writes a formated dump of the System tree to file.

Args:

nest : int, optional

Starting nesting level. Defaults to 0.

out_stream : file-like, optional

Where output is written. Defaults to sys.stdout.

verbose : bool, optional

If True, output additional info beyond just the tree structure. Default is False.

dvecs : bool, optional

If True, show contents of du and dp vectors instead of u and p (the default).

sizes : bool, optional

If True, include vector sizes and comm sizes. Default is False.

find_subsystem(name)[source]

Returns a reference to a named subsystem that is a direct or an indirect subsystem of the this system. Raises an exception if the given name doesn’t reference a subsystem.

Args:

name : str

Name of the subsystem to retrieve.

Returns:

System

A reference to the named subsystem.

get_req_procs()[source]
Returns:

tuple

A tuple of the form (min_procs, max_procs), indicating the min and max processors usable by this Group.

linearize(params, unknowns, resids)[source]

Linearize all our subsystems.

Args:

params : VecWrapper

VecWrapper containing parameters. (p)

unknowns : VecWrapper

VecWrapper containing outputs and states. (u)

resids : VecWrapper

VecWrapper containing residuals. (r)

list_auto_order()[source]
Returns:

list of str

Names of subsystems listed in the order that they would be executed if a manual order was not set.

list of str

Edges that where removed from the graph to allow sorting.

list_order()[source]

Lists execution order for systems in this Group.

Returns:list of str : List of system names in execution order.
set_order(new_order)[source]

Specifies a new execution order for this system. This should only be called after all subsystems have been added.

Args:

new_order : list of str

List of system names in desired new execution order.

solve_linear(dumat, drmat, vois, mode=None, solver=None, rel_inputs=None)[source]

Single linear solution applied to whatever input is sitting in the rhs vector.

Args:

dumat : dict of VecWrappers

In forward mode, each VecWrapper contains the incoming vector for the states. There is one vector per quantity of interest for this problem. In reverse mode, it contains the outgoing vector for the states. (du)

drmat : dict of VecWrappers

VecWrapper containing either the outgoing result in forward mode or the incoming vector in reverse mode. There is one vector per quantity of interest for this problem. (dr)

vois: list of strings

List of all quantities of interest to key into the mats.

mode : string, optional

Derivative mode, can be ‘fwd’ or ‘rev’, but generally should be called without mode so that the user can set the mode in this system’s ln_solver.options.

solver : LinearSolver, optional

Solver to use for the linear solution on this system. If not specified, then the system’s ln_solver is used.

rel_inputs : list or None (optional)

List of inputs that are relevant for linear solve in a subsystem. This list only includes interior connections and states.

solve_nonlinear(params=None, unknowns=None, resids=None, metadata=None)[source]

Solves the group using the nonlinear solver specified in self.nl_solver.

Args:

params : VecWrapper, optional

VecWrapper containing parameters. (p)

unknowns : VecWrapper, optional

VecWrapper containing outputs and states. (u)

resids : VecWrapper, optional

VecWrapper containing residuals. (r)

metadata : dict, optional

Dictionary containing execution metadata (e.g. iteration coordinate).

subgroups(local=False, recurse=False, include_self=False)[source]
Returns:

iterator

Iterator over subgroups.

subsystems(local=False, recurse=False, typ=<class 'openmdao.core.system.System'>, include_self=False)[source]
Args:

local : bool, optional

If True, only return those Components that are local. Default is False.

recurse : bool, optional

If True, return all Components in the system tree, subject to the value of the local arg. Default is False.

typ : type, optional

If a class is specified here, only those subsystems that are instances of that type will be returned. Default type is System.

include_self : bool, optional

If True, yield self before iterating over subsystems, assuming type of self is appropriate. Default is False.

Returns:

iterator

Iterator over subsystems.