petsc_ksp.py

LinearSolver that uses PetSC KSP to solve for a system’s derivatives.

class openmdao.solvers.linear.petsc_ksp.Monitor(solver)[source]

Bases: object

Prints output from PETSc’s KSP solvers.

Callable object given to KSP as a callback for printing the residual.

__init__(solver)[source]

Store pointer to the openmdao solver and initialize norms.

Parameters:
solver : object

the openmdao solver.

class openmdao.solvers.linear.petsc_ksp.PETScKrylov(**kwargs)[source]

Bases: openmdao.solvers.solver.LinearSolver

LinearSolver that uses PetSC KSP to solve for a system’s derivatives.

Attributes

precon (Solver) Preconditioner for linear solve. Default is None for no preconditioner.
SOLVER = 'LN: PETScKrylov'
__init__(**kwargs)[source]

Declare the solver options.

Parameters:
**kwargs : dict

dictionary of options set by the instantiating class/script.

add_recorder(recorder)

Add a recorder to the driver’s RecordingManager.

Parameters:
recorder : <BaseRecorder>

A recorder instance to be added to RecManager.

apply(mat, in_vec, result)[source]

Apply preconditioner.

Parameters:
mat : PETSc.Mat

PETSc matrix object.

in_vec : PETSc.Vector

Incoming vector

result : PETSc.Vector

Empty vector in which the preconditioned in_vec is stored.

mult(mat, in_vec, result)[source]

Apply Jacobian matrix (KSP Callback).

The following attributes must be defined when solve is called to provide information used in this callback:

_system : System
pointer to the owning system.
_vec_name : str
the right-hand-side (RHS) vector name.
_mode : str
‘fwd’ or ‘rev’.
Parameters:
mat : PETSc.Mat

PETSc matrix object.

in_vec : PetSC Vector

Incoming vector.

result : PetSC Vector

Empty array into which we place the matrix-vector product.

preconditioner

Provide ‘preconditioner’ property for backwards compatibility.

Returns:
<LinearSolver>

reference to the ‘precon’ property.

record_iteration(**kwargs)

Record an iteration of the current Solver.

Parameters:
**kwargs : dict

Keyword arguments (used for abs and rel error).

solve(vec_names, mode, rel_systems=None)[source]

Solve the linear system for the problem in self._system.

The full solution vector is returned.

Parameters:
vec_names : list

list of vector names.

mode : string

Derivative mode, can be ‘fwd’ or ‘rev’.

rel_systems : set of str

Names of systems relevant to the current solve.

Returns:
boolean

Failure flag; True if failed to converge, False is successful.

float

absolute error.

float

relative error.

class openmdao.solvers.linear.petsc_ksp.PetscKSP(**kwargs)[source]

Bases: openmdao.solvers.linear.petsc_ksp.PETScKrylov

Deprecated. Use PETScKrylov.

SOLVER = 'LN: PETScKrylov'
__init__(**kwargs)[source]

Initialize attributes.

Parameters:
**kwargs : dict

Named args.

add_recorder(recorder)

Add a recorder to the driver’s RecordingManager.

Parameters:
recorder : <BaseRecorder>

A recorder instance to be added to RecManager.

apply(mat, in_vec, result)

Apply preconditioner.

Parameters:
mat : PETSc.Mat

PETSc matrix object.

in_vec : PETSc.Vector

Incoming vector

result : PETSc.Vector

Empty vector in which the preconditioned in_vec is stored.

mult(mat, in_vec, result)

Apply Jacobian matrix (KSP Callback).

The following attributes must be defined when solve is called to provide information used in this callback:

_system : System
pointer to the owning system.
_vec_name : str
the right-hand-side (RHS) vector name.
_mode : str
‘fwd’ or ‘rev’.
Parameters:
mat : PETSc.Mat

PETSc matrix object.

in_vec : PetSC Vector

Incoming vector.

result : PetSC Vector

Empty array into which we place the matrix-vector product.

preconditioner

Provide ‘preconditioner’ property for backwards compatibility.

Returns:
<LinearSolver>

reference to the ‘precon’ property.

record_iteration(**kwargs)

Record an iteration of the current Solver.

Parameters:
**kwargs : dict

Keyword arguments (used for abs and rel error).

solve(vec_names, mode, rel_systems=None)

Solve the linear system for the problem in self._system.

The full solution vector is returned.

Parameters:
vec_names : list

list of vector names.

mode : string

Derivative mode, can be ‘fwd’ or ‘rev’.

rel_systems : set of str

Names of systems relevant to the current solve.

Returns:
boolean

Failure flag; True if failed to converge, False is successful.

float

absolute error.

float

relative error.