Skip to main content

RealSparseSystem

Struct RealSparseSystem 

Source
pub struct RealSparseSystem { /* private fields */ }
Expand description

A real sparse system whose sparsity pattern is fixed across repeated solves (Newton-Raphson’s Jacobian: same bus topology every iteration, only numeric values change) — caches both the LU symbolic factorization (ordering + fill-in) and the triplet argsort (which sparse-matrix slot each triplet’s value lands in) once, and reuses both on each call.

Reusing the argsort matters on its own, separately from the LU symbolic reuse: without it, every call would still re-sort and re-deduplicate the full triplet list from scratch even though only the values differ between calls — profiling with perf on a 2,605-node benchmark showed this re-sorting cost was ~10% of total Newton-Raphson time (comparable to the LU factorization itself), since a fresh try_new_from_triplets was being paid for on every iteration despite the (row, col) pattern never changing. new_from_argsort skips straight to placing values using the cached order.

Implementations§

Source§

impl RealSparseSystem

Source

pub fn new(n: usize, entries: &[(usize, usize, f64)]) -> Option<Self>

Builds the symbolic factorization and argsort from an initial sparsity pattern. Subsequent calls to factor_and_solve must supply entries with the exact same (row, col) pairs in the exact same order (values may differ) — the cached argsort assumes positional correspondence, not just set equality.

Source

pub fn factor_and_solve( &self, entries: &[(usize, usize, f64)], rhs: &[f64], ) -> Option<Vec<f64>>

Numeric-only refactorization against the cached symbolic pattern and argsort, then solves A x = b. Returns None if the matrix is singular (see solve_complex’s doc comment for why this needs an explicit check).

Source

pub fn solve_values(&self, vals: &[f64], rhs: &[f64]) -> Option<Vec<f64>>

The body of factor_and_solve once the (row, col) half of the triplets has been dropped — which this backend never needed after new built the argsort.

A vals length other than the one new was given means the caller’s pattern is not this factorization’s — a stale cache, which gridoxide’s PersistentSolver::invalidate_admittances can produce when a topology change alters the bus types and therefore the unknown count. That is refused here rather than left to trip an assertion inside faer: this type’s whole contract is None on a system it cannot solve, and a panic crossing an FFI boundary is a much worse failure than a reported one.

Trait Implementations§

Source§

impl LinearSolver for RealSparseSystem

factor_and_solve is inherently &self here (faer keeps no mutable per-solve state), but the trait takes &mut self because the FFI-backed backends genuinely need it. Taking the stricter receiver costs nothing.

Source§

fn new(n: usize, entries: &[(usize, usize, f64)]) -> Option<Self>

Analyzes entries’ sparsity pattern (fill-reducing ordering, elimination structure) and factors it once. None if the pattern is structurally invalid or the matrix is singular.
Source§

fn factor_and_solve( &mut self, entries: &[(usize, usize, f64)], rhs: &[f64], ) -> Option<Vec<f64>>

Numeric-only refactorization against the cached pattern, then solves A x = b. None if the matrix is singular at these values.
Source§

fn factor_and_solve_values( &mut self, values: &[f64], rhs: &[f64], ) -> Option<Vec<f64>>

As factor_and_solve, but taking only the nonzero values, positionally matching the entries passed to new. Read more

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V