DiFfRG
Loading...
Searching...
No Matches
GMRES.hh
Go to the documentation of this file.
1#pragma once
2
3// external libraries
4#include <deal.II/lac/precondition.h>
5#include <deal.II/lac/solver_gmres.h>
6
7// DiFfRG
9
10namespace DiFfRG
11{
12 template <typename SparseMatrixType, typename VectorType>
13 class GMRES : public AbstractLinearSolver<SparseMatrixType, VectorType>
14 {
15 public:
16 GMRES() : matrix(nullptr) {}
17
18 void init(const SparseMatrixType &matrix) { this->matrix = &matrix; }
19
20 bool invert() { return false; }
21
22 int solve(const VectorType &src, VectorType &dst, const double tol)
23 {
24 if (!matrix) throw std::runtime_error("GMRES::solve: matrix not initialized");
25 dealii::SolverControl solver_control(std::max<std::size_t>(1000, src.size() / 10), tol);
26 dealii::SolverGMRES<VectorType> solver(solver_control);
27
28 preconditioner.initialize(*matrix, 1.0);
29 solver.solve(*matrix, dst, src, preconditioner);
30
31 return solver_control.last_step();
32 }
33
34 private:
35 const SparseMatrixType *matrix;
36 dealii::PreconditionJacobi<SparseMatrixType> preconditioner;
37 };
38} // namespace DiFfRG
Definition abstract_linear_solver.hh:9
Definition GMRES.hh:14
int solve(const VectorType &src, VectorType &dst, const double tol)
Definition GMRES.hh:22
const SparseMatrixType * matrix
Definition GMRES.hh:35
GMRES()
Definition GMRES.hh:16
dealii::PreconditionJacobi< SparseMatrixType > preconditioner
Definition GMRES.hh:36
bool invert()
Definition GMRES.hh:20
void init(const SparseMatrixType &matrix)
Definition GMRES.hh:18
Definition complex_math.hh:14