dune-fem  2.4.1-rc
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 
55  void setFatherChildWeight ( const DomainFieldType &weight ) const
56  {
57  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().setFatherChildWeight( weight ) );
58  }
59 
61  template< class Entity >
62  void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
63  {
64  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().restrictLocal( father, son, initialize ) );
65  }
66 
68  template< class Entity, class LocalGeometry >
69  void restrictLocal ( const Entity &father, const Entity &son,
70  const LocalGeometry &geometryInFather,
71  bool initialize ) const
72  {
73  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().restrictLocal( father, son, geometryInFather, initialize ) );
74  }
75 
77  template< class Entity >
78  void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
79  {
80  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().prolongLocal( father, son, initialize ) );
81  }
82 
84  template< class Entity, class LocalGeometry >
85  void prolongLocal ( const Entity &father, const Entity &son,
86  const LocalGeometry &geometryInFather,
87  bool initialize ) const
88  {
89  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().prolongLocal( father, son, geometryInFather, initialize ) );
90  }
91 
95  template< class Communicator >
96  void addToList ( Communicator &comm )
97  {
98  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().addToList( comm ) );
99  }
100 
104  template< class LoadBalancer >
106  {
107  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().addToLoadBalancer( lb ) );
108  }
109 
110  protected:
116  template< class Entity >
117  DomainFieldType calcWeight ( const Entity &father, const Entity &son ) const
118  {
119  const DomainFieldType weight = son.geometry().volume() / father.geometry().volume();
120  assert( weight > DomainFieldType( 0 ) );
121  return weight;
122  }
123 
124  protected:
125  const RestProlImp &asImp () const { return static_cast< const RestProlImp & >( *this ); }
126  RestProlImp &asImp () { return static_cast< RestProlImp & >( *this ); }
127  };
128 
129 
131  template< class Impl, class DomainField >
133  {
134  typedef Impl RestProlImp;
135  typedef DomainField DomainFieldType;
136  };
137 
138 
139 
141  template< class Traits >
143  : public RestrictProlongInterface< Traits >
144  {
147 
148  public:
150 
151  protected:
153  template< class IndexSet, class Entity >
154  bool entitiesAreCopies ( const IndexSet &indexSet,
155  const Entity &father, const Entity &son ) const
156  {
157  return (indexSet.index( father ) == indexSet.index( son ));
158  }
159 
160  public:
162  void setFatherChildWeight ( const DomainFieldType &weight ) const {}
163  };
164 
165 
166 
171  template< class DiscreteFunction >
173  : public RestrictProlongInterfaceDefault< RestrictProlongTraits< RestrictProlongDefault< DiscreteFunction >, typename DiscreteFunction::DomainFieldType > >
174  {
177 
178  public:
179  typedef DiscreteFunction DiscreteFunctionType;
180 
182 
183  typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
184  typedef typename DiscreteFunctionType::LocalFunctionType LocalFunctionType;
185  typedef typename DiscreteFunctionType::GridPartType GridPartType;
186 
188 
189  explicit RestrictProlongDefault ( DiscreteFunctionType &discreteFunction )
190  : discreteFunction_( discreteFunction ),
191  constLf_( discreteFunction ),
192  localRP_( discreteFunction_.space() )
193  {
194  // enable dof compression for this discrete function
195  discreteFunction_.enableDofCompression();
196  }
197 
198  protected:
199  using BaseType::calcWeight;
200  using BaseType::entitiesAreCopies;
201 
202  public:
209  void setFatherChildWeight ( const DomainFieldType &weight ) const
210  {
211  localRP_.setFatherChildWeight( weight );
212  }
213 
215  template< class Entity >
216  void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
217  {
218  assert( !father.isLeaf() );
219 
220  // convert from grid entities to grid part entities
221  typedef typename GridPartType::template Codim< Entity::codimension >::EntityType GridPartEntityType;
222  const GridPartType &gridPart = discreteFunction_.gridPart();
223  const GridPartEntityType &gpFather = gridPart.convert( father );
224  const GridPartEntityType &gpSon = gridPart.convert( son );
225 
226  if( !entitiesAreCopies( gridPart.indexSet(), gpFather, gpSon ) )
227  restrictLocal( gpFather, gpSon, son.geometryInFather(), initialize );
228  }
229 
231  template< class Entity, class LocalGeometry >
232  void restrictLocal ( const Entity &father, const Entity &son,
233  const LocalGeometry &geometryInFather,
234  bool initialize ) const
235  {
236  constLf_.init( son );
237  LocalFunctionType lfFather = discreteFunction_.localFunction( father );
238 
239  localRP_.restrictLocal( lfFather, constLf_, geometryInFather, initialize );
240  }
241 
243  template< class Entity >
244  void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
245  {
246  assert( !father.isLeaf() );
247 
248  // convert from grid entities to grid part entities
249  typedef typename GridPartType::template Codim< Entity::codimension >::EntityType GridPartEntityType;
250  const GridPartType &gridPart = discreteFunction_.gridPart();
251  const GridPartEntityType &gpFather = gridPart.convert( father );
252  const GridPartEntityType &gpSon = gridPart.convert( son );
253 
254  if( !entitiesAreCopies( gridPart.indexSet(), gpFather, gpSon ) )
255  prolongLocal( gpFather, gpSon, son.geometryInFather(), initialize );
256  }
257 
259  template< class Entity, class LocalGeometry >
260  void prolongLocal ( const Entity &father, const Entity &son,
261  const LocalGeometry &geometryInFather,
262  bool initialize ) const
263  {
264  constLf_.init( father );
265  LocalFunctionType lfSon = discreteFunction_.localFunction( son );
266 
267  localRP_.prolongLocal( constLf_, lfSon, geometryInFather, initialize );
268  }
269 
271  template< class Communicator >
272  void addToList ( Communicator &comm )
273  {
274  if( localRP_.needCommunication() )
275  comm.addToList( discreteFunction_ );
276  }
278  template< class Communicator >
279  void removeFromList ( Communicator &comm )
280  {
281  if( localRP_.needCommunication() )
282  comm.removeFromList( discreteFunction_ );
283  }
284 
286  template< class LoadBalancer >
288  {
289  lb.addToLoadBalancer( discreteFunction_ );
290  }
291 
292  protected:
293  DiscreteFunctionType &discreteFunction_;
294  mutable LocalFunctionType constLf_;
295  mutable LocalRestrictProlongType localRP_;
296  };
298 
299  } // namespace Fem
300 
301 } // namespace Dune
302 
303 #endif // #ifndef DUNE_FEM_RESTRICTPROLONGINTERFACE_HH
RestrictProlongDefault(DiscreteFunctionType &discreteFunction)
Definition: restrictprolonginterface.hh:189
void prolongLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:260
This is a wrapper for the default implemented restriction/prolongation operator, which only takes a d...
Definition: restrictprolonginterface.hh:172
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition: restrictprolonginterface.hh:105
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:78
interface documentation for (grid part) index sets
Definition: common/indexset.hh:25
Traits::DomainFieldType DomainFieldType
field type of domain vector space
Definition: restrictprolonginterface.hh:47
Interface default implementation for derived classes.
Definition: restrictprolonginterface.hh:142
IndexType index(const Entity &entity) const
return index for given entity
Definition: common/indexset.hh:166
DiscreteFunctionType::GridPartType GridPartType
Definition: restrictprolonginterface.hh:185
DiscreteFunctionType & discreteFunction_
Definition: restrictprolonginterface.hh:293
DomainField DomainFieldType
Definition: restrictprolonginterface.hh:135
BaseType::DomainFieldType DomainFieldType
Definition: restrictprolonginterface.hh:149
LocalFunctionType constLf_
Definition: restrictprolonginterface.hh:294
Interface class defining the local behaviour of the restrict/prolong operation (using BN) ...
Definition: restrictprolonginterface.hh:38
Traits::RestProlImp RestProlImp
type of restrict-prolong operator implementation
Definition: restrictprolonginterface.hh:44
BaseType::DomainFieldType DomainFieldType
Definition: restrictprolonginterface.hh:181
DefaultLocalRestrictProlong< DiscreteFunctionSpaceType > LocalRestrictProlongType
Definition: restrictprolonginterface.hh:187
LocalRestrictProlongType localRP_
Definition: restrictprolonginterface.hh:295
Definition: coordinate.hh:4
DomainFieldType calcWeight(const Entity &father, const Entity &son) const
calculates the weight, i.e. (volume son)/(volume father)
Definition: restrictprolonginterface.hh:117
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: restrictprolonginterface.hh:183
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:154
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:244
Impl RestProlImp
Definition: restrictprolonginterface.hh:134
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:55
void restrictLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:232
DiscreteFunctionType::LocalFunctionType LocalFunctionType
Definition: restrictprolonginterface.hh:184
void addToList(Communicator &comm)
add discrete function to communicator
Definition: restrictprolonginterface.hh:272
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:209
void prolongLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:85
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:62
DiscreteFunction DiscreteFunctionType
Definition: restrictprolonginterface.hh:179
void addToLoadBalancer(DiscreteFunctionType &df)
add discrete function to data inliner/xtractor list
Definition: loadbalancer.hh:275
This class manages the adaptation process. If the method adapt is called, then the grid is adapted an...
Definition: loadbalancer.hh:69
void restrictLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:69
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:162
void removeFromList(Communicator &comm)
remove discrete function from communicator
Definition: restrictprolonginterface.hh:279
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:216
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition: restrictprolonginterface.hh:287
void addToList(Communicator &comm)
add discrete function to communicator
Definition: restrictprolonginterface.hh:96
Traits class for derivation from RestrictProlongInterface.
Definition: restrictprolonginterface.hh:132
RestProlImp & asImp()
Definition: restrictprolonginterface.hh:126
const RestProlImp & asImp() const
Definition: restrictprolonginterface.hh:125