ParallelOverlappingILU0.hpp
Go to the documentation of this file.
1/*
2 Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services
3 Copyright 2015 Statoil AS
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef OPM_PARALLELOVERLAPPINGILU0_HEADER_INCLUDED
21#define OPM_PARALLELOVERLAPPINGILU0_HEADER_INCLUDED
22#include <opm/common/TimingMacros.hpp>
25#include <dune/istl/paamg/smoother.hh>
26
27#include <cstddef>
28#include <vector>
29#include <type_traits>
30
31namespace Opm
32{
33
34//template<class M, class X, class Y, class C>
35//class ParallelOverlappingILU0;
36template<class Matrix, class Domain, class Range, class ParallelInfo>
37class ParallelOverlappingILU0;
38
39template<class F>
41 : public Dune::Amg::DefaultSmootherArgs<F>
42{
43 public:
45 : milu_(milu), n_(0)
46 {}
48 {
49 milu_ = milu;
50 }
52 {
53 return milu_;
54 }
55 void setN(int n)
56 {
57 n_ = n;
58 }
59 int getN() const
60 {
61 return n_;
62 }
63 private:
64 MILU_VARIANT milu_;
65 int n_;
66};
67} // end namespace Opm
68
69namespace Dune
70{
71
72namespace Amg
73{
74
75
76template<class M, class X, class Y, class C>
77struct SmootherTraits<Opm::ParallelOverlappingILU0<M,X,Y,C> >
78{
80};
81
88template<class Matrix, class Domain, class Range, class ParallelInfo>
89struct ConstructionTraits<Opm::ParallelOverlappingILU0<Matrix,Domain,Range,ParallelInfo> >
90{
92 using Arguments = DefaultParallelConstructionArgs<T,ParallelInfo>;
93
94 using ParallelOverlappingILU0Pointer = std::shared_ptr<T>;
95
97 {
99 new T(args.getMatrix(),
100 args.getComm(),
101 args.getArgs().getN(),
102 args.getArgs().relaxationFactor,
103 args.getArgs().getMilu()) );
104 }
105};
106
107} // end namespace Amg
108
109} // end namespace Dune
110
111namespace Opm
112{
128template<class Matrix, class Domain, class Range, class ParallelInfoT>
130 : public Dune::PreconditionerWithUpdate<Domain,Range>
131{
132 using ParallelInfo = ParallelInfoT;
133
134public:
136 using matrix_type = typename std::remove_const<Matrix>::type;
138 using domain_type = Domain;
140 using range_type = Range;
142 using field_type = typename Domain::field_type;
143
144 using block_type = typename matrix_type::block_type;
145 using size_type = typename matrix_type::size_type;
146
147protected:
148 struct CRS
149 {
150 CRS() : nRows_( 0 ) {}
151
152 size_type rows() const { return nRows_; }
153
155 {
156 assert( rows_[ rows() ] != size_type(-1) );
157 return rows_[ rows() ];
158 }
159
160 void resize( const size_type nRows )
161 {
162 if( nRows_ != nRows )
163 {
164 nRows_ = nRows ;
165 rows_.resize( nRows_+1, size_type(-1) );
166 }
167 }
168
170 {
171 const size_type needed = values_.size() + nonZeros ;
172 if( values_.capacity() < needed )
173 {
174 const size_type estimate = needed * 1.1;
175 values_.reserve( estimate );
176 cols_.reserve( estimate );
177 }
178 }
179
180 void push_back( const block_type& value, const size_type index )
181 {
182 values_.push_back( value );
183 cols_.push_back( index );
184 }
185
186 void clear()
187 {
188 rows_.clear();
189 values_.clear();
190 cols_.clear();
191 nRows_= 0;
192 }
193
194 std::vector<size_type> rows_;
195 std::vector<block_type> values_;
196 std::vector<size_type> cols_;
198 };
199
200public:
201 Dune::SolverCategory::Category category() const override;
202
216 ParallelOverlappingILU0 (const Matrix& A,
217 const int n, const field_type w,
218 MILU_VARIANT milu, bool redblack = false,
219 bool reorder_sphere = true);
220
233 ParallelOverlappingILU0 (const Matrix& A,
234 const ParallelInfo& comm, const int n, const field_type w,
235 MILU_VARIANT milu, bool redblack = false,
236 bool reorder_sphere = true);
237
250 ParallelOverlappingILU0 (const Matrix& A,
251 const field_type w, MILU_VARIANT milu,
252 bool redblack = false,
253 bool reorder_sphere = true);
254
268 ParallelOverlappingILU0 (const Matrix& A,
269 const ParallelInfo& comm, const field_type w,
270 MILU_VARIANT milu, bool redblack = false,
271 bool reorder_sphere = true);
272
287 ParallelOverlappingILU0 (const Matrix& A,
288 const ParallelInfo& comm,
289 const field_type w, MILU_VARIANT milu,
290 size_type interiorSize, bool redblack = false,
291 bool reorder_sphere = true);
292
298 void pre (Domain&, Range&) override
299 {}
300
306 void apply (Domain& v, const Range& d) override;
307
308 template <class V>
309 void copyOwnerToAll( V& v ) const;
310
316 void post (Range&) override
317 {}
318
319 void update() override;
320
321protected:
323 Range& reorderD(const Range& d);
324
326 Domain& reorderV(Domain& v);
327
328 void reorderBack(const Range& reorderedV, Range& v);
329
331 std::unique_ptr<Matrix> ILU_;
334 std::vector< block_type > inv_;
336 std::vector< std::size_t > ordering_;
341
342 const ParallelInfo* comm_;
345 const bool relaxation_;
347 const Matrix* A_;
352};
353
354} // end namespace Opm
355#endif
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:32
Definition: ParallelOverlappingILU0.hpp:42
void setMilu(MILU_VARIANT milu)
Definition: ParallelOverlappingILU0.hpp:47
int getN() const
Definition: ParallelOverlappingILU0.hpp:59
MILU_VARIANT getMilu() const
Definition: ParallelOverlappingILU0.hpp:51
ParallelOverlappingILU0Args(MILU_VARIANT milu=MILU_VARIANT::ILU)
Definition: ParallelOverlappingILU0.hpp:44
void setN(int n)
Definition: ParallelOverlappingILU0.hpp:55
A two-step version of an overlapping Schwarz preconditioner using one step ILU0 as.
Definition: ParallelOverlappingILU0.hpp:131
const Matrix * A_
Definition: ParallelOverlappingILU0.hpp:347
ParallelOverlappingILU0(const Matrix &A, const int n, const field_type w, MILU_VARIANT milu, bool redblack=false, bool reorder_sphere=true)
Constructor.
Definition: ParallelOverlappingILU0_impl.hpp:201
std::unique_ptr< Matrix > ILU_
The ILU0 decomposition of the matrix.
Definition: ParallelOverlappingILU0.hpp:331
Domain & reorderV(Domain &v)
Reorder V if needed and return a reference to it.
Definition: ParallelOverlappingILU0_impl.hpp:555
typename std::remove_const< Matrix >::type matrix_type
The matrix type the preconditioner is for.
Definition: ParallelOverlappingILU0.hpp:136
Domain domain_type
The domain type of the preconditioner.
Definition: ParallelOverlappingILU0.hpp:138
size_type interiorSize_
Definition: ParallelOverlappingILU0.hpp:346
std::vector< std::size_t > ordering_
the reordering of the unknowns
Definition: ParallelOverlappingILU0.hpp:336
void reorderBack(const Range &reorderedV, Range &v)
Definition: ParallelOverlappingILU0_impl.hpp:575
const ParallelInfo * comm_
Definition: ParallelOverlappingILU0.hpp:342
Domain reorderedV_
The reordered left hand side.
Definition: ParallelOverlappingILU0.hpp:340
void post(Range &) override
Clean up.
Definition: ParallelOverlappingILU0.hpp:316
Range reorderedD_
The reordered right hand side.
Definition: ParallelOverlappingILU0.hpp:338
const field_type w_
The relaxation factor to use.
Definition: ParallelOverlappingILU0.hpp:344
Range & reorderD(const Range &d)
Reorder D if needed and return a reference to it.
Definition: ParallelOverlappingILU0_impl.hpp:531
void copyOwnerToAll(V &v) const
Definition: ParallelOverlappingILU0_impl.hpp:351
Range range_type
The range type of the preconditioner.
Definition: ParallelOverlappingILU0.hpp:140
bool redBlack_
Definition: ParallelOverlappingILU0.hpp:350
std::vector< block_type > inv_
Definition: ParallelOverlappingILU0.hpp:334
MILU_VARIANT milu_
Definition: ParallelOverlappingILU0.hpp:349
CRS lower_
Definition: ParallelOverlappingILU0.hpp:332
Dune::SolverCategory::Category category() const override
Definition: ParallelOverlappingILU0_impl.hpp:193
const bool relaxation_
Definition: ParallelOverlappingILU0.hpp:345
void update() override
Definition: ParallelOverlappingILU0_impl.hpp:360
int iluIteration_
Definition: ParallelOverlappingILU0.hpp:348
bool reorderSphere_
Definition: ParallelOverlappingILU0.hpp:351
void apply(Domain &v, const Range &d) override
Apply the preconditoner.
Definition: ParallelOverlappingILU0_impl.hpp:290
typename matrix_type::size_type size_type
Definition: ParallelOverlappingILU0.hpp:145
typename matrix_type::block_type block_type
Definition: ParallelOverlappingILU0.hpp:144
CRS upper_
Definition: ParallelOverlappingILU0.hpp:333
void pre(Domain &, Range &) override
Prepare the preconditioner.
Definition: ParallelOverlappingILU0.hpp:298
typename Domain::field_type field_type
The field type of the preconditioner.
Definition: ParallelOverlappingILU0.hpp:142
Definition: SupportsFaceTag.hpp:27
Definition: BlackoilPhases.hpp:27
MILU_VARIANT
Definition: MILU.hpp:34
@ ILU
Do not perform modified ILU.
static ParallelOverlappingILU0Pointer construct(Arguments &args)
Definition: ParallelOverlappingILU0.hpp:96
DefaultParallelConstructionArgs< T, ParallelInfo > Arguments
Definition: ParallelOverlappingILU0.hpp:92
std::shared_ptr< T > ParallelOverlappingILU0Pointer
Definition: ParallelOverlappingILU0.hpp:94
Definition: ParallelOverlappingILU0.hpp:149
std::vector< block_type > values_
Definition: ParallelOverlappingILU0.hpp:195
CRS()
Definition: ParallelOverlappingILU0.hpp:150
void push_back(const block_type &value, const size_type index)
Definition: ParallelOverlappingILU0.hpp:180
void clear()
Definition: ParallelOverlappingILU0.hpp:186
std::vector< size_type > rows_
Definition: ParallelOverlappingILU0.hpp:194
void reserveAdditional(const size_type nonZeros)
Definition: ParallelOverlappingILU0.hpp:169
void resize(const size_type nRows)
Definition: ParallelOverlappingILU0.hpp:160
std::vector< size_type > cols_
Definition: ParallelOverlappingILU0.hpp:196
size_type nonZeros() const
Definition: ParallelOverlappingILU0.hpp:154
size_type rows() const
Definition: ParallelOverlappingILU0.hpp:152
size_type nRows_
Definition: ParallelOverlappingILU0.hpp:197