alugrid/3d/datahandle.hh

Go to the documentation of this file.
00001 #ifndef DUNE_ALU3DGRIDDATAHANDLE_HH
00002 #define DUNE_ALU3DGRIDDATAHANDLE_HH
00003 
00004 //- system includes 
00005 #include <iostream>
00006 
00007 #include <dune/grid/common/grid.hh>
00008 #include <dune/grid/common/adaptcallback.hh>
00009 
00010 //- local includes 
00011 #include "alu3dinclude.hh"
00012 
00013 using std::endl;
00014 using std::cout;
00015 using std::flush;
00016 
00017 namespace ALUGridSpace
00018 {
00019 
00021 template <class GridType, class DataCollectorType, int codim >
00022 class GatherScatterBaseImpl
00023 : public GatherScatter
00024 {
00025 protected:  
00026   const GridType & grid_;
00027   typedef typename GridType::template Codim<codim>::Entity EntityType;
00028   typedef Dune :: MakeableInterfaceObject<
00029     typename GridType::template Codim<codim>::Entity> MakeableEntityType;
00030   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00031 
00032   typedef typename GridType::MPICommunicatorType Comm;
00033   
00034   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00035   typedef typename ImplTraits::template Codim< codim >::ImplementationType ImplElementType;
00036   typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
00037 
00038   EntityType  & entity_;
00039   RealEntityType & realEntity_;
00040 
00041   DataCollectorType & dc_;
00042 
00043   const bool variableSize_;
00044 
00045   typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
00046 
00047   typedef typename DataCollectorType:: DataType DataType;
00048 public:
00050   GatherScatterBaseImpl(const GridType & grid, MakeableEntityType & en, 
00051       RealEntityType & realEntity , DataCollectorType & dc) 
00052     : grid_(grid), entity_(en), realEntity_(realEntity) , dc_(dc)
00053     , variableSize_( ! dc_.fixedsize(EntityType::dimension,codim) )
00054   {
00055   }
00056 
00058   bool contains(int dim, int cd) const { return dc_.contains(dim,cd); }
00059 
00060   // returns true, if element is contained in set of comm interface 
00061   // this method must be overlaoded by the impl classes 
00062   virtual bool containsItem (const HElementType & elem) const = 0;
00063 
00064   // set elem to realEntity
00065   virtual void setElement(const HElementType & elem) = 0;
00066     
00067   void setData ( ObjectStreamType & str , HElementType & elem )
00068   {
00069     // one of this should be either true 
00070     assert( this->containsItem( elem ) || elem.isGhost() );
00071 
00072     // set element and then start 
00073     setElement(elem);
00074 
00075     // make sure partition type is set correct 
00076     assert( elem.isGhost() == (entity_.partitionType() == Dune :: GhostEntity) );
00077 
00078     size_t size = getSize(str, entity_);
00079     // use normal scatter method 
00080     dc_.scatter(str,entity_, size ); 
00081   }
00082 
00084   void sendData ( ObjectStreamType & str , HElementType & elem )
00085   {
00086     // make sure element is contained in communication interface
00087     //assert( this->containsItem( elem ) );
00088     setElement(elem);
00089 
00090     // if varaible size, also send size 
00091     if( variableSize_ )
00092     {
00093       size_t size = dc_.size( entity_ );
00094       str.write( size );
00095     }
00096 
00097     dc_.gather(str, entity_ );
00098   }
00099 
00101   void recvData ( ObjectStreamType & str , HElementType & elem )
00102   {
00103     assert( this->containsItem( elem ) );
00104     setElement( elem );
00105 
00106     size_t size = getSize(str, entity_);
00107     dc_.scatter(str,entity_, size );
00108   }
00109 
00110 protected:  
00111   size_t getSize(ObjectStreamType & str, EntityType & en)
00112   {
00113     if(variableSize_) 
00114     {
00115       size_t size;
00116       str.read(size);
00117       return size;
00118     }
00119     else 
00120       return dc_.size(en);
00121   }
00122 };
00123 
00124 //***********************************************************
00125 //
00126 //  --specialisation for codim 0 
00127 //
00128 //***********************************************************
00129 
00131 template <class GridType, class DataCollectorType >
00132 class GatherScatterBaseImpl<GridType,DataCollectorType,0> : public GatherScatter
00133 {
00134 protected:  
00135   enum { codim = 0 };
00136   const GridType & grid_;
00137   typedef typename GridType::template Codim<0>::Entity EntityType;
00138   typedef Dune :: MakeableInterfaceObject<
00139     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00140   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00141   
00142   typedef typename GridType::MPICommunicatorType Comm;
00143 
00144   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00145   typedef typename ImplTraits::template Codim< codim >::ImplementationType ImplElementType;
00146   typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
00147   
00148   typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
00149   
00150   typedef typename ImplTraits::template Codim< codim >::GhostInterfaceType HGhostType;
00151   typedef typename ImplTraits::template Codim< codim >::GhostImplementationType ImplGhostType;
00152 
00153   typedef typename ImplTraits::PllElementType PllElementType;
00154 
00155   EntityType& entity_;
00156   RealEntityType & realEntity_;
00157 
00158   // data handle 
00159   DataCollectorType & dc_;
00160 
00161   const bool variableSize_;
00162 
00163   // used MessageBuffer 
00164   typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
00165 
00166 public:
00168   GatherScatterBaseImpl(const GridType & grid, MakeableEntityType & en, 
00169       RealEntityType & realEntity , DataCollectorType & dc) 
00170     : grid_(grid), entity_(en), realEntity_(realEntity) 
00171     , dc_(dc) , variableSize_ ( ! dc_.fixedsize( EntityType :: dimension, codim ))
00172   {}
00173 
00174   // return true if dim,codim combination is contained in data set 
00175   bool contains(int dim, int codim) const 
00176   {
00177     return dc_.contains(dim,codim);
00178   }
00179 
00180   // return true if item might from entity belonging to data set  
00181   virtual bool containsItem (const HElementType & elem) const 
00182   {
00183     return elem.isLeafEntity();
00184   }
00185 
00186   // return true if item might from entity belonging to data set  
00187   virtual bool containsItem (const HGhostType & ghost) const = 0; 
00188 
00190   void sendData ( ObjectStreamType & str , const HElementType & elem )
00191   {
00192     assert( this->containsItem(elem) );
00193     realEntity_.setElement( const_cast<HElementType &> (elem) );
00194 
00195     // write size in case of variable size 
00196     writeSize( str, entity_);
00197     // gather data 
00198     dc_.gather(str, entity_);
00199   }
00200  
00202   void sendData ( ObjectStreamType & str , const HGhostType& ghost)
00203   {
00204     assert( this->containsItem( ghost ) );
00205 
00206     // set ghost as entity
00207     realEntity_.setGhost( const_cast <HGhostType &> (ghost) );
00208 
00209     // write size in case of variable size 
00210     writeSize( str, entity_);
00211     // gather data 
00212     dc_.gather(str, entity_);
00213   }
00214  
00216   void recvData ( ObjectStreamType & str , HElementType & elem )
00217   {
00218     assert( this->containsItem( elem ) );
00219     realEntity_.setElement( elem ); 
00220     
00221     size_t size = getSize(str, entity_); 
00222     dc_.scatter(str, entity_, size);
00223   }
00224 
00226   void recvData ( ObjectStreamType & str , HGhostType & ghost )
00227   {
00228     assert( this->containsItem( ghost ) );
00229 
00230     // set ghost as entity
00231     realEntity_.setGhost( ghost );
00232 
00233     size_t size = getSize(str , entity_ ); 
00234     dc_.scatter(str, entity_, size );
00235   }
00236   
00237 protected:  
00238   size_t getSize(ObjectStreamType & str, EntityType & en)
00239   {
00240     if(variableSize_) 
00241     {
00242       size_t size;
00243       str.read(size);
00244       return size;
00245     }
00246     else 
00247       return dc_.size(en);
00248   }
00249   
00250   // write variable size to stream 
00251   void writeSize(ObjectStreamType & str, EntityType & en)
00252   {
00253     if( variableSize_ )
00254     {
00255       size_t size = dc_.size( en );
00256       str.write( size );
00257     }
00258   }
00259 };
00260 
00261 #if ALU3DGRID_PARALLEL
00262 
00263 template< class GridType, class DataCollectorType, int codim >
00264 class GatherScatterLeafData 
00265 : public GatherScatterBaseImpl< GridType, DataCollectorType, codim >
00266 {
00267   enum { dim = GridType :: dimension };
00268 
00269   typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
00270   typedef typename GridType::template Codim<codim>::Entity EntityType;
00271   typedef Dune :: MakeableInterfaceObject<
00272     typename GridType::template Codim<codim>::Entity> MakeableEntityType;
00273   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00274 
00275   typedef typename GridType::MPICommunicatorType Comm;
00276 
00277   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00278   typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
00279   typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
00280   
00281   typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
00282   
00283   typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
00284   typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
00285 
00286   typedef typename ImplTraits::PllElementType PllElementType;
00287 
00288 public:
00290   GatherScatterLeafData(const GridType & grid, MakeableEntityType & en, 
00291       RealEntityType & realEntity , DataCollectorType & dc)
00292     : BaseType(grid,en,realEntity,dc) 
00293   {
00294     // if leaf vertices are communicated, 
00295     // make sure that vertex list is up2date 
00296     // but only do this, if vertex data contained,
00297     // because the list update is expensive  
00298     if( (codim == 3) && dc.contains(dim,codim) ) 
00299     {
00300       // call of this method forces update of list, 
00301       // if list is not up to date
00302       grid.getLeafVertexList();
00303     }
00304   } 
00305 
00306   // returns true, if element is contained in set of comm interface 
00307   bool containsItem (const HElementType & elem) const 
00308   {
00309     return elem.isLeafEntity();
00310   }
00311 
00312   // returns true, if element is contained in set of comm interface 
00313   bool containsItem (const HGhostType & ghost) const 
00314   {
00315     return ghost.isLeafEntity();
00316   }
00317 
00318   // returns true, if interior element is contained in set of comm interface 
00319   bool containsInterior (const HFaceType & face, PllElementType & pll) const 
00320   {
00321     return face.isInteriorLeaf();
00322   }
00323 
00324   // returns true, if ghost is contianed in set of comm interface 
00325   bool containsGhost (const HFaceType & face , PllElementType & pll) const 
00326   {
00327     return pll.ghostLeaf();
00328   }
00329 
00330   // set elem to realEntity
00331   void setElement(const HElementType & elem)
00332   {
00333     this->realEntity_.setElement(elem); 
00334   }
00335 };
00336 
00338 template <class GridType, class DataCollectorType , int codim >
00339 class GatherScatterLevelData 
00340 : public GatherScatterBaseImpl<GridType,DataCollectorType,codim> 
00341 {
00342   typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
00343   typedef typename GridType::template Codim<codim>::Entity EntityType;
00344   typedef Dune :: MakeableInterfaceObject<
00345     typename GridType::template Codim<codim>::Entity> MakeableEntityType;
00346   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00347 
00348   typedef typename GridType::MPICommunicatorType Comm;
00349 
00350   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00351   typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
00352   typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
00353   
00354   typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
00355   
00356   typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
00357   typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
00358 
00359   typedef typename ImplTraits::PllElementType PllElementType;
00360 
00361   typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;
00362 
00363   const LevelIndexSetImp & levelSet_;
00364   const int level_;
00365 public:
00367   GatherScatterLevelData(const GridType & grid, MakeableEntityType & en, 
00368       RealEntityType & realEntity , DataCollectorType & dc, 
00369       const LevelIndexSetImp & levelSet, const int level)
00370     : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level) 
00371   {
00372   } 
00373 
00374   // returns true, if element is contained in set of comm interface 
00375   bool containsItem (const HElementType & elem) const 
00376   {
00377     return levelSet_.containsIndex(codim, elem.getIndex() );
00378   }
00379 
00380   // set elem to realEntity
00381   void setElement(const HElementType & elem)
00382   {
00383     this->realEntity_.setElement(elem,level_); 
00384   }
00385     
00386 };
00387 
00388 
00390 template <class GridType, class DataCollectorType>
00391 class GatherScatterLevelData<GridType,DataCollectorType,0>
00392 : public GatherScatterBaseImpl<GridType,DataCollectorType,0> 
00393 {
00394   enum { codim = 0 };
00395   typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
00396   typedef typename GridType::template Codim<codim>::Entity EntityType;
00397   typedef Dune :: MakeableInterfaceObject<
00398     typename GridType::template Codim<codim>::Entity> MakeableEntityType;
00399   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00400 
00401   typedef typename GridType::MPICommunicatorType Comm;
00402 
00403   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00404   typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
00405   typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
00406   
00407   typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
00408   
00409   typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
00410   typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
00411 
00412   typedef typename ImplTraits::PllElementType PllElementType;
00413 
00414   typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;
00415 
00416   const LevelIndexSetImp & levelSet_;
00417   const int level_;
00418 public:
00420   GatherScatterLevelData(const GridType & grid, MakeableEntityType & en, 
00421       RealEntityType & realEntity , DataCollectorType & dc, 
00422       const LevelIndexSetImp & levelSet, const int level)
00423     : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level) {} 
00424 
00425   // returns true, if element is contained in set of comm interface 
00426   bool containsItem (const HElementType & elem) const 
00427   {
00428     return levelSet_.containsIndex(codim, elem.getIndex() );
00429   }
00430 
00431   // returns true, if element is contained in set of comm interface 
00432   bool containsItem (const HGhostType & ghost) const 
00433   {
00434     assert( ghost.getGhost().first );
00435     return containsItem( * (ghost.getGhost().first) );
00436   }
00437   
00438   // returns true, if interior element is contained in set of comm interface 
00439   bool containsInterior (const HFaceType & face, PllElementType & pll) const 
00440   {
00441     // if face level is not level_ then interior cannot be contained 
00442     if(face.level() != level_) return false;
00443 
00444     typedef Gitter::helement_STI HElementType;
00445     typedef Gitter::hbndseg_STI HBndSegType;
00446 
00447     // check interior element here, might have a coarser level
00448     pair< HElementType *, HBndSegType * > p( (HElementType *)0, (HBndSegType *)0 );
00449     pll.getAttachedElement( p );
00450     assert( p.first );
00451     // check inside level 
00452     bool contained = (p.first->level() == level_);
00453     assert( contained == this->containsItem( *p.first ));
00454     return contained;
00455   }
00456 
00457   // returns true, if ghost is contianed in set of comm interface 
00458   bool containsGhost (const HFaceType & face, PllElementType & pll) const 
00459   {
00460     // if face level is not level_ then ghost cannot be contained 
00461     if(face.level() != level_) return false;
00462     // otherwise check ghost level 
00463     return (pll.ghostLevel() == level_);
00464   }
00465 };
00466 #endif // #if ALU3DGRID_PARALLEL
00467 
00469 template <class GridType, class DataCollectorType, class IndexOperatorType> 
00470 class GatherScatterLoadBalance : public GatherScatter
00471 {
00472 protected:  
00473   enum { codim = 0 };
00474   typedef typename GridType::template Codim<0>::Entity EntityType;
00475   typedef Dune :: MakeableInterfaceObject<
00476     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00477   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00478 
00479   typedef typename GridType::MPICommunicatorType Comm;
00480 
00481   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00482   typedef typename ImplTraits::template Codim< codim >::ImplementationType IMPLElementType;
00483   typedef typename ImplTraits::template Codim< codim >::InterfaceType HElementType;
00484   
00485   typedef typename ImplTraits::template Codim< 1 >::InterfaceType HFaceType;
00486   
00487   typedef typename ImplTraits::template Codim< 0 >::GhostInterfaceType HGhostType;
00488   typedef typename ImplTraits::template Codim< 0 >::GhostImplementationType ImplGhostType;
00489 
00490   typedef typename ImplTraits::PllElementType PllElementType;
00491 
00492   GridType & grid_;
00493 
00494   EntityType     & entity_;
00495   RealEntityType & realEntity_;
00496 
00497   // data handle 
00498   DataCollectorType & dc_;
00499   IndexOperatorType & idxOp_;
00500 
00501   // used MessageBuffer 
00502   typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
00503 
00504 public:
00506   GatherScatterLoadBalance(GridType & grid, MakeableEntityType & en, 
00507       RealEntityType & realEntity , DataCollectorType & dc, IndexOperatorType & idxOp ) 
00508     : grid_(grid), entity_(en), realEntity_(realEntity) 
00509     , dc_(dc) , idxOp_(idxOp) 
00510   {}
00511 
00512   // return true if dim,codim combination is contained in data set 
00513   bool contains(int dim, int codim) const 
00514   {
00515     return true; 
00516   }
00517 
00521   void inlineData ( ObjectStreamType & str , HElementType & elem )
00522   {
00523     str.write(grid_.maxLevel());
00524     // set element and then start 
00525     assert( elem.level () == 0 );
00526     realEntity_.setElement(elem);
00527     dc_.inlineData(str,entity_);
00528   }
00529 
00533   void xtractData ( ObjectStreamType & str , HElementType & elem )
00534   {
00535     assert( elem.level () == 0 );
00536     int mxl; 
00537     str.read(mxl);
00538     // set element and then start 
00539     grid_.setMaxLevel(mxl);
00540 
00541     // reserve memory for new elements 
00542     size_t elChunk = idxOp_.newElements();
00543     assert( elChunk > 0 );
00544     
00545     realEntity_.setElement(elem);
00546     dc_.xtractData(str,entity_, elChunk);
00547   }
00548 
00550   void compress () 
00551   {
00552     dc_.compress();
00553   } 
00554 };
00555 
00557 //
00558 //  --AdaptRestrictProlong 
00559 //
00561 template< class GridType, class AdaptDataHandle >
00562 class AdaptRestrictProlongImpl
00563 : public AdaptRestrictProlongType
00564 {
00565   GridType & grid_;
00566   typedef typename GridType::template Codim<0>::Entity EntityType;
00567   typedef Dune :: MakeableInterfaceObject<
00568     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00569   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00570   
00571   EntityType & reFather_;
00572   EntityType & reSon_;
00573   RealEntityType & realFather_;
00574   RealEntityType & realSon_;
00575  
00576   //DofManagerType & dm_;
00577   AdaptDataHandle &rp_;
00578 
00579   typedef typename GridType::MPICommunicatorType Comm;
00580 
00581   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00582   typedef typename ImplTraits::HElementType HElementType;
00583   typedef typename ImplTraits::HBndSegType HBndSegType;
00584   typedef typename ImplTraits::BNDFaceType BNDFaceType;
00585 
00586 public:
00588   AdaptRestrictProlongImpl ( GridType &grid,
00589                              MakeableEntityType &f, RealEntityType &rf,
00590                              MakeableEntityType &s, RealEntityType &rs,
00591                              AdaptDataHandle &rp ) 
00592     : grid_(grid)
00593     , reFather_(f)
00594     , reSon_(s)
00595     , realFather_(rf) 
00596     , realSon_(rs) 
00597     , rp_(rp) 
00598   {
00599   }
00600 
00601   virtual ~AdaptRestrictProlongImpl () 
00602   {
00603   }
00604 
00606   int preCoarsening ( HElementType & elem )
00607   {
00608     realFather_.setElement( elem );
00609     rp_.preCoarsening( reFather_ );
00610    
00611     // reset refinement marker 
00612     elem.resetRefinedTag();
00613     return 0;
00614   }
00615 
00617   int postRefinement ( HElementType & elem )
00618   {
00619     realFather_.setElement( elem );
00620     rp_.postRefinement( reFather_ );
00621 
00622     // resert refinement markers
00623     elem.resetRefinedTag();
00624     for( HElementType *son = elem.down(); son != 0; son = son->next() )
00625       son->resetRefinedTag();
00626 
00627     return 0;
00628   }
00629 
00632   int preCoarsening ( HBndSegType & el )
00633   {
00634     return 0;
00635   }
00636 
00637 
00639   int postRefinement ( HBndSegType & el )
00640   {
00641     return 0;
00642   }
00643 };
00644 
00645 
00646 
00647 template< class GridType, class AdaptDataHandle, class GlobalIdSetImp >
00648 class AdaptRestrictProlongGlSet
00649 : public AdaptRestrictProlongImpl< GridType, AdaptDataHandle >
00650 {
00651   typedef AdaptRestrictProlongImpl< GridType, AdaptDataHandle > BaseType;
00652   GlobalIdSetImp & set_;
00653   typedef typename GridType::template Codim<0>::Entity EntityType;
00654   typedef Dune :: MakeableInterfaceObject<
00655     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00656   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00657   
00658   typedef typename GridType::MPICommunicatorType Comm;
00659 
00660   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00661   typedef typename ImplTraits::HElementType HElementType;
00662   typedef typename ImplTraits::HBndSegType HBndSegType;
00663 
00664 public:
00666   AdaptRestrictProlongGlSet ( GridType &grid,
00667                               MakeableEntityType &f, RealEntityType &rf,
00668                               MakeableEntityType &s, RealEntityType &rs,
00669                               AdaptDataHandle &rp,
00670                               GlobalIdSetImp & set )
00671   : BaseType( grid, f, rf, s, rs, rp ),
00672     set_( set )
00673   {}
00674 
00675   virtual ~AdaptRestrictProlongGlSet () {}
00676 
00678   int preCoarsening ( HElementType & elem )
00679   {
00680     return BaseType :: preCoarsening (elem );
00681   }
00682 
00684   int postRefinement ( HElementType & elem )
00685   {
00686     set_.postRefinement( elem );
00687     return BaseType :: postRefinement(elem );
00688   }
00689 
00692   int preCoarsening ( HBndSegType & el )
00693   {
00694     return 0;
00695   }
00696 };
00697 
00698 // this class is for counting the tree depth of the 
00699 // element when unpacking data from load balance 
00700 template <class GridType , class DofManagerType>
00701 class LoadBalanceElementCount : public AdaptRestrictProlongType
00702 {
00703   GridType & grid_;
00704   typedef typename GridType::template Codim<0>::Entity EntityType;
00705   typedef Dune :: MakeableInterfaceObject<
00706     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00707   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00708 
00709   typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType; 
00710 
00711   EntityType & reFather_;
00712   EntityType & reSon_;
00713   RealEntityType & realFather_;
00714   RealEntityType & realSon_;
00715  
00716   DofManagerType & dm_;
00717 
00718   typedef typename GridType::MPICommunicatorType Comm;
00719 
00720   typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits;
00721   typedef typename ImplTraits::HElementType HElementType;
00722   typedef typename ImplTraits::HBndSegType HBndSegType;
00723 
00724   int newMemSize_;
00725 public:
00727   LoadBalanceElementCount (GridType & grid, 
00728       MakeableEntityType & f, RealEntityType & rf, MakeableEntityType & s, RealEntityType & rs,DofManagerType & dm) 
00729     : grid_(grid)
00730     , reFather_(f)
00731     , reSon_(s)
00732     , realFather_(rf) 
00733     , realSon_(rs) 
00734     , dm_(dm) 
00735     , newMemSize_ (1) // we have at least one element (the macro element)
00736   {
00737   }
00738 
00739   virtual ~LoadBalanceElementCount () {};
00740 
00742   int postRefinement ( HElementType & elem )
00743   {
00744     // when called for a macro element, then a new tree is starting 
00745     // set to 1 because for only macro elements this method is not called 
00746     if( elem.level() == 0 ) newMemSize_ = 1;
00747 
00748     for( HElementType * son = elem.down() ; son ; son= son->next()) 
00749     {
00750       ++ newMemSize_;
00751     }
00752     return 0;
00753   }
00754 
00756   int preCoarsening ( HElementType & elem )
00757   {
00758     return 0;
00759   }
00760 
00763   int preCoarsening ( HBndSegType & el )
00764   {
00765     return 0;
00766   }
00767 
00772   int postRefinement ( HBndSegType & el )
00773   {
00774     return 0;
00775   }
00776 
00777   int newElements () const { return newMemSize_; }
00778 };
00779 
00780 } // end namespace ALUGridSpace
00781 
00782 #endif // #ifndef DUNE_ALU3DGRIDDATAHANDLE_HH

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].