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 */
43 #ifndef EWOMS_ISTL_SOLVER_WRAPPERS_HH
44 #define EWOMS_ISTL_SOLVER_WRAPPERS_HH
45 
48 
49 #include <dune/istl/solvers.hh>
50 
51 namespace Ewoms {
52 namespace Properties {
53 NEW_PROP_TAG(Scalar);
54 NEW_PROP_TAG(JacobianMatrix);
55 NEW_PROP_TAG(OverlappingMatrix);
56 NEW_PROP_TAG(OverlappingVector);
57 NEW_PROP_TAG(GMResRestart);
58 NEW_PROP_TAG(LinearSolverTolerance);
59 NEW_PROP_TAG(LinearSolverMaxIterations);
60 NEW_PROP_TAG(LinearSolverVerbosity);
61 } // namespace Properties
62 
63 namespace Linear {
64 
68 #define EWOMS_WRAP_ISTL_SOLVER(SOLVER_NAME, ISTL_SOLVER_NAME) \
69  template <class TypeTag> \
70  class SolverWrapper##SOLVER_NAME \
71  { \
72  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; \
73  typedef typename GET_PROP_TYPE(TypeTag, \
74  OverlappingMatrix) OverlappingMatrix; \
75  typedef typename GET_PROP_TYPE(TypeTag, \
76  OverlappingVector) OverlappingVector; \
77  \
78  public: \
79  typedef ISTL_SOLVER_NAME<OverlappingVector> RawSolver; \
80  \
81  SolverWrapper##SOLVER_NAME() \
82  {} \
83  \
84  static void registerParameters() \
85  {} \
86  \
87  template <class LinearOperator, class ScalarProduct, class Preconditioner> \
88  std::shared_ptr<RawSolver> get(LinearOperator& parOperator, \
89  ScalarProduct& parScalarProduct, \
90  Preconditioner& parPreCond) \
91  { \
92  Scalar tolerance = EWOMS_GET_PARAM(TypeTag, Scalar, \
93  LinearSolverTolerance); \
94  int maxIter = EWOMS_GET_PARAM(TypeTag, int, LinearSolverMaxIterations);\
95  \
96  int verbosity = 0; \
97  if (parOperator.overlap().myRank() == 0) \
98  verbosity = EWOMS_GET_PARAM(TypeTag, int, LinearSolverVerbosity); \
99  solver_ = std::make_shared<RawSolver>(parOperator, parScalarProduct, \
100  parPreCond, tolerance, maxIter, \
101  verbosity); \
102  \
103  return solver_; \
104  } \
105  \
106  void cleanup() \
107  { solver_.reset(); } \
108  \
109  private: \
110  std::shared_ptr<RawSolver> solver_; \
111  };
112 
113 EWOMS_WRAP_ISTL_SOLVER(Richardson, Dune::LoopSolver)
114 EWOMS_WRAP_ISTL_SOLVER(SteepestDescent, Dune::GradientSolver)
115 EWOMS_WRAP_ISTL_SOLVER(ConjugatedGradients, Dune::CGSolver)
116 EWOMS_WRAP_ISTL_SOLVER(BiCGStab, Dune::BiCGSTABSolver)
117 EWOMS_WRAP_ISTL_SOLVER(MinRes, Dune::MINRESSolver)
118 
119 
124 template <class TypeTag>
126 {
127  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
128  typedef typename GET_PROP_TYPE(TypeTag, OverlappingMatrix) OverlappingMatrix;
129  typedef typename GET_PROP_TYPE(TypeTag, OverlappingVector) OverlappingVector;
130 
131 public:
132  typedef Dune::RestartedGMResSolver<OverlappingVector> RawSolver;
133 
135  {}
136 
137  static void registerParameters()
138  {
139  EWOMS_REGISTER_PARAM(TypeTag, int, GMResRestart,
140  "Number of iterations after which the GMRES linear solver is restarted");
141  }
142 
143  template <class LinearOperator, class ScalarProduct, class Preconditioner>
144  std::shared_ptr<RawSolver> get(LinearOperator& parOperator,
145  ScalarProduct& parScalarProduct,
146  Preconditioner& parPreCond)
147  {
148  Scalar tolerance = EWOMS_GET_PARAM(TypeTag, Scalar, LinearSolverTolerance);
149  int maxIter = EWOMS_GET_PARAM(TypeTag, int, LinearSolverMaxIterations);
150 
151  int verbosity = 0;
152  if (parOperator.overlap().myRank() == 0)
153  verbosity = EWOMS_GET_PARAM(TypeTag, int, LinearSolverVerbosity);
154  int restartAfter = EWOMS_GET_PARAM(TypeTag, int, GMResRestart);
155  solver_ = std::make_shared<RawSolver>(parOperator,
156  parScalarProduct,
157  parPreCond,
158  tolerance,
159  restartAfter,
160  maxIter,
161  verbosity);
162 
163  return solver_;
164  }
165 
166  void cleanup()
167  { solver_.reset(); }
168 
169 private:
170  std::shared_ptr<RawSolver> solver_;
171 };
172 
173 #undef EWOMS_WRAP_ISTL_SOLVER
174 
175 }} // namespace Linear, Ewoms
176 
177 #endif
#define EWOMS_WRAP_ISTL_SOLVER(SOLVER_NAME, ISTL_SOLVER_NAME)
Macro to create a wrapper around an ISTL solver.
Definition: istlsolverwrappers.hh:68
Solver wrapper for the restarted GMRES solver of dune-istl.
Definition: istlsolverwrappers.hh:125
Definition: baseauxiliarymodule.hh:37
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:68
This file provides the infrastructure to retrieve run-time parameters.
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
Provides the magic behind the eWoms property system.
#define NEW_PROP_TAG(PTagName)
Define a property tag.
Definition: propertysystem.hh:247