dune-grid
2.2.0
|
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 AdaptDataHandle &rp_; 00577 00578 typedef typename GridType::MPICommunicatorType Comm; 00579 00580 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits; 00581 typedef typename ImplTraits::HElementType HElementType; 00582 typedef typename ImplTraits::HBndSegType HBndSegType; 00583 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00584 00585 public: 00587 AdaptRestrictProlongImpl ( GridType &grid, 00588 MakeableEntityType &f, RealEntityType &rf, 00589 MakeableEntityType &s, RealEntityType &rs, 00590 AdaptDataHandle &rp ) 00591 : grid_(grid) 00592 , reFather_(f) 00593 , reSon_(s) 00594 , realFather_(rf) 00595 , realSon_(rs) 00596 , rp_(rp) 00597 { 00598 } 00599 00600 virtual ~AdaptRestrictProlongImpl () 00601 { 00602 } 00603 00605 int preCoarsening ( HElementType & father ) 00606 { 00607 realFather_.setElement( father ); 00608 rp_.preCoarsening( reFather_ ); 00609 00610 // reset refinement marker 00611 father.resetRefinedTag(); 00612 return 0; 00613 } 00614 00616 int postRefinement ( HElementType & father ) 00617 { 00618 realFather_.setElement( father ); 00619 rp_.postRefinement( reFather_ ); 00620 00621 // resert refinement markers 00622 father.resetRefinedTag(); 00623 for( HElementType *son = father.down(); son ; son = son->next() ) 00624 son->resetRefinedTag(); 00625 00626 return 0; 00627 } 00628 00630 int preCoarsening ( HBndSegType & ghost ) 00631 { 00632 /* 00633 assert( ghost.bndtype() == ALU3DSPACE ProcessorBoundary_t ); 00634 realFather_.setGhost( ghost ); 00635 rp_.preCoarsening( reFather_ ); 00636 */ 00637 return 0; 00638 } 00639 00640 00642 int postRefinement ( HBndSegType & ghost ) 00643 { 00644 /* 00645 assert( ghost.bndtype() == ALU3DSPACE ProcessorBoundary_t ); 00646 realFather_.setGhost( ghost ); 00647 rp_.postRefinement( reFather_ ); 00648 */ 00649 return 0; 00650 } 00651 }; 00652 00653 00654 00655 template< class GridType, class AdaptDataHandle, class GlobalIdSetImp > 00656 class AdaptRestrictProlongGlSet 00657 : public AdaptRestrictProlongImpl< GridType, AdaptDataHandle > 00658 { 00659 typedef AdaptRestrictProlongImpl< GridType, AdaptDataHandle > BaseType; 00660 GlobalIdSetImp & set_; 00661 typedef typename GridType::template Codim<0>::Entity EntityType; 00662 typedef Dune :: MakeableInterfaceObject< 00663 typename GridType::template Codim<0>::Entity> MakeableEntityType; 00664 typedef typename MakeableEntityType :: ImplementationType RealEntityType; 00665 00666 typedef typename GridType::MPICommunicatorType Comm; 00667 00668 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits; 00669 typedef typename ImplTraits::HElementType HElementType; 00670 typedef typename ImplTraits::HBndSegType HBndSegType; 00671 00672 public: 00674 AdaptRestrictProlongGlSet ( GridType &grid, 00675 MakeableEntityType &f, RealEntityType &rf, 00676 MakeableEntityType &s, RealEntityType &rs, 00677 AdaptDataHandle &rp, 00678 GlobalIdSetImp & set ) 00679 : BaseType( grid, f, rf, s, rs, rp ), 00680 set_( set ) 00681 {} 00682 00683 virtual ~AdaptRestrictProlongGlSet () {} 00684 00686 int postRefinement ( HElementType & elem ) 00687 { 00688 set_.postRefinement( elem ); 00689 return BaseType :: postRefinement(elem ); 00690 } 00691 }; 00692 00693 // this class is for counting the tree depth of the 00694 // element when unpacking data from load balance 00695 template <class GridType , class DataHandleType> 00696 class LoadBalanceElementCount : public AdaptRestrictProlongType 00697 { 00698 GridType & grid_; 00699 typedef typename GridType::template Codim<0>::Entity EntityType; 00700 typedef Dune :: MakeableInterfaceObject< 00701 typename GridType::template Codim<0>::Entity> MakeableEntityType; 00702 typedef typename MakeableEntityType :: ImplementationType RealEntityType; 00703 00704 typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType; 00705 00706 EntityType & reFather_; 00707 EntityType & reSon_; 00708 RealEntityType & realFather_; 00709 RealEntityType & realSon_; 00710 00711 DataHandleType & dh_; 00712 00713 typedef typename GridType::MPICommunicatorType Comm; 00714 00715 typedef Dune::ALU3dImplTraits< GridType::elementType, Comm > ImplTraits; 00716 typedef typename ImplTraits::HElementType HElementType; 00717 typedef typename ImplTraits::HBndSegType HBndSegType; 00718 00719 int newMemSize_; 00720 public: 00722 LoadBalanceElementCount (GridType & grid, 00723 MakeableEntityType & f, RealEntityType & rf, 00724 MakeableEntityType & s, RealEntityType & rs, 00725 DataHandleType & dh) 00726 : grid_(grid) 00727 , reFather_(f) 00728 , reSon_(s) 00729 , realFather_(rf) 00730 , realSon_(rs) 00731 , dh_(dh) 00732 , newMemSize_ (1) // we have at least one element (the macro element) 00733 { 00734 } 00735 00736 virtual ~LoadBalanceElementCount () {} 00737 00739 int postRefinement ( HElementType & elem ) 00740 { 00741 // when called for a macro element, then a new tree is starting 00742 // set to 1 because for only macro elements this method is not called 00743 if( elem.level() == 0 ) newMemSize_ = 1; 00744 00745 for( HElementType * son = elem.down() ; son ; son= son->next()) 00746 { 00747 ++ newMemSize_; 00748 } 00749 return 0; 00750 } 00751 00753 int preCoarsening ( HElementType & elem ) 00754 { 00755 return 0; 00756 } 00757 00760 int preCoarsening ( HBndSegType & el ) 00761 { 00762 return 0; 00763 } 00764 00769 int postRefinement ( HBndSegType & el ) 00770 { 00771 return 0; 00772 } 00773 00774 int newElements () const { return newMemSize_; } 00775 }; 00776 00777 } // end namespace ALUGridSpace 00778 00779 #endif // #ifndef DUNE_ALU3DGRIDDATAHANDLE_HH