default_vector.py

default_vector.py#

Define the default Vector class.

class openmdao.vectors.default_vector.DefaultVector(name, kind, system, root_vector=None, alloc_complex=False)[source]

Bases: Vector

Default NumPy vector.

Parameters:
namestr

The name of the vector: ‘nonlinear’ or ‘linear’.

kindstr

The kind of vector, ‘input’, ‘output’, or ‘residual’.

system<System>

Pointer to the owning system.

root_vector<Vector>

Pointer to the vector owned by the root system.

alloc_complexbool

Whether to allocate any imaginary storage to perform complex step. Default is False.

Attributes:
_views_reldict or None

If owning system is a component, this will contain a mapping of relative names to views.

TRANSFER

alias of DefaultTransfer

__contains__(name)

Check if the variable is found in this vector.

Parameters:
namestr

Promoted or relative variable name in the owning system’s namespace.

Returns:
bool

True or False.

__getitem__(name)[source]

Get the variable value.

Parameters:
namestr

Promoted or relative variable name in the owning system’s namespace.

Returns:
float or ndarray

variable value.

__init__(name, kind, system, root_vector=None, alloc_complex=False)[source]

Initialize all attributes.

__iter__()

Return an iterator over variables involved in the current mat-vec product (relative names).

Returns:
listiterator

iterator over the variable names.

__setitem__(name, value)[source]

Set the variable value.

Parameters:
namestr

Promoted or relative variable name in the owning system’s namespace.

valuefloat or list or tuple or ndarray

variable value to set

add_scal_vec(val, vec)[source]

Perform in-place addition of a vector times a scalar.

Parameters:
valint or float

Scalar.

vec<Vector>

This vector times val is added to self.

asarray(copy=False)[source]

Return an array representation of this vector.

If copy is True, return a copy.

Parameters:
copybool

If True, return a copy of the array.

Returns:
ndarray

Array representation of this vector.

cite = ''
distributed = False
dot(vec)[source]

Compute the dot product of the real parts of the current vec and the incoming vec.

Parameters:
vec<Vector>

The incoming vector being dotted with self.

Returns:
float

The computed dot product value.

get_hash(alg=<built-in function openssl_sha1>)[source]

Return a hash string for the array contained in this Vector.

Parameters:
algfunction

Algorithm used to generate the hash. Default is hashlib.sha1.

Returns:
str

The hash string.

get_norm()[source]

Return the norm of this vector.

Returns:
float

Norm of this vector.

get_slice_dict()[source]

Return a dict of var names mapped to their slice in the local data array.

Returns:
dict

Mapping of var name to slice.

iadd(val, idxs=slice(None, None, None))[source]

Add the value to the data array at the specified indices or slice(s).

Parameters:
valndarray

Value to set into the data array.

idxsint or slice or tuple of ints and/or slices

The locations where the data array should be updated.

idxs2nameloc(idxs)[source]

Given some indices, return a dict mapping variable name to corresponding local indices.

This is slow and is meant to be used only for debugging or maybe error messages.

Parameters:
idxslist of int

Vector indices to be converted to local indices for each corresponding variable.

Returns:
dict

Mapping of variable name to a list of local indices into that variable.

imul(val, idxs=slice(None, None, None))[source]

Multiply the value to the data array at the specified indices or slice(s).

Parameters:
valndarray

Value to set into the data array.

idxsint or slice or tuple of ints and/or slices

The locations where the data array should be updated.

iscomplex()[source]

Return True if this vector contains complex values.

This checks the type of the values, not whether they have a nonzero imaginary part.

Returns:
bool

True if this vector contains complex values.

isub(val, idxs=slice(None, None, None))[source]

Subtract the value from the data array at the specified indices or slice(s).

Parameters:
valndarray

Value to set into the data array.

idxsint or slice or tuple of ints and/or slices

The locations where the data array should be updated.

items()

Return (name, value) for variables contained in this vector.

Yields:
str

Relative name of each variable.

ndarray or float

Value of each variable.

keys()

Return variable names of variables contained in this vector (relative names).

Returns:
listiterator (Python 3.x) or list (Python 2.x)

The variable names.

nvars()

Return the number of variables in this Vector.

Returns:
int

Number of variables in this Vector.

scale_to_norm(mode='fwd')[source]

Scale this vector to normalized form.

Parameters:
modestr

Derivative direction.

scale_to_phys(mode='fwd')[source]

Scale this vector to physical form.

Parameters:
modestr

Derivative direction.

set_complex_step_mode(active)

Turn on or off complex stepping mode.

Parameters:
activebool

Complex mode flag; set to True prior to commencing complex step.

set_val(val, idxs=slice(None, None, None))[source]

Set the data array of this vector to a value, with optional indexing.

Parameters:
valfloat or ndarray

Scalar or array to set data array to.

idxsint or slice or tuple of ints and/or slices

The locations where the data array should be updated.

set_vals(vals)

Set the data array of this vector using a value or iter of values, one for each variable.

The values must be in the same order as the variables appear in this Vector.

Parameters:
valsiter of ndarrays

Values for each variable contained in this vector, in the proper order.

set_var(name, val, idxs=slice(None, None, None), flat=False, var_name=None)

Set the array view corresponding to the named variable, with optional indexing.

Parameters:
namestr

The name of the variable.

valfloat or ndarray

Scalar or array to set data array to.

idxsint or slice or tuple of ints and/or slices

The locations where the data array should be updated.

flatbool

If True, set into flattened variable.

var_namestr or None

If specified, the variable name to use when reporting errors. This is useful when setting an AutoIVC value that the user only knows by a connected input name.

set_vec(vec)[source]

Set the value of this vector to that of the incoming vector.

Parameters:
vec<Vector>

The vector whose values self is set to.

values()

Return values of variables contained in this vector.

Yields:
ndarray or float

Value of each variable.