exec_comp.py

Class definition for ExecComp, a component that evaluates an expression.

class openmdao.components.exec_comp.ExecComp(exprs, **kwargs)[source]

Bases: openmdao.core.component.Component

Given a list of assignment statements, this component creates input and output variables at construction time. All variables appearing on the left-hand side of the assignments are outputs, and the rest are inputs. Each variable is assumed to be of type float unless the initial value for that variable is supplied in **kwargs. Derivatives are calculated using complex step.

Args:

exprs: str or iter of str

An assignment statement or iter of them. These express how the outputs are calculated based on the inputs.

**kwargs: dict of named args

Initial values of variables can be set by setting a named arg with the var name.

jacobian(params, unknowns, resids)[source]

Uses complex step method to calculate a Jacobian dict.

Args:

params : VecWrapper

VecWrapper containing parameters. (p)

unknowns : VecWrapper

VecWrapper containing outputs and states. (u)

resids : VecWrapper

VecWrapper containing residuals. (r)

Returns:

dict

Dictionary whose keys are tuples of the form (‘unknown’, ‘param’) and whose values are ndarrays.

solve_nonlinear(params, unknowns, resids)[source]

Executes this component’s assignment statemens.

Args:

params : VecWrapper, optional

VecWrapper containing parameters. (p)

unknowns : VecWrapper, optional

VecWrapper containing outputs and states. (u)

resids : VecWrapper, optional

VecWrapper containing residuals. (r)