15 #ifndef ALLIUM_LA_CG_HPP
16 #define ALLIUM_LA_CG_HPP
18 #include <allium/util/extern.hpp>
19 #include "vector_storage.hpp"
20 #include "sparse_matrix.hpp"
21 #include "linear_solver.hpp"
22 #include <allium/util/warnings.hpp>
33 using Real = real_part_t<N>;
46 int iteration_count() {
return m_iteration_count; }
49 int m_iteration_count;
64 using typename LinearSolver<V>::Vector;
65 using Number =
typename Vector::Number;
66 using Real =
typename Vector::Real;
71 void setup(std::shared_ptr<Matrix> mat)
override {
75 void solve(Vector& solution,
82 std::shared_ptr<Matrix> m_mat;
85 ALLIUM_NO_NONNULL_WARNING
86 allium_assert(
dynamic_cast<const V*
>(&in) !=
nullptr);
87 allium_assert(
dynamic_cast<V*
>(&out) !=
nullptr);
88 ALLIUM_RESTORE_WARNING
89 allium_assert(
static_cast<bool>(m_mat),
"operator provided");
91 m_mat->apply(
static_cast<V&
>(out),
92 static_cast<const V&
>(in));
103 template <
typename V,
typename M>
104 void cg(V& solution, std::shared_ptr<M> mat,
const V& rhs, real_part_t<typename V::Number> tol = 1e-8)
108 solver.solve(solution, rhs);
111 #define ALLIUM_CG_DECL(extern, N) \
112 extern template class CgSolverBase<N>;
113 ALLIUM_EXTERN_N(ALLIUM_CG_DECL)
Base for the conjugate gradient method.
Definition: cg.hpp:30
The conjugate gradient method, solves .
Definition: cg.hpp:61
Linear operator for the use in iterative linear solvers.
Definition: linear_operator.hpp:29
Linear solver interface.
Definition: linear_solver.hpp:42
Abstract base class for any vector storage.
Definition: vector_storage.hpp:41
void cg(V &solution, std::shared_ptr< M > mat, const V &rhs, real_part_t< typename V::Number > tol=1e-8)
The conjugate gradient method.
Definition: cg.hpp:104
InitialGuess
Behavior for the initial guess.
Definition: linear_solver.hpp:32
@ NOT_PROVIDED
Initialize with zero.