pub fn cg_op<A, M>(
a: &A,
b: &[f64],
x0: Option<&[f64]>,
precond: &M,
settings: &KrylovSettings,
) -> (Vec<f64>, KrylovResult)Expand description
Preconditioned conjugate gradients for a symmetric positive-definite operator.
The right solver for a finite-element stiffness matrix, which is symmetric
by construction (K = integral of B^T D B with D symmetric), and for the
finite-volume pressure Poisson equation.
§Not a replacement for [crate::ldu_matrix::solvers::conjugate_gradient]
That function is the finite-volume path and keeps its DIC preconditioner and
its &LduMatrix signature unchanged. This one is generic over the operator
and takes the preconditioner from the caller. Neither calls the other.
§Arguments
a— the SPD system operator. Behaviour on a non-symmetric or indefinite operator is undefined (CG may stagnate or diverge); usegmres_oporbicgstab_opthere.b— right-hand side, lengtha.n_rows(), caller’s units.x0— optional initial guess;Nonemeans the zero vector. Pass the previous Newton iterate to warm-start.precond— SPD preconditionerM^{-1}.settings—tolerance(relative, on||b - A x||_2 / ||b||_2) andmax_iter.restartis ignored.
§Returns
(x, result). result.final_residual is the true relative residual of
the returned iterate, recomputed from a and b, never an internal
estimate. An exactly-zero b returns x = 0, converged, 0 iterations.
§Cost
One LinearOperator::apply and one OperatorPreconditioner::apply per
iteration, plus O(n) vector work. Storage O(n).