DUNE-FEM (unstable)

restrictprolonginterface.hh
1#ifndef DUNE_FEM_RESTRICTPROLONGINTERFACE_HH
2#define DUNE_FEM_RESTRICTPROLONGINTERFACE_HH
3
4//- Dune includes
7
8//- local includes
9#include <dune/fem/function/localfunction/const.hh>
10#include <dune/fem/function/localfunction/mutable.hh>
11#include <dune/fem/space/common/localrestrictprolong.hh>
12#include <dune/fem/gridpart/common/indexset.hh>
13
14namespace Dune
15{
16
17 namespace Fem
18 {
19
38 template< class Traits >
40 {
42
43 public:
45 typedef typename Traits::RestProlImp RestProlImp;
46
48 typedef typename Traits::DomainFieldType DomainFieldType;
49
52 void initialize ()
53 {
55 }
56
59 void finalize ()
60 {
62 }
63
70 void setFatherChildWeight ( const DomainFieldType &weight ) const
71 {
73 }
74
76 template< class Entity >
77 void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
78 {
80 }
81
83 template< class Entity, class LocalGeometry >
84 void restrictLocal ( const Entity &father, const Entity &son,
85 const LocalGeometry &geometryInFather,
86 bool initialize ) const
87 {
88 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().restrictLocal( father, son, geometryInFather, initialize ) );
89 }
90
92 template <class Entity>
93 void restrictFinalize(const Entity &father) const
94 {
96 }
97
99 template< class Entity >
100 void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
101 {
103 }
104
106 template< class Entity, class LocalGeometry >
107 void prolongLocal ( const Entity &father, const Entity &son,
108 const LocalGeometry &geometryInFather,
109 bool initialize ) const
110 {
111 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION( asImp().prolongLocal( father, son, geometryInFather, initialize ) );
112 }
113
117 template< class Communicator >
118 void addToList ( Communicator &comm )
119 {
121 }
122
126 template< class LoadBalancer >
128 {
130 }
131
132 protected:
138 template< class Entity >
139 DomainFieldType calcWeight ( const Entity &father, const Entity &son ) const
140 {
141 const DomainFieldType weight = son.geometry().volume() / father.geometry().volume();
142 assert( weight > DomainFieldType( 0 ) );
143 return weight;
144 }
145
146 protected:
147 const RestProlImp &asImp () const { return static_cast< const RestProlImp & >( *this ); }
148 RestProlImp &asImp () { return static_cast< RestProlImp & >( *this ); }
149 };
150
151
153 template< class Impl, class DomainField >
155 {
156 typedef Impl RestProlImp;
157 typedef DomainField DomainFieldType;
158 };
159
160
161
163 template< class Traits >
165 : public RestrictProlongInterface< Traits >
166 {
169
170 public:
172
173 protected:
175 template< class IndexSet, class Entity >
176 bool entitiesAreCopies ( const IndexSet &indexSet,
177 const Entity &father, const Entity &son ) const
178 {
179 // adaptation and restriction/prolongation only works
180 // for index set derived from Dune::Fem::IndexSet
182 return (indexSet.index( father ) == indexSet.index( son ));
183 }
184
185
186 public:
188 void setFatherChildWeight ( const DomainFieldType &weight ) const {}
189
190 void initialize () {}
191 void finalize () {}
192
194 template <class Entity>
195 void restrictFinalize( const Entity& father ) const {}
196 };
197
198
199
204 template< class DiscreteFunction >
206 : public RestrictProlongInterfaceDefault< RestrictProlongTraits< RestrictProlongDefault< DiscreteFunction >, typename DiscreteFunction::DomainFieldType > >
207 {
210
211 public:
212 typedef DiscreteFunction DiscreteFunctionType;
213
214 typedef typename BaseType::DomainFieldType DomainFieldType;
215
216 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
217
218 typedef ConstLocalFunction< DiscreteFunctionType > ConstLocalFunctionType;
220
221 typedef typename DiscreteFunctionType::GridPartType GridPartType;
222
223 typedef DefaultLocalRestrictProlong< DiscreteFunctionSpaceType > LocalRestrictProlongType;
224
226 : discreteFunction_( const_cast< RestrictProlongDefault& > (other).discreteFunction_ ),
227 constLf_( discreteFunction_ ),
228 targetLf_( discreteFunction_ ),
229 localRP_( discreteFunction_.space() )
230 {
231 // enable dof compression for this discrete function
232 discreteFunction_.enableDofCompression();
233 }
234
235 explicit RestrictProlongDefault ( DiscreteFunctionType &discreteFunction )
236 : discreteFunction_( discreteFunction ),
237 constLf_( discreteFunction ),
238 targetLf_( discreteFunction_ ),
239 localRP_( discreteFunction_.space() )
240 {
241 // enable dof compression for this discrete function
242 discreteFunction_.enableDofCompression();
243 }
244
245 protected:
248
249 public:
256 void setFatherChildWeight ( const DomainFieldType &weight ) const
257 {
258 localRP_.setFatherChildWeight( weight );
259 }
260
262 template< class Entity >
263 void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
264 {
265 assert( !father.isLeaf() );
266
267 // convert from grid entities to grid part entities
268 typedef typename GridPartType::template Codim< Entity::codimension >::EntityType GridPartEntityType;
269 const GridPartType &gridPart = discreteFunction_.gridPart();
270 const GridPartEntityType &gpFather = gridPart.convert( father );
271 const GridPartEntityType &gpSon = gridPart.convert( son );
272
273 if( !entitiesAreCopies( gridPart.indexSet(), gpFather, gpSon ) )
274 restrictLocal( gpFather, gpSon, son.geometryInFather(), initialize );
275 }
276
278 template< class Entity, class LocalGeometry >
279 void restrictLocal ( const Entity &father, const Entity &son,
280 const LocalGeometry &geometryInFather,
281 bool initialize ) const
282 {
283 auto clf = bindGuard( constLf_, son );
284
285 if( initialize || ! targetLf_.valid() )
286 {
287 targetLf_.bind( father );
288 // unbind is done in restrictFinalize
289 }
290
291 assert( father == targetLf_.entity() );
292 localRP_.restrictLocal( targetLf_, constLf_, geometryInFather, initialize );
293 }
294
296 template <class Entity>
297 void restrictFinalize(const Entity &father) const
298 {
299 // make sure targetLf_ still is bound to father
300 assert( discreteFunction_.gridPart().convert( father ) == targetLf_.entity() );
301
302 localRP_.restrictFinalize( targetLf_ );
303
304 // release target local function
305 targetLf_.unbind();
306 }
307
308
310 template< class Entity >
311 void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
312 {
313 assert( !father.isLeaf() );
314
315 // convert from grid entities to grid part entities
316 typedef typename GridPartType::template Codim< Entity::codimension >::EntityType GridPartEntityType;
317 const GridPartType &gridPart = discreteFunction_.gridPart();
318 const GridPartEntityType &gpFather = gridPart.convert( father );
319 const GridPartEntityType &gpSon = gridPart.convert( son );
320
321 if( !entitiesAreCopies( gridPart.indexSet(), gpFather, gpSon ) )
322 prolongLocal( gpFather, gpSon, son.geometryInFather(), initialize );
323 }
324
326 template< class Entity, class LocalGeometry >
327 void prolongLocal ( const Entity &father, const Entity &son,
328 const LocalGeometry &geometryInFather,
329 bool initialize ) const
330 {
331 // initialize father local function (only once)
332 //if( initialize )
333 {
334 constLf_.unbind();
335 constLf_.bind( father );
336 }
337
338 auto tlf = bindGuard( targetLf_, son );
339
340 localRP_.prolongLocal( constLf_, targetLf_, geometryInFather, initialize );
341 // write to discrete function
342 discreteFunction_.setLocalDofs( son, targetLf_ );
343 }
344
346 template< class Communicator, class Operation >
347 void addToList ( Communicator &comm, const Operation& op)
348 {
349 if( localRP_.needCommunication() )
350 comm.addToList( discreteFunction_, op );
351 }
352
354 template< class Communicator >
355 void addToList ( Communicator &comm )
356 {
357 if( localRP_.needCommunication() )
358 comm.addToList( discreteFunction_ );
359 }
360
362 template< class Communicator >
363 void removeFromList ( Communicator &comm )
364 {
365 if( localRP_.needCommunication() )
366 comm.removeFromList( discreteFunction_ );
367 }
368
370 template< class LoadBalancer >
372 {
373 lb.addToLoadBalancer( discreteFunction_ );
374 }
375
376 protected:
377 DiscreteFunctionType &discreteFunction_;
378 mutable ConstLocalFunctionType constLf_;
379 mutable MutableLocalFunctionType targetLf_;
380 mutable LocalRestrictProlongType localRP_;
381 };
383
384 } // namespace Fem
385
386} // namespace Dune
387
388#endif // #ifndef DUNE_FEM_RESTRICTPROLONGINTERFACE_HH
Provides check for implementation of interface methods when using static polymorphism,...
#define CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(__interface_method_to_call__)
Definition: bartonnackmanifcheck.hh:61
Wrapper class for entities.
Definition: entity.hh:66
Geometry geometry() const
obtain geometric realization of the entity
Definition: entity.hh:141
BaseType::GridPartType GridPartType
type of the underlying grid part
Definition: discretefunction.hh:609
interface documentation for (grid part) index sets
Definition: indexset.hh:123
IndexType index(const Entity &entity) const
return index for given entity
Definition: indexset.hh:172
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:201
const EntityType & entity() const
obtain the entity, this local function lives on
Definition: localfunction.hh:305
bool valid() const
Returns true if local function if bind or init was previously called.
Definition: localfunction.hh:432
This is a wrapper for the default implemented restriction/prolongation operator, which only takes a d...
Definition: restrictprolonginterface.hh:207
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:256
void addToList(Communicator &comm, const Operation &op)
add discrete function to communicator with given unpack operation
Definition: restrictprolonginterface.hh:347
void restrictFinalize(const Entity &father) const
finalize restriction on father
Definition: restrictprolonginterface.hh:297
void removeFromList(Communicator &comm)
remove discrete function from communicator
Definition: restrictprolonginterface.hh:363
void restrictLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:279
void prolongLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:327
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:176
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:311
void addToList(Communicator &comm)
add discrete function to communicator
Definition: restrictprolonginterface.hh:355
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition: restrictprolonginterface.hh:371
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:263
Interface default implementation for derived classes.
Definition: restrictprolonginterface.hh:166
void restrictFinalize(const Entity &father) const
restrictFinalize is for some spaces where a local matrix inversion is carried out after restriction.
Definition: restrictprolonginterface.hh:195
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:176
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:188
Interface class defining the local behaviour of the restrict/prolong operation (using BN)
Definition: restrictprolonginterface.hh:40
void addToList(Communicator &comm)
add discrete function to communicator
Definition: restrictprolonginterface.hh:118
Traits::DomainFieldType DomainFieldType
field type of domain vector space
Definition: restrictprolonginterface.hh:48
void prolongLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:107
void setFatherChildWeight(const DomainFieldType &weight) const
explicit set volume ratio of son and father
Definition: restrictprolonginterface.hh:70
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:77
void restrictFinalize(const Entity &father) const
finalize restriction on father
Definition: restrictprolonginterface.hh:93
Traits::RestProlImp RestProlImp
type of restrict-prolong operator implementation
Definition: restrictprolonginterface.hh:45
DomainFieldType calcWeight(const Entity &father, const Entity &son) const
calculates the weight, i.e. (volume son)/(volume father)
Definition: restrictprolonginterface.hh:139
void addToLoadBalancer(LoadBalancer &lb)
add discrete function to load balancer
Definition: restrictprolonginterface.hh:127
void finalize()
finalize restrict prolong object (if necessary) after adaptation and dof compression was finished
Definition: restrictprolonginterface.hh:59
void initialize()
initialize restrict prolong object (if necessary) before adaptation takes place
Definition: restrictprolonginterface.hh:52
void restrictLocal(const Entity &father, const Entity &son, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: restrictprolonginterface.hh:84
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
prolong data to children
Definition: restrictprolonginterface.hh:100
forward declaration
Definition: discretefunction.hh:51
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
A set of traits classes to store static information about grid implementation.
Dune namespace.
Definition: alignedallocator.hh:13
Static tag representing a codimension.
Definition: dimension.hh:24
specialize with true if index set implements the dune-fem interface for index sets
Definition: indexset.hh:39
Traits class for derivation from RestrictProlongInterface.
Definition: restrictprolonginterface.hh:155
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)