Skip to main content

Preconditioner

Enum Preconditioner 

Source
pub enum Preconditioner {
    Identity,
    Jacobi(JacobiPreconditioner),
    Ilu0(Ilu0Preconditioner),
}
Expand description

Preconditioner M^{-1} ≈ A^{-1}, dispatched by enum (no trait objects).

A preconditioner turns a residual r into z = M^{-1} r, an approximate error, which the Krylov solvers use to accelerate convergence. Construct one from the system matrix with Preconditioner::jacobi or Preconditioner::ilu0, or use Preconditioner::identity for none.

Variants§

§

Identity

No preconditioning: M = I, so z = r.

§

Jacobi(JacobiPreconditioner)

Diagonal (Jacobi) scaling: z = r / diag(A).

§

Ilu0(Ilu0Preconditioner)

ILU(0) incomplete factorisation: z = (LU)^{-1} r.

Implementations§

Source§

impl Preconditioner

Source

pub fn identity() -> Self

Identity preconditioner (M = I) — equivalent to no preconditioning.

Source

pub fn jacobi(a: &LduMatrix) -> Self

Build a Jacobi (reciprocal-diagonal) preconditioner from a.

Cannot break down: a zero diagonal entry is treated as 1.0. The guaranteed-robust choice when ILU(0) is not warranted.

Source

pub fn ilu0(a: &LduMatrix) -> Self

Build an ILU(0) preconditioner from a (same sparsity pattern as A).

A genuine incomplete LU factorisation with a small-pivot guard; see Ilu0Preconditioner. Typically far stronger than Jacobi on diagonally-dominant / mildly ill-conditioned systems.

Source

pub fn apply(&self, r: &[f64], z: &mut [f64])

Apply the preconditioner serially: write z = M^{-1} r.

r and z must both have length n_cells. For Preconditioner::Identity this copies r into z. Equivalent to Self::apply_on with ComputeBackend::Serial.

Source

pub fn apply_on(&self, r: &[f64], z: &mut [f64], backend: ComputeBackend)

Apply the preconditioner on the chosen ComputeBackend: write z = M^{-1} r.

§How much each variant actually parallelises
VariantBackend honoured?Why
Identityno — copy_from_slicealready a single memcpy; there is nothing to thread
Jacobiyesone independent multiply per cell — embarrassingly parallel
Ilu0no — always serialthe triangular solves have a loop-carried dependence; see Ilu0Preconditioner::apply_on

This table is the honest answer to “did the preconditioners move onto the backend?”: one of the three did, and the reason the other two did not is structural rather than unfinished work.

§Determinism

All three variants are bitwise identical across backends and thread counts, and bitwise identical to Self::apply. Two are serial anyway, and Jacobi is element-wise, so no summation is reassociated. A caller may therefore switch backend without perturbing a solver’s iteration count or residual history through the preconditioner.

§Arguments
  • r — residual to precondition, length n_cells.
  • z — output buffer, length n_cells. Fully overwritten.
  • backend — requested execution backend.

Trait Implementations§

Source§

impl OperatorPreconditioner for Preconditioner

Source§

fn apply(&self, r: &[f64], z: &mut [f64])

Bridges the existing finite-volume preconditioner enum onto the generic contract, so an LduMatrix caller can use cg_op / gmres_op / bicgstab_op with ILU(0) as well as Jacobi.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.