component.py¶
Defines the base class for a Component in OpenMDAO.
-
class
openmdao.core.component.
Component
[source]¶ Bases:
openmdao.core.system.System
Base class for a Component system. The Component can declare variables and operates on its params to produce unknowns, which can be explicit outputs or implicit states.
-
add_output
(name, val=<object object>, **kwargs)[source]¶ Add an output to this component.
Args: name : string
Name of the variable output.
val : float or ndarray
Initial value for the output. While the value is overwritten during execution, it is useful for infering size.
-
add_param
(name, val=<object object>, **kwargs)[source]¶ Add a param input to this component.
Args: name : string
Name of the input.
val : float or ndarray or object
Initial value for the input.
-
add_state
(name, val=<object object>, **kwargs)[source]¶ Add an implicit state to this component.
Args: name : string
Name of the state.
val : float or ndarray
Initial value for the state.
-
apply_linear
(params, unknowns, dparams, dunknowns, dresids, mode)[source]¶ Multiplies incoming vector by the Jacobian (fwd mode) or the transpose Jacobian (rev mode). If the user doesn’t provide this method, then we just multiply by the cached jacobian.
Args: params : VecWrapper
VecWrapper containing parameters. (p)
unknowns : VecWrapper
VecWrapper containing outputs and states. (u)
dparams : VecWrapper
VecWrapper containing either the incoming vector in forward mode or the outgoing result in reverse mode. (dp)
dunknowns : VecWrapper
In forward mode, this VecWrapper contains the incoming vector for the states. In reverse mode, it contains the outgoing vector for the states. (du)
dresids : VecWrapper
VecWrapper containing either the outgoing result in forward mode or the incoming vector in reverse mode. (dr)
mode : string
Derivative mode, can be ‘fwd’ or ‘rev’.
-
apply_nonlinear
(params, unknowns, resids)[source]¶ Evaluates the residuals for this component. For explicit components, the residual is the output produced by the current params minus the previously calculated output. Thus, an explicit component must execute its solve nonlinear method. Implicit components should override this and calculate their residuals in place.
Args: params : VecWrapper
VecWrapper containing parameters. (p)
unknowns : VecWrapper
VecWrapper containing outputs and states. (u)
resids : VecWrapper
VecWrapper containing residuals. (r)
-
dump
(nest=0, out_stream=<open file '<stdout>', mode 'w'>, verbose=True, dvecs=False)[source]¶ Writes a formated dump of this Component to file.
Args: nest : int, optional
Starting nesting level. Defaults to 0.
out_stream : an open file, optional
Where output is written. Defaults to sys.stdout.
verbose : bool, optional
If True (the default), output additional info beyond just the tree structure.
dvecs : bool, optional
If True, show contents of du and dp vectors instead of u and p (the default).
-
generate_docstring
()[source]¶ Generates a numpy-style docstring for a user’s component.
Returns: docstring : str
string that contains a basic numpy docstring.
-
jacobian
(params, unknowns, resids)[source]¶ Returns Jacobian. Returns None unless component overides this method and returns something. J should be a dictionary whose keys are tuples of the form (‘unknown’, ‘param’) and whose values are ndarrays.
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.
-
setup_param_indices
()[source]¶ Override this in your Component to set specific indices that will be pulled from source variables to fill your parameters. This method should set the ‘src_indices’ metadata for any parameters that require it.
-
solve_linear
(dumat, drmat, vois, mode=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
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.
-
solve_nonlinear
(params, unknowns, resids)[source]¶ Runs the component. The user is required to define this function in all components.
Args: params : VecWrapper, optional
VecWrapper containing parameters. (p)
unknowns : VecWrapper, optional
VecWrapper containing outputs and states. (u)
resids : VecWrapper, optional
VecWrapper containing residuals. (r)
-