numerics
0.1.0
Loading...
Searching...
No Matches
krylov.cpp
Go to the documentation of this file.
1
#include "
linalg/solvers/krylov.hpp
"
2
#include "
operator/operators.hpp
"
3
#include <stdexcept>
4
5
namespace
num
{
6
7
// Sparse overload
8
SolverResult
gmres
(
const
SparseMatrix
& A,
9
const
Vector
& b,
10
Vector
& x,
11
real
tol,
12
idx
max_iter,
13
idx
restart) {
14
if
(A.
n_rows
() != A.
n_cols
())
15
throw
std::invalid_argument(
"GMRES requires a square matrix"
);
16
operators::SparseOp
op(A);
17
return
gmres
(op, b, x, tol, max_iter, restart);
18
}
19
20
// Dense overload -- wraps the matrix-free core with a backend-parameterized
21
// matvec
22
SolverResult
gmres
(
const
Matrix
& A,
23
const
Vector
& b,
24
Vector
& x,
25
real
tol,
26
idx
max_iter,
27
idx
restart,
28
Backend
backend) {
29
if
(A.
rows
() != A.
cols
())
30
throw
std::invalid_argument(
"GMRES requires a square matrix"
);
31
operators::DenseOp
op(A, backend);
32
return
gmres
(op, b, x, tol, max_iter, restart);
33
}
34
35
}
// namespace num
num::BasicMatrix< real >
num::BasicMatrix::rows
constexpr idx rows() const noexcept
Definition
matrix.hpp:87
num::BasicMatrix::cols
constexpr idx cols() const noexcept
Definition
matrix.hpp:88
num::BasicVector< real >
num::SparseMatrix
Sparse matrix in Compressed Sparse Row (CSR) format.
Definition
sparse.hpp:15
num::SparseMatrix::n_cols
idx n_cols() const
Definition
sparse.hpp:34
num::SparseMatrix::n_rows
idx n_rows() const
Definition
sparse.hpp:33
krylov.hpp
Restarted GMRES for general linear systems.
num
Definition
quadrature.hpp:8
num::real
double real
Definition
types.hpp:10
num::Backend
Backend
Definition
policy.hpp:7
num::gmres
SolverResult gmres(const Op &A, const Vector &b, Vector &x, real tol=1e-6, idx max_iter=1000, idx restart=30)
Operator GMRES for any adapter.
Definition
krylov.hpp:24
num::idx
std::size_t idx
Definition
types.hpp:11
operators.hpp
Umbrella include for operator concepts and adapters.
num::SolverResult
Definition
solver_result.hpp:8
num::operators::DenseOp
Adapt a dense Matrix to the operator protocol.
Definition
dense.hpp:12
num::operators::SparseOp
Adapt a SparseMatrix to the operator protocol.
Definition
sparse.hpp:11
src
linalg
solvers
krylov.cpp
Generated by
1.9.8