fastoad.model_base.openmdao.group module
Convenience classes to be used in OpenMDAO components.
- class fastoad.model_base.openmdao.group.CycleGroup(**kwargs)[source]
Bases:
Group,ABCUse this class as a base class if your model should contain solvers.
This class defines standard options to control inner solvers.
Please be sure to call the super() method when using initialize() and setup() in the derived class.
By default, the inner solver is activated. If you want your subclass to deactivate the solver by default, you can define it when subclassing:
class MyGroup(CycleGroup, use_solver_by_default=False): ...
You may also specify default solver settings for your subclass. They will be used when adding the solver, unless overwritten through OpenMDAO options when instantiating:
class MyGroup( CycleGroup, default_linear_solver="om.ScipyKrylov", default_nonlinear_solver="om.NewtonSolver", default_nonlinear_options={"maxiter": 50, "iprint": 0}, default_linear_options={"maxiter": 100, "rtol": 1.e-6}, ): ...
Set the solvers to nonlinear and linear block Gauss–Seidel by default.
- setup()[source]
Build this group.
This method should be overidden by your Group’s method. The reason for using this method to add subsystem is to save memory and setup time when using your Group while running under MPI. This avoids the creation of systems that will not be used in the current process.
You may call ‘add_subsystem’ to add systems to this group. You may also issue connections, and set the linear and nonlinear solvers for this group level. You cannot safely change anything on children systems; use the ‘configure’ method instead.
- Available attributes:
name pathname comm options
- abs_name_iter(iotype, local=True, cont=True, discrete=False)
Iterate over absolute variable names for this System.
By setting appropriate values for ‘cont’ and ‘discrete’, yielded variable names can be continuous only, discrete only, or both.
- Parameters:
- Yields:
str
- add_constraint(name, lower=None, upper=None, equals=None, ref=None, ref0=None, adder=None, scaler=None, units=None, indices=None, linear=False, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=False, alias=None)
Add a constraint variable to this system.
- Parameters:
name (str) – Name of the response variable in the system.
lower (float or ndarray, optional) – Lower boundary for the variable.
upper (float or ndarray, optional) – Upper boundary for the variable.
equals (float or ndarray, optional) – Equality constraint value for the variable.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
units (str, optional) – Units to convert to before applying scaling.
indices (sequence of int, optional) – If variable is an array, these indicate which entries are of interest for this particular response. These may be positive or negative integers.
linear (bool) – Set to True if constraint is linear. Default is False.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
alias (str) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1. The arguments (lower,upper,equals) can not be strings or variable names.
- add_design_var(name, lower=None, upper=None, ref=None, ref0=None, indices=None, adder=None, scaler=None, units=None, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=False)
Add a design variable to this system.
- Parameters:
name (str) – Promoted name of the design variable in the system.
lower (float or ndarray, optional) – Lower boundary for the input.
upper (upper or ndarray, optional) – Upper boundary for the input.
ref (float or ndarray, optional) – Value of design var that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of design var that scales to 0.0 in the driver.
indices (iter of int, optional) – If an input is an array, these indicate which entries are of interest for this particular design variable. These may be positive or negative integers.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
units (str, optional) – Units to convert to before applying scaling.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.
- add_objective(name, ref=None, ref0=None, index=None, units=None, adder=None, scaler=None, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=False, alias=None)
Add a response variable to this system.
- Parameters:
name (str) – Name of the response variable in the system.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
index (int, optional) – If variable is an array, this indicates which entry is of interest for this particular response. This may be a positive or negative integer.
units (str, optional) – Units to convert to before applying scaling.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
alias (str) – Alias for this response. Necessary when adding multiple objectives on different indices or slices of a single variable.
Notes
The objective can be scaled using scaler and adder, where
\[x_{scaled} = scaler(x + adder)\]or through the use of ref/ref0, which map to scaler and adder through the equations:
\[ \begin{align}\begin{aligned}0 = scaler(ref_0 + adder)\\1 = scaler(ref + adder)\end{aligned}\end{align} \]which results in:
\[ \begin{align}\begin{aligned}adder = -ref_0\\scaler = \frac{1}{ref + adder}\end{aligned}\end{align} \]
- add_recorder(recorder, recurse=False)
Add a recorder to the system.
- Parameters:
recorder (<CaseRecorder>) – A recorder instance.
recurse (bool) – Flag indicating if the recorder should be added to all the subsystems.
- add_response(name, type_, lower=None, upper=None, equals=None, ref=None, ref0=None, indices=None, index=None, units=None, adder=None, scaler=None, linear=False, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=None, alias=None)
Add a response variable to this system.
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.- Parameters:
name (str) – Promoted name of the response variable in the system.
type (str) – The type of response. Supported values are ‘con’ and ‘obj’.
lower (float or ndarray, optional) – Lower boundary for the variable.
upper (upper or ndarray, optional) – Upper boundary for the variable.
equals (equals or ndarray, optional) – Equality constraint value for the variable.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (upper or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
indices (sequence of int, optional) – If variable is an array, these indicate which entries are of interest for this particular response.
index (int, optional) – If variable is an array, this indicates which entry is of interest for this particular response.
units (str, optional) – Units to convert to before applying scaling.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
linear (bool) – Set to True if constraint is linear. Default is False.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
alias (str or None) – Alias for this response. Necessary when adding multiple responses on different indices of the same variable.
- add_subsystem(name, subsys, promotes=None, promotes_inputs=None, promotes_outputs=None, min_procs=1, max_procs=None, proc_weight=1.0, proc_group=None)
Add a subsystem.
- Parameters:
name (str) – Name of the subsystem being added.
subsys (<System>) – An instantiated, but not-yet-set up system object.
promotes (iter of (str or tuple), optional) – A list of variable names specifying which subsystem variables to ‘promote’ up to this group. If an entry is a tuple of the form (old_name, new_name), this will rename the variable in the parent group.
promotes_inputs (iter of (str or tuple), optional) – A list of input variable names specifying which subsystem input variables to ‘promote’ up to this group. If an entry is a tuple of the form (old_name, new_name), this will rename the variable in the parent group.
promotes_outputs (iter of (str or tuple), optional) – A list of output variable names specifying which subsystem output variables to ‘promote’ up to this group. If an entry is a tuple of the form (old_name, new_name), this will rename the variable in the parent group.
min_procs (int) – Minimum number of MPI processes usable by the subsystem. Defaults to 1.
max_procs (int or None) – Maximum number of MPI processes usable by the subsystem. A value of None (the default) indicates there is no maximum limit.
proc_weight (float) – Weight given to the subsystem when allocating available MPI processes to all subsystems. Default is 1.0.
proc_group (str or None) – Name of a processor group such that any system with that processor group name within the same parent group will be allocated on the same mpi process(es). If this is not None, then any other systems sharing the same proc_group must have identical values of min_procs, max_procs, and proc_weight or an exception will be raised.
- Returns:
The subsystem that was passed in. This is returned to enable users to instantiate and add a subsystem at the same time, and get the reference back.
- Return type:
<System>
- all_connected_nodes(graph, start, local=False)
Yield all downstream nodes starting at the given node.
- Parameters:
graph (network.DiGraph) – Graph being traversed.
start (hashable object) – Identifier of the starting node.
local (bool) – If True and a non-local node is encountered in the traversal, the traversal ends on that branch.
- Yields:
str – Each node found when traversal starts at start.
- approx_totals(method='fd', step=None, form=None, step_calc=None)
Approximate derivatives for a Group using the specified approximation method.
- Parameters:
method (str) – The type of approximation that should be used. Valid options include: ‘fd’: Finite Difference, ‘cs’: Complex Step.
step (float) – Step size for approximation. Defaults to None, in which case, the approximation method provides its default value.
form (str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Defaults to None, in which case, the approximation method provides its default value.
step_calc (str) – Step type for computing the size of the finite difference step. It can be ‘abs’ for absolute, ‘rel_avg’ for a size relative to the absolute value of the vector input, or ‘rel_element’ for a size relative to each value in the vector input. In addition, it can be ‘rel_legacy’ for a size relative to the norm of the vector. For backwards compatibilty, it can be ‘rel’, which is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.
- check_config(logger)
Perform optional error checks.
- Parameters:
logger (object) – The object that manages logging output.
- cleanup()
Clean up resources prior to exit.
- compute_sys_graph(comps_only=False, add_edge_info=True)
Compute a dependency graph for subsystems in this group.
Variable connection information is stored in each edge of the system graph if comps_only is True and add_edge_info is True.
- Parameters:
comps_only (bool (False)) – If True, return a graph of all components within this group or any of its descendants. No sub-groups will be included. Otherwise, a graph containing only direct children (both Components and Groups) of this group will be returned.
add_edge_info (bool (True)) – If True and comps_only is also True, store variable connection information in each edge of the system graph.
- Returns:
A directed graph containing names of subsystems and their connections.
- Return type:
DiGraph
- configure()
Configure this group to assign children settings.
This method may optionally be overidden by your Group’s method.
You may only use this method to change settings on your children subsystems. This includes setting solvers in cases where you want to override the defaults.
You can assume that the full hierarchy below your level has been instantiated and has already called its own configure methods.
- Available attributes:
name pathname comm options system hieararchy with attribute access
- connect(src_name, tgt_name, src_indices=None, flat_src_indices=None)
Connect source src_name to target tgt_name in this namespace.
- Parameters:
src_name (str) – Name of the source variable to connect.
tgt_name (str or [str, ... ] or (str, ...)) – Name of the target variable(s) to connect.
src_indices (int or list of ints or tuple of ints or int ndarray or Iterable or None) – The global indices of the source variable to transfer data from. The shapes of the target and src_indices must match, and form of the entries within is determined by the value of ‘flat_src_indices’.
flat_src_indices (bool) – If True, each entry of src_indices is assumed to be an index into the flattened source. Otherwise it must be a tuple or list of size equal to the number of dimensions of the source.
- convert2units(name, val, units)
Convert the given value to the specified units.
- convert_from_units(name, val, units)
Convert the given value from the specified units to those of the named variable.
- convert_units(name, val, units_from, units_to)
Wrap the utility convert_units and give a good error message.
- declare_coloring(wrt=('*',), method='fd', form=None, step=None, per_instance=True, num_full_jacs=3, tol=1e-25, orders=None, perturb_size=1e-09, min_improve_pct=5.0, show_summary=True, show_sparsity=False)
Set options for deriv coloring of a set of wrt vars matching the given pattern(s).
- Parameters:
wrt (str or list of str) – The name or names of the variables that derivatives are taken with respect to. This can contain input names, output names, or glob patterns.
method (str) – Method used to compute derivative: “fd” for finite difference, “cs” for complex step.
form (str) – Finite difference form, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.
step (float) – Step size for finite difference. Leave undeclared to keep unchanged from previous or default value.
per_instance (bool) – If True, a separate coloring will be generated for each instance of a given class. Otherwise, only one coloring for a given class will be generated and all instances of that class will use it.
num_full_jacs (int) – Number of times to repeat partial jacobian computation when computing sparsity.
tol (float) – Tolerance used to determine if an array entry is nonzero during sparsity determination.
orders (int) – Number of orders above and below the tolerance to check during the tolerance sweep.
perturb_size (float) – Size of input/output perturbation during generation of sparsity.
min_improve_pct (float) – If coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.
show_summary (bool) – If True, display summary information after generating coloring.
show_sparsity (bool) – If True, display sparsity with coloring info after generating coloring.
- get_coloring_fname()
Return the full pathname to a coloring file.
- Returns:
Full pathname of the coloring file.
- Return type:
- get_constraints(recurse=True, get_sizes=True, use_prom_ivc=False)
Get the Constraint settings from this system.
Retrieve the constraint settings for the current system as a dict, keyed by variable name.
- Parameters:
- Returns:
The constraints defined in the current system.
- Return type:
- get_design_vars(recurse=True, get_sizes=True, use_prom_ivc=True)
Get the DesignVariable settings from this system.
Retrieve all design variable settings from the system and, if recurse is True, all of its subsystems.
- Parameters:
- Returns:
The design variables defined in the current system and, if recurse=True, its subsystems.
- Return type:
- get_io_metadata(iotypes=('input', 'output'), metadata_keys=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, tags=(), get_remote=False, rank=None, return_rel_names=True)
Retrieve metadata for a filtered list of variables.
- Parameters:
iotypes (str or iter of str) – Will contain either ‘input’, ‘output’, or both. Defaults to both.
metadata_keys (iter of str or None) – Names of metadata entries to be retrieved or None, meaning retrieve all available ‘allprocs’ metadata. If ‘val’ or ‘src_indices’ are required, their keys must be provided explicitly since they are not found in the ‘allprocs’ metadata and must be retrieved from local metadata located in each process.
includes (str, iter of str or None) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all variables.
excludes (str, iter of str or None) – Collection of glob patterns for pathnames of variables to exclude. Default is None.
is_indep_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.
is_design_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.
tags (str or iter of strs) – User defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.
get_remote (bool) – If True, retrieve variables from other MPI processes as well.
rank (int or None) – If None, and get_remote is True, retrieve values from all MPI process to all other MPI processes. Otherwise, if get_remote is True, retrieve values from all MPI processes only to the specified rank.
return_rel_names (bool) – If True, the names returned will be relative to the scope of this System. Otherwise they will be absolute names.
- Returns:
A dict of metadata keyed on name, where name is either absolute or relative based on the value of the return_rel_names arg, and metadata is a dict containing entries based on the value of the metadata_keys arg. Every metadata dict will always contain two entries, ‘promoted_name’ and ‘discrete’, to indicate a given variable’s promoted name and whether or not it is discrete.
- Return type:
- get_linear_vectors()
Return the linear inputs, outputs, and residuals vectors.
- Returns:
(inputs, outputs, residuals) – Yields the linear inputs, outputs, and residuals vectors.
- Return type:
tuple of <Vector> instances
- get_nonlinear_vectors()
Return the inputs, outputs, and residuals vectors.
- Returns:
Yields the inputs, outputs, and residuals nonlinear vectors.
- Return type:
(inputs, outputs, residuals)
- get_objectives(recurse=True, get_sizes=True, use_prom_ivc=False)
Get the Objective settings from this system.
Retrieve all objectives settings from the system as a dict, keyed by variable name.
- Parameters:
- Returns:
The objectives defined in the current system.
- Return type:
- get_promotions(inprom=None, outprom=None)
Return all promotions for the given promoted variable(s).
In other words, how and where did promotions occur to convert absolute variable names into the given promoted name(s) at the current System level.
- Parameters:
- Returns:
Dictionary keyed on system pathname containing input and/or output promotion lists for each System where promotions occurred to produce the given promoted variable(s).
- Return type:
- get_relevant_vars(desvars, responses, mode)
Find all relevant vars between desvars and responses.
Both vars are assumed to be outputs (either design vars or responses).
- Parameters:
- Returns:
Dict of ({‘outputs’: dep_outputs, ‘inputs’: dep_inputs}, dep_systems) keyed by design vars and responses.
- Return type:
- get_reports_dir()
Get the path to the directory where the report files should go.
If it doesn’t exist, it will be created.
- Returns:
The path to the directory where reports should be written.
- Return type:
- get_responses(recurse=True, get_sizes=True, use_prom_ivc=False)
Get the response variable settings from this system.
Retrieve all response variable settings from the system as a dict, keyed by either absolute variable name, promoted name, or alias name, depending on the value of use_prom_ivc and whether the original key was a promoted output, promoted input, or an alias.
- Parameters:
- Returns:
The responses defined in the current system and, if recurse=True, its subsystems.
- Return type:
- get_source(name)
Return the source variable connected to the given named variable.
The name can be a promoted name or an absolute name. If the given variable is an input, the absolute name of the connected source will be returned. If the given variable itself is a source, its own absolute name will be returned.
- get_val(name, units=None, indices=None, get_remote=False, rank=None, vec_name='nonlinear', kind=None, flat=False, from_src=True)
Get an output/input/residual variable.
Function is used if you want to specify display units.
- Parameters:
name (str) – Promoted or relative variable name in the root system’s namespace.
units (str, optional) – Units to convert to before return.
indices (int or list of ints or tuple of ints or int ndarray or Iterable or None, optional) – Indices or slice to return.
get_remote (bool or None) – If True, retrieve the value even if it is on a remote process. Note that if the variable is remote on ANY process, this function must be called on EVERY process in the Problem’s MPI communicator. If False, only retrieve the value if it is on the current process, or only the part of the value that’s on the current process for a distributed variable. If None and the variable is remote or distributed, a RuntimeError will be raised.
rank (int or None) – If not None, only gather the value to this rank.
vec_name (str) – Name of the vector to use. Defaults to ‘nonlinear’.
kind (str or None) – Kind of variable (‘input’, ‘output’, or ‘residual’). If None, returned value will be either an input or output.
flat (bool) – If True, return the flattened version of the value.
from_src (bool) – If True, retrieve value of an input variable from its connected source.
- Returns:
The value of the requested output/input variable.
- Return type:
- guess_nonlinear(inputs, outputs, residuals, discrete_inputs=None, discrete_outputs=None)
Provide initial guess for states.
Override this method to set the initial guess for states.
- Parameters:
inputs (Vector) – Unscaled, dimensional input variables read via inputs[key].
outputs (Vector) – Unscaled, dimensional output variables read via outputs[key].
residuals (Vector) – Unscaled, dimensional residuals written to via residuals[key].
discrete_inputs (dict or None) – If not None, dict containing discrete input values.
discrete_outputs (dict or None) – If not None, dict containing discrete output values.
- is_explicit()
Return True if this is an explicit component.
- Returns:
True if this is an explicit component.
- Return type:
- property linear_solver
Get the linear solver for this system.
- list_inputs(val=True, prom_name=True, units=False, shape=False, global_shape=False, desc=False, hierarchical=True, print_arrays=False, tags=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, out_stream=DEFAULT_OUT_STREAM, print_min=False, print_max=False, return_format='list')
Write a list of input names and other optional information to a specified stream.
- Parameters:
val (bool, optional) – When True, display/return input values. Default is True.
prom_name (bool, optional) – When True, display/return the promoted name of the variable. Default is True.
units (bool, optional) – When True, display/return units. Default is False.
shape (bool, optional) – When True, display/return the shape of the value. Default is False.
global_shape (bool, optional) – When True, display/return the global shape of the value. Default is False.
desc (bool, optional) – When True, display/return description. Default is False.
hierarchical (bool, optional) – When True, human readable output shows variables in hierarchical format.
print_arrays (bool, optional) – When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.
tags (str or list of strs) – User defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.
includes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all input variables.
excludes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to exclude. Default is None.
is_indep_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.
is_design_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.
all_procs (bool, optional) – When True, display output on all ranks. Default is False, which will display output only from rank 0.
out_stream (file-like object) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.
print_min (bool) – When true, if the input value is an array, print its smallest value.
print_max (bool) – When true, if the input value is an array, print its largest value.
return_format (str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of input names and other optional information about those inputs.
- Return type:
metadata}
- list_outputs(explicit=True, implicit=True, val=True, prom_name=True, residuals=False, residuals_tol=None, units=False, shape=False, global_shape=False, bounds=False, scaling=False, desc=False, hierarchical=True, print_arrays=False, tags=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=DEFAULT_OUT_STREAM, print_min=False, print_max=False, return_format='list')
Write a list of output names and other optional information to a specified stream.
- Parameters:
explicit (bool, optional) – Include outputs from explicit components. Default is True.
implicit (bool, optional) – Include outputs from implicit components. Default is True.
val (bool, optional) – When True, display output values. Default is True.
prom_name (bool, optional) – When True, display the promoted name of the variable. Default is True.
residuals (bool, optional) – When True, display residual values. Default is False.
residuals_tol (float, optional) – If set, limits the output of list_outputs to only variables where the norm of the resids array is greater than the given ‘residuals_tol’. Default is None.
units (bool, optional) – When True, display units. Default is False.
shape (bool, optional) – When True, display/return the shape of the value. Default is False.
global_shape (bool, optional) – When True, display/return the global shape of the value. Default is False.
bounds (bool, optional) – When True, display/return bounds (lower and upper). Default is False.
scaling (bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.
desc (bool, optional) – When True, display/return description. Default is False.
hierarchical (bool, optional) – When True, human readable output shows variables in hierarchical format.
print_arrays (bool, optional) – When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.
tags (str or list of strs) – User defined tags that can be used to filter what gets listed. Only outputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.
includes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.
excludes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to exclude. Default is None.
is_indep_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.
is_design_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.
all_procs (bool, optional) – When True, display output on all processors. Default is False.
list_autoivcs (bool) – If True, include auto_ivc outputs in the listing. Defaults to False.
out_stream (file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.
print_min (bool) – When true, if the output value is an array, print its smallest value.
print_max (bool) – When true, if the output value is an array, print its largest value.
return_format (str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata}
- load_model_options()
Load the relevant model options from Problem._metadata[‘model_options’].
This method examines each path filter and corresponding options in self._problem_meta[‘model_options’]. If this System’s pathname matches the given path filter, it will assume the value for each given option which it possesses.
- property model_options
Get the model options from self._problem_meta.
The user may change the contents of model_options to impact values sent to subsystems of this Group.
- Returns:
The model options metadata provided by the associated Problem object.
- Return type:
- property msginfo
Our instance pathname, if available, or our class name. For use in error messages.
- Returns:
Either our instance pathname or class name.
- Return type:
- property nonlinear_solver
Get the nonlinear solver for this system.
- promotes(subsys_name, any=None, inputs=None, outputs=None, src_indices=None, flat_src_indices=None, src_shape=None)
Promote a variable in the model tree.
- Parameters:
subsys_name (str) – The name of the child subsystem whose inputs/outputs are being promoted.
any (Sequence of str or tuple) – A Sequence of variable names (or tuples) to be promoted, regardless of if they are inputs or outputs. This is equivalent to the items passed via the promotes= argument to add_subsystem. If given as a tuple, we use the “promote as” standard of “(‘real name’, ‘promoted name’)*[]:”.
inputs (Sequence of str or tuple) – A Sequence of input names (or tuples) to be promoted. Tuples are used for the “promote as” capability.
outputs (Sequence of str or tuple) – A Sequence of output names (or tuples) to be promoted. Tuples are used for the “promote as” capability.
src_indices (int or list of ints or tuple of ints or int ndarray or Iterable or None) – This argument applies only to promoted inputs. The global indices of the source variable to transfer data from. A value of None implies this input depends on all entries of source. Default is None. The shapes of the target and src_indices must match, and form of the entries within is determined by the value of ‘flat_src_indices’.
flat_src_indices (bool) – This argument applies only to promoted inputs. If True, each entry of src_indices is assumed to be an index into the flattened source. Otherwise each entry must be a tuple or list of size equal to the number of dimensions of the source.
src_shape (int or tuple) – Assumed shape of any connected source or higher level promoted input.
- record_iteration()
Record an iteration of the current System.
- run_apply_linear(mode, scope_out=None, scope_in=None)
Compute jac-vec product.
This calls _apply_linear, but with the model assumed to be in an unscaled state.
- run_apply_nonlinear()
Compute residuals.
This calls _apply_nonlinear, but with the model assumed to be in an unscaled state.
- run_linearize(sub_do_ln=True)
Compute jacobian / factorization.
This calls _linearize, but with the model assumed to be in an unscaled state.
- Parameters:
sub_do_ln (bool) – Flag indicating if the children should call linearize on their linear solvers.
- run_solve_linear(mode)
Apply inverse jac product.
This calls _solve_linear, but with the model assumed to be in an unscaled state.
- Parameters:
mode (str) – ‘fwd’ or ‘rev’.
- run_solve_nonlinear()
Compute outputs.
This calls _solve_nonlinear, but with the model assumed to be in an unscaled state.
- set_constraint_options(name, ref=UNDEFINED, ref0=UNDEFINED, equals=UNDEFINED, lower=UNDEFINED, upper=UNDEFINED, adder=UNDEFINED, scaler=UNDEFINED, alias=UNDEFINED)
Set options for objectives in the model.
Can be used to set options that were set using add_constraint.
- Parameters:
name (str) – Name of the response variable in the system.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
equals (float or ndarray, optional) – Equality constraint value for the variable.
lower (float or ndarray, optional) – Lower boundary for the variable.
upper (float or ndarray, optional) – Upper boundary for the variable.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
alias (str, optional) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
- set_design_var_options(name, lower=UNDEFINED, upper=UNDEFINED, scaler=UNDEFINED, adder=UNDEFINED, ref=UNDEFINED, ref0=UNDEFINED)
Set options for design vars in the model.
Can be used to set the options outside of setting them when calling add_design_var
- Parameters:
name (str) – Name of the variable in this system’s namespace.
lower (float or ndarray, optional) – Lower boundary for the input.
upper (upper or ndarray, optional) – Upper boundary for the input.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
ref (float or ndarray, optional) – Value of design var that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of design var that scales to 0.0 in the driver.
- set_initial_values()
Set all input and output variables to their declared initial values.
- set_input_defaults(name, val=UNDEFINED, units=None, src_shape=None)
Specify metadata to be assumed when multiple inputs are promoted to the same name.
- set_objective_options(name, ref=UNDEFINED, ref0=UNDEFINED, adder=UNDEFINED, scaler=UNDEFINED, alias=UNDEFINED)
Set options for objectives in the model.
Can be used to set options after they have been set by add_objective.
- Parameters:
name (str) – Name of the response variable in the system.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
alias (str) – Alias for this response. Necessary when adding multiple objectives on different indices or slices of a single variable.
- set_order(new_order)
Specify a new execution order for this system.
- set_output_solver_options(name, lower=UNDEFINED, upper=UNDEFINED, ref=UNDEFINED, ref0=UNDEFINED, res_ref=UNDEFINED)
Set solver output options.
Allows the user to set output solver options after the output has been defined and metadata set using the add_ouput method.
- Parameters:
name (str) – Name of the variable in this system’s namespace.
lower (float or list or tuple or ndarray or None) – Lower bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no lower bound. Default is None.
upper (float or list or tuple or ndarray or None) – Upper bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no upper bound. Default is None.
ref (float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.
ref0 (float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.
res_ref (float) – Scaling parameter. The value in the user-defined res_units of this output’s residual when the scaled value is 1. Default is None, which means residual scaling matches output scaling.
- set_solver_print(level=2, depth=1e+99, type_='all')
Control printing for solvers and subsolvers in the model.
- Parameters:
level (int) – Iprint level. Set to 2 to print residuals each iteration; set to 1 to print just the iteration totals; set to 0 to disable all printing except for failures, and set to -1 to disable all printing including failures.
depth (int) – How deep to recurse. For example, you can set this to 0 if you only want to print the top level linear and nonlinear solver messages. Default prints everything.
type (str) – Type of solver to set: ‘LN’ for linear, ‘NL’ for nonlinear, or ‘all’ for all.
- set_val(name, val, units=None, indices=None)
Set an input or output variable.
- system_iter(include_self=False, recurse=True, typ=None)
Yield a generator of local subsystems of this system.
- property under_approx
Return True if under complex step or finite difference.
- Returns:
True if under CS or FD.
- Return type:
- use_fixed_coloring(coloring=<object object>, recurse=True)
Use a precomputed coloring for this System.
- class fastoad.model_base.openmdao.group.BaseCycleGroup(**kwargs)[source]
Bases:
CycleGroupInherited from
CycleGroupwith no modification of default behavior.Set the solvers to nonlinear and linear block Gauss–Seidel by default.
- abs_name_iter(iotype, local=True, cont=True, discrete=False)
Iterate over absolute variable names for this System.
By setting appropriate values for ‘cont’ and ‘discrete’, yielded variable names can be continuous only, discrete only, or both.
- Parameters:
- Yields:
str
- add_constraint(name, lower=None, upper=None, equals=None, ref=None, ref0=None, adder=None, scaler=None, units=None, indices=None, linear=False, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=False, alias=None)
Add a constraint variable to this system.
- Parameters:
name (str) – Name of the response variable in the system.
lower (float or ndarray, optional) – Lower boundary for the variable.
upper (float or ndarray, optional) – Upper boundary for the variable.
equals (float or ndarray, optional) – Equality constraint value for the variable.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
units (str, optional) – Units to convert to before applying scaling.
indices (sequence of int, optional) – If variable is an array, these indicate which entries are of interest for this particular response. These may be positive or negative integers.
linear (bool) – Set to True if constraint is linear. Default is False.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
alias (str) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1. The arguments (lower,upper,equals) can not be strings or variable names.
- add_design_var(name, lower=None, upper=None, ref=None, ref0=None, indices=None, adder=None, scaler=None, units=None, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=False)
Add a design variable to this system.
- Parameters:
name (str) – Promoted name of the design variable in the system.
lower (float or ndarray, optional) – Lower boundary for the input.
upper (upper or ndarray, optional) – Upper boundary for the input.
ref (float or ndarray, optional) – Value of design var that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of design var that scales to 0.0 in the driver.
indices (iter of int, optional) – If an input is an array, these indicate which entries are of interest for this particular design variable. These may be positive or negative integers.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
units (str, optional) – Units to convert to before applying scaling.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.
- add_objective(name, ref=None, ref0=None, index=None, units=None, adder=None, scaler=None, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=False, alias=None)
Add a response variable to this system.
- Parameters:
name (str) – Name of the response variable in the system.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
index (int, optional) – If variable is an array, this indicates which entry is of interest for this particular response. This may be a positive or negative integer.
units (str, optional) – Units to convert to before applying scaling.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
alias (str) – Alias for this response. Necessary when adding multiple objectives on different indices or slices of a single variable.
Notes
The objective can be scaled using scaler and adder, where
\[x_{scaled} = scaler(x + adder)\]or through the use of ref/ref0, which map to scaler and adder through the equations:
\[ \begin{align}\begin{aligned}0 = scaler(ref_0 + adder)\\1 = scaler(ref + adder)\end{aligned}\end{align} \]which results in:
\[ \begin{align}\begin{aligned}adder = -ref_0\\scaler = \frac{1}{ref + adder}\end{aligned}\end{align} \]
- add_recorder(recorder, recurse=False)
Add a recorder to the system.
- Parameters:
recorder (<CaseRecorder>) – A recorder instance.
recurse (bool) – Flag indicating if the recorder should be added to all the subsystems.
- add_response(name, type_, lower=None, upper=None, equals=None, ref=None, ref0=None, indices=None, index=None, units=None, adder=None, scaler=None, linear=False, parallel_deriv_color=None, cache_linear_solution=False, flat_indices=None, alias=None)
Add a response variable to this system.
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.- Parameters:
name (str) – Promoted name of the response variable in the system.
type (str) – The type of response. Supported values are ‘con’ and ‘obj’.
lower (float or ndarray, optional) – Lower boundary for the variable.
upper (upper or ndarray, optional) – Upper boundary for the variable.
equals (equals or ndarray, optional) – Equality constraint value for the variable.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (upper or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
indices (sequence of int, optional) – If variable is an array, these indicate which entries are of interest for this particular response.
index (int, optional) – If variable is an array, this indicates which entry is of interest for this particular response.
units (str, optional) – Units to convert to before applying scaling.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
linear (bool) – Set to True if constraint is linear. Default is False.
parallel_deriv_color (str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.
cache_linear_solution (bool) – If True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.
flat_indices (bool) – If True, interpret specified indices as being indices into a flat source array.
alias (str or None) – Alias for this response. Necessary when adding multiple responses on different indices of the same variable.
- add_subsystem(name, subsys, promotes=None, promotes_inputs=None, promotes_outputs=None, min_procs=1, max_procs=None, proc_weight=1.0, proc_group=None)
Add a subsystem.
- Parameters:
name (str) – Name of the subsystem being added.
subsys (<System>) – An instantiated, but not-yet-set up system object.
promotes (iter of (str or tuple), optional) – A list of variable names specifying which subsystem variables to ‘promote’ up to this group. If an entry is a tuple of the form (old_name, new_name), this will rename the variable in the parent group.
promotes_inputs (iter of (str or tuple), optional) – A list of input variable names specifying which subsystem input variables to ‘promote’ up to this group. If an entry is a tuple of the form (old_name, new_name), this will rename the variable in the parent group.
promotes_outputs (iter of (str or tuple), optional) – A list of output variable names specifying which subsystem output variables to ‘promote’ up to this group. If an entry is a tuple of the form (old_name, new_name), this will rename the variable in the parent group.
min_procs (int) – Minimum number of MPI processes usable by the subsystem. Defaults to 1.
max_procs (int or None) – Maximum number of MPI processes usable by the subsystem. A value of None (the default) indicates there is no maximum limit.
proc_weight (float) – Weight given to the subsystem when allocating available MPI processes to all subsystems. Default is 1.0.
proc_group (str or None) – Name of a processor group such that any system with that processor group name within the same parent group will be allocated on the same mpi process(es). If this is not None, then any other systems sharing the same proc_group must have identical values of min_procs, max_procs, and proc_weight or an exception will be raised.
- Returns:
The subsystem that was passed in. This is returned to enable users to instantiate and add a subsystem at the same time, and get the reference back.
- Return type:
<System>
- all_connected_nodes(graph, start, local=False)
Yield all downstream nodes starting at the given node.
- Parameters:
graph (network.DiGraph) – Graph being traversed.
start (hashable object) – Identifier of the starting node.
local (bool) – If True and a non-local node is encountered in the traversal, the traversal ends on that branch.
- Yields:
str – Each node found when traversal starts at start.
- approx_totals(method='fd', step=None, form=None, step_calc=None)
Approximate derivatives for a Group using the specified approximation method.
- Parameters:
method (str) – The type of approximation that should be used. Valid options include: ‘fd’: Finite Difference, ‘cs’: Complex Step.
step (float) – Step size for approximation. Defaults to None, in which case, the approximation method provides its default value.
form (str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Defaults to None, in which case, the approximation method provides its default value.
step_calc (str) – Step type for computing the size of the finite difference step. It can be ‘abs’ for absolute, ‘rel_avg’ for a size relative to the absolute value of the vector input, or ‘rel_element’ for a size relative to each value in the vector input. In addition, it can be ‘rel_legacy’ for a size relative to the norm of the vector. For backwards compatibilty, it can be ‘rel’, which is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.
- check_config(logger)
Perform optional error checks.
- Parameters:
logger (object) – The object that manages logging output.
- cleanup()
Clean up resources prior to exit.
- compute_sys_graph(comps_only=False, add_edge_info=True)
Compute a dependency graph for subsystems in this group.
Variable connection information is stored in each edge of the system graph if comps_only is True and add_edge_info is True.
- Parameters:
comps_only (bool (False)) – If True, return a graph of all components within this group or any of its descendants. No sub-groups will be included. Otherwise, a graph containing only direct children (both Components and Groups) of this group will be returned.
add_edge_info (bool (True)) – If True and comps_only is also True, store variable connection information in each edge of the system graph.
- Returns:
A directed graph containing names of subsystems and their connections.
- Return type:
DiGraph
- configure()
Configure this group to assign children settings.
This method may optionally be overidden by your Group’s method.
You may only use this method to change settings on your children subsystems. This includes setting solvers in cases where you want to override the defaults.
You can assume that the full hierarchy below your level has been instantiated and has already called its own configure methods.
- Available attributes:
name pathname comm options system hieararchy with attribute access
- connect(src_name, tgt_name, src_indices=None, flat_src_indices=None)
Connect source src_name to target tgt_name in this namespace.
- Parameters:
src_name (str) – Name of the source variable to connect.
tgt_name (str or [str, ... ] or (str, ...)) – Name of the target variable(s) to connect.
src_indices (int or list of ints or tuple of ints or int ndarray or Iterable or None) – The global indices of the source variable to transfer data from. The shapes of the target and src_indices must match, and form of the entries within is determined by the value of ‘flat_src_indices’.
flat_src_indices (bool) – If True, each entry of src_indices is assumed to be an index into the flattened source. Otherwise it must be a tuple or list of size equal to the number of dimensions of the source.
- convert2units(name, val, units)
Convert the given value to the specified units.
- convert_from_units(name, val, units)
Convert the given value from the specified units to those of the named variable.
- convert_units(name, val, units_from, units_to)
Wrap the utility convert_units and give a good error message.
- declare_coloring(wrt=('*',), method='fd', form=None, step=None, per_instance=True, num_full_jacs=3, tol=1e-25, orders=None, perturb_size=1e-09, min_improve_pct=5.0, show_summary=True, show_sparsity=False)
Set options for deriv coloring of a set of wrt vars matching the given pattern(s).
- Parameters:
wrt (str or list of str) – The name or names of the variables that derivatives are taken with respect to. This can contain input names, output names, or glob patterns.
method (str) – Method used to compute derivative: “fd” for finite difference, “cs” for complex step.
form (str) – Finite difference form, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.
step (float) – Step size for finite difference. Leave undeclared to keep unchanged from previous or default value.
per_instance (bool) – If True, a separate coloring will be generated for each instance of a given class. Otherwise, only one coloring for a given class will be generated and all instances of that class will use it.
num_full_jacs (int) – Number of times to repeat partial jacobian computation when computing sparsity.
tol (float) – Tolerance used to determine if an array entry is nonzero during sparsity determination.
orders (int) – Number of orders above and below the tolerance to check during the tolerance sweep.
perturb_size (float) – Size of input/output perturbation during generation of sparsity.
min_improve_pct (float) – If coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.
show_summary (bool) – If True, display summary information after generating coloring.
show_sparsity (bool) – If True, display sparsity with coloring info after generating coloring.
- default_linear_solver = 'om.DirectSolver'
- default_nonlinear_solver = 'om.NonlinearBlockGS'
- default_solver_options = {'linear_solver_options': {}, 'nonlinear_solver_options': {}}
- get_coloring_fname()
Return the full pathname to a coloring file.
- Returns:
Full pathname of the coloring file.
- Return type:
- get_constraints(recurse=True, get_sizes=True, use_prom_ivc=False)
Get the Constraint settings from this system.
Retrieve the constraint settings for the current system as a dict, keyed by variable name.
- Parameters:
- Returns:
The constraints defined in the current system.
- Return type:
- get_design_vars(recurse=True, get_sizes=True, use_prom_ivc=True)
Get the DesignVariable settings from this system.
Retrieve all design variable settings from the system and, if recurse is True, all of its subsystems.
- Parameters:
- Returns:
The design variables defined in the current system and, if recurse=True, its subsystems.
- Return type:
- get_io_metadata(iotypes=('input', 'output'), metadata_keys=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, tags=(), get_remote=False, rank=None, return_rel_names=True)
Retrieve metadata for a filtered list of variables.
- Parameters:
iotypes (str or iter of str) – Will contain either ‘input’, ‘output’, or both. Defaults to both.
metadata_keys (iter of str or None) – Names of metadata entries to be retrieved or None, meaning retrieve all available ‘allprocs’ metadata. If ‘val’ or ‘src_indices’ are required, their keys must be provided explicitly since they are not found in the ‘allprocs’ metadata and must be retrieved from local metadata located in each process.
includes (str, iter of str or None) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all variables.
excludes (str, iter of str or None) – Collection of glob patterns for pathnames of variables to exclude. Default is None.
is_indep_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.
is_design_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.
tags (str or iter of strs) – User defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.
get_remote (bool) – If True, retrieve variables from other MPI processes as well.
rank (int or None) – If None, and get_remote is True, retrieve values from all MPI process to all other MPI processes. Otherwise, if get_remote is True, retrieve values from all MPI processes only to the specified rank.
return_rel_names (bool) – If True, the names returned will be relative to the scope of this System. Otherwise they will be absolute names.
- Returns:
A dict of metadata keyed on name, where name is either absolute or relative based on the value of the return_rel_names arg, and metadata is a dict containing entries based on the value of the metadata_keys arg. Every metadata dict will always contain two entries, ‘promoted_name’ and ‘discrete’, to indicate a given variable’s promoted name and whether or not it is discrete.
- Return type:
- get_linear_vectors()
Return the linear inputs, outputs, and residuals vectors.
- Returns:
(inputs, outputs, residuals) – Yields the linear inputs, outputs, and residuals vectors.
- Return type:
tuple of <Vector> instances
- get_nonlinear_vectors()
Return the inputs, outputs, and residuals vectors.
- Returns:
Yields the inputs, outputs, and residuals nonlinear vectors.
- Return type:
(inputs, outputs, residuals)
- get_objectives(recurse=True, get_sizes=True, use_prom_ivc=False)
Get the Objective settings from this system.
Retrieve all objectives settings from the system as a dict, keyed by variable name.
- Parameters:
- Returns:
The objectives defined in the current system.
- Return type:
- get_promotions(inprom=None, outprom=None)
Return all promotions for the given promoted variable(s).
In other words, how and where did promotions occur to convert absolute variable names into the given promoted name(s) at the current System level.
- Parameters:
- Returns:
Dictionary keyed on system pathname containing input and/or output promotion lists for each System where promotions occurred to produce the given promoted variable(s).
- Return type:
- get_relevant_vars(desvars, responses, mode)
Find all relevant vars between desvars and responses.
Both vars are assumed to be outputs (either design vars or responses).
- Parameters:
- Returns:
Dict of ({‘outputs’: dep_outputs, ‘inputs’: dep_inputs}, dep_systems) keyed by design vars and responses.
- Return type:
- get_reports_dir()
Get the path to the directory where the report files should go.
If it doesn’t exist, it will be created.
- Returns:
The path to the directory where reports should be written.
- Return type:
- get_responses(recurse=True, get_sizes=True, use_prom_ivc=False)
Get the response variable settings from this system.
Retrieve all response variable settings from the system as a dict, keyed by either absolute variable name, promoted name, or alias name, depending on the value of use_prom_ivc and whether the original key was a promoted output, promoted input, or an alias.
- Parameters:
- Returns:
The responses defined in the current system and, if recurse=True, its subsystems.
- Return type:
- get_source(name)
Return the source variable connected to the given named variable.
The name can be a promoted name or an absolute name. If the given variable is an input, the absolute name of the connected source will be returned. If the given variable itself is a source, its own absolute name will be returned.
- get_val(name, units=None, indices=None, get_remote=False, rank=None, vec_name='nonlinear', kind=None, flat=False, from_src=True)
Get an output/input/residual variable.
Function is used if you want to specify display units.
- Parameters:
name (str) – Promoted or relative variable name in the root system’s namespace.
units (str, optional) – Units to convert to before return.
indices (int or list of ints or tuple of ints or int ndarray or Iterable or None, optional) – Indices or slice to return.
get_remote (bool or None) – If True, retrieve the value even if it is on a remote process. Note that if the variable is remote on ANY process, this function must be called on EVERY process in the Problem’s MPI communicator. If False, only retrieve the value if it is on the current process, or only the part of the value that’s on the current process for a distributed variable. If None and the variable is remote or distributed, a RuntimeError will be raised.
rank (int or None) – If not None, only gather the value to this rank.
vec_name (str) – Name of the vector to use. Defaults to ‘nonlinear’.
kind (str or None) – Kind of variable (‘input’, ‘output’, or ‘residual’). If None, returned value will be either an input or output.
flat (bool) – If True, return the flattened version of the value.
from_src (bool) – If True, retrieve value of an input variable from its connected source.
- Returns:
The value of the requested output/input variable.
- Return type:
- guess_nonlinear(inputs, outputs, residuals, discrete_inputs=None, discrete_outputs=None)
Provide initial guess for states.
Override this method to set the initial guess for states.
- Parameters:
inputs (Vector) – Unscaled, dimensional input variables read via inputs[key].
outputs (Vector) – Unscaled, dimensional output variables read via outputs[key].
residuals (Vector) – Unscaled, dimensional residuals written to via residuals[key].
discrete_inputs (dict or None) – If not None, dict containing discrete input values.
discrete_outputs (dict or None) – If not None, dict containing discrete output values.
- initialize()
Perform any one-time initialization run at instantiation.
- is_explicit()
Return True if this is an explicit component.
- Returns:
True if this is an explicit component.
- Return type:
- property linear_solver
Get the linear solver for this system.
- list_inputs(val=True, prom_name=True, units=False, shape=False, global_shape=False, desc=False, hierarchical=True, print_arrays=False, tags=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, out_stream=DEFAULT_OUT_STREAM, print_min=False, print_max=False, return_format='list')
Write a list of input names and other optional information to a specified stream.
- Parameters:
val (bool, optional) – When True, display/return input values. Default is True.
prom_name (bool, optional) – When True, display/return the promoted name of the variable. Default is True.
units (bool, optional) – When True, display/return units. Default is False.
shape (bool, optional) – When True, display/return the shape of the value. Default is False.
global_shape (bool, optional) – When True, display/return the global shape of the value. Default is False.
desc (bool, optional) – When True, display/return description. Default is False.
hierarchical (bool, optional) – When True, human readable output shows variables in hierarchical format.
print_arrays (bool, optional) – When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.
tags (str or list of strs) – User defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.
includes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all input variables.
excludes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to exclude. Default is None.
is_indep_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.
is_design_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.
all_procs (bool, optional) – When True, display output on all ranks. Default is False, which will display output only from rank 0.
out_stream (file-like object) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.
print_min (bool) – When true, if the input value is an array, print its smallest value.
print_max (bool) – When true, if the input value is an array, print its largest value.
return_format (str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of input names and other optional information about those inputs.
- Return type:
metadata}
- list_outputs(explicit=True, implicit=True, val=True, prom_name=True, residuals=False, residuals_tol=None, units=False, shape=False, global_shape=False, bounds=False, scaling=False, desc=False, hierarchical=True, print_arrays=False, tags=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=DEFAULT_OUT_STREAM, print_min=False, print_max=False, return_format='list')
Write a list of output names and other optional information to a specified stream.
- Parameters:
explicit (bool, optional) – Include outputs from explicit components. Default is True.
implicit (bool, optional) – Include outputs from implicit components. Default is True.
val (bool, optional) – When True, display output values. Default is True.
prom_name (bool, optional) – When True, display the promoted name of the variable. Default is True.
residuals (bool, optional) – When True, display residual values. Default is False.
residuals_tol (float, optional) – If set, limits the output of list_outputs to only variables where the norm of the resids array is greater than the given ‘residuals_tol’. Default is None.
units (bool, optional) – When True, display units. Default is False.
shape (bool, optional) – When True, display/return the shape of the value. Default is False.
global_shape (bool, optional) – When True, display/return the global shape of the value. Default is False.
bounds (bool, optional) – When True, display/return bounds (lower and upper). Default is False.
scaling (bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.
desc (bool, optional) – When True, display/return description. Default is False.
hierarchical (bool, optional) – When True, human readable output shows variables in hierarchical format.
print_arrays (bool, optional) – When False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.
tags (str or list of strs) – User defined tags that can be used to filter what gets listed. Only outputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.
includes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.
excludes (None, str, or iter of str) – Collection of glob patterns for pathnames of variables to exclude. Default is None.
is_indep_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.
is_design_var (bool or None) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.
all_procs (bool, optional) – When True, display output on all processors. Default is False.
list_autoivcs (bool) – If True, include auto_ivc outputs in the listing. Defaults to False.
out_stream (file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.
print_min (bool) – When true, if the output value is an array, print its smallest value.
print_max (bool) – When true, if the output value is an array, print its largest value.
return_format (str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata}
- load_model_options()
Load the relevant model options from Problem._metadata[‘model_options’].
This method examines each path filter and corresponding options in self._problem_meta[‘model_options’]. If this System’s pathname matches the given path filter, it will assume the value for each given option which it possesses.
- property model_options
Get the model options from self._problem_meta.
The user may change the contents of model_options to impact values sent to subsystems of this Group.
- Returns:
The model options metadata provided by the associated Problem object.
- Return type:
- property msginfo
Our instance pathname, if available, or our class name. For use in error messages.
- Returns:
Either our instance pathname or class name.
- Return type:
- property nonlinear_solver
Get the nonlinear solver for this system.
- promotes(subsys_name, any=None, inputs=None, outputs=None, src_indices=None, flat_src_indices=None, src_shape=None)
Promote a variable in the model tree.
- Parameters:
subsys_name (str) – The name of the child subsystem whose inputs/outputs are being promoted.
any (Sequence of str or tuple) – A Sequence of variable names (or tuples) to be promoted, regardless of if they are inputs or outputs. This is equivalent to the items passed via the promotes= argument to add_subsystem. If given as a tuple, we use the “promote as” standard of “(‘real name’, ‘promoted name’)*[]:”.
inputs (Sequence of str or tuple) – A Sequence of input names (or tuples) to be promoted. Tuples are used for the “promote as” capability.
outputs (Sequence of str or tuple) – A Sequence of output names (or tuples) to be promoted. Tuples are used for the “promote as” capability.
src_indices (int or list of ints or tuple of ints or int ndarray or Iterable or None) – This argument applies only to promoted inputs. The global indices of the source variable to transfer data from. A value of None implies this input depends on all entries of source. Default is None. The shapes of the target and src_indices must match, and form of the entries within is determined by the value of ‘flat_src_indices’.
flat_src_indices (bool) – This argument applies only to promoted inputs. If True, each entry of src_indices is assumed to be an index into the flattened source. Otherwise each entry must be a tuple or list of size equal to the number of dimensions of the source.
src_shape (int or tuple) – Assumed shape of any connected source or higher level promoted input.
- record_iteration()
Record an iteration of the current System.
- run_apply_linear(mode, scope_out=None, scope_in=None)
Compute jac-vec product.
This calls _apply_linear, but with the model assumed to be in an unscaled state.
- run_apply_nonlinear()
Compute residuals.
This calls _apply_nonlinear, but with the model assumed to be in an unscaled state.
- run_linearize(sub_do_ln=True)
Compute jacobian / factorization.
This calls _linearize, but with the model assumed to be in an unscaled state.
- Parameters:
sub_do_ln (bool) – Flag indicating if the children should call linearize on their linear solvers.
- run_solve_linear(mode)
Apply inverse jac product.
This calls _solve_linear, but with the model assumed to be in an unscaled state.
- Parameters:
mode (str) – ‘fwd’ or ‘rev’.
- run_solve_nonlinear()
Compute outputs.
This calls _solve_nonlinear, but with the model assumed to be in an unscaled state.
- set_constraint_options(name, ref=UNDEFINED, ref0=UNDEFINED, equals=UNDEFINED, lower=UNDEFINED, upper=UNDEFINED, adder=UNDEFINED, scaler=UNDEFINED, alias=UNDEFINED)
Set options for objectives in the model.
Can be used to set options that were set using add_constraint.
- Parameters:
name (str) – Name of the response variable in the system.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
equals (float or ndarray, optional) – Equality constraint value for the variable.
lower (float or ndarray, optional) – Lower boundary for the variable.
upper (float or ndarray, optional) – Upper boundary for the variable.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
alias (str, optional) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
- set_design_var_options(name, lower=UNDEFINED, upper=UNDEFINED, scaler=UNDEFINED, adder=UNDEFINED, ref=UNDEFINED, ref0=UNDEFINED)
Set options for design vars in the model.
Can be used to set the options outside of setting them when calling add_design_var
- Parameters:
name (str) – Name of the variable in this system’s namespace.
lower (float or ndarray, optional) – Lower boundary for the input.
upper (upper or ndarray, optional) – Upper boundary for the input.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
ref (float or ndarray, optional) – Value of design var that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of design var that scales to 0.0 in the driver.
- set_initial_values()
Set all input and output variables to their declared initial values.
- set_input_defaults(name, val=UNDEFINED, units=None, src_shape=None)
Specify metadata to be assumed when multiple inputs are promoted to the same name.
- set_objective_options(name, ref=UNDEFINED, ref0=UNDEFINED, adder=UNDEFINED, scaler=UNDEFINED, alias=UNDEFINED)
Set options for objectives in the model.
Can be used to set options after they have been set by add_objective.
- Parameters:
name (str) – Name of the response variable in the system.
ref (float or ndarray, optional) – Value of response variable that scales to 1.0 in the driver.
ref0 (float or ndarray, optional) – Value of response variable that scales to 0.0 in the driver.
adder (float or ndarray, optional) – Value to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.
scaler (float or ndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.
alias (str) – Alias for this response. Necessary when adding multiple objectives on different indices or slices of a single variable.
- set_order(new_order)
Specify a new execution order for this system.
- set_output_solver_options(name, lower=UNDEFINED, upper=UNDEFINED, ref=UNDEFINED, ref0=UNDEFINED, res_ref=UNDEFINED)
Set solver output options.
Allows the user to set output solver options after the output has been defined and metadata set using the add_ouput method.
- Parameters:
name (str) – Name of the variable in this system’s namespace.
lower (float or list or tuple or ndarray or None) – Lower bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no lower bound. Default is None.
upper (float or list or tuple or ndarray or None) – Upper bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no upper bound. Default is None.
ref (float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.
ref0 (float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.
res_ref (float) – Scaling parameter. The value in the user-defined res_units of this output’s residual when the scaled value is 1. Default is None, which means residual scaling matches output scaling.
- set_solver_print(level=2, depth=1e+99, type_='all')
Control printing for solvers and subsolvers in the model.
- Parameters:
level (int) – Iprint level. Set to 2 to print residuals each iteration; set to 1 to print just the iteration totals; set to 0 to disable all printing except for failures, and set to -1 to disable all printing including failures.
depth (int) – How deep to recurse. For example, you can set this to 0 if you only want to print the top level linear and nonlinear solver messages. Default prints everything.
type (str) – Type of solver to set: ‘LN’ for linear, ‘NL’ for nonlinear, or ‘all’ for all.
- set_val(name, val, units=None, indices=None)
Set an input or output variable.
- setup()
Build this group.
This method should be overidden by your Group’s method. The reason for using this method to add subsystem is to save memory and setup time when using your Group while running under MPI. This avoids the creation of systems that will not be used in the current process.
You may call ‘add_subsystem’ to add systems to this group. You may also issue connections, and set the linear and nonlinear solvers for this group level. You cannot safely change anything on children systems; use the ‘configure’ method instead.
- Available attributes:
name pathname comm options
- system_iter(include_self=False, recurse=True, typ=None)
Yield a generator of local subsystems of this system.
- property under_approx
Return True if under complex step or finite difference.
- Returns:
True if under CS or FD.
- Return type:
- use_fixed_coloring(coloring=<object object>, recurse=True)
Use a precomputed coloring for this System.
- use_solvers_by_default = True