My Project
ParallelRestrictedAdditiveSchwarz.hpp
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_PARALLELRESTRICTEDADDITIVESCHWARZ_HEADER_INCLUDED
21 #define OPM_PARALLELRESTRICTEDADDITIVESCHWARZ_HEADER_INCLUDED
22 
23 #include <opm/common/utility/platform_dependent/disable_warnings.h>
24 #include <dune/istl/preconditioner.hh>
25 #include <dune/istl/paamg/smoother.hh>
26 #include <opm/common/utility/platform_dependent/reenable_warnings.h>
27 
28 namespace Opm
29 {
30 
31 template<class X, class Y, class C, class T>
32 class ParallelRestrictedOverlappingSchwarz;
33 
34 } // end namespace Opm
35 
36 namespace Dune
37 {
38 
39 namespace Amg
40 {
41 
48 template<class Range, class Domain, class ParallelInfo, class SeqPreconditioner>
49 struct ConstructionTraits<Opm::ParallelRestrictedOverlappingSchwarz<Range,
50  Domain,
51  ParallelInfo,
52  SeqPreconditioner> >
53 {
54  typedef DefaultParallelConstructionArgs<SeqPreconditioner,ParallelInfo> Arguments;
55  typedef ConstructionTraits<SeqPreconditioner> SeqConstructionTraits;
56 
58 #if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 7)
59  typedef std::shared_ptr< Opm::ParallelRestrictedOverlappingSchwarz<Range,
60  Domain,
61  ParallelInfo,
63 #else
65  Domain,
66  ParallelInfo,
68 #endif
69 
71  construct(Arguments& args)
72  {
73  return
74 #if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 7)
75  std::make_shared(
76 #endif
78  <Range,Domain,ParallelInfo,SeqPreconditioner>(*SeqConstructionTraits ::construct(args),
79  args.getComm())
80 #if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 7)
81  );
82 #else
83  ;
84 #endif
85  }
86 
89  <Range,Domain,ParallelInfo,SeqPreconditioner>* bp)
90  {
91  SeqConstructionTraits
92  ::deconstruct(static_cast<SeqPreconditioner*>(&bp->preconditioner));
93  delete bp;
94  }
95 
96 };
97 
104 template<class Range, class Domain, class ParallelInfo, class SeqPreconditioner>
105 struct SmootherTraits<Opm::ParallelRestrictedOverlappingSchwarz<Range,
106  Domain,
107  ParallelInfo,
108  SeqPreconditioner> >
109 {
110  typedef DefaultSmootherArgs<typename SeqPreconditioner::matrix_type::field_type> Arguments;
111 
112 };
113 
114 } // end namespace Amg
115 
116 } // end namespace Dune
117 
118 namespace Opm{
119 
140 template<class Range, class Domain, class ParallelInfo, class SeqPreconditioner=Dune::Preconditioner<Range,Domain> >
142  : public Dune::Preconditioner<Range,Domain> {
143  friend class Dune::Amg
144  ::ConstructionTraits<ParallelRestrictedOverlappingSchwarz<Range,
145  Domain,
146  ParallelInfo,
147  SeqPreconditioner> >;
148 public:
150  typedef Domain domain_type;
152  typedef Range range_type;
154  typedef typename Domain::field_type field_type;
156  typedef ParallelInfo communication_type;
157 
158  // define the category
159  enum {
161  category=Dune::SolverCategory::overlapping
162  };
163 
172  : preconditioner_(p), communication_(c)
173  { }
174 
180  virtual void pre (Domain& x, Range& b)
181  {
182  communication_.copyOwnerToAll(x,x); // make dirichlet values consistent
183  preconditioner_.pre(x,b);
184  }
185 
191  virtual void apply (Domain& v, const Range& d)
192  {
193  apply<true>(v, d);
194  }
195 
196  template<bool forward>
197  void apply (Domain& v, const Range& d)
198  {
199  // hack us a mutable d to prevent copying.
200  Range& md = const_cast<Range&>(d);
201  communication_.copyOwnerToAll(md,md);
202  preconditioner_.template apply<forward>(v,d);
203  communication_.copyOwnerToAll(v,v);
204  // Make sure that d is the same as at the beginning of apply.
205  communication_.project(md);
206  }
207 
213  virtual void post (Range& x)
214  {
215  preconditioner_.post(x);
216  }
217 
218 private:
220  SeqPreconditioner& preconditioner_;
221 
223  const communication_type& communication_;
224 };
225 
226 
227 } // end namespace OPM
228 #endif
Block parallel preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:142
ParallelRestrictedOverlappingSchwarz(SeqPreconditioner &p, const communication_type &c)
Constructor.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:171
virtual void post(Range &x)
Clean up.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:213
Domain::field_type field_type
The field type of the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:154
Domain domain_type
The domain type of the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:150
Range range_type
The range type of the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:152
@ category
The category the precondtioner is part of.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:161
ParallelInfo communication_type
The type of the communication object.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:156
virtual void apply(Domain &v, const Range &d)
Apply the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:191
virtual void pre(Domain &x, Range &b)
Prepare the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:180
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:26
Opm::ParallelRestrictedOverlappingSchwarz< Range, Domain, ParallelInfo, SeqPreconditioner > * ParallelRestrictedOverlappingSchwarzPointer
Construct a parallel restricted overlapping schwarz preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:67
static void deconstruct(Opm::ParallelRestrictedOverlappingSchwarz< Range, Domain, ParallelInfo, SeqPreconditioner > *bp)
Deconstruct and free a parallel restricted overlapping schwarz preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:88