dune-fem  2.8-git
restrictprolonginterface.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_RESTRICTPROLONGINTERFACE_HH
2 #define DUNE_FEM_RESTRICTPROLONGINTERFACE_HH
3 
4 //- Dune includes
5 #include <dune/common/bartonnackmanifcheck.hh>
6 #include <dune/grid/common/capabilities.hh>
7 
8 //- local includes
12 
13 namespace Dune
14 {
15 
16  namespace Fem
17  {
18 
37  template< class Traits >
39  {
41 
42  public:
44  typedef typename Traits::RestProlImp RestProlImp;
45 
47  typedef typename Traits::DomainFieldType DomainFieldType;
48 
51  void initialize ()
52  {
53  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().initialize() );
54  }
55 
58  void finalize ()
59  {
60  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().finalize() );
61  }
62 
69  void setFatherChildWeight ( const DomainFieldType &weight ) const
70  {
71  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().setFatherChildWeight( weight ) );
72  }
73 
75  template< class Entity >
76  void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
77  {
78  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().restrictLocal( father, son, initialize ) );
79  }
80 
82  template< class Entity, class LocalGeometry >
83  void restrictLocal ( const Entity &father, const Entity &son,
84  const LocalGeometry &geometryInFather,
85  bool initialize ) const
86  {
87  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().restrictLocal( father, son, geometryInFather, initialize ) );
88  }
89 
91  template <class Entity>
92  void restrictFinalize(const Entity &father) const
93  {
94  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().restrictFinalize( father ) );
95  }
96 
98  template< class Entity >
99  void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
100  {
101  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().prolongLocal( father, son, initialize ) );
102  }
103 
105  template< class Entity, class LocalGeometry >
106  void prolongLocal ( const Entity &father, const Entity &son,
107  const LocalGeometry &geometryInFather,
108  bool initialize ) const
109  {
110  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().prolongLocal( father, son, geometryInFather, initialize ) );
111  }
112 
116  template< class Communicator >
117  void addToList ( Communicator &comm )
118  {
119  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().addToList( comm ) );
120  }
121 
125  template< class LoadBalancer >
127  {
128  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().addToLoadBalancer( lb ) );
129  }
130 
131  protected:
137  template< class Entity >
138  DomainFieldType calcWeight ( const Entity &father, const Entity &son ) const
139  {
140  const DomainFieldType weight = son.geometry().volume() / father.geometry().volume();
141  assert( weight > DomainFieldType( 0 ) );
142  return weight;
143  }
144 
145  protected:
146  const RestProlImp &asImp () const { return static_cast< const RestProlImp & >( *this ); }
147  RestProlImp &asImp () { return static_cast< RestProlImp & >( *this ); }
148  };
149 
150 
152  template< class Impl, class DomainField >
154  {
155  typedef Impl RestProlImp;
156  typedef DomainField DomainFieldType;
157  };
158 
159 
160 
162  template< class Traits >
164  : public RestrictProlongInterface< Traits >
165  {
168 
169  public:
171 
172  protected:
174  template< class IndexSet, class Entity >
175  bool entitiesAreCopies ( const IndexSet &indexSet,
176  const Entity &father, const Entity &son ) const
177  {
178  return (indexSet.index( father ) == indexSet.index( son ));
179  }
180 
181 
182  public:
184  void setFatherChildWeight ( const DomainFieldType &weight ) const {}
185 
186  void initialize () {}
187  void finalize () {}
188 
190  template <class Entity>
191  void restrictFinalize( const Entity& father ) const {}
192  };
193 
194 
195 
200  template< class DiscreteFunction >
202  : public RestrictProlongInterfaceDefault< RestrictProlongTraits< RestrictProlongDefault< DiscreteFunction >, typename DiscreteFunction::DomainFieldType > >
203  {
206 
207  public:
208  typedef DiscreteFunction DiscreteFunctionType;
209 
211 
212  typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
213 
216 
217  typedef typename DiscreteFunctionType::GridPartType GridPartType;
218 
220 
222  : discreteFunction_( const_cast< RestrictProlongDefault& > (other).discreteFunction_ ),
225  localRP_( discreteFunction_.space() )
226  {
227  // enable dof compression for this discrete function
228  discreteFunction_.enableDofCompression();
229  }
230 
231  explicit RestrictProlongDefault ( DiscreteFunctionType &discreteFunction )
232  : discreteFunction_( discreteFunction ),
233  constLf_( discreteFunction ),
235  localRP_( discreteFunction_.space() )
236  {
237  // enable dof compression for this discrete function
238  discreteFunction_.enableDofCompression();
239  }
240 
241  protected:
242  using BaseType::calcWeight;
244 
245  public:
252  void setFatherChildWeight ( const DomainFieldType &weight ) const
253  {
254  localRP_.setFatherChildWeight( weight );
255  }
256 
258  template< class Entity >
259  void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
260  {
261  assert( !father.isLeaf() );
262 
263  // convert from grid entities to grid part entities
264  typedef typename GridPartType::template Codim< Entity::codimension >::EntityType GridPartEntityType;
265  const GridPartType &gridPart = discreteFunction_.gridPart();
266  const GridPartEntityType &gpFather = gridPart.convert( father );
267  const GridPartEntityType &gpSon = gridPart.convert( son );
268 
269  if( !entitiesAreCopies( gridPart.indexSet(), gpFather, gpSon ) )
270  restrictLocal( gpFather, gpSon, son.geometryInFather(), initialize );
271  }
272 
274  template< class Entity, class LocalGeometry >
275  void restrictLocal ( const Entity &father, const Entity &son,
276  const LocalGeometry &geometryInFather,
277  bool initialize ) const
278  {
279  auto clf = bindGuard( constLf_, son );
280 
281  if( initialize || ! targetLf_.valid() )
282  {
283  targetLf_.bind( father );
284  // unbind is done in restrictFinalize
285  }
286 
287  assert( father == targetLf_.entity() );
288  localRP_.restrictLocal( targetLf_, constLf_, geometryInFather, initialize );
289  }
290 
292  template <class Entity>
293  void restrictFinalize(const Entity &father) const
294  {
295  // make sure targetLf_ still is bound to father
296  assert( discreteFunction_.gridPart().convert( father ) == targetLf_.entity() );
297 
298  localRP_.restrictFinalize( targetLf_ );
299 
300  // release target local function
301  targetLf_.unbind();
302  }
303 
304 
306  template< class Entity >
307  void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
308  {
309  assert( !father.isLeaf() );
310 
311  // convert from grid entities to grid part entities
312  typedef typename GridPartType::template Codim< Entity::codimension >::EntityType GridPartEntityType;
313  const GridPartType &gridPart = discreteFunction_.gridPart();
314  const GridPartEntityType &gpFather = gridPart.convert( father );
315  const GridPartEntityType &gpSon = gridPart.convert( son );
316 
317  if( !entitiesAreCopies( gridPart.indexSet(), gpFather, gpSon ) )
318  prolongLocal( gpFather, gpSon, son.geometryInFather(), initialize );
319  }
320 
322  template< class Entity, class LocalGeometry >
323  void prolongLocal ( const Entity &father, const Entity &son,
324  const LocalGeometry &geometryInFather,
325  bool initialize ) const
326  {
327  // initialize father local function (only once)
328  //if( initialize )
329  {
330  constLf_.unbind();
331  constLf_.bind( father );
332  }
333 
334  auto tlf = bindGuard( targetLf_, son );
335 
336  localRP_.prolongLocal( constLf_, targetLf_, geometryInFather, initialize );
337  // write to discrete function
338  discreteFunction_.setLocalDofs( son, targetLf_ );
339  }
340 
342  template< class Communicator, class Operation >
343  void addToList ( Communicator &comm, const Operation& op)
344  {
345  if( localRP_.needCommunication() )
346  comm.addToList( discreteFunction_, op );
347  }
348 
350  template< class Communicator >
351  void addToList ( Communicator &comm )
352  {
353  if( localRP_.needCommunication() )
354  comm.addToList( discreteFunction_ );
355  }
356 
358  template< class Communicator >
359  void removeFromList ( Communicator &comm )
360  {
361  if( localRP_.needCommunication() )
362  comm.removeFromList( discreteFunction_ );
363  }
364 
366  template< class LoadBalancer >
368  {
370  }
371 
372  protected:
377  };
379 
380  } // namespace Fem
381 
382 } // namespace Dune
383 
384 #endif // #ifndef DUNE_FEM_RESTRICTPROLONGINTERFACE_HH
Definition: bindguard.hh:11
typename Impl::ConstLocalFunction< GridFunction >::Type ConstLocalFunction
Definition: const.hh:517
static auto bindGuard(Object &object, Args &&... args) -> std::enable_if_t< isBindable< Object, Args... >::value, BindGuard< Object > >
Definition: bindguard.hh:67
const EntityType & entity() const
obtain the entity, this local function lives on
Definition: localfunction.hh:302
bool valid() const
Returns true if local function if bind or init was previously called.
Definition: localfunction.hh:423
void unbind()
Definition: mutable.hh:103
void bind(const EntityType &entity)
Definition: mutable.hh:98
interface documentation for (grid part) index sets
Definition: common/indexset.hh:104
IndexType index(const Entity &entity) const
return index for given entity
Definition: common/indexset.hh:153
This class manages the adaptation process. If the method adapt is called, then the grid is adapted an...
Definition: loadbalancer.hh:66
void addToLoadBalancer(DiscreteFunctionType &df)
add discrete function to data inliner/xtractor list
Definition: loadbalancer.hh:192
Interface class defining the local behaviour of the restrict/prolong operation (using BN)
Definition: restrictprolonginterface.hh:39
void addToList(Communicator &comm)
add discrete function to communicator
Definition: restrictprolonginterface.hh:117
Traits::DomainFieldType DomainFieldType
field type of domain vector space
Definition: restrictprolonginterface.hh:47
void prolongLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:106
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:69
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:76
RestProlImp & asImp()
Definition: restrictprolonginterface.hh:147
void restrictFinalize(const Entity &father) const
finalize restriction on father
Definition: restrictprolonginterface.hh:92
Traits::RestProlImp RestProlImp
type of restrict-prolong operator implementation
Definition: restrictprolonginterface.hh:44
DomainFieldType calcWeight(const Entity &father, const Entity &son) const
calculates the weight, i.e. (volume son)/(volume father)
Definition: restrictprolonginterface.hh:138
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition: restrictprolonginterface.hh:126
void finalize()
finalize restrict prolong object (if necessary) after adaptation and dof compression was finished
Definition: restrictprolonginterface.hh:58
void initialize()
initialize restrict prolong object (if necessary) before adaptation takes place
Definition: restrictprolonginterface.hh:51
void restrictLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:83
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:99
const RestProlImp & asImp() const
Definition: restrictprolonginterface.hh:146
Traits class for derivation from RestrictProlongInterface.
Definition: restrictprolonginterface.hh:154
Impl RestProlImp
Definition: restrictprolonginterface.hh:155
DomainField DomainFieldType
Definition: restrictprolonginterface.hh:156
Interface default implementation for derived classes.
Definition: restrictprolonginterface.hh:165
void restrictFinalize(const Entity &father) const
restrictFinalize is for some spaces where a local matrix inversion is carried out after restriction.
Definition: restrictprolonginterface.hh:191
bool entitiesAreCopies(const IndexSet &indexSet, const Entity &father, const Entity &son) const
return true if father and son have the same index
Definition: restrictprolonginterface.hh:175
BaseType::DomainFieldType DomainFieldType
Definition: restrictprolonginterface.hh:170
void finalize()
Definition: restrictprolonginterface.hh:187
void initialize()
Definition: restrictprolonginterface.hh:186
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:184
This is a wrapper for the default implemented restriction/prolongation operator, which only takes a d...
Definition: restrictprolonginterface.hh:203
LocalRestrictProlongType localRP_
Definition: restrictprolonginterface.hh:376
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:252
RestrictProlongDefault(DiscreteFunctionType &discreteFunction)
Definition: restrictprolonginterface.hh:231
DefaultLocalRestrictProlong< DiscreteFunctionSpaceType > LocalRestrictProlongType
Definition: restrictprolonginterface.hh:219
void addToList(Communicator &comm, const Operation &op)
add discrete function to communicator with given unpack operation
Definition: restrictprolonginterface.hh:343
DiscreteFunctionType & discreteFunction_
Definition: restrictprolonginterface.hh:373
void restrictFinalize(const Entity &father) const
finalize restriction on father
Definition: restrictprolonginterface.hh:293
void removeFromList(Communicator &comm)
remove discrete function from communicator
Definition: restrictprolonginterface.hh:359
DiscreteFunction DiscreteFunctionType
Definition: restrictprolonginterface.hh:208
RestrictProlongDefault(const RestrictProlongDefault &other)
Definition: restrictprolonginterface.hh:221
void restrictLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:275
ConstLocalFunctionType constLf_
Definition: restrictprolonginterface.hh:374
void prolongLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:323
BaseType::DomainFieldType DomainFieldType
Definition: restrictprolonginterface.hh:210
bool entitiesAreCopies(const IndexSet &indexSet, const Entity &father, const Entity &son) const
return true if father and son have the same index
Definition: restrictprolonginterface.hh:175
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:307
MutableLocalFunctionType targetLf_
Definition: restrictprolonginterface.hh:375
void addToList(Communicator &comm)
add discrete function to communicator
Definition: restrictprolonginterface.hh:351
DiscreteFunctionType::GridPartType GridPartType
Definition: restrictprolonginterface.hh:217
MutableLocalFunction< DiscreteFunctionType > MutableLocalFunctionType
Definition: restrictprolonginterface.hh:215
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition: restrictprolonginterface.hh:367
ConstLocalFunction< DiscreteFunctionType > ConstLocalFunctionType
Definition: restrictprolonginterface.hh:214
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:259
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: restrictprolonginterface.hh:212