vector.py

Define the base Vector and Transfer classes.

class openmdao.vectors.vector.Vector(name, kind, system, root_vector=None, resize=False, alloc_complex=False, ncol=1, relevant=None)[source]

Bases: object

Base Vector class.

This class is instantiated for inputs, outputs, and residuals. It provides a dictionary interface and an arithmetic operations interface. Implementations:

  • <DefaultVector>

  • <PETScVector>

Attributes

read_only

(bool) When True, values in the vector cannot be changed via the user __setitem__ API.

__contains__(self, name)[source]

Check if the variable is involved in the current mat-vec product.

Parameters
namestr

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

Returns
boolean

True or False.

__getitem__(self, name)[source]

Get the unscaled variable value in true units.

Parameters
namestr

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

Returns
float or ndarray

variable value (not scaled, not dimensionless).

__init__(self, name, kind, system, root_vector=None, resize=False, alloc_complex=False, ncol=1, relevant=None)[source]

Initialize all attributes.

Parameters
namestr

The name of the vector: ‘nonlinear’, ‘linear’, or right-hand side name.

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.

resizebool

If true, resize the root vector.

alloc_complexbool

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

ncolint

Number of columns for multi-vectors.

relevantdict

Mapping of a VOI to a tuple containing dependent inputs, dependent outputs, and dependent systems.

__iter__(self)[source]

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

Returns
listiterator

iterator over the variable names.

__setitem__(self, name, value)[source]

Set the unscaled variable value in true units.

Parameters
namestr

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

valuefloat or list or tuple or ndarray

variable value to set (not scaled, not dimensionless)

add_scal_vec(self, val, vec)[source]

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

Must be implemented by the subclass.

Parameters
valint or float

scalar.

vec<Vector>

this vector times val is added to self.

cite = ''
dot(self, vec)[source]

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

Must be implemented by the subclass.

Parameters
vec<Vector>

The incoming vector being dotted with self.

get_norm(self)[source]

Return the norm of this vector.

Must be implemented by the subclass.

Returns
float

norm of this vector.

keys(self)[source]

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

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

the variable names.

print_variables(self)[source]

Print the names and values of all variables in this vector, one per line.

scale(self, scale_to)[source]

Scale this vector to normalized or physical form.

Parameters
scale_tostr

Values are “phys” or “norm” to scale to physical or normalized.

set_complex_step_mode(self, active, keep_real=False)[source]

Turn on or off complex stepping mode.

When turned on, the default real ndarray is replaced with a complex ndarray and all pointers are updated to point to it.

Parameters
activebool

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

keep_realbool

When this flag is True, keep the real value when turning off complex step. You only need to do this when temporarily disabling complex step for guess_nonlinear.

set_const(self, val)[source]

Set the value of this vector to a constant scalar value.

Must be implemented by the subclass.

Parameters
valint or float

scalar to set self to.

set_vec(self, vec)[source]

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

Must be implemented by the subclass.

Parameters
vec<Vector>

the vector whose values self is set to.