pub struct PerronSolver {
pub tol: f64,
pub max_iter: usize,
pub shift_margin: f64,
}Expand description
Power-iteration solver for the principal eigenpair of a symmetric operator.
Fields§
§tol: f64Convergence tolerance on the L2 distance between consecutive iterates.
max_iter: usizeMaximum number of power iterations.
shift_margin: f64Extra shift added to the Gershgorin lower bound. A positive margin guarantees a strictly positive definite shifted operator.
Implementations§
Source§impl PerronSolver
impl PerronSolver
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a solver with default settings.
§Examples
use solver::numeric::ergodic::PerronSolver;
let solver = PerronSolver::new();
assert_eq!(solver.tol, 1e-10);Sourcepub fn with_max_iter(self, max_iter: usize) -> Self
pub fn with_max_iter(self, max_iter: usize) -> Self
Sourcepub fn with_shift_margin(self, shift_margin: f64) -> Self
pub fn with_shift_margin(self, shift_margin: f64) -> Self
Sourcepub fn solve<const N: usize, P: StationaryEigenProblem<N>>(
&self,
grid: &Grid<N>,
problem: &P,
) -> PerronSolution
pub fn solve<const N: usize, P: StationaryEigenProblem<N>>( &self, grid: &Grid<N>, problem: &P, ) -> PerronSolution
Solves for the principal eigenpair of problem on grid.
Power iteration is applied to A + shift * I, where A is the
operator and shift is chosen from the Gershgorin lower bound so that
the shifted operator is positive definite. Shifting preserves
eigenvectors and moves every eigenvalue by the same constant, so the
returned eigenvalue subtracts the shift.
§Panics
Panics if problem.operator(grid) has a different size from the grid.
§Examples
use solver::core::grid::Grid;
use solver::linalg::csr::CsrMatrix;
use solver::numeric::ergodic::{PerronSolver, StationaryEigenProblem};
struct Single;
impl StationaryEigenProblem<1> for Single {
fn operator(&self, _grid: &Grid<1>) -> CsrMatrix {
let mut mat = CsrMatrix::new(1, 1);
mat.add_entry(0, 5.0);
mat.finish_row();
mat
}
}
let grid = Grid::<1>::new([1], [0.0], [0.0]);
let solution = PerronSolver::new().solve(&grid, &Single);
assert!((solution.eigenvalue - 5.0).abs() < 1e-12);Trait Implementations§
Source§impl Clone for PerronSolver
impl Clone for PerronSolver
Source§fn clone(&self) -> PerronSolver
fn clone(&self) -> PerronSolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for PerronSolver
Source§impl Debug for PerronSolver
impl Debug for PerronSolver
Auto Trait Implementations§
impl Freeze for PerronSolver
impl RefUnwindSafe for PerronSolver
impl Send for PerronSolver
impl Sync for PerronSolver
impl Unpin for PerronSolver
impl UnsafeUnpin for PerronSolver
impl UnwindSafe for PerronSolver
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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