# petsc_ksp.py

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

- Parameters

solverobjectThe openmdao solver.

- Attributes

_solver_solverThe openmdao solver.

_normfloatThe current norm.

_norm0floatThe norm for the first iteration.

`__init__`

(solver)[source]Store pointer to the openmdao solver and initialize norms.

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.

- Parameters

**kwargsdictDictionary of options set by the instantiating class/script.

- Attributes

preconSolverPreconditioner for linear solve. Default is None for no preconditioner.

_kspdistDictionary of KSP instances (keyed on vector name).

`SOLVER`

= 'LN: PETScKrylov'

`__init__`

(**kwargs)[source]Declare the solver options.

`add_recorder`

(recorder)Add a recorder to the solver’s RecordingManager.

- Parameters

recorder<CaseRecorder>A recorder instance to be added to RecManager.

`apply`

(mat,in_vec,result)[source]Apply preconditioner.

- Parameters

matPETSc.MatPETSc matrix object.

in_vecPETSc.VectorIncoming vector.

resultPETSc.VectorEmpty vector in which the preconditioned in_vec is stored.

`cleanup`

()Clean up resources prior to exit.

property`msginfo`

Return info to prepend to messages.

- Returns

- str
Info to prepend to messages.

`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:

- _systemSystem
pointer to the owning system.

- _vec_namestr
the right-hand-side (RHS) vector name.

- _modestr
‘fwd’ or ‘rev’.

- Parameters

matPETSc.MatPETSc matrix object.

in_vecPetSC VectorIncoming vector.

resultPetSC VectorEmpty array into which we place the matrix-vector product.

`record_iteration`

(**kwargs)Record an iteration of the current Solver.

- Parameters

**kwargsdictKeyword arguments (used for abs and rel error).

`solve`

(mode,rel_systems=None)[source]Solve the linear system for the problem in self._system().

The full solution vector is returned.

- Parameters

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

rel_systemsset of strNames of systems relevant to the current solve.