vec_wrapper.py¶
Class definition for VecWrapper
-
class
openmdao.core.vec_wrapper.
Accessor
(vecwrapper, slice, val, meta, probdata, alloc_complex, owned=True, imag_val=None, dangling=False)[source]¶ Bases:
object
-
class
openmdao.core.vec_wrapper.
SrcVecWrapper
(sysdata, probdata, comm=None)[source]¶ Bases:
openmdao.core.vec_wrapper.VecWrapper
Vecwrapper for unknowns, resids, dunknowns, and dresids.
-
distance_along_vector_to_limit
(alpha, duvec)[source]¶ Returns a new alpha so that new_u = current_u + alpha*duvec does not violate any lower or upper limits if specified.
Args: alpha: ndarray
Initial value for step in gradient direction.
duvec: `Vecwrapper`
Direction to apply step. generally the gradient.
Returns: ndarray
New step size(s), backtracked to prevent violation.
-
setup
(unknowns_dict, relevance=None, var_of_interest=None, store_byobjs=False, shared_vec=None, alloc_complex=False, vectype='u')[source]¶ Configure this vector to store a flattened array of the variables in unknowns. If store_byobjs is True, then ‘pass by object’ variables will also be stored.
Args: unknowns_dict : dict
Dictionary of metadata for unknown variables collected from components.
relevance : Relevance object
Object that knows what vars are relevant for each var_of_interest.
var_of_interest : str or None
Name of the current variable of interest.
store_byobjs : bool, optional
If True, then store ‘pass by object’ variables. By default only ‘pass by vector’ variables will be stored.
shared_vec : ndarray, optional
If not None, create vec as a subslice of this array.
alloc_complex : bool, optional
If True, allocate space for the imaginary part of the vector and configure all functions to support complex computation.
vectype : str(‘u’), optional
Type of vector, can be ‘u’ (unknown), ‘r’ (resids), ‘du’ (dunknowns), or ‘dr’ (dresids).
-
-
class
openmdao.core.vec_wrapper.
TgtVecWrapper
(sysdata, probdata, comm=None)[source]¶ Bases:
openmdao.core.vec_wrapper.VecWrapper
VecWrapper for params and dparams.
-
setup
(parent_params_vec, params_dict, srcvec, my_params, connections, relevance=None, var_of_interest=None, store_byobjs=False, shared_vec=None, alloc_complex=False)[source]¶ Configure this vector to store a flattened array of the variables in params_dict. Variable shape and value are retrieved from srcvec.
Args: parent_params_vec : VecWrapper or None
VecWrapper of parameters from the parent System.
params_dict : OrderedDict
Dictionary of parameter absolute name mapped to metadata dict.
srcvec : VecWrapper
Source VecWrapper corresponding to the target VecWrapper we’re building.
my_params : list of str
A list of absolute names of parameters that the VecWrapper we’re building will ‘own’.
connections : dict of str
A dict of absolute target names mapped to the absolute name of their source variable.
relevance : Relevance object
Object that knows what vars are relevant for each var_of_interest.
var_of_interest : str or None
Name of the current variable of interest.
store_byobjs : bool, optional
If True, store ‘pass by object’ variables in the VecWrapper we’re building.
shared_vec : ndarray, optional
If not None, create vec as a subslice of this array.
alloc_complex : bool, optional
If True, allocate space for the imaginary part of the vector and configure all functions to support complex computation.
-
-
class
openmdao.core.vec_wrapper.
VecWrapper
(sysdata, probdata, comm=None)[source]¶ Bases:
object
A dict-like container of a collection of variables.
Args: sysdata : _SysData
A data object for system level data
probdata : _ProbData
A data object for Problem level data that we need in order to store flags that span multiple layers in the hierarchy.
comm : an MPI communicator (real or fake)
a communicator that can be used for distributed operations when running under MPI. If not running under MPI, it is ignored
Attributes
idx_arr_type (dtype, optional) A dtype indicating how index arrays are to be represented. The value ‘i’ indicates an numpy integer array, other implementations, e.g., petsc, will define this differently. -
dump
(out_stream=<open file '<stdout>', mode 'w'>)[source]¶ Args: out_stream : file_like
Where to send human readable output. Default is sys.stdout. Set to None to return a str.
-
get_view
(system, comm, varmap)[source]¶ Return a new VecWrapper that is a view into this one.
Args: system : System
System for which the view is being created.
comm : an MPI communicator (real or fake)
A communicator that is used in the creation of the view.
varmap : dict
Mapping of variable names in the old VecWrapper to the names they will have in the new VecWrapper.
Returns: VecWrapper
A new VecWrapper that is a view into this one.
-
idx_arr_type
= 'i'¶
-
items
()[source]¶ Returns: list of (str, dict)
List of tuples containing the name and metadata dict for each variable.
-
iteritems
()[source]¶ Returns: iterator
Iterator returning the name and metadata dict for each variable.
-
make_idx_array
(start, end)[source]¶ Return an index vector of the right int type for the current implementation.
Args: start : int
The starting index.
end : int
The ending index.
Returns: ndarray of idx_arr_type
index array containing all indices from start up to but not including end
-
merge_idxs
(idxs)[source]¶ Return source and target index arrays, built up from smaller index arrays.
Args: idxs : array
Indices.
Returns: ndarray of idx_arr_type
Index array containing all of the merged indices.
-
metadata
(name)[source]¶ Returns the metadata for the named variable.
Args: name : str
Name of variable to get the metadata for.
Returns: dict
The metadata dict for the named variable.
Raises: KeyError
If the named variable is not in this vector.
-