alu3diterators.hh

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

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)