3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_LINEAR_SOLVER_HH
25#define DUMUX_LINEAR_SOLVER_HH
26
27#include <dune/common/exceptions.hh>
29
30namespace Dumux {
31
37{
38public:
41 using Scalar = double;
42
53 LinearSolver(const std::string& paramGroup = "")
54 : paramGroup_(paramGroup)
55 {
56 verbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Verbosity", 0);
57 maxIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.MaxIterations", 250);
58 residReduction_ = getParamFromGroup<double>(paramGroup, "LinearSolver.ResidualReduction", 1e-13);
59
60 // for deprecation period we ask also for the "old" parameters but print a warning
61 // the "new" style parameter takes precedence
62 // TODO: Remove all this code after 3.2 and use commented code below
63 if (hasParamInGroup(paramGroup, "LinearSolver.PreconditionerRelaxation"))
64 {
65 std::cerr << "Deprecation warning: parameter LinearSolver.PreconditionerRelaxation is deprecated and will be removed after 3.2. "
66 << "Use LinearSolver.Preconditioner.Relaxation instead (Preconditioner subgroup)." << std::endl;
67 relaxation_ = getParamFromGroup<double>(paramGroup, "LinearSolver.PreconditionerRelaxation");
68 }
69 else
70 relaxation_ = getParamFromGroup<double>(paramGroup, "LinearSolver.Preconditioner.Relaxation", 1);
71
72 if (hasParamInGroup(paramGroup, "LinearSolver.PreconditionerIterations"))
73 {
74 std::cerr << "Deprecation warning: parameter LinearSolver.PreconditionerIterations is deprecated and will be removed after 3.2. "
75 << "Use LinearSolver.Preconditioner.Iterations instead (Preconditioner subgroup)." << std::endl;
76 precondIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.PreconditionerIterations");
77 }
78 else
79 precondIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Iterations", 1);
80
81 if (hasParamInGroup(paramGroup, "LinearSolver.PreconditionerVerbosity"))
82 {
83 std::cerr << "Deprecation warning: parameter LinearSolver.PreconditionerVerbosity is deprecated and will be removed after 3.2. "
84 << "Use LinearSolver.Preconditioner.Verbosity instead (Preconditioner subgroup)." << std::endl;
85 precondVerbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.PreconditionerVerbosity");
86 }
87 else
88 precondVerbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Verbosity", 0);
89
90 // TODO: use this code instead of the above code after release 3.2
91 // relaxation_ = getParamFromGroup<double>(paramGroup, "LinearSolver.Preconditioner.Relaxation", 1);
92 // precondIter_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Iterations", 1);
93 // precondVerbosity_ = getParamFromGroup<int>(paramGroup, "LinearSolver.Preconditioner.Verbosity", 0);
94 }
95
100 template<class Matrix, class Vector>
101 bool solve(const Matrix& A, Vector& x, const Vector& b)
102 {
103 DUNE_THROW(Dune::NotImplemented, "Linear solver doesn't implement a solve method!");
104 }
105
107 std::string name() const
108 { return "unknown solver"; }
109
111 const std::string& paramGroup() const
112 { return paramGroup_; }
113
115 int verbosity() const
116 { return verbosity_; }
117
119 void setVerbosity(int v)
120 { verbosity_ = v; }
121
123 int maxIter() const
124 { return maxIter_; }
125
127 void setMaxIter(int i)
128 { maxIter_ = i; }
129
131 double residReduction() const
132 { return residReduction_; }
133
135 void setResidualReduction(double r)
136 { residReduction_ = r; }
137
139 double relaxation() const
140 { return relaxation_; }
141
143 void setRelaxation(double r)
144 { relaxation_ = r; }
145
147 int precondIter() const
148 { return precondIter_; }
149
151 void setPrecondIter(int i)
152 { precondIter_ = i; }
153
156 { return precondVerbosity_; }
157
159 void setPrecondVerbosity(int verbosityLevel)
160 { precondVerbosity_ = verbosityLevel; }
161
162private:
163 int verbosity_;
164 int maxIter_;
165 double residReduction_;
166 double relaxation_;
167 int precondIter_;
168 int precondVerbosity_;
169 const std::string paramGroup_;
170};
171
172} // end namespace Dumux
173
174#endif
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
bool hasParamInGroup(const std::string &paramGroup, const std::string &param)
Check whether a key exists in the parameter tree with a model group prefix.
Definition: parameters.hh:391
Definition: adapt.hh:29
Base class for linear solvers.
Definition: solver.hh:37
bool solve(const Matrix &A, Vector &x, const Vector &b)
Solve the linear system Ax = b.
Definition: solver.hh:101
int precondVerbosity() const
the preconditioner verbosity
Definition: solver.hh:155
void setResidualReduction(double r)
set the linear solver residual reduction
Definition: solver.hh:135
void setMaxIter(int i)
set the maximum number of linear solver iterations
Definition: solver.hh:127
int precondIter() const
the number of preconditioner iterations
Definition: solver.hh:147
double residReduction() const
the linear solver residual reduction
Definition: solver.hh:131
int maxIter() const
the maximum number of linear solver iterations
Definition: solver.hh:123
void setPrecondIter(int i)
set the number of preconditioner iterations
Definition: solver.hh:151
void setVerbosity(int v)
set the verbosity level
Definition: solver.hh:119
void setPrecondVerbosity(int verbosityLevel)
set the preconditioner verbosity
Definition: solver.hh:159
const std::string & paramGroup() const
the parameter group for getting parameter from the parameter tree
Definition: solver.hh:111
void setRelaxation(double r)
set the linear solver relaxation factor
Definition: solver.hh:143
LinearSolver(const std::string &paramGroup="")
Contruct the solver.
Definition: solver.hh:53
int verbosity() const
the verbosity level
Definition: solver.hh:115
std::string name() const
the name of the linear solver
Definition: solver.hh:107
double Scalar
Definition: solver.hh:41
double relaxation() const
the linear solver relaxation factor
Definition: solver.hh:139