opm-simulators
istlpreconditionerwrappers.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_PRECONDITIONER_WRAPPERS_HH
45 #define EWOMS_ISTL_PRECONDITIONER_WRAPPERS_HH
46 
47 #include <dune/common/version.hh>
48 
51 
54 
55 #include <opm/simulators/linalg/ilufirstelement.hh> // definitions needed in next header
56 #include <dune/istl/preconditioners.hh>
57 
58 namespace Opm {
59 namespace Linear {
60 #define EWOMS_WRAP_ISTL_PRECONDITIONER(PREC_NAME, ISTL_PREC_TYPE) \
61  template <class TypeTag> \
62  class PreconditionerWrapper##PREC_NAME \
63  { \
64  using Scalar = GetPropType<TypeTag, Properties::Scalar>; \
65  using SparseMatrixAdapter = GetPropType<TypeTag, Properties::SparseMatrixAdapter>; \
66  using IstlMatrix = typename SparseMatrixAdapter::IstlMatrix; \
67  using OverlappingVector = GetPropType<TypeTag, Properties::OverlappingVector>; \
68  \
69  public: \
70  using SequentialPreconditioner = ISTL_PREC_TYPE<IstlMatrix, \
71  OverlappingVector, \
72  OverlappingVector>; \
73  PreconditionerWrapper##PREC_NAME() \
74  {} \
75  \
76  static void registerParameters() \
77  { \
78  Parameters::Register<Parameters::PreconditionerOrder> \
79  ("The order of the preconditioner"); \
80  Parameters::Register<Parameters::PreconditionerRelaxation<Scalar>> \
81  ("The relaxation factor of the preconditioner"); \
82  } \
83  \
84  void prepare(IstlMatrix& matrix) \
85  { \
86  int order = Parameters::Get<Parameters::PreconditionerOrder>(); \
87  Scalar relaxationFactor = Parameters::Get<Parameters::PreconditionerRelaxation<Scalar>>(); \
88  seqPreCond_ = new SequentialPreconditioner(matrix, order, \
89  relaxationFactor); \
90  } \
91  \
92  SequentialPreconditioner& get() \
93  { return *seqPreCond_; } \
94  \
95  void cleanup() \
96  { delete seqPreCond_; } \
97  \
98  private: \
99  SequentialPreconditioner *seqPreCond_; \
100  };
101 
102 // the same as the EWOMS_WRAP_ISTL_PRECONDITIONER macro, but without
103 // an 'order' argument for the preconditioner's constructor
104 #define EWOMS_WRAP_ISTL_SIMPLE_PRECONDITIONER(PREC_NAME, ISTL_PREC_TYPE) \
105  template <class TypeTag> \
106  class PreconditionerWrapper##PREC_NAME \
107  { \
108  using Scalar = GetPropType<TypeTag, Properties::Scalar>; \
109  using OverlappingMatrix = GetPropType<TypeTag, Properties::OverlappingMatrix>; \
110  using OverlappingVector = GetPropType<TypeTag, Properties::OverlappingVector>; \
111  \
112  public: \
113  using SequentialPreconditioner = ISTL_PREC_TYPE<OverlappingMatrix, \
114  OverlappingVector, \
115  OverlappingVector>; \
116  PreconditionerWrapper##PREC_NAME() \
117  {} \
118  \
119  static void registerParameters() \
120  { \
121  Parameters::Register<Parameters::PreconditionerRelaxation<Scalar>> \
122  ("The relaxation factor of the preconditioner"); \
123  } \
124  \
125  void prepare(OverlappingMatrix& matrix) \
126  { \
127  Scalar relaxationFactor = \
128  Parameters::Get<Parameters::PreconditionerRelaxation<Scalar>>();\
129  seqPreCond_ = new SequentialPreconditioner(matrix, \
130  relaxationFactor); \
131  } \
132  \
133  SequentialPreconditioner& get() \
134  { return *seqPreCond_; } \
135  \
136  void cleanup() \
137  { delete seqPreCond_; } \
138  \
139  private: \
140  SequentialPreconditioner *seqPreCond_; \
141  };
142 
143 EWOMS_WRAP_ISTL_PRECONDITIONER(Jacobi, Dune::SeqJac)
144 // EWOMS_WRAP_ISTL_PRECONDITIONER(Richardson, Dune::Richardson)
145 EWOMS_WRAP_ISTL_PRECONDITIONER(GaussSeidel, Dune::SeqGS)
146 EWOMS_WRAP_ISTL_PRECONDITIONER(SOR, Dune::SeqSOR)
147 EWOMS_WRAP_ISTL_PRECONDITIONER(SSOR, Dune::SeqSSOR)
148 
149 // we need a custom preconditioner wrapper for ILU because the Dune::SeqILU class uses a
150 // non-standard extra template parameter to specify its order.
151 template <class TypeTag>
153 {
155  using OverlappingMatrix = GetPropType<TypeTag, Properties::OverlappingMatrix>;
156  using OverlappingVector = GetPropType<TypeTag, Properties::OverlappingVector>;
157 
158  static constexpr int order = 0;
159 
160 public:
161  using SequentialPreconditioner = Dune::SeqILU<OverlappingMatrix, OverlappingVector, OverlappingVector, order>;
162 
164  {}
165 
166  static void registerParameters()
167  {
168  Parameters::Register<Parameters::PreconditionerRelaxation<Scalar>>
169  ("The relaxation factor of the preconditioner");
170  Parameters::Register<Parameters::PreconditionerOrder>
171  ("The order of the preconditioner");
172  }
173 
174  void prepare(OverlappingMatrix& matrix)
175  {
176  Scalar relaxationFactor = Parameters::Get<Parameters::PreconditionerRelaxation<Scalar>>();
177 
178  // create the sequential preconditioner.
179  seqPreCond_ = new SequentialPreconditioner(matrix, relaxationFactor);
180  }
181 
182  SequentialPreconditioner& get()
183  { return *seqPreCond_; }
184 
185  void cleanup()
186  { delete seqPreCond_; }
187 
188 private:
189  SequentialPreconditioner *seqPreCond_;
190 };
191 
192 #undef EWOMS_WRAP_ISTL_PRECONDITIONER
193 }} // namespace Linear, Opm
194 
195 #endif
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:233
This file provides the infrastructure to retrieve run-time parameters.
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Definition: istlpreconditionerwrappers.hh:152
Declares the parameters for the black oil model.
The Opm property system, traits with inheritance.
Declares the properties required by the black oil model.