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
50
51#include <dune/istl/solvers.hh>
52
53namespace Opm::Linear {
54
58#define EWOMS_WRAP_ISTL_SOLVER(SOLVER_NAME, ISTL_SOLVER_NAME) \
59 template <class TypeTag> \
60 class SolverWrapper##SOLVER_NAME \
61 { \
62 using Scalar = GetPropType<TypeTag, Properties::Scalar>; \
63 using OverlappingMatrix = GetPropType<TypeTag, Properties::OverlappingMatrix>; \
64 using OverlappingVector = GetPropType<TypeTag, Properties::OverlappingVector>; \
65 \
66 public: \
67 using RawSolver = ISTL_SOLVER_NAME<OverlappingVector>; \
68 \
69 SolverWrapper##SOLVER_NAME() \
70 {} \
71 \
72 static void registerParameters() \
73 {} \
74 \
75 template <class LinearOperator, class ScalarProduct, class Preconditioner> \
76 std::shared_ptr<RawSolver> get(LinearOperator& parOperator, \
77 ScalarProduct& parScalarProduct, \
78 Preconditioner& parPreCond) \
79 { \
80 Scalar tolerance = Parameters::get<TypeTag, Properties::LinearSolverTolerance>(); \
81 int maxIter = Parameters::get<TypeTag, Properties::LinearSolverMaxIterations>();\
82 \
83 int verbosity = 0; \
84 if (parOperator.overlap().myRank() == 0) \
85 verbosity = Parameters::get<TypeTag, Properties::LinearSolverVerbosity>(); \
86 solver_ = std::make_shared<RawSolver>(parOperator, parScalarProduct, \
87 parPreCond, tolerance, maxIter, \
88 verbosity); \
89 \
90 return solver_; \
91 } \
92 \
93 void cleanup() \
94 { solver_.reset(); } \
95 \
96 private: \
97 std::shared_ptr<RawSolver> solver_; \
98 };
99
100EWOMS_WRAP_ISTL_SOLVER(Richardson, Dune::LoopSolver)
101EWOMS_WRAP_ISTL_SOLVER(SteepestDescent, Dune::GradientSolver)
102EWOMS_WRAP_ISTL_SOLVER(ConjugatedGradients, Dune::CGSolver)
103EWOMS_WRAP_ISTL_SOLVER(BiCGStab, Dune::BiCGSTABSolver)
104EWOMS_WRAP_ISTL_SOLVER(MinRes, Dune::MINRESSolver)
105
106
111template <class TypeTag>
113{
117
118public:
119 using RawSolver = Dune::RestartedGMResSolver<OverlappingVector>;
120
122 {}
123
124 static void registerParameters()
125 {
126 Parameters::registerParam<TypeTag, Properties::GMResRestart>
127 ("Number of iterations after which the GMRES linear solver is restarted");
128 }
129
130 template <class LinearOperator, class ScalarProduct, class Preconditioner>
131 std::shared_ptr<RawSolver> get(LinearOperator& parOperator,
132 ScalarProduct& parScalarProduct,
133 Preconditioner& parPreCond)
134 {
135 Scalar tolerance = Parameters::get<TypeTag, Properties::LinearSolverTolerance>();
136 int maxIter = Parameters::get<TypeTag, Properties::LinearSolverMaxIterations>();
137
138 int verbosity = 0;
139 if (parOperator.overlap().myRank() == 0)
140 verbosity = Parameters::get<TypeTag, Properties::LinearSolverVerbosity>();
141 int restartAfter = Parameters::get<TypeTag, Properties::GMResRestart>();
142 solver_ = std::make_shared<RawSolver>(parOperator,
143 parScalarProduct,
144 parPreCond,
145 tolerance,
146 restartAfter,
147 maxIter,
148 verbosity);
149
150 return solver_;
151 }
152
153 void cleanup()
154 { solver_.reset(); }
155
156private:
157 std::shared_ptr<RawSolver> solver_;
158};
159
160#undef EWOMS_WRAP_ISTL_SOLVER
161
162} // namespace Opm::Linear
163
164#endif
Solver wrapper for the restarted GMRES solver of dune-istl.
Definition: istlsolverwrappers.hh:113
std::shared_ptr< RawSolver > get(LinearOperator &parOperator, ScalarProduct &parScalarProduct, Preconditioner &parPreCond)
Definition: istlsolverwrappers.hh:131
void cleanup()
Definition: istlsolverwrappers.hh:153
static void registerParameters()
Definition: istlsolverwrappers.hh:124
Dune::RestartedGMResSolver< OverlappingVector > RawSolver
Definition: istlsolverwrappers.hh:119
SolverWrapperRestartedGMRes()
Definition: istlsolverwrappers.hh:121
#define EWOMS_WRAP_ISTL_SOLVER(SOLVER_NAME, ISTL_SOLVER_NAME)
Macro to create a wrapper around an ISTL solver.
Definition: istlsolverwrappers.hh:58
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:242
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.