alugrid/3d/datahandle.hh

00001 #ifndef DUNE_ALU3DGRIDDATAHANDLE_HH
00002 #define DUNE_ALU3DGRIDDATAHANDLE_HH
00003 
00004 //- system includes 
00005 #include <iostream>
00006 
00007 //- local includes 
00008 #include "alu3dinclude.hh"
00009 
00010 using std::endl;
00011 using std::cout;
00012 using std::flush;
00013 
00014 namespace ALUGridSpace {
00015 
00017 template <class GridType, class DataCollectorType , int codim >
00018 class GatherScatterBaseImpl : public GatherScatter
00019 {
00020 protected:  
00021   const GridType & grid_;
00022   typedef typename GridType::template Codim<codim>::Entity EntityType;
00023   typedef Dune :: MakeableInterfaceObject<
00024     typename GridType::template Codim<codim>::Entity> MakeableEntityType;
00025   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00026   
00027   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00028     template Codim<codim>::ImplementationType ImplElementType;
00029   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00030     template Codim<codim>::InterfaceType HElementType;
00031 
00032   EntityType  & entity_;
00033   RealEntityType & realEntity_;
00034 
00035   DataCollectorType & dc_;
00036 
00037   const bool variableSize_;
00038 
00039   typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
00040 
00041   typename DataCollectorType::DataType tmp_;
00042 public:
00044   GatherScatterBaseImpl(const GridType & grid, MakeableEntityType & en, 
00045       RealEntityType & realEntity , DataCollectorType & dc) 
00046     : grid_(grid), entity_(en), realEntity_(realEntity) , dc_(dc)
00047     , variableSize_( ! dc_.fixedsize(EntityType::dimension,codim) )
00048   {
00049   }
00050 
00052   bool contains(int dim, int cd) const { return dc_.contains(dim,cd); }
00053 
00054   // returns true, if element is contained in set of comm interface 
00055   // this method must be overlaoded by the impl classes 
00056   virtual bool containsItem (const HElementType & elem) const = 0;
00057 
00058   // set elem to realEntity
00059   virtual void setElement(const HElementType & elem) = 0;
00060     
00061   void setData ( ObjectStreamType & str , HElementType & elem )
00062   {
00063     // one of this should be either true 
00064     assert( this->containsItem( elem ) || elem.isGhost() );
00065 
00066     // set element and then start 
00067     setElement(elem);
00068 
00069     // make sure partition type is set correct 
00070     assert( elem.isGhost() == (entity_.partitionType() == Dune :: GhostEntity) );
00071 
00072     size_t size = getSize(str, entity_);
00073     // use normal scatter method 
00074     dc_.scatter(str,entity_, size ); 
00075   }
00076 
00078   void sendData ( ObjectStreamType & str , HElementType & elem )
00079   {
00080     // make sure element is contained in communication interface
00081     assert( this->containsItem( elem ) );
00082     setElement(elem);
00083 
00084     // if varaible size, also send size 
00085     if( variableSize_ )
00086     {
00087       size_t size = dc_.size( entity_ );
00088       str.write( size );
00089     }
00090 
00091     dc_.gather(str, entity_ );
00092   }
00093 
00095   void recvData ( ObjectStreamType & str , HElementType & elem )
00096   {
00097     assert( this->containsItem( elem ) );
00098     setElement( elem );
00099 
00100     size_t size = getSize(str, entity_);
00101     dc_.scatter(str,entity_, size );
00102   }
00103 
00104 protected:  
00105   size_t getSize(ObjectStreamType & str, EntityType & en)
00106   {
00107     if(variableSize_) 
00108     {
00109       size_t size;
00110       str.read(size);
00111       return size;
00112     }
00113     else 
00114       return dc_.size(en);
00115   }
00116 };
00117 
00118 //***********************************************************
00119 //
00120 //  --specialisation for codim 0 
00121 //
00122 //***********************************************************
00123 
00125 template <class GridType, class DataCollectorType >
00126 class GatherScatterBaseImpl<GridType,DataCollectorType,0> : public GatherScatter
00127 {
00128 protected:  
00129   enum { codim = 0 };
00130   const GridType & grid_;
00131   typedef typename GridType::template Codim<0>::Entity EntityType;
00132   typedef Dune :: MakeableInterfaceObject<
00133     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00134   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00135   
00136   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00137     template Codim<codim>::ImplementationType IMPLElementType;
00138   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00139     template Codim<codim>::InterfaceType HElementType;
00140   
00141   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00142     template Codim<1>::InterfaceType HFaceType;
00143   
00144   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00145     template Codim<codim>::GhostInterfaceType HGhostType;
00146   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00147     template Codim<codim>::GhostImplementationType ImplGhostType;
00148 
00149 #if ALU3DGRID_PARALLEL 
00150   typedef ALU3DSPACE ElementPllXIF_t PllElementType;
00151 #else 
00152   typedef HElementType PllElementType;
00153 #endif
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
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 Dune::ALU3dImplTraits<GridType::elementType>::
00276     template Codim<codim>::ImplementationType IMPLElementType;
00277   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00278     template Codim<codim>::InterfaceType HElementType;
00279   
00280   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00281     template Codim<1>::InterfaceType HFaceType;
00282   
00283   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00284     template Codim<0>::GhostInterfaceType HGhostType;
00285   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00286     template Codim<0>::GhostImplementationType ImplGhostType;
00287 
00288   typedef ALU3DSPACE ElementPllXIF_t PllElementType;
00289 
00290 public:
00292   GatherScatterLeafData(const GridType & grid, MakeableEntityType & en, 
00293       RealEntityType & realEntity , DataCollectorType & dc)
00294     : BaseType(grid,en,realEntity,dc) 
00295   {
00296     // if leaf vertices are communicated, 
00297     // make sure that vertex list is up2date 
00298     // but only do this, if vertex data contained,
00299     // because the list update is expensive  
00300     if( (codim == 3) && dc.contains(dim,codim) ) 
00301     {
00302       // call of this method forces update of list, 
00303       // if list is not up to date
00304       grid.getLeafVertexList();
00305     }
00306   } 
00307 
00308   // returns true, if element is contained in set of comm interface 
00309   bool containsItem (const HElementType & elem) const 
00310   {
00311     return elem.isLeafEntity();
00312   }
00313 
00314   // returns true, if element is contained in set of comm interface 
00315   bool containsItem (const HGhostType & ghost) const 
00316   {
00317     return ghost.isLeafEntity();
00318   }
00319 
00320   // returns true, if interior element is contained in set of comm interface 
00321   bool containsInterior (const HFaceType & face, PllElementType & pll) const 
00322   {
00323     return face.isInteriorLeaf();
00324   }
00325 
00326   // returns true, if ghost is contianed in set of comm interface 
00327   bool containsGhost (const HFaceType & face , PllElementType & pll) const 
00328   {
00329     return pll.ghostLeaf();
00330   }
00331 
00332   // set elem to realEntity
00333   void setElement(const HElementType & elem)
00334   {
00335     this->realEntity_.setElement(elem); 
00336   }
00337     
00338 
00339 };
00340 
00342 template <class GridType, class DataCollectorType , int codim >
00343 class GatherScatterLevelData 
00344 : public GatherScatterBaseImpl<GridType,DataCollectorType,codim> 
00345 {
00346   typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
00347   typedef typename GridType::template Codim<codim>::Entity EntityType;
00348   typedef Dune :: MakeableInterfaceObject<
00349     typename GridType::template Codim<codim>::Entity> MakeableEntityType;
00350   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00351 
00352   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00353     template Codim<codim>::ImplementationType IMPLElementType;
00354   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00355     template Codim<codim>::InterfaceType HElementType;
00356   
00357   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00358     template Codim<1>::InterfaceType HFaceType;
00359   
00360   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00361     template Codim<0>::GhostInterfaceType HGhostType;
00362   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00363     template Codim<0>::GhostImplementationType ImplGhostType;
00364 
00365   typedef ALU3DSPACE ElementPllXIF_t PllElementType;
00366   typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;
00367 
00368   const LevelIndexSetImp & levelSet_;
00369   const int level_;
00370 public:
00372   GatherScatterLevelData(const GridType & grid, MakeableEntityType & en, 
00373       RealEntityType & realEntity , DataCollectorType & dc, 
00374       const LevelIndexSetImp & levelSet, const int level)
00375     : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level) 
00376   {
00377   } 
00378 
00379   // returns true, if element is contained in set of comm interface 
00380   bool containsItem (const HElementType & elem) const 
00381   {
00382     return levelSet_.containsIndex(codim, elem.getIndex() );
00383   }
00384 
00385   // set elem to realEntity
00386   void setElement(const HElementType & elem)
00387   {
00388     this->realEntity_.setElement(elem,level_); 
00389   }
00390     
00391 };
00392 
00393 
00395 template <class GridType, class DataCollectorType>
00396 class GatherScatterLevelData<GridType,DataCollectorType,0>
00397 : public GatherScatterBaseImpl<GridType,DataCollectorType,0> 
00398 {
00399   enum { codim = 0 };
00400   typedef GatherScatterBaseImpl<GridType,DataCollectorType,codim> BaseType;
00401   typedef typename GridType::template Codim<codim>::Entity EntityType;
00402   typedef Dune :: MakeableInterfaceObject<
00403     typename GridType::template Codim<codim>::Entity> MakeableEntityType;
00404   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00405 
00406   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00407     template Codim<codim>::ImplementationType IMPLElementType;
00408   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00409     template Codim<codim>::InterfaceType HElementType;
00410   
00411   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00412     template Codim<1>::InterfaceType HFaceType;
00413   
00414   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00415     template Codim<0>::GhostInterfaceType HGhostType;
00416   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00417     template Codim<0>::GhostImplementationType ImplGhostType;
00418 
00419   typedef ALU3DSPACE ElementPllXIF_t PllElementType;
00420   typedef typename GridType::LevelIndexSetImp LevelIndexSetImp;
00421 
00422   const LevelIndexSetImp & levelSet_;
00423   const int level_;
00424 public:
00426   GatherScatterLevelData(const GridType & grid, MakeableEntityType & en, 
00427       RealEntityType & realEntity , DataCollectorType & dc, 
00428       const LevelIndexSetImp & levelSet, const int level)
00429     : BaseType(grid,en,realEntity,dc) , levelSet_(levelSet) , level_(level) {} 
00430 
00431   // returns true, if element is contained in set of comm interface 
00432   bool containsItem (const HElementType & elem) const 
00433   {
00434     return levelSet_.containsIndex(codim, elem.getIndex() );
00435   }
00436 
00437   // returns true, if element is contained in set of comm interface 
00438   bool containsItem (const HGhostType & ghost) const 
00439   {
00440     assert( ghost.getGhost().first );
00441     return containsItem( * (ghost.getGhost().first) );
00442   }
00443   
00444   // returns true, if interior element is contained in set of comm interface 
00445   bool containsInterior (const HFaceType & face, PllElementType & pll) const 
00446   {
00447     // if face level is not level_ then interior cannot be contained 
00448     if(face.level() != level_) return false;
00449 
00450     // check interior element here, might have a coarser level 
00451     pair < Gitter::helement_STI * , Gitter::hbndseg_STI * > p (0,0);
00452     pll.getAttachedElement( p );
00453     assert( p.first );
00454     // check inside level 
00455     bool contained = (p.first->level() == level_);
00456     assert( contained == this->containsItem( *p.first ));
00457     return contained;
00458   }
00459 
00460   // returns true, if ghost is contianed in set of comm interface 
00461   bool containsGhost (const HFaceType & face, PllElementType & pll) const 
00462   {
00463     // if face level is not level_ then ghost cannot be contained 
00464     if(face.level() != level_) return false;
00465     // otherwise check ghost level 
00466     return (pll.ghostLevel() == level_);
00467   }
00468 };
00469 #endif
00470 
00472 template <class GridType, class DataCollectorType, class IndexOperatorType> 
00473 class GatherScatterLoadBalance : public GatherScatter
00474 {
00475 protected:  
00476   enum { codim = 0 };
00477   typedef typename GridType::template Codim<0>::Entity EntityType;
00478   typedef Dune :: MakeableInterfaceObject<
00479     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00480   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00481   
00482   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00483     template Codim<codim>::ImplementationType IMPLElementType;
00484   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00485     template Codim<codim>::InterfaceType HElementType;
00486   
00487   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00488     template Codim<1>::InterfaceType HFaceType;
00489   
00490   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00491     template Codim<codim>::GhostInterfaceType HGhostType;
00492   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::
00493     template Codim<codim>::GhostImplementationType ImplGhostType;
00494 
00495 #if ALU3DGRID_PARALLEL 
00496   typedef ALU3DSPACE ElementPllXIF_t PllElementType;
00497 #else 
00498   typedef HElementType PllElementType;
00499 #endif
00500   GridType & grid_;
00501 
00502   EntityType     & entity_;
00503   RealEntityType & realEntity_;
00504 
00505   // data handle 
00506   DataCollectorType & dc_;
00507   IndexOperatorType & idxOp_;
00508 
00509   // used MessageBuffer 
00510   typedef typename GatherScatter :: ObjectStreamType ObjectStreamType;
00511 
00512 public:
00514   GatherScatterLoadBalance(GridType & grid, MakeableEntityType & en, 
00515       RealEntityType & realEntity , DataCollectorType & dc, IndexOperatorType & idxOp ) 
00516     : grid_(grid), entity_(en), realEntity_(realEntity) 
00517     , dc_(dc) , idxOp_(idxOp) 
00518   {}
00519 
00520   // return true if dim,codim combination is contained in data set 
00521   bool contains(int dim, int codim) const 
00522   {
00523     return true; 
00524   }
00525 
00529   void inlineData ( ObjectStreamType & str , HElementType & elem )
00530   {
00531     str.write(grid_.maxLevel());
00532     // set element and then start 
00533     assert( elem.level () == 0 );
00534     realEntity_.setElement(elem);
00535     dc_.inlineData(str,entity_);
00536   }
00537 
00541   void xtractData ( ObjectStreamType & str , HElementType & elem )
00542   {
00543     assert( elem.level () == 0 );
00544     int mxl; 
00545     str.read(mxl);
00546     // set element and then start 
00547     grid_.setMaxLevel(mxl);
00548 
00549     // reserve memory for new elements 
00550     size_t elChunk = idxOp_.newElements();
00551     assert( elChunk > 0 );
00552     
00553     realEntity_.setElement(elem);
00554     dc_.xtractData(str,entity_, elChunk);
00555   }
00556 
00558   void compress () 
00559   {
00560     dc_.compress();
00561   } 
00562 };
00563 
00565 //
00566 //  --AdaptRestrictProlong 
00567 //
00569 template <class GridType , class RestrictProlongOperatorType >
00570 class AdaptRestrictProlongImpl : public AdaptRestrictProlongType
00571 {
00572   GridType & grid_;
00573   typedef typename GridType::template Codim<0>::Entity EntityType;
00574   typedef Dune :: MakeableInterfaceObject<
00575     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00576   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00577   
00578   EntityType & reFather_;
00579   EntityType & reSon_;
00580   RealEntityType & realFather_;
00581   RealEntityType & realSon_;
00582  
00583   //DofManagerType & dm_;
00584   RestrictProlongOperatorType & rp_;
00585 
00586   typedef typename Dune::ALU3dImplTraits<GridType::elementType>::PLLBndFaceType PLLBndFaceType;
00587 
00588 public:
00590   AdaptRestrictProlongImpl (GridType & grid, 
00591       MakeableEntityType & f, RealEntityType & rf, MakeableEntityType & s, RealEntityType & rs
00592       , RestrictProlongOperatorType & rp) 
00593     : grid_(grid)
00594     , reFather_(f)
00595     , reSon_(s)
00596     , realFather_(rf) 
00597     , realSon_(rs) 
00598     , rp_(rp) 
00599   {
00600   }
00601 
00602   virtual ~AdaptRestrictProlongImpl () 
00603   {
00604   }
00605 
00607   int preCoarsening ( HElementType & elem )
00608   {
00609     // set element and then start 
00610     HElementType * son = elem.down();
00611 
00612     assert( son );
00613    
00614     realSon_.setElement(*son);
00615     realFather_.setElement(elem);
00616     rp_.restrictLocal(reFather_,reSon_,true);
00617 
00618     son = son->next();
00619     while( son )
00620     {
00621       realSon_.setElement(*son);
00622       rp_.restrictLocal(reFather_,reSon_,false);
00623       son = son->next();
00624     }
00625    
00626     // reset refinement marker 
00627     elem.resetRefinedTag();
00628     return 0;
00629   }
00630 
00632   int postRefinement ( HElementType & elem )
00633   {
00634     // set element and then start 
00635     HElementType * son = elem.down();
00636     assert( son );
00637 
00638     // reset refinement marker 
00639     elem.resetRefinedTag();
00640    
00641     realFather_.setElement(elem);
00642     realSon_.setElement(*son);
00643     
00644     rp_.prolongLocal(reFather_,reSon_, false);
00645 
00646     son = son->next();
00647     while( son )
00648     {
00649       assert( son );
00650   
00651       realSon_.setElement(*son);
00652       rp_.prolongLocal(reFather_,reSon_, false);
00653 
00654       // reset refinement tag 
00655       son->resetRefinedTag();
00656       
00657       son = son->next();
00658     }
00659     return 0;
00660   }
00661 
00664   int preCoarsening ( HBndSegType & el )
00665   {
00666     return 0;
00667   }
00668 
00669 
00671   int postRefinement ( HBndSegType & el )
00672   {
00673     return 0;
00674   }
00675 };
00676 
00677 template <class GridType , class RestrictProlongOperatorType ,
00678           class GlobalIdSetImp >
00679 class AdaptRestrictProlongGlSet
00680   : public AdaptRestrictProlongImpl<GridType,RestrictProlongOperatorType>
00681 {
00682   typedef AdaptRestrictProlongImpl<GridType,RestrictProlongOperatorType> BaseType;
00683   GlobalIdSetImp & set_;
00684   typedef typename GridType::template Codim<0>::Entity EntityType;
00685   typedef Dune :: MakeableInterfaceObject<
00686     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00687   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00688   
00689 public:
00691   AdaptRestrictProlongGlSet(GridType & grid,
00692       MakeableEntityType & f, RealEntityType & rf, MakeableEntityType & s, RealEntityType & rs
00693       , RestrictProlongOperatorType & rp
00694       , GlobalIdSetImp & set )
00695     : BaseType(grid,f,rf,s,rs,rp)
00696     , set_(set)
00697   {
00698   }
00699 
00700   virtual ~AdaptRestrictProlongGlSet () {}
00701 
00703   int preCoarsening ( HElementType & elem )
00704   {
00705     return BaseType :: preCoarsening (elem );
00706   }
00707 
00709   int postRefinement ( HElementType & elem )
00710   {
00711     set_.postRefinement( elem );
00712     return BaseType :: postRefinement(elem );
00713   }
00714 
00717   int preCoarsening ( HBndSegType & el )
00718   {
00719     return 0;
00720   }
00721 
00722 };
00723 
00724 // this class is for counting the tree depth of the 
00725 // element when unpacking data from load balance 
00726 template <class GridType , class DofManagerType>
00727 class LoadBalanceElementCount : public AdaptRestrictProlongType
00728 {
00729   GridType & grid_;
00730   typedef typename GridType::template Codim<0>::Entity EntityType;
00731   typedef Dune :: MakeableInterfaceObject<
00732     typename GridType::template Codim<0>::Entity> MakeableEntityType;
00733   typedef typename MakeableEntityType :: ImplementationType RealEntityType;
00734 
00735   typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType; 
00736 
00737   EntityType & reFather_;
00738   EntityType & reSon_;
00739   RealEntityType & realFather_;
00740   RealEntityType & realSon_;
00741  
00742   DofManagerType & dm_;
00743   typedef typename  Dune::ALU3dImplTraits<GridType::elementType>::PLLBndFaceType PLLBndFaceType;
00744 
00745   int newMemSize_;
00746 public:
00748   LoadBalanceElementCount (GridType & grid, 
00749       MakeableEntityType & f, RealEntityType & rf, MakeableEntityType & s, RealEntityType & rs,DofManagerType & dm) 
00750     : grid_(grid)
00751     , reFather_(f)
00752     , reSon_(s)
00753     , realFather_(rf) 
00754     , realSon_(rs) 
00755     , dm_(dm) 
00756     , newMemSize_ (1) // we have at least one element (the macro element)
00757   {
00758   }
00759 
00760   virtual ~LoadBalanceElementCount () {};
00761 
00763   int postRefinement ( HElementType & elem )
00764   {
00765     // when called for a macro element, then a new tree is starting 
00766     // set to 1 because for only macro elements this method is not called 
00767     if( elem.level() == 0 ) newMemSize_ = 1;
00768 
00769     for( HElementType * son = elem.down() ; son ; son= son->next()) 
00770     {
00771       ++ newMemSize_;
00772     }
00773     return 0;
00774   }
00775 
00777   int preCoarsening ( HElementType & elem )
00778   {
00779     return 0;
00780   }
00781 
00784   int preCoarsening ( HBndSegType & el )
00785   {
00786     return 0;
00787   }
00788 
00793   int postRefinement ( HBndSegType & el )
00794   {
00795     return 0;
00796   }
00797 
00798   int newElements () const { return newMemSize_; }
00799 };
00800 
00801 } // end namespace 
00802 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].