vecwrapper.py

Class definition for VecWrapper

class openmdao.core.vecwrapper.PlaceholderVecWrapper(name='')[source]

Bases: object

A placeholder for a dict-like container of a collection of variables.

Args:

name : str

the name of the vector

class openmdao.core.vecwrapper.SrcVecWrapper(pathname='', comm=None)[source]

Bases: openmdao.core.vecwrapper.VecWrapper

VecWrapper for params and dparams.

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

relevant_vars : iter of str

Names of variables that are relevant a particular 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.

class openmdao.core.vecwrapper.TgtVecWrapper(pathname='', comm=None)[source]

Bases: openmdao.core.vecwrapper.VecWrapper

Vecwrapper for unknowns, resids, dunknowns, and dresids.

setup(parent_params_vec, params_dict, srcvec, my_params, connections, relevant_vars=None, store_byobjs=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.

relevant_vars : iter of str

Names of variables that are relevant a particular variable of interest.

store_byobjs : bool, optional

If True, store ‘pass by object’ variables in the VecWrapper we’re building.

class openmdao.core.vecwrapper.VecWrapper(pathname='', 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_byobjs()[source]
Returns:

list

A list of names of variables that are passed by object rather than through scattering entries from one array to another.

get_local_idxs(name, idx_dict)[source]

Returns all of the indices for the named variable in this vector.

Args:

name : str

Name of variable to get the indices for.

Returns:

size

The size of the named variable.

ndarray

Index array containing all local indices for the named variable.

get_promoted_varname(abs_name)[source]

Returns the relative pathname for the given absolute variable pathname.

Args:

abs_name : str

Absolute pathname of a variable.

Returns:

rel_name : str

Relative name mapped to the given absolute pathname.

get_states()[source]
Returns:

list

A list of names of state variables.

get_vecvars()[source]
Returns:A list of names of variables found in our ‘vec’ array.
get_view(sys_pathname, comm, varmap, relevance, var_of_interest)[source]

Return a new VecWrapper that is a view into this one.

Args:

sys_pathname : str

pathname of the 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:

iterator

Iterator returning the name and 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(src_idxs, tgt_idxs)[source]

Return source and target index arrays, built up from smaller index arrays and combined in order of ascending source index (to allow us to convert src indices to a slice in some cases).

Args:

src_idxs : array

Source indices.

tgt_idxs : array

Target 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:

iterator

Iterator returning a metadata dict for each variable.

openmdao.core.vecwrapper.idx_merge(idxs)[source]

Combines a mixed iterator of int and iterator indices into an array of int indices.