numerics
Loading...
Searching...
No Matches
krylov.hpp
Go to the documentation of this file.
1/// @file krylov.hpp
2/// @brief Restarted GMRES -- a Krylov subspace solver for general Ax = b
3#pragma once
5#include "linalg/solvers/cg.hpp" // MatVecFn
7#include "core/matrix.hpp"
8#include "core/vector.hpp"
9#include "core/policy.hpp"
10
11namespace num {
12
13/// @brief Restarted GMRES(restart) -- matrix-free interface
14///
15/// Works for any invertible A (symmetric or non-symmetric, indefinite).
16/// The Krylov subspace is restarted every @p restart steps to bound memory.
17///
18/// @param matvec Callable computing y = A*x
19/// @param n System dimension
20/// @param b Right-hand side
21/// @param x Initial guess (modified in-place -> solution)
22/// @param tol Convergence tolerance on residual norm
23/// @param max_iter Maximum total matrix-vector products
24/// @param restart Krylov subspace size before restart (default 30)
25/// @return SolverResult with convergence info
26SolverResult gmres(MatVecFn matvec, idx n, const Vector& b, Vector& x,
27 real tol = 1e-6, idx max_iter = 1000, idx restart = 30);
28
29/// @brief Restarted GMRES with a sparse (CSR) matrix
30SolverResult gmres(const SparseMatrix& A, const Vector& b, Vector& x,
31 real tol = 1e-6, idx max_iter = 1000, idx restart = 30);
32
33/// @brief Restarted GMRES with a dense matrix
34/// @param backend Backend for the internal matvec at each Arnoldi step
35SolverResult gmres(const Matrix& A, const Vector& b, Vector& x,
36 real tol = 1e-6, idx max_iter = 1000, idx restart = 30,
37 Backend backend = default_backend);
38
39} // namespace num
Conjugate gradient solvers (dense and matrix-free)
Matrix operations.
double real
Definition types.hpp:10
Backend
Selects which backend handles a linalg operation.
Definition policy.hpp:19
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
std::size_t idx
Definition types.hpp:11
void matvec(const Matrix &A, const Vector &x, Vector &y, Backend b=default_backend)
y = A * x
Definition matrix.cpp:94
SolverResult gmres(MatVecFn matvec, idx n, const Vector &b, Vector &x, real tol=1e-6, idx max_iter=1000, idx restart=30)
Restarted GMRES(restart) – matrix-free interface.
Definition krylov.cpp:11
constexpr real e
Definition math.hpp:41
BasicVector< real > Vector
Real-valued dense vector with full backend dispatch (CPU + GPU)
Definition vector.hpp:122
constexpr Backend default_backend
Definition policy.hpp:57
std::function< void(const Vector &, Vector &)> MatVecFn
Callable type for matrix-free matvec: computes y = A*x.
Definition cg.hpp:13
Backend enum for linear algebra operations.
Common result type shared by all iterative solvers.
Compressed Sparse Row (CSR) matrix and operations.
Vector operations.