istlsolverwrappers.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 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 2 of the License, or
9 (at your option) any later version.
10
11 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
44#ifndef EWOMS_ISTL_SOLVER_WRAPPERS_HH
45#define EWOMS_ISTL_SOLVER_WRAPPERS_HH
46
47#include <dune/istl/solvers.hh>
48
51
54
55namespace Opm::Linear {
56
60#define EWOMS_WRAP_ISTL_SOLVER(SOLVER_NAME, ISTL_SOLVER_NAME) \
61 template <class TypeTag> \
62 class SolverWrapper##SOLVER_NAME \
63 { \
64 using Scalar = GetPropType<TypeTag, Properties::Scalar>; \
65 using OverlappingMatrix = GetPropType<TypeTag, Properties::OverlappingMatrix>; \
66 using OverlappingVector = GetPropType<TypeTag, Properties::OverlappingVector>; \
67 \
68 public: \
69 using RawSolver = ISTL_SOLVER_NAME<OverlappingVector>; \
70 \
71 SolverWrapper##SOLVER_NAME() \
72 {} \
73 \
74 static void registerParameters() \
75 {} \
76 \
77 template <class LinearOperator, class ScalarProduct, class Preconditioner> \
78 std::shared_ptr<RawSolver> get(LinearOperator& parOperator, \
79 ScalarProduct& parScalarProduct, \
80 Preconditioner& parPreCond) \
81 { \
82 Scalar tolerance = Parameters::Get<Parameters::LinearSolverTolerance<Scalar>>(); \
83 int maxIter = Parameters::Get<Parameters::LinearSolverMaxIterations>();\
84 \
85 int verbosity = 0; \
86 if (parOperator.overlap().myRank() == 0) \
87 verbosity = Parameters::Get<Parameters::LinearSolverVerbosity>(); \
88 solver_ = std::make_shared<RawSolver>(parOperator, parScalarProduct, \
89 parPreCond, tolerance, maxIter, \
90 verbosity); \
91 \
92 return solver_; \
93 } \
94 \
95 void cleanup() \
96 { solver_.reset(); } \
97 \
98 private: \
99 std::shared_ptr<RawSolver> solver_; \
100 };
101
102EWOMS_WRAP_ISTL_SOLVER(Richardson, Dune::LoopSolver)
103EWOMS_WRAP_ISTL_SOLVER(SteepestDescent, Dune::GradientSolver)
104EWOMS_WRAP_ISTL_SOLVER(ConjugatedGradients, Dune::CGSolver)
105EWOMS_WRAP_ISTL_SOLVER(BiCGStab, Dune::BiCGSTABSolver)
106EWOMS_WRAP_ISTL_SOLVER(MinRes, Dune::MINRESSolver)
107
108
113template <class TypeTag>
115{
119
120public:
121 using RawSolver = Dune::RestartedGMResSolver<OverlappingVector>;
122
124 {}
125
126 static void registerParameters()
127 {
128 Parameters::Register<Parameters::GMResRestart>
129 ("Number of iterations after which the GMRES linear solver is restarted");
130 }
131
132 template <class LinearOperator, class ScalarProduct, class Preconditioner>
133 std::shared_ptr<RawSolver> get(LinearOperator& parOperator,
134 ScalarProduct& parScalarProduct,
135 Preconditioner& parPreCond)
136 {
137 Scalar tolerance = Parameters::Get<Parameters::LinearSolverTolerance<Scalar>>();
138 int maxIter = Parameters::Get<Parameters::LinearSolverMaxIterations>();
139
140 int verbosity = 0;
141 if (parOperator.overlap().myRank() == 0)
142 verbosity = Parameters::Get<Parameters::LinearSolverVerbosity>();
143 int restartAfter = Parameters::Get<Parameters::GMResRestart>();
144 solver_ = std::make_shared<RawSolver>(parOperator,
145 parScalarProduct,
146 parPreCond,
147 tolerance,
148 restartAfter,
149 maxIter,
150 verbosity);
151
152 return solver_;
153 }
154
155 void cleanup()
156 { solver_.reset(); }
157
158private:
159 std::shared_ptr<RawSolver> solver_;
160};
161
162#undef EWOMS_WRAP_ISTL_SOLVER
163
164} // namespace Opm::Linear
165
166#endif
Solver wrapper for the restarted GMRES solver of dune-istl.
Definition: istlsolverwrappers.hh:115
std::shared_ptr< RawSolver > get(LinearOperator &parOperator, ScalarProduct &parScalarProduct, Preconditioner &parPreCond)
Definition: istlsolverwrappers.hh:133
void cleanup()
Definition: istlsolverwrappers.hh:155
static void registerParameters()
Definition: istlsolverwrappers.hh:126
Dune::RestartedGMResSolver< OverlappingVector > RawSolver
Definition: istlsolverwrappers.hh:121
SolverWrapperRestartedGMRes()
Definition: istlsolverwrappers.hh:123
#define EWOMS_WRAP_ISTL_SOLVER(SOLVER_NAME, ISTL_SOLVER_NAME)
Macro to create a wrapper around an ISTL solver.
Definition: istlsolverwrappers.hh:60
Declares the parameters for the black oil model.
Declares the properties required by the black oil model.
Definition: bicgstabsolver.hh:42
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:235
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.