petsc_vector.py

Define the PETSc Vector classe.

class openmdao.vectors.petsc_vector.PETScVector(name, kind, system, root_vector=None, alloc_complex=False, ncol=1)[source]

Bases: openmdao.vectors.default_vector.DefaultVector

PETSc Vector implementation for running in parallel.

Most methods use the DefaultVector’s implementation.

TRANSFER

alias of openmdao.vectors.petsc_transfer.PETScTransfer

__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
boolean

True or False.

__getitem__(name)

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, ncol=1)[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.

alloc_complexbool

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

ncolint

Number of columns for multi-vectors.

__iter__()

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

Returns
listiterator

iterator over the variable names.

__setitem__(name, value)

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)

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)

Return an array representation of this vector.

If copy is True, return a copy. Otherwise, try to avoid it.

Parameters
copybool

If True, return a copy of the array.

Returns
ndarray

Array representation of this vector.

cite = '@InProceedings{petsc-efficient,\n Author = "Satish Balay and William D. Gropp and Lois Curfman McInnes and Barry F. Smith",\n Title = "Efficient Management of Parallelism in Object Oriented Numerical Software Libraries",\n Booktitle = "Modern Software Tools in Scientific Computing",\n Editor = "E. Arge and A. M. Bruaset and H. P. Langtangen",\n Pages = "163--202",\n Publisher = "Birkh{"{a}}user Press",\n Year = "1997"\n}'
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_norm()[source]

Return the norm of this vector.

Returns
float

norm of this vector.

get_slice_dict()

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))

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))

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()

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))

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.

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.

scale(scale_to)

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(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))

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_var(name, val, idxs=slice(None, None, None), flat=False)

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.

set_vec(vec)

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.

Returns
list

the variable values.