3#ifndef DUNE_ALU3DGRIDDATAHANDLE_HH
4#define DUNE_ALU3DGRIDDATAHANDLE_HH
13#include "alu3dinclude.hh"
23 template <
class Gr
idType,
class DataCollectorType,
int codim >
25 :
public GatherScatter
28 const GridType & grid_;
29 typedef typename GridType::template Codim<codim>::Entity EntityType;
30 typedef Dune :: MakeableInterfaceObject<
31 typename GridType::template Codim<codim>::Entity> MakeableEntityType;
32 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
34 typedef typename GridType::MPICommunicatorType Comm;
36 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
37 typedef typename ImplTraits::template Codim< codim >::ImplementationType ImplElementType;
38 typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
41 RealEntityType & realEntity_;
43 DataCollectorType & dc_;
45 const bool variableSize_;
47 typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
49 typedef typename DataCollectorType:: DataType DataType;
51 using GatherScatter :: setData ;
54 using GatherScatter :: containsItem ;
59 RealEntityType & realEntity , DataCollectorType & dc)
60 : grid_(grid), entity_(en), realEntity_(realEntity) , dc_(dc)
61 , variableSize_( ! dc_.fixedsize(EntityType::dimension,codim) )
65 bool contains(
int dim,
int cd)
const {
return dc_.contains(dim,cd); }
69 virtual bool containsItem (
const HElementType & elem)
const = 0;
72 virtual void setElement(
const HElementType & elem) = 0;
74 void setData ( ObjectStreamType & str , HElementType & elem )
77 assert( this->containsItem( elem ) || elem.isGhost() );
83 assert( elem.isGhost() == (entity_.partitionType() == Dune :: GhostEntity) );
85 size_t size = getSize(str, entity_);
87 dc_.scatter(str,entity_, size );
91 void sendData ( ObjectStreamType & str , HElementType & elem )
100 size_t size = dc_.size( entity_ );
104 dc_.gather(str, entity_ );
108 void recvData ( ObjectStreamType & str , HElementType & elem )
110 assert( this->containsItem( elem ) );
113 size_t size = getSize(str, entity_);
114 dc_.scatter(str,entity_, size );
118 size_t getSize(ObjectStreamType & str, EntityType & en)
138 template <
class Gr
idType,
class DataCollectorType >
143 const GridType & grid_;
144 typedef typename GridType::template Codim<0>::Entity EntityType;
145 typedef Dune :: MakeableInterfaceObject<
146 typename GridType::template Codim<0>::Entity> MakeableEntityType;
147 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
149 typedef typename GridType::MPICommunicatorType Comm;
151 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
152 typedef typename ImplTraits::template Codim< codim >::ImplementationType ImplElementType;
153 typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
155 typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
157 typedef typename ImplTraits::template Codim< codim >::GhostInterfaceType HGhostType;
158 typedef typename ImplTraits::template Codim< codim >::GhostImplementationType ImplGhostType;
160 typedef typename ImplTraits::PllElementType PllElementType;
163 RealEntityType & realEntity_;
166 DataCollectorType & dc_;
168 const bool variableSize_;
171 typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
174 using GatherScatter :: setData ;
180 using GatherScatter :: containsItem ;
184 RealEntityType & realEntity , DataCollectorType & dc)
185 : grid_(grid), entity_(en), realEntity_(realEntity)
186 , dc_(dc) , variableSize_ ( ! dc_.fixedsize( EntityType :: dimension, codim ))
190 bool contains(
int dim,
int codim)
const
192 return dc_.contains(dim,codim);
196 virtual bool containsItem (
const HElementType & elem)
const
198 return elem.isLeafEntity();
202 virtual bool containsItem (
const HGhostType & ghost)
const = 0;
205 void sendData ( ObjectStreamType & str ,
const HElementType & elem )
207 assert( this->containsItem(elem) );
208 realEntity_.setElement(
const_cast<HElementType &
> (elem) );
211 writeSize( str, entity_);
213 dc_.gather(str, entity_);
217 void sendData ( ObjectStreamType & str ,
const HGhostType& ghost)
219 assert( this->containsItem( ghost ) );
222 realEntity_.setGhost(
const_cast <HGhostType &
> (ghost) );
225 writeSize( str, entity_);
227 dc_.gather(str, entity_);
231 void recvData ( ObjectStreamType & str , HElementType & elem )
234 realEntity_.setElement( elem );
236 size_t size = getSize(str, entity_);
237 dc_.scatter(str, entity_, size);
241 void recvData ( ObjectStreamType & str , HGhostType & ghost )
243 assert( this->containsItem( ghost ) );
246 realEntity_.setGhost( ghost );
248 size_t size = getSize(str , entity_ );
249 dc_.scatter(str, entity_, size );
253 size_t getSize(ObjectStreamType & str, EntityType & en)
266 void writeSize(ObjectStreamType & str, EntityType & en)
270 size_t size = dc_.size( en );
276#if ALU3DGRID_PARALLEL
278 template<
class Gr
idType,
class DataCollectorType,
int codim >
279 class GatherScatterLeafData
280 :
public GatherScatterBaseImpl< GridType, DataCollectorType, codim >
282 enum { dim = GridType :: dimension };
284 typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
285 typedef typename GridType::template Codim<codim>::Entity EntityType;
286 typedef Dune :: MakeableInterfaceObject<
287 typename GridType::template Codim<codim>::Entity> MakeableEntityType;
288 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
290 typedef typename GridType::MPICommunicatorType Comm;
292 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
293 typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
294 typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
296 typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
298 typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
299 typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
301 typedef typename ImplTraits::PllElementType PllElementType;
305 using BaseType :: containsItem ;
308 GatherScatterLeafData(
const GridType & grid, MakeableEntityType & en,
309 RealEntityType & realEntity , DataCollectorType & dc)
310 : BaseType(grid,en,realEntity,dc)
316 if( (codim == 3) && dc.contains(dim,codim) )
320 grid.getLeafVertexList();
325 bool containsItem (
const HElementType & elem)
const
327 return elem.isLeafEntity();
331 bool containsItem (
const HGhostType & ghost)
const
333 return ghost.isLeafEntity();
337 bool containsInterior (
const HFaceType & face, PllElementType & pll)
const
339 return face.isInteriorLeaf();
343 bool containsGhost (
const HFaceType & face , PllElementType & pll)
const
345 return pll.ghostLeaf();
349 void setElement(
const HElementType & elem)
351 this->realEntity_.setElement(elem);
356 template <
class Gr
idType,
class DataCollectorType ,
int codim >
357 class GatherScatterLevelData
358 :
public GatherScatterBaseImpl<GridType,DataCollectorType,codim>
360 typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
361 typedef typename GridType::template Codim<codim>::Entity EntityType;
362 typedef Dune :: MakeableInterfaceObject<
363 typename GridType::template Codim<codim>::Entity> MakeableEntityType;
364 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
366 typedef typename GridType::MPICommunicatorType Comm;
368 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
369 typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
370 typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
372 typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
374 typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
375 typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
377 typedef typename ImplTraits::PllElementType PllElementType;
379 typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;
381 const LevelIndexSetImp & levelSet_;
385 using BaseType :: containsItem ;
388 GatherScatterLevelData(
const GridType & grid, MakeableEntityType & en,
389 RealEntityType & realEntity , DataCollectorType & dc,
390 const LevelIndexSetImp & levelSet,
const int level)
391 : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level)
395 bool containsItem (
const HElementType & elem)
const
397 return levelSet_.containsIndex(codim, elem.getIndex() );
401 void setElement(
const HElementType & elem)
403 this->realEntity_.setElement(elem,level_);
410 template <
class Gr
idType,
class DataCollectorType>
411 class GatherScatterLevelData<GridType,DataCollectorType,0>
412 :
public GatherScatterBaseImpl<GridType,DataCollectorType,0>
415 typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
416 typedef typename GridType::template Codim<codim>::Entity EntityType;
417 typedef Dune :: MakeableInterfaceObject<
418 typename GridType::template Codim<codim>::Entity> MakeableEntityType;
419 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
421 typedef typename GridType::MPICommunicatorType Comm;
423 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
424 typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
425 typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
427 typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
429 typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
430 typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
432 typedef typename ImplTraits::PllElementType PllElementType;
434 typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;
436 const LevelIndexSetImp & levelSet_;
440 GatherScatterLevelData(
const GridType & grid, MakeableEntityType & en,
441 RealEntityType & realEntity , DataCollectorType & dc,
442 const LevelIndexSetImp & levelSet,
const int level)
443 : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level) {}
446 bool containsItem (
const HElementType & elem)
const
448 return levelSet_.containsIndex(codim, elem.getIndex() );
452 bool containsItem (
const HGhostType & ghost)
const
454 assert( ghost.getGhost().first );
455 return containsItem( * (ghost.getGhost().first) );
459 bool containsInterior (
const HFaceType & face, PllElementType & pll)
const
462 if(face.level() != level_)
return false;
464 typedef Gitter::helement_STI HElementType;
465 typedef Gitter::hbndseg_STI HBndSegType;
468 pair< HElementType *, HBndSegType * > p( (HElementType *)0, (HBndSegType *)0 );
469 pll.getAttachedElement( p );
472 bool contained = (p.first->level() == level_);
473 assert( contained == this->containsItem( *p.first ));
478 bool containsGhost (
const HFaceType & face, PllElementType & pll)
const
481 if(face.level() != level_)
return false;
483 return (pll.ghostLevel() == level_);
489 template <
class Gr
idType,
class DataCollectorType,
class IndexOperatorType>
494 typedef typename GridType::template Codim<0>::Entity EntityType;
495 typedef Dune :: MakeableInterfaceObject<
496 typename GridType::template Codim<0>::Entity> MakeableEntityType;
497 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
499 typedef typename GridType::MPICommunicatorType Comm;
501 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
502 typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
503 typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
505 typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
507 typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
508 typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
510 typedef typename ImplTraits::PllElementType PllElementType;
514 EntityType & entity_;
515 RealEntityType & realEntity_;
518 DataCollectorType & dc_;
519 IndexOperatorType & idxOp_;
522 typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
530 RealEntityType & realEntity , DataCollectorType & dc, IndexOperatorType & idxOp )
531 : grid_(grid), entity_(en), realEntity_(realEntity)
532 , dc_(dc) , idxOp_(idxOp)
536 bool contains(
int dim,
int codim)
const
544 void inlineData ( ObjectStreamType & str , HElementType & elem )
546 str.write(grid_.maxLevel());
548 assert( elem.level () == 0 );
549 realEntity_.setElement(elem);
550 dc_.inlineData(str,entity_);
556 void xtractData ( ObjectStreamType & str , HElementType & elem )
558 assert( elem.level () == 0 );
562 grid_.setMaxLevel(mxl);
565 size_t elChunk = idxOp_.newElements();
566 assert( elChunk > 0 );
568 realEntity_.setElement(elem);
569 dc_.xtractData(str,entity_, elChunk);
584 template<
class Gr
idType,
class AdaptDataHandle >
585 class AdaptRestrictProlongImpl
586 :
public AdaptRestrictProlongType
589 typedef typename GridType::template Codim<0>::Entity EntityType;
590 typedef Dune :: MakeableInterfaceObject<
591 typename GridType::template Codim<0>::Entity> MakeableEntityType;
592 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
594 EntityType & reFather_;
596 RealEntityType & realFather_;
597 RealEntityType & realSon_;
599 AdaptDataHandle &rp_;
601 typedef typename GridType::MPICommunicatorType Comm;
603 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
604 typedef typename ImplTraits::HElementType HElementType;
605 typedef typename ImplTraits::HBndSegType HBndSegType;
606 typedef typename ImplTraits::BNDFaceType BNDFaceType;
613 AdaptRestrictProlongImpl ( GridType &grid,
614 MakeableEntityType &f, RealEntityType &rf,
615 MakeableEntityType &s, RealEntityType &rs,
616 AdaptDataHandle &rp )
625 virtual ~AdaptRestrictProlongImpl ()
629 int preCoarsening ( HElementType & father )
631 realFather_.setElement( father );
632 rp_.preCoarsening( reFather_ );
635 father.resetRefinedTag();
640 int postRefinement ( HElementType & father )
642 realFather_.setElement( father );
643 rp_.postRefinement( reFather_ );
646 father.resetRefinedTag();
647 for( HElementType *son = father.down(); son ; son = son->next() )
648 son->resetRefinedTag();
654 int preCoarsening ( HBndSegType & ghost ) {
return 0; }
658 int postRefinement ( HBndSegType & ghost ) {
return 0; }
663 template<
class Gr
idType,
class AdaptDataHandle,
class GlobalIdSetImp >
664 class AdaptRestrictProlongGlSet
665 :
public AdaptRestrictProlongImpl< GridType, AdaptDataHandle >
667 typedef AdaptRestrictProlongImpl< GridType, AdaptDataHandle > BaseType;
668 GlobalIdSetImp & set_;
669 typedef typename GridType::template Codim<0>::Entity EntityType;
670 typedef Dune :: MakeableInterfaceObject<
671 typename GridType::template Codim<0>::Entity> MakeableEntityType;
672 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
674 typedef typename GridType::MPICommunicatorType Comm;
676 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
677 typedef typename ImplTraits::HElementType HElementType;
678 typedef typename ImplTraits::HBndSegType HBndSegType;
680 using AdaptRestrictProlongType :: postRefinement ;
681 using AdaptRestrictProlongType :: preCoarsening ;
685 AdaptRestrictProlongGlSet ( GridType &grid,
686 MakeableEntityType &f, RealEntityType &rf,
687 MakeableEntityType &s, RealEntityType &rs,
689 GlobalIdSetImp & set )
690 : BaseType( grid, f, rf, s, rs, rp ),
694 virtual ~AdaptRestrictProlongGlSet () {}
697 int postRefinement ( HElementType & elem )
699 set_.postRefinement( elem );
700 return BaseType :: postRefinement(elem );
706 template <
class Gr
idType ,
class DataHandleType>
707 class LoadBalanceElementCount :
public AdaptRestrictProlongType
710 typedef typename GridType::template Codim<0>::Entity EntityType;
711 typedef Dune :: MakeableInterfaceObject<
712 typename GridType::template Codim<0>::Entity> MakeableEntityType;
713 typedef typename MakeableEntityType :: ImplementationType RealEntityType;
715 typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType;
717 EntityType & reFather_;
719 RealEntityType & realFather_;
720 RealEntityType & realSon_;
722 DataHandleType & dh_;
724 typedef typename GridType::MPICommunicatorType Comm;
726 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
727 typedef typename ImplTraits::HElementType HElementType;
728 typedef typename ImplTraits::HBndSegType HBndSegType;
732 using AdaptRestrictProlongType :: postRefinement ;
733 using AdaptRestrictProlongType :: preCoarsening ;
737 LoadBalanceElementCount (GridType & grid,
738 MakeableEntityType & f, RealEntityType & rf,
739 MakeableEntityType & s, RealEntityType & rs,
750 virtual ~LoadBalanceElementCount () {}
753 int postRefinement ( HElementType & elem )
757 if( elem.level() == 0 ) newMemSize_ = 1;
759 for( HElementType * son = elem.down() ; son ; son= son->next())
767 int preCoarsening ( HElementType & elem )
774 int preCoarsening ( HBndSegType & el )
783 int postRefinement ( HBndSegType & el )
788 int newElements ()
const {
return newMemSize_; }
interfaces and wrappers needed for the callback adaptation provided by AlbertaGrid and ALUGrid
void sendData(ObjectStreamType &str, const HElementType &elem)
write Data of one element to stream
Definition: datahandle.hh:205
void recvData(ObjectStreamType &str, HGhostType &ghost)
read Data of one element from stream
Definition: datahandle.hh:241
GatherScatterBaseImpl(const GridType &grid, MakeableEntityType &en, RealEntityType &realEntity, DataCollectorType &dc)
Constructor.
Definition: datahandle.hh:183
void sendData(ObjectStreamType &str, const HGhostType &ghost)
write Data of one ghost element to stream
Definition: datahandle.hh:217
void recvData(ObjectStreamType &str, HElementType &elem)
read Data of one element from stream
Definition: datahandle.hh:231
the corresponding interface class is defined in bsinclude.hh
Definition: datahandle.hh:26
GatherScatterBaseImpl(const GridType &grid, MakeableEntityType &en, RealEntityType &realEntity, DataCollectorType &dc)
Constructor.
Definition: datahandle.hh:58
bool contains(int dim, int cd) const
returns contains of dc_
Definition: datahandle.hh:65
void recvData(ObjectStreamType &str, HElementType &elem)
read Data of one element from stream
Definition: datahandle.hh:108
void sendData(ObjectStreamType &str, HElementType &elem)
write Data of one element to stream
Definition: datahandle.hh:91
the corresponding interface class is defined in bsinclude.hh
Definition: datahandle.hh:491
void xtractData(ObjectStreamType &str, HElementType &elem)
Definition: datahandle.hh:556
GatherScatterLoadBalance(GridType &grid, MakeableEntityType &en, RealEntityType &realEntity, DataCollectorType &dc, IndexOperatorType &idxOp)
Constructor.
Definition: datahandle.hh:529
void inlineData(ObjectStreamType &str, HElementType &elem)
Definition: datahandle.hh:544
void compress()
call compress on data
Definition: datahandle.hh:573
Different resources needed by all grid implementations.