dune-fem  2.4.1-rc
restrictprolongtuple.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_SPACE_COMMON_RESTRICTPROLONGTUPLE_HH
2 #define DUNE_FEM_SPACE_COMMON_RESTRICTPROLONGTUPLE_HH
3 
4 #include <tuple>
5 #include <utility>
6 
7 #include <dune/common/deprecated.hh>
8 #include <dune/common/forloop.hh>
9 #include <dune/common/tupleutility.hh>
10 
12 
13 namespace Dune
14 {
15 
16  namespace Fem
17  {
18 
19  // Internal forward declaration
20  // ----------------------------
21 
22  template< class... RestrictProlongInterfaces >
24  template< class... DiscreteFunctions >
26 
27 
28 
29  // RestrictProlongTuple
30  // --------------------
31 
45  template< class Head, class... Tail >
46  class RestrictProlongTuple< Head, Tail... >
47  : public Dune::Fem::RestrictProlongInterface< RestrictProlongTraits< RestrictProlongTuple< Head, Tail... >, typename Head::DomainFieldType > >
48  {
49  typedef Dune::Fem::RestrictProlongInterface< RestrictProlongTraits< RestrictProlongTuple< Head, Tail... >, typename Head::DomainFieldType > > BaseType;
50 
51  template< int i > struct AddToList;
52  template< int i > struct AddToLoadBalancer;
53  template< int i > struct ProlongLocal;
54  template< int i > struct RestrictLocal;
55  template< int i > struct SetFatherChildWeight;
56 
57  public:
60 
65  explicit RestrictProlongTuple ( Head &&head, Tail &&... tail )
66  : tuple_( std::forward< Head >( head ), std::forward< Tail >( tail )... )
67  {}
68 
69  explicit RestrictProlongTuple ( std::tuple< Head, Tail... > &&tuple )
70  : tuple_( tuple )
71  {}
72 
80  void setFatherChildWeight ( const DomainFieldType &weight ) const
81  {
82  Dune::ForLoop< SetFatherChildWeight, 0, sizeof...( Tail ) >::apply( weight, tuple_ );
83  }
84 
86  template< class Entity >
87  void restrictLocal ( const Entity &father, const Entity &child, bool initialize ) const
88  {
89  Dune::ForLoop< RestrictLocal, 0, sizeof...( Tail ) >::apply( father, child, initialize, tuple_ );
90  }
91 
93  template< class Entity, class LocalGeometry >
94  void restrictLocal ( const Entity &father, const Entity &child,
95  const LocalGeometry &geometryInFather, bool initialize ) const
96  {
97  Dune::ForLoop< RestrictLocal, 0, sizeof...( Tail ) >::apply( father, child, geometryInFather, initialize, tuple_ );
98  }
99 
101  template< class Entity >
102  void prolongLocal ( const Entity &father, const Entity &child, bool initialize ) const
103  {
104  Dune::ForLoop< ProlongLocal, 0, sizeof...( Tail ) >::apply( father, child, initialize, tuple_ );
105  }
106 
108  template< class Entity, class LocalGeometry >
109  void prolongLocal ( const Entity &father, const Entity &child,
110  const LocalGeometry &geometryInFather, bool initialize ) const
111  {
112  Dune::ForLoop< ProlongLocal, 0, sizeof...( Tail ) >::apply( father, child, geometryInFather, initialize, tuple_ );
113  }
114 
116  template< class Communicator >
117  void addToList ( Communicator &comm )
118  {
119  Dune::ForLoop< AddToList, 0, sizeof...( Tail ) >::apply( comm, tuple_ );
120  }
121 
123  template< class LoadBalancer >
124  void addToLoadBalancer ( LoadBalancer &loadBalancer )
125  {
126  Dune::ForLoop< AddToLoadBalancer, 0, sizeof...( Tail ) >::apply( loadBalancer, tuple_ );
127  }
128 
131  private:
132  std::tuple< Head, Tail... > tuple_;
133  };
134 
135 
136 
137  // RestrictProlongTuple< Head, Tail... >::AddToList
138  // ------------------------------------------------
139 
140  template< class Head, class... Tail >
141  template< int i >
142  struct RestrictProlongTuple< Head, Tail... >::AddToList
143  {
144  template< class Communicator >
145  static void apply ( Communicator &comm, std::tuple< Head, Tail... > &tuple )
146  {
147  std::get< i >( tuple ).addToList( comm );
148  }
149  };
150 
151 
152 
153  // RestrictProlongTuple< Head, Tail... >::AddToLoadBalancer
154  // --------------------------------------------------------
155 
156  template< class Head, class... Tail >
157  template< int i >
158  struct RestrictProlongTuple< Head, Tail... >::AddToLoadBalancer
159  {
160  template< class LoadBalancer >
161  static void apply ( LoadBalancer &loadBalancer, std::tuple< Head, Tail... > &tuple )
162  {
163  std::get< i >( tuple ).addToLoadBalancer( loadBalancer );
164  }
165  };
166 
167 
168 
169  // RestrictProlongTuple< Head, Tail... >::ProlongLocal
170  // ---------------------------------------------------
171 
172  template< class Head, class... Tail >
173  template< int i >
174  struct RestrictProlongTuple< Head, Tail... >::ProlongLocal
175  {
176  template< class Entity >
177  static void apply ( const Entity &father, const Entity &child, bool initialize,
178  const std::tuple< Head, Tail... > &tuple )
179  {
180  std::get< i >( tuple ).prolongLocal( father, child, initialize );
181  }
182 
183  template< class Entity, class LocalGeometry >
184  static void apply ( const Entity &father, const Entity &child, const LocalGeometry &geometryInFather, bool initialize,
185  const std::tuple< Head, Tail... > &tuple )
186  {
187  std::get< i >( tuple ).prolongLocal( father, child, geometryInFather, initialize );
188  }
189  };
190 
191 
192 
193  // RestrictProlongTuple< Head, Tail... >::RestrictLocal
194  // ----------------------------------------------------
195 
196  template< class Head, class... Tail >
197  template< int i >
198  struct RestrictProlongTuple< Head, Tail... >::RestrictLocal
199  {
200  template< class Entity >
201  static void apply ( const Entity &father, const Entity &child, bool initialize,
202  const std::tuple< Head, Tail... > &tuple )
203  {
204  std::get< i >( tuple ).restrictLocal( father, child, initialize );
205  }
206 
207  template< class Entity, class LocalGeometry >
208  static void apply ( const Entity &father, const Entity &child, const LocalGeometry &geometryInFather, bool initialize,
209  const std::tuple< Head, Tail... > &tuple )
210  {
211  std::get< i >( tuple ).restrictLocal( father, child, geometryInFather, initialize );
212  }
213  };
214 
215 
216 
217  // RestrictProlongTuple< Head, Tail... >::SetFatherChildWeight
218  // -----------------------------------------------------------
219 
220  template< class Head, class... Tail >
221  template< int i >
222  struct RestrictProlongTuple< Head, Tail... >::SetFatherChildWeight
223  {
224  static void apply ( const DomainFieldType &weight, const std::tuple< Head, Tail... > &tuple )
225  {
226  std::get< i >( tuple ).setFatherChildWeight( weight );
227  }
228  };
229 
230 
231 
232  // RestrictProlongDefaultTuple
233  // ---------------------------
234 
243  template< class... DiscreteFunctions >
245  : public RestrictProlongTuple< RestrictProlongDefault< DiscreteFunctions >... >
246  {
248 
249  template< class DiscreteFunction >
250  struct Operation
251  {
252  typedef typename std::decay< DiscreteFunction >::type DiscreteFunctionType;
254 
255  static Type apply ( DiscreteFunctionType &discreteFunction )
256  {
257  return Type( discreteFunction );
258  }
259  };
260 
261  public:
262  explicit RestrictProlongDefaultTuple ( DiscreteFunctions &... discreteFunctions )
263  : BaseType( RestrictProlongDefault< DiscreteFunctions >( discreteFunctions )... )
264  {}
265 
266  explicit RestrictProlongDefaultTuple ( std::tuple< DiscreteFunctions &... > tuple )
267  : BaseType( Dune::transformTuple< Operation >( tuple ) )
268  {}
269  };
270 
271  // RestrictProlongDefaultTraits
272  template<class... DiscreteFunctions>
274  {
275  typedef RestrictProlongDefaultTuple<DiscreteFunctions...> Type;
276  };
277 
278  template<class... DiscreteFunctions>
279  struct RestrictProlongDefaultTraits<std::tuple<DiscreteFunctions&...> >
280  {
281  typedef RestrictProlongDefaultTuple<DiscreteFunctions...> Type;
282  };
283 
284  // makeRestrictProlongDefault
285  // --------------------------
286 
295  template< class... DiscreteFunctions >
296  static inline RestrictProlongDefaultTuple< DiscreteFunctions... >
297  DUNE_DEPRECATED makeRestrictProlongDefault ( DiscreteFunctions &... discreteFunctions )
298  {
299  return RestrictProlongDefaultTuple< DiscreteFunctions... >( discreteFunctions... );
300  }
301 
302  template< class... DiscreteFunctions >
303  static inline RestrictProlongDefaultTuple< DiscreteFunctions... >
304  DUNE_DEPRECATED makeRestrictProlongDefault ( std::tuple< DiscreteFunctions &... > tuple )
305  {
306  return RestrictProlongDefaultTuple< DiscreteFunctions ... >( tuple );
307  }
308 
311  } // namespace Fem
312 
313 } // namespace Dune
314 
315 #endif // #ifndef DUNE_FEM_SPACE_COMMON_RESTRICTPROLONGTUPLE_HH
void addToList(Communicator &comm)
add discrete function to communicator
Definition: restrictprolongtuple.hh:117
This is a wrapper for the default implemented restriction/prolongation operator, which only takes a d...
Definition: restrictprolonginterface.hh:172
Traits::DomainFieldType DomainFieldType
field type of domain vector space
Definition: restrictprolonginterface.hh:47
void addToLoadBalancer(LoadBalancer &loadBalancer)
add discrete function to load balancer
Definition: restrictprolongtuple.hh:124
RestrictProlongTuple(std::tuple< Head, Tail... > &&tuple)
Definition: restrictprolongtuple.hh:69
void restrictLocal(const Entity &father, const Entity &child, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: restrictprolongtuple.hh:94
RestrictProlongTuple(Head &&head, Tail &&...tail)
Definition: restrictprolongtuple.hh:65
Definition: restrictprolongtuple.hh:273
RestrictProlongDefaultTuple(DiscreteFunctions &...discreteFunctions)
Definition: restrictprolongtuple.hh:262
BaseType::DomainFieldType DomainFieldType
field type of domain vector space
Definition: restrictprolongtuple.hh:55
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolongtuple.hh:80
static RestrictProlongDefaultTuple< DiscreteFunctions... > makeRestrictProlongDefault(DiscreteFunctions &...discreteFunctions)
Definition: restrictprolongtuple.hh:297
Interface class defining the local behaviour of the restrict/prolong operation (using BN) ...
Definition: restrictprolonginterface.hh:38
Definition: coordinate.hh:4
combine a variadic number of Dune::Fem::RestrictProlongInterface instances into a single object again...
Definition: restrictprolongtuple.hh:23
STL namespace.
void prolongLocal(const Entity &father, const Entity &child, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: restrictprolongtuple.hh:109
RestrictProlongDefaultTuple(std::tuple< DiscreteFunctions &... > tuple)
Definition: restrictprolongtuple.hh:266
conveniently set up a tuple of Dune::Fem::RestrictProlongDefault restriction/prolongation objects cre...
Definition: restrictprolongtuple.hh:25
void restrictLocal(const Entity &father, const Entity &child, bool initialize) const
restrict data to father
Definition: restrictprolongtuple.hh:87
RestrictProlongDefaultTuple< DiscreteFunctions... > Type
Definition: restrictprolongtuple.hh:281
void prolongLocal(const Entity &father, const Entity &child, bool initialize) const
prolong data to children
Definition: restrictprolongtuple.hh:102
This class manages the adaptation process. If the method adapt is called, then the grid is adapted an...
Definition: loadbalancer.hh:69
RestrictProlongDefaultTuple< DiscreteFunctions... > Type
Definition: restrictprolongtuple.hh:275
Traits class for derivation from RestrictProlongInterface.
Definition: restrictprolonginterface.hh:132