pub trait LinearOperator {
// Required methods
fn n_rows(&self) -> usize;
fn n_cols(&self) -> usize;
fn apply(&self, x: &[f64], y: &mut [f64]);
fn diagonal(&self, d: &mut [f64]);
// Provided method
fn residual(&self, x: &[f64], b: &[f64], r: &mut [f64]) { ... }
}Expand description
A square linear map A that can be applied to a vector.
This is the single contract the discretisation-agnostic Krylov solvers in
this module need. Implement it for any sparse (or dense, or matrix-free)
representation and cg_op / bicgstab_op / gmres_op work on it
unchanged.
§Contract
n_rowsandn_colsmust be equal and constant for the lifetime of the operator: these solvers are square-system solvers.applymust be linear and deterministic: the samexmust give bitwise the samey, andA(u + v) = Au + Avto rounding. A Krylov method that is handed a non-linear or noisy operator does not merely converge slowly, it converges to the wrong answer.diagonalmust writeA[i][i]intod[i].
§Units
Dimensionless. x and y are bare f64 slices in whatever units the
assembling layer chose; this contract neither knows nor enforces them.
§Implemented by
LduMatrix in this crate (face-addressed, finite-volume), and
farrer_park::sparse::CsrMatrix (row-compressed, finite-element).
Required Methods§
Sourcefn n_rows(&self) -> usize
fn n_rows(&self) -> usize
Number of rows of A (dimensionless count). Equals the length of y in
apply.
Sourcefn diagonal(&self, d: &mut [f64])
fn diagonal(&self, d: &mut [f64])
Write the main diagonal A[i][i] into d, which has length
n_rows.
Used to build a Jacobi preconditioner without exposing the storage
format. A structurally-zero diagonal entry must be written as 0.0;
JacobiOperatorPreconditioner is the layer that decides what to do
about it.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".