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