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:
- solverobject
The openmdao solver.
- Attributes:
- _solver_solver
The openmdao solver.
- _normfloat
The current norm.
- _norm0float
The 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:
LinearSolver
LinearSolver that uses PetSC KSP to solve for a system’s derivatives.
- Parameters:
- **kwargsdict
Dictionary of options set by the instantiating class/script.
- Attributes:
- preconSolver
Preconditioner for linear solve. Default is None for no preconditioner.
- _kspdist
Dictionary of KSP instances (keyed on vector name).
- _lin_rhs_checkerLinearRHSChecker or None
Object for checking the right-hand side of the linear solve.
- 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.Mat
PETSc matrix object.
- in_vecPETSc.Vector
Incoming vector.
- resultPETSc.Vector
Empty vector in which the preconditioned in_vec is stored.
- can_solve_cycle()
Return True if this solver can solve groups with cycles.
- Returns:
- bool
True if this solver can solve groups with cycles.
- cleanup()
Clean up resources prior to exit.
- does_recursive_applies()
Return False.
By default, assume linear solvers don’t do recursive apply_linear calls.
- Returns:
- bool
True if solver makes recursive apply_linear calls on its subsystems.
- get_outputs_dir(*subdirs, mkdir=True)
Get the path under which all output files of this solver are to be placed.
- Parameters:
- *subdirsstr
Subdirectories nested under the relevant problem output directory. To create {prob_output_dir}/a/b one would pass solver.get_outputs_dir(‘a’, ‘b’).
- mkdirbool
If True, attempt to create this directory if it does not exist.
- Returns:
- pathlib.Path
The path of the outputs directory for the problem.
- get_reports_dir()
Get the path to the directory where the report files should go.
If it doesn’t exist, it will be created.
- Returns:
- str
The path to the directory where reports should be written.
- 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.Mat
PETSc matrix object.
- in_vecPetSC Vector
Incoming vector.
- resultPetSC Vector
Empty array into which we place the matrix-vector product.
- record_iteration(**kwargs)
Record an iteration of the current Solver.
- Parameters:
- **kwargsdict
Keyword arguments (used for abs and rel error).
- report_failure(msg)
Report a failure that has occurred.
The msg may be printed or ignored depending on the iprint option, and may raise an AnalysisError depending on the err_on_non_converge option.
- Parameters:
- msgstr
Message indicating the failure.
- solve(mode, rel_systems=None)[source]
Solve the linear system for the problem in self._system().
The full solution vector is returned.
- Parameters:
- modestr
Derivative mode, can be ‘fwd’ or ‘rev’.
- rel_systemsset of str
Names of systems relevant to the current solve. Deprecated.
- use_relevance()[source]
Return True if relevance should be active.
- Returns:
- bool
True if relevance should be active.