version 3.8
solver.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_LINEAR_SOLVER_HH
13#define DUMUX_LINEAR_SOLVER_HH
14
15#include <dune/common/parallel/mpihelper.hh>
16#include <dune/common/exceptions.hh>
17#include <dune/istl/scalarproducts.hh>
19
20namespace Dumux {
21
27{
28public:
31 using Scalar = double;
32
43 LinearSolver(const std::string& paramGroup = "")
44 : paramGroup_(paramGroup)
45 {
46 verbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Verbosity", 0);
47 maxIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.MaxIterations", 250);
48 residReduction_ = getParamFromGroup<Scalar>(paramGroup, "LinearSolver.ResidualReduction", 1e-13);
49 relaxation_ = getParamFromGroup<Scalar>(paramGroup, "LinearSolver.Preconditioner.Relaxation", 1);
50 precondIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Iterations", 1);
51 precondVerbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Verbosity", 0);
52 }
53
58 template<class Matrix, class Vector>
59 bool solve(const Matrix& A, Vector& x, const Vector& b)
60 {
61 DUNE_THROW(Dune::NotImplemented, "Linear solver doesn't implement a solve method!");
62 }
63
64 template<class Vector>
65 auto norm(const Vector& x) const
66 {
67 if (Dune::MPIHelper::getCommunication().size() > 1)
68 DUNE_THROW(Dune::NotImplemented, "norm in parallel");
69
70 return Dune::SeqScalarProduct<Vector>().norm(x);
71 }
72
74 std::string name() const
75 { return "unknown solver"; }
76
78 const std::string& paramGroup() const
79 { return paramGroup_; }
80
82 int verbosity() const
83 { return verbosity_; }
84
86 void setVerbosity(int v)
87 { verbosity_ = v; }
88
90 int maxIter() const
91 { return maxIter_; }
92
94 void setMaxIter(int i)
95 { maxIter_ = i; }
96
99 { return residReduction_; }
100
103 { residReduction_ = r; }
104
107 { return relaxation_; }
108
111 { relaxation_ = r; }
112
114 int precondIter() const
115 { return precondIter_; }
116
118 void setPrecondIter(int i)
119 { precondIter_ = i; }
120
123 { return precondVerbosity_; }
124
126 void setPrecondVerbosity(int verbosityLevel)
127 { precondVerbosity_ = verbosityLevel; }
128
129private:
130 int verbosity_;
131 int maxIter_;
132 Scalar residReduction_;
133 Scalar relaxation_;
134 int precondIter_;
135 int precondVerbosity_;
136 const std::string paramGroup_;
137};
138
139} // end namespace Dumux
140
141#endif
Base class for linear solvers.
Definition: solver.hh:27
Scalar residReduction() const
the linear solver residual reduction
Definition: solver.hh:98
Scalar relaxation() const
the linear solver relaxation factor
Definition: solver.hh:106
bool solve(const Matrix &A, Vector &x, const Vector &b)
Solve the linear system Ax = b.
Definition: solver.hh:59
int precondVerbosity() const
the preconditioner verbosity
Definition: solver.hh:122
void setMaxIter(int i)
set the maximum number of linear solver iterations
Definition: solver.hh:94
int precondIter() const
the number of preconditioner iterations
Definition: solver.hh:114
auto norm(const Vector &x) const
Definition: solver.hh:65
int maxIter() const
the maximum number of linear solver iterations
Definition: solver.hh:90
void setPrecondIter(int i)
set the number of preconditioner iterations
Definition: solver.hh:118
void setVerbosity(int v)
set the verbosity level
Definition: solver.hh:86
void setPrecondVerbosity(int verbosityLevel)
set the preconditioner verbosity
Definition: solver.hh:126
const std::string & paramGroup() const
the parameter group for getting parameter from the parameter tree
Definition: solver.hh:78
void setRelaxation(Scalar r)
set the linear solver relaxation factor
Definition: solver.hh:110
LinearSolver(const std::string &paramGroup="")
Construct the solver.
Definition: solver.hh:43
int verbosity() const
the verbosity level
Definition: solver.hh:82
std::string name() const
the name of the linear solver
Definition: solver.hh:74
void setResidualReduction(Scalar r)
set the linear solver residual reduction
Definition: solver.hh:102
double Scalar
Definition: solver.hh:31
Definition: adapt.hh:17
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.