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 */
43 #ifndef EWOMS_ISTL_PRECONDITIONER_WRAPPERS_HH
44 #define EWOMS_ISTL_PRECONDITIONER_WRAPPERS_HH
45 
48 
49 #include <dune/istl/preconditioners.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(PreconditionerOrder);
58 NEW_PROP_TAG(PreconditionerRelaxation);
59 } // namespace Properties
60 
61 namespace Linear {
62 #define EWOMS_WRAP_ISTL_PRECONDITIONER(PREC_NAME, ISTL_PREC_TYPE) \
63  template <class TypeTag> \
64  class PreconditionerWrapper##PREC_NAME \
65  { \
66  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; \
67  typedef typename GET_PROP_TYPE(TypeTag, JacobianMatrix) JacobianMatrix; \
68  typedef typename GET_PROP_TYPE(TypeTag, OverlappingVector) OverlappingVector; \
69  \
70  public: \
71  typedef ISTL_PREC_TYPE<JacobianMatrix, OverlappingVector, \
72  OverlappingVector> SequentialPreconditioner; \
73  PreconditionerWrapper##PREC_NAME() \
74  {} \
75  \
76  static void registerParameters() \
77  { \
78  EWOMS_REGISTER_PARAM(TypeTag, int, PreconditionerOrder, \
79  "The order of the preconditioner"); \
80  EWOMS_REGISTER_PARAM(TypeTag, Scalar, PreconditionerRelaxation, \
81  "The relaxation factor of the " \
82  "preconditioner"); \
83  } \
84  \
85  void prepare(JacobianMatrix& matrix) \
86  { \
87  int order = EWOMS_GET_PARAM(TypeTag, int, PreconditionerOrder); \
88  Scalar relaxationFactor = EWOMS_GET_PARAM(TypeTag, Scalar, PreconditionerRelaxation); \
89  seqPreCond_ = new SequentialPreconditioner(matrix, order, \
90  relaxationFactor); \
91  } \
92  \
93  SequentialPreconditioner& get() \
94  { return *seqPreCond_; } \
95  \
96  void cleanup() \
97  { delete seqPreCond_; } \
98  \
99  private: \
100  SequentialPreconditioner *seqPreCond_; \
101  };
102 
103 // the same as the EWOMS_WRAP_ISTL_PRECONDITIONER macro, but without
104 // an 'order' argument for the preconditioner's constructor
105 #define EWOMS_WRAP_ISTL_SIMPLE_PRECONDITIONER(PREC_NAME, ISTL_PREC_TYPE) \
106  template <class TypeTag> \
107  class PreconditionerWrapper##PREC_NAME \
108  { \
109  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; \
110  typedef typename GET_PROP_TYPE(TypeTag, OverlappingMatrix) OverlappingMatrix; \
111  typedef typename GET_PROP_TYPE(TypeTag, OverlappingVector) OverlappingVector; \
112  \
113  public: \
114  typedef ISTL_PREC_TYPE<OverlappingMatrix, OverlappingVector, \
115  OverlappingVector> SequentialPreconditioner; \
116  PreconditionerWrapper##PREC_NAME() \
117  {} \
118  \
119  static void registerParameters() \
120  { \
121  EWOMS_REGISTER_PARAM(TypeTag, Scalar, PreconditionerRelaxation, \
122  "The relaxation factor of the " \
123  "preconditioner"); \
124  } \
125  \
126  void prepare(OverlappingMatrix& matrix) \
127  { \
128  Scalar relaxationFactor = \
129  EWOMS_GET_PARAM(TypeTag, Scalar, PreconditionerRelaxation); \
130  seqPreCond_ = new SequentialPreconditioner(matrix, \
131  relaxationFactor); \
132  } \
133  \
134  SequentialPreconditioner& get() \
135  { return *seqPreCond_; } \
136  \
137  void cleanup() \
138  { delete seqPreCond_; } \
139  \
140  private: \
141  SequentialPreconditioner *seqPreCond_; \
142  };
143 
144 EWOMS_WRAP_ISTL_PRECONDITIONER(Jacobi, Dune::SeqJac)
145 // EWOMS_WRAP_ISTL_PRECONDITIONER(Richardson, Dune::Richardson)
146 EWOMS_WRAP_ISTL_PRECONDITIONER(GaussSeidel, Dune::SeqGS)
147 EWOMS_WRAP_ISTL_PRECONDITIONER(SOR, Dune::SeqSOR)
148 EWOMS_WRAP_ISTL_PRECONDITIONER(SSOR, Dune::SeqSSOR)
149 EWOMS_WRAP_ISTL_SIMPLE_PRECONDITIONER(ILU0, Dune::SeqILU0)
150 EWOMS_WRAP_ISTL_PRECONDITIONER(ILUn, Dune::SeqILUn)
151 
152 #undef EWOMS_WRAP_ISTL_PRECONDITIONER
153 }} // namespace Linear, Ewoms
154 
155 #endif
Definition: baseauxiliarymodule.hh:37
This file provides the infrastructure to retrieve run-time parameters.
Provides the magic behind the eWoms property system.
#define NEW_PROP_TAG(PTagName)
Define a property tag.
Definition: propertysystem.hh:247