default_vector.py

default_vector.py#

Define the default Vector class.

class openmdao.vectors.default_vector.DefaultVector(name, kind, system, parent_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.

parent_vector<Vector>

Parent vector.

alloc_complexbool

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

Attributes:
dtype

Return the dtype of this vector.

Methods

TRANSFER

alias of DefaultTransfer

add_scal_vec(val, vec)

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

add_to_slice(slc, val)

Add a value to a slice of the vector.

asarray([copy])

Return an array representation of this vector.

dot(vec)

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

get_hash([alg])

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

get_info(name)

Get the info object for the given variable.

get_mask()

Return a mask for the vector based on the current matvec context.

get_norm()

Return the norm of this vector.

get_range(name)

Return the range of the variable in the local data array.

get_slice(slc)

Get a slice of the vector.

get_val(name[, flat])

Get the variable value.

iadd(val[, idxs])

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

imul(val[, idxs])

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

iscomplex()

Return True if this vector contains complex values.

isub(val[, idxs])

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

items([relative_to])

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

keys()

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

nvars()

Return the number of variables in this Vector.

ranges()

Yield (name, start, stop) for variables contained in this vector.

scale_to_norm([mode])

Scale this vector to normalized form.

scale_to_phys([mode])

Scale this vector to physical form.

set_complex_step_mode(active)

Turn on or off complex stepping mode.

set_val(val[, idxs])

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

set_vals(vals)

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

set_var(name, val[, idxs, flat, var_name])

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

set_vec(vec)

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

values()

Return values of variables contained in this vector.

TRANSFER

alias of DefaultTransfer

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.

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_range(name)[source]

Return the range of the variable in the local data array.

Parameters:
namestr

Name of the variable.

Returns:
tuple

Start and stop indices of the variable in the local data array.

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.

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.

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_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_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.