pub struct ComplexLinSolver<'a> {
pub actual: Box<dyn Send + ComplexLinSolTrait + 'a>,
}Expand description
Unifies the access to linear system solvers
Fields§
§actual: Box<dyn Send + ComplexLinSolTrait + 'a>Holds the actual implementation
Implementations§
Source§impl<'a> ComplexLinSolver<'a>
impl<'a> ComplexLinSolver<'a>
Sourcepub fn compute(
genie: Genie,
x: &mut ComplexVector,
mat: &ComplexCooMatrix,
rhs: &ComplexVector,
params: Option<LinSolParams>,
) -> Result<Self, StrError>
pub fn compute( genie: Genie, x: &mut ComplexVector, mat: &ComplexCooMatrix, rhs: &ComplexVector, params: Option<LinSolParams>, ) -> Result<Self, StrError>
Computes the solution of a complex linear system
Solves the linear system:
A · x = rhs
(m,n) (n) (m)§Output
x– the vector of unknown values with dimension equal to mat.ncol
§Input
genie– the actual implementation that does all the magicmat– the matrix representing the sparse coefficient matrix A (see Notes below)rhs– the right-hand side vector with know values an dimension equal to coo.nrowverbose– shows messages
§Notes
- For symmetric matrices,
MUMPSrequires crate::Sym::YesLower - For symmetric matrices,
UMFPACKrequires crate::Sym::YesFull - This function calls the actual implementation (genie) via the functions
factorize, andsolve. - This function is best for a single-use, whereas the actual solver should be considered for a recurrent use (e.g., inside a loop).
§Examples
use russell_lab::{complex_vec_approx_eq, cpx, ComplexVector};
use russell_sparse::prelude::*;
use russell_sparse::StrError;
fn main() -> Result<(), StrError> {
let ndim = 3;
let nnz = 7;
// allocate the coefficient matrix
// ┌ ┐
// │ 2+1i -1-1i 0 │
// │ -1-1i 2+2i -1+1i │
// │ 0 -1+1i 2-1i │
// └ ┘
let mut mat = ComplexCooMatrix::new(ndim, ndim, nnz, Sym::No)?;
mat.put(0, 0, cpx!(2.0, 1.0))?;
mat.put(0, 1, cpx!(-1.0, -1.0))?;
mat.put(1, 0, cpx!(-1.0, -1.0))?;
mat.put(1, 1, cpx!(2.0, 2.0))?;
mat.put(1, 2, cpx!(-1.0, 1.0))?;
mat.put(2, 1, cpx!(-1.0, 1.0))?;
mat.put(2, 2, cpx!(2.0, -1.0))?;
let rhs = ComplexVector::from(&[cpx!(-3.0, 3.0), cpx!(2.0, -2.0), cpx!(9.0, 7.0)]);
let mut x = ComplexVector::new(ndim);
ComplexLinSolver::compute(Genie::Umfpack, &mut x, &mat, &rhs, None)?;
let correct = &[cpx!(1.0, 1.0), cpx!(2.0, -2.0), cpx!(3.0, 3.0)];
complex_vec_approx_eq(&x, correct, 1e-14);
Ok(())
}Auto Trait Implementations§
impl<'a> !RefUnwindSafe for ComplexLinSolver<'a>
impl<'a> !Sync for ComplexLinSolver<'a>
impl<'a> !UnwindSafe for ComplexLinSolver<'a>
impl<'a> Freeze for ComplexLinSolver<'a>
impl<'a> Send for ComplexLinSolver<'a>
impl<'a> Unpin for ComplexLinSolver<'a>
impl<'a> UnsafeUnpin for ComplexLinSolver<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more