All Classes Namespaces Files Functions Variables Typedefs Enumerator Pages
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>
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 
59  Domain,
60  ParallelInfo,
61  SeqPreconditioner>*
62  construct(Arguments& args)
63  {
65  <Range,Domain,ParallelInfo,SeqPreconditioner>(*SeqConstructionTraits
66  ::construct(args),
67  args.getComm());
68  }
69 
72  <Range,Domain,ParallelInfo,SeqPreconditioner>* bp)
73  {
74  SeqConstructionTraits
75  ::deconstruct(static_cast<SeqPreconditioner*>(&bp->preconditioner));
76  delete bp;
77  }
78 
79 };
80 
87 template<class Range, class Domain, class ParallelInfo, class SeqPreconditioner>
88 struct SmootherTraits<Opm::ParallelRestrictedOverlappingSchwarz<Range,
89  Domain,
90  ParallelInfo,
91  SeqPreconditioner> >
92 {
93  typedef DefaultSmootherArgs<typename SeqPreconditioner::matrix_type::field_type> Arguments;
94 
95 };
96 
97 } // end namespace Amg
98 
99 } // end namespace Dune
100 
101 namespace Opm{
102 
123 template<class Range, class Domain, class ParallelInfo, class SeqPreconditioner=Dune::Preconditioner<Range,Domain> >
124 class ParallelRestrictedOverlappingSchwarz
125  : public Dune::Preconditioner<Range,Domain> {
126  friend class Dune::Amg
127  ::ConstructionTraits<ParallelRestrictedOverlappingSchwarz<Range,
128  Domain,
129  ParallelInfo,
130  SeqPreconditioner> >;
131 public:
133  typedef Domain domain_type;
135  typedef Range range_type;
137  typedef typename Domain::field_type field_type;
139  typedef ParallelInfo communication_type;
140 
141  // define the category
142  enum {
144  category=Dune::SolverCategory::overlapping
145  };
146 
155  : preconditioner_(p), communication_(c)
156  { }
157 
163  virtual void pre (Domain& x, Range& b)
164  {
165  communication_.copyOwnerToAll(x,x); // make dirichlet values consistent
166  preconditioner_.pre(x,b);
167  }
168 
174  virtual void apply (Domain& v, const Range& d)
175  {
176  apply<true>(v, d);
177  }
178 
179  template<bool forward>
180  void apply (Domain& v, const Range& d)
181  {
182  // hack us a mutable d to prevent copying.
183  Range& md = const_cast<Range&>(d);
184  communication_.copyOwnerToAll(md,md);
185  preconditioner_.template apply<forward>(v,d);
186  communication_.copyOwnerToAll(v,v);
187  // Make sure that d is the same as at the beginning of apply.
188  communication_.project(md);
189  }
190 
196  virtual void post (Range& x)
197  {
198  preconditioner_.post(x);
199  }
200 
201 private:
203  SeqPreconditioner& preconditioner_;
204 
206  const communication_type& communication_;
207 };
208 
209 
210 } // end namespace OPM
211 #endif
ParallelInfo communication_type
The type of the communication object.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:139
ParallelRestrictedOverlappingSchwarz(SeqPreconditioner &p, const communication_type &c)
Constructor.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:154
virtual void pre(Domain &x, Range &b)
Prepare the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:163
static void deconstruct(Opm::ParallelRestrictedOverlappingSchwarz< Range, Domain, ParallelInfo, SeqPreconditioner > *bp)
Deconstruct and free a parallel restricted overlapping schwarz preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:71
Block parallel preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:32
virtual void apply(Domain &v, const Range &d)
Apply the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:174
Domain domain_type
The domain type of the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:133
virtual void post(Range &x)
Clean up.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:196
The category the precondtioner is part of.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:144
Range range_type
The range type of the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:135
Domain::field_type field_type
The field type of the preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:137
static Opm::ParallelRestrictedOverlappingSchwarz< Range, Domain, ParallelInfo, SeqPreconditioner > * construct(Arguments &args)
Construct a parallel restricted overlapping schwarz preconditioner.
Definition: ParallelRestrictedAdditiveSchwarz.hpp:62