petsc_vector.py

Define the PETSc Vector and Transfer classes.

class openmdao.vectors.petsc_vector.PETScTransfer(in_vec, out_vec, in_inds, out_inds, comm)[source]

Bases: openmdao.vectors.default_vector.DefaultTransfer

PETSc Transfer implementation for running in parallel.

__init__(in_vec, out_vec, in_inds, out_inds, comm)

Initialize all attributes.

Parameters:

in_vec : <Vector>

pointer to the input vector.

out_vec : <Vector>

pointer to the output vector.

in_inds : int ndarray

input indices for the transfer.

out_inds : int ndarray

output indices for the transfer.

comm : MPI.Comm or <FakeComm>

communicator of the system that owns this transfer.

multi_transfer(in_vec, out_vec, mode='fwd')[source]

Perform transfer.

Parameters:

in_vec : <Vector>

pointer to the input vector.

out_vec : <Vector>

pointer to the output vector.

mode : str

‘fwd’ or ‘rev’.

transfer(in_vec, out_vec, mode='fwd')[source]

Perform transfer.

Parameters:

in_vec : <Vector>

pointer to the input vector.

out_vec : <Vector>

pointer to the output vector.

mode : str

‘fwd’ or ‘rev’.

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

Bases: openmdao.vectors.default_vector.DefaultVector

PETSc Vector implementation for running in parallel.

Most methods use the DefaultVector’s implementation.

TRANSFER

alias of PETScTransfer

__contains__(name)

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

Parameters:

name : str

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

Returns:

boolean

True or False.

__getitem__(name)

Get the unscaled variable value in true units.

Parameters:

name : str

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

Returns:

float or ndarray

variable value (not scaled, not dimensionless).

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

Initialize all attributes.

Parameters:

name : str

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

kind : str

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.

resize : bool

If true, resize the root vector.

alloc_complex : bool

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

ncol : int

Number of columns for multi-vectors.

relevant : dict

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

__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 unscaled variable value in true units.

Parameters:

name : str

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

value : float or list or tuple or ndarray

variable value to set (not scaled, not dimensionless)

add_scal_vec(val, vec)

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

Parameters:

val : int or float

scalar.

vec : <Vector>

this vector times val is added to self.

change_scaling_state(c0, c1)

Change the scaling state.

Parameters:

c0 : int ndarray[nvar_myproc]

0th order coefficients for scaling/unscaling.

c1 : int ndarray[nvar_myproc]

1st order coefficients for scaling/unscaling.

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)

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_data(new_array=None)

Get the array combining the data of all the varsets.

Parameters:

new_array : ndarray or None

Array to fill in with the values; otherwise new array created.

Returns:

ndarray

Array combining the data of all the varsets.

get_norm()[source]

Return the norm of this vector.

Returns:

float

norm of this vector.

iadd_data(array)

In-place add the incoming combined array.

Parameters:

array : ndarray

Array to set to the data for all the varsets.

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.

print_variables()

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

scale(scale_to)

Scale this vector to normalized or physical form.

Parameters:

scale_to : str

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

set_const(val)

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

Parameters:

val : int or float

scalar to set self to.

set_data(array)

Set the incoming array combining the data of all the varsets.

Parameters:

array : ndarray

Array to set to the data for all the varsets.

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.