Linear Solvers
This section describes the interface for a linear solver. This also provides a means to access some of the functions implemented by AbstractPC
and AbstractLO
. Whenever a linear solver is used, the linear solver API should be used rather than accessing the AbstractPC
and AbstractLO
Type Hierarchy
LinearSolver
StandardLinearSolver
StandardLinearSolver(::Any, ::Any, ::MPI.Comm)
API
LinearSolvers.calcPC
— Method.Calculates the preconditioner for the linear solver. Thsi preconditioner will be used for all linear solves until this function is called again.
For direct solvers, this function calculates the linear operator itself. Prefer calcPCandLO
whenever possible.
Inputs
ls: StandardLinearSolver
mesh
sbp
eqn
opts
ctx_residual: the ctx required by
physicsRhs
like functionst: current time
Keyword Arguments
start_comm: start parallel communication (if required by the PC), default false. This means the user is generally required to make sure parallel communication is started before calling this function.
LinearSolvers.calcLinearOperator
— Method.Calculates the linear operator. Use this function only if you want to calculate the linear operator and not the preconditioner. Prefer calcPCandLO
, which avoids calculating the matrix twice if the preconditioner and linear operator share the same matrix
Inputs
ls: StandardLinearSolver
mesh
sbp
eqn
opts
ctx_residual: the ctx required by
physicsRhs
like functionst: current time
Keyword Arguments
start_comm: start parallel communication (if required by the lo), default false. This means the user is generally required to make sure parallel communication is started before calling this function.
LinearSolvers.calcPCandLO
— Method.Calculates both the preconditioner and linear operator. In the case where they share the matrix, the calculation is only performed once. This function should be preferred to calling calcPC
and calcLinearOperator
one after the other
Inputs
ls: StandardLinearSolver
mesh
sbp
eqn
opts
ctx_residual: the ctx required by
physicsRhs
like functionst: current time
Keyword Arguments
start_comm: start parallel communication (if required by the lo), default false. This means the user is generally required to make sure parallel communication is started before calling this function. Note that it is not possible to interleave communication and computation in this case, so performing communication will be very expensive.
LinearSolvers.applyPC
— Method.Apply the preconditioner, ie. x = inv(Ap)*b, where Ap is an approximation to the linear operator used for preconditioner. This function also works for matrix-free methods.
Note that calcPC
or calcPCandLO
must be called before this function can be used.
For direct methods, a linear solve is performed because there is no preconditioner.
LinearSolvers.applyPCTranspose
— Method.Like applyPC
, but applies the transpose (if possible, otherwise throws an error).
LinearSolvers.linearSolve
— Function.Solves the linear system Ax = b for x. This function does not recompute the precondtioner or linear operator, The preconditioner and linear operator used are the ones calculated by the most recent call to calcPC
, calcLinearOperator
(or calcPCandLO
.
For Petsc matrices, this function does the final matrix assembly.
Inputs
ls: the
StandardLinearSolver
object.b: the right hand side vector (local process portion only)
verbose: verbosity level, default 5, < 4 indicates no output
Inputs/Outputs
x: vector overwritten with result (local process portion only)
Implementation Notes:
The preconditioner and matrix factorization (for direct solves) might be computed during this function, but they will be computed at the state correspondong to the last call to the functions that calculate them.
LinearSolvers.linearSolveTranspose
— Function.Similar to linearSolve
, but solves A.'x = b. See that function for details.
LinearSolvers.isLOMatFree
— Function.Returns true if the linear operator is matrix free, false otherwise
LinearSolvers.isPCMatFree
— Function.Returns true if the preconditioner is matrix free, false otherwise
LinearSolvers.setTolerances
— Function.Set the tolerances for iterative solves. Has no effect for direct solves. Supplying a negative value results in retaining the original value.
Inputs
ls: StandardLinearSolver
reltol: relative residual tolerance
abstol: absolute residual tolerance
dtol: divergence tolerance
itermax: maximum number of iterations
Utils.free
— Method.This function frees any memory owned by external libraries, both in the StandardLinearSolver object itself and in the pc and lo objects. Therefore, at the end of a run, all you need to do is free the StandardLinearSolver and everything will be taken care of.
It is safe to call this function multiple times.