/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/timestepping/linear_solver/GMRES.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/timestepping/linear_solver/GMRES.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
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// standard library
8#include <type_traits>
9
10// DiFfRG
12
13namespace DiFfRG
14{
15 template <typename SparseMatrixType, typename VectorType,
16 typename PreconditionerType = dealii::PreconditionJacobi<SparseMatrixType>>
17 class GMRES : public AbstractLinearSolver<SparseMatrixType, VectorType>
18 {
19 public:
20 static constexpr bool performs_factorization = false;
21
22 GMRES() : matrix(nullptr) {}
23
24 void init(const SparseMatrixType &matrix)
25 {
26 this->matrix = &matrix;
27 if constexpr (std::is_same_v<PreconditionerType, dealii::PreconditionIdentity>)
28 preconditioner.initialize(matrix, dealii::PreconditionIdentity::AdditionalData{});
29 else
30 preconditioner.initialize(matrix, 1.0);
31 }
32
33 bool invert() { return false; }
34
35 int solve(const VectorType &src, VectorType &dst, const double tol)
36 {
37 if (!matrix) throw std::runtime_error("GMRES::solve: matrix not initialized");
38 dealii::SolverControl solver_control(std::max<std::size_t>(1000, src.size() / 10), tol);
39 dealii::SolverGMRES<VectorType> solver(solver_control);
40
41 solver.solve(*matrix, dst, src, preconditioner);
42
43 int steps = solver_control.last_step();
44 return steps;
45 }
46
47 private:
48 const SparseMatrixType *matrix;
49 PreconditionerType preconditioner;
50 };
51} // namespace DiFfRG
Definition abstract_linear_solver.hh:11
Definition GMRES.hh:18
GMRES()
Definition GMRES.hh:22
bool invert()
Definition GMRES.hh:33
void init(const SparseMatrixType &matrix)
Definition GMRES.hh:24
int solve(const VectorType &src, VectorType &dst, const double tol)
Definition GMRES.hh:35
static constexpr bool performs_factorization
Definition GMRES.hh:20
PreconditionerType preconditioner
Definition GMRES.hh:49
const SparseMatrixType * matrix
Definition GMRES.hh:48
Definition complex_math.hh:10