dune-grid
2.1.1
|
00001 #ifndef DUNE_ALU3DITERATORS_HH 00002 #define DUNE_ALU3DITERATORS_HH 00003 00004 // System includes 00005 00006 // Dune includes 00007 #include <dune/grid/common/grid.hh> 00008 00009 // Local includes 00010 #include "alu3dinclude.hh" 00011 #include "topology.hh" 00012 00013 namespace ALUGridSpace 00014 { 00015 00016 //************************************************************* 00017 // definition of original LeafIterators of ALUGrid 00018 // 00019 // default is element (codim = 0) 00020 template< int codim, class Comm > 00021 struct BSMacroIterator 00022 { 00023 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType; 00024 typedef typename AccessIterator< HElementType >::Handle IteratorType; 00025 }; 00026 00027 //****************************************************************** 00028 // LevelIterators 00029 //****************************************************************** 00030 template< int codim, class Comm > 00031 struct ALUHElementType; 00032 00033 template< class Comm > 00034 struct ALUHElementType< 0, Comm > 00035 { 00036 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType ElementType; 00037 }; 00038 00039 template< class Comm > 00040 struct ALUHElementType< 1, Comm > 00041 { 00042 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HFaceType ElementType; 00043 }; 00044 00045 template< class Comm > 00046 struct ALUHElementType< 2, Comm > 00047 { 00048 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HEdgeType ElementType; 00049 }; 00050 00051 template< class Comm > 00052 struct ALUHElementType< 3, Comm > 00053 { 00054 typedef typename Dune::ALU3dBasicImplTraits< Comm >::VertexType ElementType; 00055 }; 00056 00057 00058 //********************************************************* 00059 // LevelIterator Wrapper 00060 //********************************************************* 00061 template< class val_t > 00062 struct IteratorWrapperInterface 00063 : public IteratorSTI< val_t > 00064 { 00065 virtual ~IteratorWrapperInterface () {} 00066 00067 virtual int size () = 0; 00068 virtual void next () = 0; 00069 virtual void first() = 0; 00070 virtual int done () const = 0; 00071 virtual val_t & item () const = 0; 00072 virtual IteratorSTI< val_t > * clone () const { assert(false); abort(); return 0; } 00073 }; 00074 00075 typedef Dune::PartitionIteratorType PartitionIteratorType; 00076 00077 // defines the pair of element and boundary 00078 template< int codim, class Comm > 00079 struct IteratorElType 00080 { 00081 typedef typename ALUHElementType< codim, Comm >::ElementType ElType; 00082 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HBndSegType HBndSegType; 00083 typedef pair< ElType *, HBndSegType * > val_t; 00084 }; 00085 00086 template< int codim, PartitionIteratorType pitype, class Comm > 00087 class ALU3dGridLevelIteratorWrapper; 00088 00089 // the element level iterator 00090 template< PartitionIteratorType pitype, class Comm > 00091 class ALU3dGridLevelIteratorWrapper< 0, pitype, Comm > 00092 : public IteratorWrapperInterface< typename IteratorElType< 0, Comm >::val_t > 00093 { 00094 typedef typename IteratorElType< 0, Comm >::ElType ElType; 00095 typedef typename IteratorElType< 0, Comm >::HBndSegType HBndSegType; 00096 typedef ALU3DSPACE LevelIterator< ElType > IteratorType; 00097 00098 // the iterator 00099 IteratorType it_; 00100 00101 public: 00102 typedef typename IteratorElType< 0, Comm >::val_t val_t; 00103 mutable val_t elem_; 00104 00105 // constructor creating iterator 00106 template< class GridImp > 00107 ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks ) 00108 : it_( grid.myGrid(), level ), 00109 elem_( (ElType *)0, (HBndSegType *)0 ) 00110 {} 00111 00112 // copy constructor 00113 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 00114 : it_( org.it_ ), elem_(org.elem_) 00115 { 00116 } 00117 00118 int size () { return it_->size(); } 00119 void next () { it_->next(); } 00120 void first() { it_->first(); } 00121 int done () const { return it_->done(); } 00122 val_t & item () const 00123 { 00124 assert( ! done () ); 00125 elem_.first = & it_->item(); 00126 return elem_; 00127 } 00128 }; 00129 00130 // the face level iterator 00131 template< PartitionIteratorType pitype, class Comm > 00132 class ALU3dGridLevelIteratorWrapper< 1, pitype, Comm > 00133 : public IteratorWrapperInterface< typename IteratorElType< 1, Comm >::val_t > 00134 { 00135 typedef typename IteratorElType< 1, Comm >::ElType ElType; 00136 typedef typename IteratorElType< 1, Comm >::HBndSegType HBndSegType; 00137 #ifdef ALUGRID_PERIODIC_BOUNDARY 00138 typedef ALU3DSPACE any_has_level_periodic< ElType > StopRule_t; 00139 typedef GridIterator< ElType, StopRule_t > IteratorType; 00140 #else 00141 typedef ALU3DSPACE LevelIterator< ElType > IteratorType; 00142 #endif 00143 00144 // the iterator 00145 IteratorType it_; 00146 00147 public: 00148 typedef typename IteratorElType< 1, Comm >::val_t val_t; 00149 mutable val_t elem_; 00150 00151 // constructor creating iterator 00152 template< class GridImp > 00153 ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks ) 00154 #ifdef ALUGRID_PERIODIC_BOUNDARY 00155 : it_( grid.myGrid(), StopRule_t(level) ), 00156 #else 00157 : it_( grid.myGrid(), level ), 00158 #endif 00159 elem_( (ElType *)0, (HBndSegType*)0 ) 00160 {} 00161 00162 // copy constructor 00163 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 00164 : it_( org.it_ ), elem_(org.elem_) 00165 {} 00166 00167 int size () { return it_->size(); } 00168 void next () { it_->next(); } 00169 void first() { it_->first(); } 00170 int done () const { return it_->done(); } 00171 val_t & item () const 00172 { 00173 assert( ! done () ); 00174 elem_.first = & it_->item(); 00175 return elem_; 00176 } 00177 }; 00178 00179 // the vertex level iterator, little bit different to the others 00180 // this implementation uses the vertex leaf iterator and runs over all 00181 // vertices with level <= the given iteration level 00182 template< PartitionIteratorType pitype, class Comm > 00183 class ALU3dGridLevelIteratorWrapper< 3, pitype, Comm > 00184 : public IteratorWrapperInterface< typename IteratorElType< 3, Comm >::val_t > 00185 { 00186 typedef typename IteratorElType< 3, Comm >::ElType ElType; 00187 typedef typename IteratorElType< 3, Comm >::HBndSegType HBndSegType; 00188 typedef Dune::ALU3dGridVertexList< Comm > VertexListType; 00189 typedef typename VertexListType::IteratorType IteratorType; 00190 00191 VertexListType & vxList_; 00192 00193 mutable int count_; 00194 const int size_; 00195 00196 public: 00197 typedef typename IteratorElType< 3, Comm >::val_t val_t; 00198 mutable val_t elem_; 00199 00200 // constructor creating iterator 00201 template< class GridImp > 00202 ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks ) 00203 : vxList_ ( grid.getVertexList( level ) ), 00204 count_( 0 ), 00205 size_( vxList_.size() ), 00206 elem_( (ElType *)0, (HBndSegType *)0 ) 00207 { 00208 assert( vxList_.up2Date() ); 00209 } 00210 00211 // copy constructor 00212 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 00213 : vxList_(org.vxList_) , count_(org.count_) , size_(org.size_) 00214 , elem_(org.elem_) 00215 { 00216 } 00217 00218 // returns size of leaf iterator, wrong here, return leaf size 00219 int size () { return size_; } 00220 00222 void next () 00223 { 00224 if( done () ) return ; 00225 ++count_; 00226 return ; 00227 } 00228 00229 void first() { count_ = 0; } 00230 int done () const { return (count_ >= size_) ? 1 : 0; } 00231 val_t & item () const 00232 { 00233 assert( ! done () ); 00234 elem_.first = vxList_.getItemList()[count_]; 00235 assert( elem_.first ); 00236 return elem_; 00237 } 00238 }; 00239 00240 template< int codim, PartitionIteratorType pitype, class Comm > 00241 class ALU3dGridLeafIteratorWrapper; 00242 00243 //typedef pair< ALUHElementType<0>::ElementType * , HBndSegType * > LeafValType; 00244 //typedef IteratorWrapperInterface<LeafValType> IteratorWrapperInterfaceType; 00245 00246 //********************************************************** 00247 // LeafIterator Wrapper 00248 //********************************************************** 00249 template< PartitionIteratorType pitype, class Comm > 00250 class ALU3dGridLeafIteratorWrapper< 0, pitype, Comm > 00251 : public IteratorWrapperInterface< typename IteratorElType< 0, Comm >::val_t > 00252 { 00253 typedef typename IteratorElType< 0, Comm >::ElType ElType; 00254 typedef typename IteratorElType< 0, Comm >::HBndSegType HBndSegType; 00255 typedef LeafIterator< ElType > IteratorType; 00256 00257 // the ALU3dGrid Iterator 00258 IteratorType it_; 00259 00260 public: 00261 typedef typename IteratorElType< 0, Comm >::val_t val_t; 00262 00263 private: 00264 mutable val_t elem_; 00265 00266 public: 00267 // constructor creating Iterator 00268 template< class GridImp > 00269 ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int links ) 00270 : it_( grid.myGrid() ), 00271 elem_( (ElType *)0, (HBndSegType *)0 ) 00272 {} 00273 00274 // constructor copying iterator 00275 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 00276 : it_( org.it_ ), elem_(org.elem_) 00277 {} 00278 00279 int size () { return it_->size(); } 00280 void next () { it_->next(); } 00281 void first() { it_->first(); } 00282 int done () const { return it_->done(); } 00283 val_t & item () const 00284 { 00285 assert( ! done () ); 00286 elem_.first = & it_->item(); 00287 return elem_; 00288 } 00289 }; 00290 00291 template< class ElType, PartitionIteratorType pitype, class Comm > 00292 struct LeafStopRule 00293 { 00294 typedef is_leaf_entity< ElType > StopRule_t; 00295 }; 00296 00297 // only in parallel we need only the interior items, in serial all items 00298 // are interior, to make the check fasterm this is only in parallel 00299 // implemented 00300 #if ALU3DGRID_PARALLEL 00301 template< class ElType > 00302 struct LeafStopRule< ElType, Dune::Interior_Partition, MPI_Comm > 00303 { 00304 typedef is_interior_leaf_entity< ElType > StopRule_t; 00305 }; 00306 #endif // #if ALU3DGRID_PARALLEL 00307 00308 00309 template< PartitionIteratorType pitype, class Comm > 00310 class ALU3dGridLeafIteratorWrapper< 1, pitype, Comm > 00311 : public IteratorWrapperInterface< typename IteratorElType< 1, Comm >::val_t > 00312 { 00313 typedef typename IteratorElType< 1, Comm >::ElType ElType; 00314 typedef typename IteratorElType< 1, Comm >::HBndSegType HBndSegType; 00315 typedef typename LeafStopRule< ElType, pitype, Comm >::StopRule_t StopRule_t; 00316 typedef GridIterator< ElType, StopRule_t > IteratorType; 00317 00318 // the face iterator 00319 IteratorType it_; 00320 00321 public: 00322 typedef typename IteratorElType< 1, Comm >::val_t val_t; 00323 private: 00324 mutable val_t elem_; 00325 public: 00326 // constructor creating Iterator 00327 template< class GridImp > 00328 ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int links ) 00329 : it_( grid.myGrid(), StopRule_t() ), 00330 elem_( (ElType *)0, (HBndSegType *)0 ) 00331 {} 00332 00333 // constructor copying iterator 00334 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 00335 : it_( org.it_ ), elem_(org.elem_) {} 00336 00337 ~ALU3dGridLeafIteratorWrapper () 00338 { 00339 } 00340 00341 int size () { return it_->size(); } 00342 void next () { it_->next(); } 00343 void first() { it_->first(); } 00344 int done () const { return it_->done(); } 00345 val_t & item () const 00346 { 00347 assert( ! done () ); 00348 elem_.first = & it_->item(); 00349 return elem_; 00350 } 00351 }; 00352 00353 template< PartitionIteratorType pitype, class Comm > 00354 class ALU3dGridLeafIteratorWrapper< 2, pitype, Comm > 00355 : public IteratorWrapperInterface< typename IteratorElType< 2, Comm >::val_t > 00356 { 00357 typedef typename IteratorElType< 2, Comm >::ElType ElType; 00358 typedef typename IteratorElType< 2, Comm >::HBndSegType HBndSegType; 00359 typedef typename LeafStopRule< ElType, pitype, Comm >::StopRule_t StopRule_t; 00360 typedef GridIterator< ElType, StopRule_t > IteratorType; 00361 00362 public: 00363 typedef typename IteratorElType< 2, Comm >::val_t val_t; 00364 00365 private: 00366 // the edge iterator 00367 IteratorType it_; 00368 00369 mutable val_t elem_; 00370 00371 public: 00372 // constructor creating Iterator 00373 template< class GridImp > 00374 ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int links ) 00375 : it_( grid.myGrid(), StopRule_t() ), 00376 elem_( (ElType *)0, (HBndSegType *)0 ) 00377 {} 00378 00379 // constructor copying iterator 00380 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 00381 : it_( org.it_ ), elem_(org.elem_) {} 00382 00383 int size () { return it_->size(); } 00384 void next () { it_->next(); } 00385 void first() { it_->first(); } 00386 int done () const { return it_->done(); } 00387 val_t & item () const 00388 { 00389 assert( ! done () ); 00390 elem_.first = & it_->item(); 00391 return elem_; 00392 } 00393 }; 00394 00395 00396 // the vertex leaf iterator, little bit different to the others 00397 template< PartitionIteratorType pitype, class Comm > 00398 class ALU3dGridLeafIteratorWrapper< 3, pitype, Comm > 00399 : public IteratorWrapperInterface< typename IteratorElType< 3, Comm >::val_t > 00400 { 00401 typedef typename IteratorElType< 3, Comm >::ElType ElType; 00402 typedef typename IteratorElType< 3, Comm >::HBndSegType HBndSegType; 00403 typedef Dune::ALU3dGridLeafVertexList< Comm > LeafVertexListType; 00404 typedef typename LeafVertexListType::IteratorType IteratorType; 00405 typedef typename LeafVertexListType::ItemType VxItemType; 00406 typedef typename LeafStopRule< ElType, pitype, Comm >::StopRule_t StopRule_t; 00407 00408 LeafVertexListType & vxList_; 00409 typedef typename LeafVertexListType :: IteratorType ListIteratorType; 00410 00411 mutable int count_; 00412 const int size_; 00413 00414 public: 00415 typedef typename IteratorElType< 3, Comm >::val_t val_t; 00416 mutable val_t elem_; 00417 const StopRule_t rule_; 00418 00419 // constructor creating iterator 00420 template< class GridImp > 00421 ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int nlinks ) 00422 : vxList_( grid.getLeafVertexList() ), 00423 count_( 0 ), 00424 size_( vxList_.size() ), 00425 elem_( (ElType *)0, (HBndSegType *)0 ), 00426 rule_() 00427 { 00428 assert( vxList_.up2Date() ); 00429 } 00430 00431 // copy constructor 00432 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 00433 : vxList_(org.vxList_) 00434 , count_(org.count_) , size_(org.size_) 00435 , elem_(org.elem_) 00436 , rule_() 00437 { 00438 } 00439 00440 // returns size of leaf iterator, wrong here, return leaf size 00441 int size () { return size_; } 00442 00444 void next () 00445 { 00446 ++count_; 00447 goNextValid(); 00448 return ; 00449 } 00450 00451 void first() 00452 { 00453 count_ = 0; 00454 goNextValid(); 00455 } 00456 int done () const { return (count_ >= size_) ? 1 : 0; } 00457 val_t & item () const 00458 { 00459 assert( ! done () ); 00460 assert( elem_.first ); 00461 return elem_; 00462 } 00463 private: 00464 val_t & getItem () const 00465 { 00466 //elem_.first = vxList_.getItemList()[count_].first; 00467 assert( ! done () ); 00468 elem_.first = vxList_.getItemList()[count_].first; 00469 return elem_; 00470 } 00471 void goNextValid() 00472 { 00473 if( done() ) return ; 00474 if( getItem().first == 0) 00475 { 00476 ++count_; 00477 goNextValid(); 00478 } 00479 else 00480 { 00481 assert( elem_.first ); 00482 if(! rule_( elem_.first ) ) 00483 { 00484 ++count_; 00485 goNextValid(); 00486 } 00487 } 00488 } 00489 }; 00490 00491 /* 00492 template <PartitionIteratorType pitype> 00493 class ALU3dGridLeafIteratorWrapper<3,pitype> 00494 : public IteratorWrapperInterface < typename IteratorElType<3>::val_t > 00495 { 00496 typedef IteratorElType<3>::ElType ElType; 00497 typedef typename LeafStopRule< ElType, pitype > :: StopRule_t StopRule_t; 00498 // ElType is vertex_STI 00499 typedef LeafIterator < ElType > IteratorType; 00500 00501 // the vertex iterator 00502 IteratorType it_; 00503 00504 public: 00505 typedef IteratorElType<3>::val_t val_t; 00506 private: 00507 mutable val_t elem_; 00508 const StopRule_t rule_; 00509 public: 00510 // constructor creating Iterator 00511 template <class GridImp> 00512 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level, const int links ) 00513 : it_(grid.myGrid()), elem_(0,0) , rule_ () {} 00514 00515 // constructor copying iterator 00516 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 00517 : it_( org.it_ ), elem_(org.elem_) , rule_() {} 00518 00519 int size () { return it_->size(); } 00520 00521 void next () 00522 { 00523 it_->next(); 00524 if (!it_->done()) 00525 { 00526 // take standard walk rule to cehck vertices again, see walk.h 00527 if(! rule_(it_->item()) ) next(); 00528 } 00529 } 00530 00531 void first() { it_->first(); } 00532 int done () const{ return it_->done(); } 00533 val_t & item () const 00534 { 00535 assert( ! done () ); 00536 elem_.first = & it_->item(); 00537 return elem_; 00538 } 00539 }; 00540 */ 00541 00542 #if ALU3DGRID_PARALLEL 00543 template< int codim > 00544 class LeafLevelIteratorTTProxy 00545 { 00546 // type is hface_STI or hedge_STI 00547 typedef typename ALUHElementType< codim, MPI_Comm >::ElementType ElType; 00548 00549 typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::GitterImplType GitterImplType; 00550 00551 typedef IteratorSTI< ElType > IteratorType; 00552 IteratorType * inner_; 00553 IteratorType * outer_; 00554 00555 public: 00556 // constructor creating leafBorderIteratorTT 00557 LeafLevelIteratorTTProxy( GitterImplType & gitter , int link ) 00558 { 00559 pair < IteratorSTI< ElType > * , IteratorSTI< ElType > * > 00560 p = gitter.leafBorderIteratorTT( (ElType *) 0 , link ); 00561 00562 inner_ = p.first; 00563 outer_ = p.second; 00564 } 00565 00566 // constructor creating levelBorderIteratorTT 00567 LeafLevelIteratorTTProxy( GitterImplType & gitter , int link , int level ) 00568 { 00569 pair < IteratorSTI< ElType > * , IteratorSTI< ElType > * > 00570 p = gitter.levelBorderIteratorTT( (ElType *) 0 , link , level ); 00571 00572 inner_ = p.first; 00573 outer_ = p.second; 00574 } 00575 00576 LeafLevelIteratorTTProxy( const LeafLevelIteratorTTProxy & org ) 00577 : inner_(org.inner_->clone()) 00578 , outer_(org.outer_->clone()) 00579 {} 00580 00581 ~LeafLevelIteratorTTProxy() 00582 { 00583 delete inner_; 00584 delete outer_; 00585 } 00586 00587 IteratorType & inner () { assert(inner_); return *inner_; } 00588 IteratorType & outer () { assert(outer_); return *outer_; } 00589 }; 00590 00591 00592 00593 typedef pair< ALUHElementType< 0, MPI_Comm >::ElementType *, Dune::ALU3dBasicImplTraits< MPI_Comm >::HBndSegType * > LeafValType; 00594 00595 //**************************** 00596 // 00597 // --GhostIterator 00598 // 00599 //**************************** 00600 struct ALU3dGridGhostIterator 00601 : public IteratorWrapperInterface< LeafValType > 00602 { 00603 typedef Dune::ALU3dBasicImplTraits< MPI_Comm >::GitterImplType GitterImplType; 00604 00605 typedef Dune::ALU3dBasicImplTraits< MPI_Comm >::HElementType HElementType; 00606 typedef Dune::ALU3dBasicImplTraits< MPI_Comm >::HBndSegType HBndSegType; 00607 00608 protected: 00609 GitterImplType & gitter_; 00610 00611 // this tpye is hface_STI 00612 typedef ALUHElementType< 1, MPI_Comm >::ElementType ElType; 00613 00614 typedef LeafLevelIteratorTTProxy< 1 > IteratorType; 00615 00616 IteratorType * iterTT_; 00617 00618 typedef IteratorSTI < ElType > InnerIteratorType; 00619 InnerIteratorType * it_; 00620 00621 // number of links 00622 const int nl_; 00623 00624 // current link 00625 int link_; 00626 00627 bool usingInner_; 00628 public: 00629 typedef LeafValType val_t; 00630 private: 00631 // the pair of elementand boundary face 00632 mutable val_t elem_; 00633 public: 00634 typedef ElementPllXIF_t ItemType; 00635 00636 template< class GridImp > 00637 ALU3dGridGhostIterator ( const GridImp &grid, int level, const int nlinks ) 00638 : gitter_( grid.myGrid() ), 00639 iterTT_( 0 ), 00640 it_( 0 ), 00641 nl_( nlinks ), 00642 link_( nlinks ), // makes default status == done 00643 elem_( (HElementType *)0, (HBndSegType *)0 ) 00644 {} 00645 00646 ALU3dGridGhostIterator (const ALU3dGridGhostIterator & org) 00647 : gitter_(org.gitter_) 00648 , iterTT_(0) , it_(0) 00649 , nl_(org.nl_) 00650 , link_(org.link_) 00651 , usingInner_(false) 00652 , elem_(org.elem_) 00653 { 00654 if( org.iterTT_ ) 00655 { 00656 iterTT_ = new IteratorType ( *org.iterTT_ ); 00657 usingInner_ = org.usingInner_; 00658 if( org.it_ ) 00659 { 00660 assert( ! org.it_->done() ); 00661 it_ = (usingInner_) ? &( iterTT_->inner() ) : &( iterTT_->outer() ); 00662 } 00663 } 00664 } 00665 00666 ~ALU3dGridGhostIterator () 00667 { 00668 removeIterators(); 00669 } 00670 00671 protected: 00672 virtual IteratorType * newIterator() 00673 { 00674 return new IteratorType ( gitter_, link_ ); 00675 } 00676 00677 void removeIterators() 00678 { 00679 if(iterTT_) delete iterTT_; 00680 iterTT_ = 0; 00681 it_ = 0; 00682 usingInner_ = false; 00683 } 00684 00685 void createIterator() 00686 { 00687 if (usingInner_) checkInnerOuter(); 00688 00689 if (!usingInner_) 00690 { 00691 ++link_; 00692 00693 removeIterators(); 00694 if(link_ < nl_) 00695 { 00696 iterTT_ = newIterator(); 00697 assert(iterTT_); 00698 checkInnerOuter(); 00699 if (!it_) createIterator(); 00700 } 00701 } 00702 } 00703 00704 void checkInnerOuter() 00705 { 00706 it_ = 0; 00707 if (!usingInner_) 00708 { 00709 assert(iterTT_); 00710 it_ = &( iterTT_->inner() ); 00711 InnerIteratorType & it = iterTT_->inner(); 00712 it.first(); 00713 if(!it.done()) 00714 { 00715 usingInner_ = true; 00716 pair < ElementPllXIF_t *, int > p = it.item ().accessPllX ().accessOuterPllX () ; 00717 pair< HElementType *, HBndSegType * > elems( (HElementType *)0, (HBndSegType *)0 ); 00718 p.first->getAttachedElement(elems); 00719 00720 assert( elems.first || elems.second ); 00721 00722 if(elems.second) 00723 { 00724 return; 00725 } 00726 } 00727 } 00728 00729 usingInner_ = false; 00730 InnerIteratorType & out = iterTT_->outer(); 00731 out.first(); 00732 if(!out.done()) 00733 { 00734 pair < ElementPllXIF_t *, int > p = out.item ().accessPllX ().accessOuterPllX () ; 00735 pair< HElementType *, HBndSegType * > elems( (HElementType *)0, (HBndSegType *)0 ); 00736 p.first->getAttachedElement(elems); 00737 00738 assert( elems.second ); 00739 it_ = &out; 00740 return ; 00741 } 00742 00743 it_ = 0; 00744 } 00745 00746 virtual void checkLeafEntity () 00747 { 00748 if(it_) 00749 { 00750 if(!it_->done()) 00751 { 00752 val_t & el = item(); 00753 HBndSegType * pll = el.second; 00754 assert( pll ); 00755 00756 // this occurs if internal element is leaf but the corresponding 00757 // ghost is not leaf, we have to go next 00758 if ( ! pll->isLeafEntity() ) next(); 00759 } 00760 } 00761 } 00762 00763 public: 00764 int size () // ???? gives size only of small part of ghost cells ???? 00765 { 00766 // if no iterator then size is zero 00767 // which can happen in the case of parallel grid with 1 processor 00768 if(!it_) 00769 { 00770 return 0; 00771 } 00772 return it_->size(); 00773 } 00774 00775 // go next ghost 00776 void next () 00777 { 00778 if(it_) 00779 { 00780 // if not done increment 00781 if( !it_->done() ) it_->next(); 00782 00783 // if now done, create new iterator 00784 if( it_->done() ) createIterator(); 00785 00786 checkLeafEntity(); 00787 } 00788 } 00789 00790 void first() 00791 { 00792 link_ = -1; 00793 usingInner_ = false; 00794 // create iterator calls also first of iterators 00795 createIterator(); 00796 checkLeafEntity(); 00797 if( it_ ) assert( !it_->done()); 00798 } 00799 00800 int done () const 00801 { 00802 assert( (link_ >= nl_) ? (it_ == 0) : 1 ); 00803 return ((link_ >= nl_ || !it_ ) ? 1 : 0); 00804 } 00805 00806 val_t & item () const 00807 { 00808 assert(it_); 00809 pair < ElementPllXIF_t *, int > p = it_->item ().accessPllX ().accessOuterPllX () ; 00810 pair < HElementType * , HBndSegType * > p2; 00811 p.first->getAttachedElement(p2); 00812 assert(p2.second); 00813 elem_.second = p2.second; 00814 return elem_; 00815 } 00816 00817 }; // end ALU3dGridGhostIterator 00818 00819 00820 // the leaf ghost partition iterator 00821 template<> 00822 class ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > 00823 : public ALU3dGridGhostIterator 00824 { 00825 protected: 00826 typedef LeafLevelIteratorTTProxy<1> IteratorType; 00827 IteratorType * newIterator() 00828 { 00829 return new IteratorType ( this->gitter_, this->link_ ); 00830 } 00831 00832 void checkLeafEntity () 00833 { 00834 if(this->it_) 00835 { 00836 if(! this->it_->done()) 00837 { 00838 val_t & el = this->item(); 00839 HBndSegType * pll = el.second; 00840 assert( pll ); 00841 00842 // this occurs if internal element is leaf but the corresponding 00843 // ghost is not leaf, we have to go next 00844 if ( ! pll->isLeafEntity() ) this->next(); 00845 } 00846 } 00847 } 00848 00849 public: 00850 template <class GridImp> 00851 ALU3dGridLeafIteratorWrapper(const GridImp & grid, int level , const int nlinks ) 00852 : ALU3dGridGhostIterator(grid,level,nlinks) {} 00853 00854 ALU3dGridLeafIteratorWrapper(const ALU3dGridLeafIteratorWrapper & org) 00855 : ALU3dGridGhostIterator(org) {} 00856 }; 00857 00858 // the level ghost partition iterator 00859 template<> 00860 class ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > 00861 : public ALU3dGridGhostIterator 00862 { 00863 const int level_; 00864 const int mxl_; 00865 protected: 00866 typedef LeafLevelIteratorTTProxy<1> IteratorType; 00867 IteratorType * newIterator() 00868 { 00869 // create new level Iterator Proxy 00870 return new IteratorType ( this->gitter_, this->link_ , level_ ); 00871 } 00872 00873 // for level iterators don't check leaf entity 00874 void checkLeafEntity () 00875 { 00876 if(this->it_) 00877 { 00878 if(! this->it_->done()) 00879 { 00880 val_t & el = this->item(); 00881 00882 assert( el.second ); 00883 HBndSegType & pll = *(el.second); 00884 00885 // this occurs if internal element is leaf but the corresponding 00886 // ghost is not leaf, we have to go next if level of ghost is not 00887 // our level 00888 if ( ! pll.down() ) 00889 { 00890 if( pll.ghostLevel() != level_ ) this->next(); 00891 } 00892 } 00893 } 00894 } 00895 00896 public: 00897 template <class GridImp> 00898 ALU3dGridLevelIteratorWrapper(const GridImp & grid,int level , const int nlinks ) 00899 : ALU3dGridGhostIterator(grid,level,nlinks) 00900 , level_(level) , mxl_(grid.maxLevel()){} 00901 00902 ALU3dGridLevelIteratorWrapper(const ALU3dGridLevelIteratorWrapper & org) 00903 : ALU3dGridGhostIterator(org) , level_(org.level_) , mxl_(org.mxl_){} 00904 }; 00905 00907 // 00908 // Helper class to get item from Helement 00909 // 00911 template< class GridImp, int cd > 00912 struct GetItem; 00913 00914 template< class GridImp > 00915 struct GetItem< GridImp, 1 > 00916 { 00917 enum { cd = 1 }; 00918 enum { elType = GridImp::elementType }; 00919 00920 typedef typename GridImp::MPICommunicatorType Comm; 00921 00922 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType; 00923 typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType; 00924 typedef typename IteratorElType< 1, Comm >::ElType ItemType; 00925 00926 static ItemType *getItemFromEl ( typename Dune::ALU3dImplTraits< Dune::tetra, Comm >::GEOElementType &el, int i ) 00927 { 00928 return el.myhface3( i ); 00929 } 00930 00931 static ItemType *getItemFromEl ( typename Dune::ALU3dImplTraits< Dune::hexa, Comm >::GEOElementType &el, int i ) 00932 { 00933 return el.myhface4( i ); 00934 } 00935 00936 static ItemType *getItem ( HElementType &el, int i ) 00937 { 00938 return getItemFromEl( static_cast< GEOElementType & >( el ), i ); 00939 } 00940 00941 static int numItems () 00942 { 00943 return Dune::EntityCount< elType >::numFaces; 00944 } 00945 }; 00946 00947 template< class GridImp > 00948 struct GetItem< GridImp, 2 > 00949 { 00950 enum { cd = 2 }; 00951 enum { elType = GridImp::elementType }; 00952 00953 typedef typename GridImp::MPICommunicatorType Comm; 00954 00955 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType; 00956 typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType; 00957 typedef typename IteratorElType< 2, Comm >::ElType ItemType; 00958 00959 static ItemType *getItem ( HElementType &el, int i ) 00960 { 00961 return static_cast< GEOElementType & >( el ).myhedge1( i ); 00962 } 00963 00964 static int numItems () 00965 { 00966 return Dune::EntityCount<elType>::numEdges; 00967 } 00968 }; 00969 00970 template< class GridImp > 00971 struct GetItem< GridImp, 3 > 00972 { 00973 enum { cd = 3 }; 00974 enum { elType = GridImp::elementType }; 00975 00976 typedef typename GridImp::MPICommunicatorType Comm; 00977 00978 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType; 00979 typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType; 00980 typedef typename IteratorElType< 3, Comm >::ElType ItemType; 00981 00982 static ItemType *getItem ( HElementType &el, int i ) 00983 { 00984 return static_cast< GEOElementType & >( el ).myvertex( i ); 00985 } 00986 00987 static int numItems () 00988 { 00989 return Dune::EntityCount< elType >::numVertices; 00990 } 00991 }; 00992 00993 00995 template< int codim > 00996 struct ALU3dGridGhostIteratorHigherCodim 00997 : public IteratorWrapperInterface< typename IteratorElType< codim, MPI_Comm >::val_t > 00998 { 00999 typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::HElementType HElementType; 01000 typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::HBndSegType HBndSegType; 01001 typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::GhostPairType GhostPairType; 01002 typedef typename IteratorElType< codim, MPI_Comm >::ElType ElType; 01003 typedef typename IteratorElType< codim, MPI_Comm >::val_t val_t; 01004 01005 private: 01006 template< Dune::ALU3dGridElementType elType, int cd > 01007 struct SelectVector; 01008 01009 template< Dune::ALU3dGridElementType elType > 01010 struct SelectVector< elType, 1 > 01011 { 01012 typedef typename Dune::ALU3dImplTraits< elType, MPI_Comm >::GEOElementType GEOElementType; 01013 01014 static const vector< int > &getNotOnItemVector ( int face ) 01015 { 01016 return GEOElementType::facesNotOnFace( face ); 01017 } 01018 }; 01019 01020 template< Dune::ALU3dGridElementType elType > 01021 struct SelectVector< elType, 2 > 01022 { 01023 typedef typename Dune::ALU3dImplTraits< elType, MPI_Comm >::GEOElementType GEOElementType; 01024 static const vector< int > &getNotOnItemVector( int face ) 01025 { 01026 return GEOElementType::edgesNotOnFace( face ); 01027 } 01028 }; 01029 01030 template< Dune::ALU3dGridElementType elType > 01031 struct SelectVector< elType, 3 > 01032 { 01033 typedef typename Dune::ALU3dImplTraits< elType, MPI_Comm >::GEOElementType GEOElementType; 01034 static const vector< int > &getNotOnItemVector ( int face ) 01035 { 01036 return GEOElementType::verticesNotOnFace( face ); 01037 } 01038 }; 01039 01040 typedef ElType *getItemFunc_t ( HElementType &el, int i ); 01041 01042 private: 01043 typedef Dune :: ALU3dGridItemListType GhostItemListType; 01044 GhostItemListType &ghList_; 01045 typedef typename GhostItemListType :: IteratorType IteratorType; 01046 IteratorType curr_; 01047 IteratorType end_; 01048 mutable val_t elem_; 01049 mutable int count_; 01050 01051 public: 01052 template< class GhostElementIteratorImp, class GridImp > 01053 ALU3dGridGhostIteratorHigherCodim ( GhostElementIteratorImp *, const GridImp &grid, 01054 int level, const int nlinks, GhostItemListType &ghList ) 01055 : ghList_( ghList ), 01056 elem_( (ElType *)0, (HBndSegType *)0 ), 01057 count_( 0 ) 01058 { 01059 if( ! ghList_.up2Date() ) 01060 { 01061 GhostElementIteratorImp ghostIter(grid,level,nlinks); 01062 updateGhostList(grid,ghostIter,ghList_); 01063 } 01064 } 01065 01066 ALU3dGridGhostIteratorHigherCodim(const ALU3dGridGhostIteratorHigherCodim & org) 01067 : ghList_( org.ghList_ ) 01068 , elem_(org.elem_) 01069 , count_(org.count_) 01070 {} 01071 01072 int size () { return ghList_.getItemList().size(); } 01073 void first() { count_ = 0; } 01074 void next () { ++count_; } 01075 int done () const { return (count_ >= (int) ghList_.getItemList().size() ? 1 : 0); } 01076 val_t & item () const 01077 { 01078 assert( ! done() ); 01079 void * item = ghList_.getItemList()[count_]; 01080 elem_.first = ((ElType * ) item); 01081 assert( elem_.first ); 01082 return elem_; 01083 } 01084 01085 protected: 01086 template <class GridImp, class GhostElementIteratorImp> 01087 void updateGhostList(const GridImp & grid, GhostElementIteratorImp & ghostIter, GhostItemListType & ghList) 01088 { 01089 int count = 0; 01090 for( ghostIter.first(); !ghostIter.done(); ghostIter.next() ) 01091 { 01092 ++count; 01093 } 01094 01095 const int numItems = SelectVector<GridImp::elementType,codim>::getNotOnItemVector(0).size(); 01096 const int maxSize = numItems * count; 01097 01098 ghList.getItemList().reserve(maxSize); 01099 ghList.getItemList().resize(0); 01100 map< int , int > visited; 01101 01102 for( ghostIter.first(); !ghostIter.done(); ghostIter.next() ) 01103 { 01104 GhostPairType ghPair = ghostIter.item().second->getGhost(); 01105 const vector<int> & notOnFace = SelectVector<GridImp::elementType,codim>:: 01106 getNotOnItemVector(ghPair.second); 01107 for(int i=0; i<numItems; ++i) 01108 { 01109 ElType * item = GetItem<GridImp,codim>::getItem( *(ghPair.first) , notOnFace[i] ); 01110 int idx = item->getIndex(); 01111 if( visited.find(idx) == visited.end() ) 01112 { 01113 ghList.getItemList().push_back( (void *) item ); 01114 visited[idx] = 1; 01115 } 01116 } 01117 } 01118 ghList.markAsUp2Date(); 01119 } 01120 }; 01121 01122 // the leaf ghost partition iterator 01123 template<> 01124 class ALU3dGridLeafIteratorWrapper< 1, Dune::Ghost_Partition, MPI_Comm > 01125 : public ALU3dGridGhostIteratorHigherCodim< 1 > 01126 { 01127 enum { codim = 1 }; 01128 typedef ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType; 01129 01130 public: 01131 template <class GridImp> 01132 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01133 : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {} 01134 01135 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 01136 : ALU3dGridGhostIteratorHigherCodim<codim>(org) {} 01137 }; 01138 01139 // the leaf ghost partition iterator 01140 template<> 01141 class ALU3dGridLeafIteratorWrapper< 2, Dune::Ghost_Partition, MPI_Comm > 01142 : public ALU3dGridGhostIteratorHigherCodim< 2 > 01143 { 01144 enum { codim = 2 }; 01145 typedef ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType; 01146 01147 public: 01148 template <class GridImp> 01149 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01150 : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {} 01151 01152 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 01153 : ALU3dGridGhostIteratorHigherCodim<codim>(org) {} 01154 }; 01155 01156 // the leaf ghost partition iterator 01157 template<> 01158 class ALU3dGridLeafIteratorWrapper< 3, Dune::Ghost_Partition, MPI_Comm > 01159 : public ALU3dGridGhostIteratorHigherCodim< 3 > 01160 { 01161 enum { codim = 3 }; 01162 typedef ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType; 01163 01164 public: 01165 template <class GridImp> 01166 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01167 : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {} 01168 01169 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 01170 : ALU3dGridGhostIteratorHigherCodim<codim>(org) {} 01171 }; 01172 01173 // the level ghost partition iterator 01174 template<> 01175 class ALU3dGridLevelIteratorWrapper< 1, Dune::Ghost_Partition, MPI_Comm > 01176 : public ALU3dGridGhostIteratorHigherCodim< 1 > 01177 { 01178 enum { codim = 1 }; 01179 typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType; 01180 01181 public: 01182 template <class GridImp> 01183 ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01184 : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {} 01185 01186 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 01187 : ALU3dGridGhostIteratorHigherCodim<codim>(org) {} 01188 }; 01189 01190 // the level ghost partition iterator 01191 template<> 01192 class ALU3dGridLevelIteratorWrapper< 2, Dune::Ghost_Partition, MPI_Comm > 01193 : public ALU3dGridGhostIteratorHigherCodim< 2 > 01194 { 01195 enum { codim = 2 }; 01196 typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType; 01197 01198 public: 01199 template <class GridImp> 01200 ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01201 : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {} 01202 01203 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 01204 : ALU3dGridGhostIteratorHigherCodim<codim>(org) {} 01205 }; 01206 01207 // the level ghost partition iterator 01208 template<> 01209 class ALU3dGridLevelIteratorWrapper< 3, Dune::Ghost_Partition, MPI_Comm > 01210 : public ALU3dGridGhostIteratorHigherCodim< 3 > 01211 { 01212 enum { codim = 3 }; 01213 typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType; 01214 01215 public: 01216 template <class GridImp> 01217 ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01218 : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {} 01219 01220 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 01221 : ALU3dGridGhostIteratorHigherCodim<codim>(org) {} 01222 }; 01223 01224 // the all partition iterator 01225 template<> 01226 class ALU3dGridLeafIteratorWrapper< 0, Dune::All_Partition, MPI_Comm > 01227 : public IteratorWrapperInterface< IteratorElType< 0, MPI_Comm >::val_t > 01228 { 01229 enum { codim = 0 }; 01230 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01231 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01232 01233 public: 01234 typedef IteratorElType< codim, MPI_Comm >::val_t val_t; 01235 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01236 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01237 private: 01238 IteratorType iter_; 01239 public: 01240 01241 template <class GridImp> 01242 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01243 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01244 GhostIteratorType ( grid, level, nlinks ) ) 01245 { 01246 } 01247 01248 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 01249 : iter_ (org.iter_) {} 01250 01251 int size () { return iter_.size(); } 01252 void next () { iter_.next(); } 01253 void first() { iter_.first(); } 01254 int done () const {return iter_.done(); } 01255 val_t & item () const { assert( ! done() ); return iter_.item(); } 01256 }; 01257 01258 // the all partition iterator 01259 template<> 01260 class ALU3dGridLeafIteratorWrapper< 1, Dune::All_Partition, MPI_Comm > 01261 : public IteratorWrapperInterface< IteratorElType< 1, MPI_Comm >::val_t > 01262 { 01263 enum { codim = 1 }; 01264 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01265 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01266 01267 public: 01268 typedef IteratorElType< codim, MPI_Comm >::val_t val_t; 01269 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01270 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01271 private: 01272 IteratorType iter_; 01273 public: 01274 01275 template <class GridImp> 01276 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01277 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01278 GhostIteratorType ( grid, level, nlinks ) ) 01279 { 01280 } 01281 01282 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 01283 : iter_ (org.iter_) {} 01284 01285 int size () { return iter_.size(); } 01286 void next () { iter_.next(); } 01287 void first() { iter_.first(); } 01288 int done () const {return iter_.done(); } 01289 val_t & item () const { assert( ! done() ); return iter_.item(); } 01290 }; 01291 01292 // the all partition iterator 01293 template<> 01294 class ALU3dGridLeafIteratorWrapper< 2, Dune::All_Partition, MPI_Comm > 01295 : public IteratorWrapperInterface< IteratorElType< 2, MPI_Comm >::val_t > 01296 { 01297 enum { codim = 2 }; 01298 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01299 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01300 01301 public: 01302 typedef IteratorElType< codim, MPI_Comm >::val_t val_t; 01303 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01304 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01305 private: 01306 IteratorType iter_; 01307 public: 01308 01309 template <class GridImp> 01310 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01311 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01312 GhostIteratorType ( grid, level, nlinks ) ) 01313 { 01314 } 01315 01316 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 01317 : iter_ (org.iter_) {} 01318 01319 int size () { return iter_.size(); } 01320 void next () { iter_.next(); } 01321 void first() { iter_.first(); } 01322 int done () const {return iter_.done(); } 01323 val_t & item () const { assert( ! done() ); return iter_.item(); } 01324 }; 01325 01326 // the all partition iterator 01327 template<> 01328 class ALU3dGridLeafIteratorWrapper< 3, Dune::All_Partition, MPI_Comm > 01329 : public IteratorWrapperInterface< IteratorElType< 3, MPI_Comm >::val_t > 01330 { 01331 enum { codim = 3 }; 01332 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01333 typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01334 01335 public: 01336 typedef IteratorElType< codim, MPI_Comm >::val_t val_t; 01337 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01338 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01339 private: 01340 IteratorType iter_; 01341 public: 01342 01343 template <class GridImp> 01344 ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01345 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01346 GhostIteratorType ( grid, level, nlinks ) ) 01347 { 01348 } 01349 01350 ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 01351 : iter_ (org.iter_) {} 01352 01353 int size () { return iter_.size(); } 01354 void next () { iter_.next(); } 01355 void first() { iter_.first(); } 01356 int done () const {return iter_.done(); } 01357 val_t & item () const { assert( ! done() ); return iter_.item(); } 01358 }; 01359 01360 // the all partition iterator 01361 template<> 01362 class ALU3dGridLevelIteratorWrapper< 0, Dune::All_Partition, MPI_Comm > 01363 : public IteratorWrapperInterface< LeafValType > 01364 { 01365 typedef ALU3dGridLevelIteratorWrapper< 0, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01366 typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01367 01368 public: 01369 typedef LeafValType val_t; 01370 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01371 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01372 private: 01373 IteratorType iter_; 01374 public: 01375 01376 template <class GridImp> 01377 ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01378 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01379 GhostIteratorType ( grid, level, nlinks ) ) 01380 { 01381 } 01382 01383 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org) 01384 : iter_(org.iter_) {} 01385 01386 int size () { return iter_.size(); } 01387 void next () { iter_.next(); } 01388 void first() { iter_.first(); } 01389 int done () const {return iter_.done(); } 01390 val_t & item () const { assert( ! done() ); return iter_.item(); } 01391 }; 01392 #endif // #if ALU3DGRID_PARALLEL 01393 01394 // placed here because we need ALU3dGridLevelIteratorWrapper<0,Dune::All_Partition> here 01395 // the edge level iterator 01396 template< PartitionIteratorType pitype, class Comm > 01397 struct ALU3dGridLevelIteratorWrapper< 2, pitype, Comm > 01398 : public IteratorWrapperInterface< typename IteratorElType< 2, Comm >::val_t > 01399 { 01400 typedef typename ALUHElementType< 2, Comm >::ElementType ElType; 01401 typedef typename Dune::ALU3dBasicImplTraits< Comm >::HBndSegType HBndSegType; 01402 typedef typename Dune::ALU3dBasicImplTraits< Comm >::GEOEdgeType GEOEdgeType; 01403 01404 typedef typename IteratorElType< 2, Comm >::val_t val_t; 01405 01406 private: 01407 mutable val_t elem_; 01408 const int level_; 01409 01410 typedef Dune :: ALU3dGridItemListType ItemListType; 01411 ItemListType & edgeList_; 01412 01413 size_t count_ ; 01414 bool maxLevel_; 01415 01416 public: 01417 // constructor creating iterator 01418 template< class GridImp > 01419 ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks ) 01420 : elem_( (ElType *)0, (HBndSegType *)0 ), 01421 level_( level ), 01422 edgeList_( grid.getEdgeList( level ) ), 01423 count_( 0 ) 01424 { 01425 if( ! edgeList_.up2Date() ) 01426 updateEdgeList(grid,level,nlinks); 01427 } 01428 01429 // copy constructor 01430 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 01431 : elem_(org.elem_) 01432 , level_(org.level_) 01433 , edgeList_( org.edgeList_ ) 01434 , count_(org.count_) 01435 { 01436 } 01437 01438 int size () { return edgeList_.getItemList().size(); } 01439 void next () 01440 { 01441 ++count_; 01442 } 01443 01444 void first() 01445 { 01446 count_ = 0; 01447 } 01448 01449 int done () const { return ((count_ >= edgeList_.size()) ? 1: 0); } 01450 01451 val_t & item () const 01452 { 01453 assert( ! done () ); 01454 elem_.first = ( (ElType *) edgeList_.getItemList()[count_]); 01455 01456 assert( elem_.first ); 01457 return elem_; 01458 } 01459 01460 private: 01461 template <class GridImp> 01462 void updateEdgeList(const GridImp & grid, int level, int nlinks) 01463 { 01464 typedef ALU3dGridLevelIteratorWrapper< 0, Dune::All_Partition, Comm > ElementLevelIterator; 01465 typedef typename ElementLevelIterator :: val_t el_val_t; 01466 ElementLevelIterator iter(grid,level,nlinks); 01467 01468 edgeList_.getItemList().resize(0); 01469 map < int , int > visited; 01470 01471 for( iter.first(); ! iter.done(); iter.next() ) 01472 { 01473 typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType; 01474 enum { numEdges = Dune::EntityCount< GridImp::elementType >::numEdges }; 01475 01476 GEOElementType *elem = 0; 01477 el_val_t & item = iter.item(); 01478 01479 if( item.first ) 01480 elem = static_cast< GEOElementType * > (item.first); 01481 else if( item.second ) 01482 elem = static_cast< GEOElementType * > (item.second->getGhost().first); 01483 01484 assert( elem ); 01485 for(int e=0; e<numEdges; ++e) 01486 { 01487 ElType * edge = elem->myhedge1(e); 01488 if( edge->isGhost() ) continue; 01489 01490 int idx = edge->getIndex(); 01491 if( visited.find(idx) == visited.end() ) 01492 { 01493 edgeList_.getItemList().push_back( (void *) edge ); 01494 visited[idx] = 1; 01495 } 01496 } 01497 } 01498 edgeList_.markAsUp2Date(); 01499 } 01500 }; 01501 01502 #if ALU3DGRID_PARALLEL 01503 // the all partition iterator 01504 template<> 01505 class ALU3dGridLevelIteratorWrapper< 1, Dune::All_Partition, MPI_Comm > 01506 : public IteratorWrapperInterface< IteratorElType< 1, MPI_Comm >::val_t > 01507 { 01508 enum { codim = 1 }; 01509 typedef ALU3dGridLevelIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01510 typedef ALU3dGridLevelIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01511 01512 public: 01513 typedef IteratorElType< codim, MPI_Comm >::val_t val_t; 01514 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01515 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01516 private: 01517 IteratorType iter_; 01518 public: 01519 01520 template <class GridImp> 01521 ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01522 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01523 GhostIteratorType ( grid, level, nlinks ) ) 01524 { 01525 } 01526 01527 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 01528 : iter_ (org.iter_) {} 01529 01530 int size () { return iter_.size(); } 01531 void next () { iter_.next(); } 01532 void first() { iter_.first(); } 01533 int done () const {return iter_.done(); } 01534 val_t & item () const { assert( ! done() ); return iter_.item(); } 01535 }; 01536 01537 // the all partition iterator 01538 template<> 01539 class ALU3dGridLevelIteratorWrapper< 2, Dune::All_Partition, MPI_Comm > 01540 : public IteratorWrapperInterface< IteratorElType< 2, MPI_Comm >::val_t > 01541 { 01542 enum { codim = 2 }; 01543 typedef ALU3dGridLevelIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01544 typedef ALU3dGridLevelIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01545 01546 public: 01547 typedef IteratorElType< codim, MPI_Comm >::val_t val_t; 01548 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01549 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01550 private: 01551 IteratorType iter_; 01552 public: 01553 01554 template <class GridImp> 01555 ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01556 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01557 GhostIteratorType ( grid, level, nlinks ) ) 01558 { 01559 } 01560 01561 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 01562 : iter_ (org.iter_) {} 01563 01564 int size () { return iter_.size(); } 01565 void next () { iter_.next(); } 01566 void first() { iter_.first(); } 01567 int done () const {return iter_.done(); } 01568 val_t & item () const { assert( ! done() ); return iter_.item(); } 01569 }; 01570 01571 // the all partition iterator 01572 template<> 01573 class ALU3dGridLevelIteratorWrapper< 3, Dune::All_Partition, MPI_Comm > 01574 : public IteratorWrapperInterface < IteratorElType< 3, MPI_Comm >::val_t > 01575 { 01576 enum { codim = 3 }; 01577 typedef ALU3dGridLevelIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType; 01578 typedef ALU3dGridLevelIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType; 01579 01580 public: 01581 typedef IteratorElType< codim, MPI_Comm >::val_t val_t; 01582 // use ALUGrids AlignIterator to combine Interior and Ghost Iterator 01583 typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType; 01584 private: 01585 IteratorType iter_; 01586 public: 01587 01588 template <class GridImp> 01589 ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 01590 : iter_ ( InteriorIteratorType ( grid, level, nlinks ) , 01591 GhostIteratorType ( grid, level, nlinks ) ) 01592 { 01593 } 01594 01595 ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 01596 : iter_ (org.iter_) {} 01597 01598 int size () { return iter_.size(); } 01599 void next () { iter_.next(); } 01600 void first() { iter_.first(); } 01601 int done () const {return iter_.done(); } 01602 val_t & item () const { assert( ! done() ); return iter_.item(); } 01603 }; 01604 #endif // #if ALU3DGRID_PARALLEL 01605 01606 } // end namespace ALUGridSpace 01607 01608 #endif // #ifndef DUNE_ALU3DITERATORS_HH