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