vec_wrapper.py

Class definition for VecWrapper

class openmdao.core.vec_wrapper.Accessor(vecwrapper, slice, val, meta, owned=True)[source]

Bases: object

flat
get
meta
owned
pbo
remote
set
slice
val
class openmdao.core.vec_wrapper.SrcVecWrapper(sysdata, 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: float

Initial value for step in gradient direction.

duvec: `Vecwrapper`

Direction to apply step. generally the gradient.

Returns:

float

New step size, backtracked to prevent violation.

setup(unknowns_dict, relevance=None, var_of_interest=None, store_byobjs=False, shared_vec=None)[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.

class openmdao.core.vec_wrapper.TgtVecWrapper(sysdata, 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)[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.

class openmdao.core.vec_wrapper.VecWrapper(sysdata, comm=None)[source]

Bases: object

A dict-like container of a collection of variables.

Args:

pathname : str, optional

the pathname of the containing System

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.

iterkeys()[source]
Returns:

iter of str

the keys (variable names) in this vector.

itervalues()[source]
Returns:

iter of dict

Iterator yielding metadata dict for each variable.

keys()[source]
Returns:

list or KeyView (python 3)

the keys (variable names) in this vector.

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.

norm()[source]

Calculates the norm of this vector.

Returns:

float

Norm of our internal vector.

to_idx_array(indices)[source]

Given some iterator of indices, return an index array of the right int type for the current implementation.

Args:

indices : iterator of ints

An iterator of indices.

Returns:

ndarray of idx_arr_type

Index array containing all of the given indices.

values()[source]
Returns:

list of dict

List containing metadata dict for each variable.

vec_val_iter()[source]
Returns:

An iterator over names and values of all variables found in the

flattened vector, i.e., no pass_by_obj variables.