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     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     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 
00873   //
00874   //  Helper class to get item from Helement 
00875   //
00877   template<class GridImp, int cd> 
00878   struct GetItem; 
00879   
00880   template<class GridImp> 
00881   struct GetItem<GridImp,1> 
00882   {
00883     enum { cd = 1 };
00884     enum { elType = GridImp::elementType };
00885 
00886     typedef typename Dune::ALU3dImplTraits<GridImp::elementType>::GEOElementType GEOElementType;
00887     typedef typename IteratorElType<1>::ElType ItemType; 
00888 
00889     static ItemType * getItemFromEl(GEOTetraElementType & el, int i)
00890     {
00891       return el.myhface3(i);
00892     }
00893    
00894     static ItemType * getItemFromEl(GEOHexaElementType & el, int i)
00895     {
00896       return el.myhface4(i);
00897     }
00898     
00899     static ItemType * getItem(HElementType & el, int i)
00900     {
00901       return getItemFromEl(static_cast<GEOElementType &> (el),i);
00902     }
00903     
00904     static int numItems() 
00905     {
00906       return Dune :: EntityCount<elType>::numFaces;
00907     }
00908   };
00909 
00910   template<class GridImp> 
00911   struct GetItem<GridImp,2> 
00912   {
00913     enum { cd = 2 };
00914     enum { elType = GridImp::elementType };
00915     typedef typename Dune::ALU3dImplTraits<GridImp::elementType>::GEOElementType GEOElementType;
00916     typedef typename IteratorElType<2>::ElType ItemType; 
00917     static ItemType * getItem(HElementType & el, int i)
00918     {
00919       return static_cast<GEOElementType &> (el).myhedge1(i); 
00920     }
00921     
00922     static int numItems() 
00923     {
00924       return Dune :: EntityCount<elType>::numEdges;
00925     }
00926   };
00927 
00928   template<class GridImp> 
00929   struct GetItem<GridImp,3> 
00930   {
00931     enum { cd = 3 };
00932     enum { elType = GridImp::elementType };
00933     typedef typename Dune::ALU3dImplTraits<GridImp::elementType>::GEOElementType GEOElementType;
00934     typedef typename IteratorElType<3>::ElType ItemType; 
00935     static ItemType * getItem(HElementType & el, int i)
00936     {
00937       return static_cast<GEOElementType &> (el).myvertex(i); 
00938     }
00939 
00940     static int numItems() 
00941     {
00942       return Dune :: EntityCount<elType>::numVertices;
00943     }
00944   };
00945 
00946 
00948   template <int codim> 
00949   class ALU3dGridGhostIteratorHigherCodim 
00950     : public IteratorWrapperInterface < typename IteratorElType<codim>::val_t > 
00951   { 
00952 
00953   public:  
00954     typedef typename IteratorElType<codim>::ElType ElType; 
00955     typedef typename IteratorElType<codim>::val_t val_t; 
00956     
00957   private:
00958     template<Dune :: ALU3dGridElementType elType, int cd> 
00959     struct SelectVector
00960     {
00961     };
00962 
00963     template<Dune :: ALU3dGridElementType elType> 
00964     struct SelectVector<elType,1> 
00965     {
00966       typedef typename Dune :: ALU3dImplTraits<elType>::GEOElementType GEOElementType;
00967       static const vector<int> & getNotOnItemVector(int face)
00968       {
00969         return GEOElementType :: facesNotOnFace( face );
00970       }
00971     };
00972 
00973     template<Dune :: ALU3dGridElementType elType> 
00974     struct SelectVector<elType,2> 
00975     {
00976       typedef typename Dune :: ALU3dImplTraits<elType>::GEOElementType GEOElementType;
00977       static const vector<int> & getNotOnItemVector(int face)
00978       {
00979         return GEOElementType :: edgesNotOnFace( face );
00980       }
00981     };
00982 
00983     template<Dune :: ALU3dGridElementType elType> 
00984     struct SelectVector<elType,3> 
00985     {
00986       typedef typename Dune :: ALU3dImplTraits<elType>::GEOElementType GEOElementType;
00987       static const vector<int> & getNotOnItemVector(int face)
00988       {
00989         return GEOElementType :: verticesNotOnFace( face );
00990       }
00991     };
00992 
00993     typedef ElType * getItemFunc_t(HElementType & el, int i);
00994 
00995   private:  
00996     typedef Dune :: ALU3dGridItemListType GhostItemListType; 
00997     GhostItemListType & ghList_;
00998     typedef typename GhostItemListType :: IteratorType IteratorType; 
00999     IteratorType curr_; 
01000     IteratorType end_; 
01001     mutable val_t elem_;
01002     mutable int count_;
01003   public:
01004     template <class GhostElementIteratorImp, class GridImp>
01005     ALU3dGridGhostIteratorHigherCodim(GhostElementIteratorImp *, const GridImp & grid, 
01006                         int level , const int nlinks, GhostItemListType & ghList) 
01007       : ghList_( ghList )
01008       , elem_(0,0)
01009       , count_(0)
01010     {
01011       if( ! ghList_.up2Date() )
01012       {
01013         GhostElementIteratorImp ghostIter(grid,level,nlinks);
01014         updateGhostList(grid,ghostIter,ghList_);
01015       }
01016     }  
01017 
01018     ALU3dGridGhostIteratorHigherCodim(const ALU3dGridGhostIteratorHigherCodim & org) 
01019       : ghList_( org.ghList_ )
01020       , elem_(org.elem_)
01021       , count_(org.count_)
01022     {}
01023 
01024     int size  () { return ghList_.getItemList().size(); }
01025     void first() { count_ = 0; } 
01026     void next () { ++count_; }
01027     int done () const { return (count_ >= (int) ghList_.getItemList().size() ? 1 : 0); } 
01028     val_t & item () const 
01029     { 
01030       assert( ! done() ); 
01031       void * item = ghList_.getItemList()[count_]; 
01032       elem_.first = ((ElType * ) item);
01033       assert( elem_.first );
01034       return elem_; 
01035     }
01036 
01037   protected:  
01038     template <class GridImp, class GhostElementIteratorImp>
01039     void updateGhostList(const GridImp & grid, GhostElementIteratorImp & ghostIter, GhostItemListType & ghList)
01040     {
01041       int count = 0;
01042       for( ghostIter.first(); !ghostIter.done(); ghostIter.next() )
01043       {
01044         ++count;
01045       }
01046 
01047       const int numItems = SelectVector<GridImp::elementType,codim>::getNotOnItemVector(0).size(); 
01048       const int maxSize = numItems * count;
01049 
01050       ghList.getItemList().reserve(maxSize);
01051       ghList.getItemList().resize(0);
01052       map< int , int > visited; 
01053 
01054       for( ghostIter.first(); !ghostIter.done(); ghostIter.next() )
01055       {
01056         GhostPairType ghPair = ghostIter.item().second->getGhost();
01057         const vector<int> & notOnFace = SelectVector<GridImp::elementType,codim>::
01058                                           getNotOnItemVector(ghPair.second); 
01059         for(int i=0; i<numItems; ++i) 
01060         {
01061           ElType * item = GetItem<GridImp,codim>::getItem( *(ghPair.first) , notOnFace[i] );
01062           int idx = item->getIndex();
01063           if( visited.find(idx) == visited.end() )
01064           {
01065             ghList.getItemList().push_back( (void *) item );
01066             visited[idx] = 1;
01067           }
01068         }
01069       }
01070       ghList.markAsUp2Date();
01071     }
01072   };
01073   
01074   // the leaf ghost partition iterator 
01075   template <> 
01076   class ALU3dGridLeafIteratorWrapper<1,Dune::Ghost_Partition> 
01077     : public ALU3dGridGhostIteratorHigherCodim<1> 
01078   {
01079     enum { codim = 1 };
01080     typedef ALU3dGridLeafIteratorWrapper<0,Dune::Ghost_Partition> GhostElementIteratorType;
01081   public:
01082     template <class GridImp> 
01083     ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01084       : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {}
01085 
01086     ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 
01087       : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
01088   };
01089   
01090   // the leaf ghost partition iterator 
01091   template <> 
01092   class ALU3dGridLeafIteratorWrapper<2,Dune::Ghost_Partition> 
01093     : public ALU3dGridGhostIteratorHigherCodim<2> 
01094   {
01095     enum { codim = 2 };
01096     typedef ALU3dGridLeafIteratorWrapper<0,Dune::Ghost_Partition> GhostElementIteratorType;
01097   public:
01098     template <class GridImp> 
01099     ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01100       : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {}
01101 
01102     ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 
01103       : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
01104   };
01105   
01106   // the leaf ghost partition iterator 
01107   template <> 
01108   class ALU3dGridLeafIteratorWrapper<3,Dune::Ghost_Partition> 
01109     : public ALU3dGridGhostIteratorHigherCodim<3> 
01110   {
01111     enum { codim = 3 };
01112     typedef ALU3dGridLeafIteratorWrapper<0,Dune::Ghost_Partition> GhostElementIteratorType;
01113   public:
01114     template <class GridImp> 
01115     ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01116       : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {}
01117 
01118     ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 
01119       : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
01120   };
01121   
01122   // the level ghost partition iterator 
01123   template <> 
01124   class ALU3dGridLevelIteratorWrapper<1,Dune::Ghost_Partition> 
01125     : public ALU3dGridGhostIteratorHigherCodim<1> 
01126   {
01127     enum { codim = 1 };
01128     typedef ALU3dGridLevelIteratorWrapper<0,Dune::Ghost_Partition> GhostElementIteratorType;
01129   public:
01130     template <class GridImp> 
01131     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01132       : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {}
01133 
01134     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 
01135       : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
01136   };
01137   
01138   // the level ghost partition iterator 
01139   template <> 
01140   class ALU3dGridLevelIteratorWrapper<2,Dune::Ghost_Partition> 
01141     : public ALU3dGridGhostIteratorHigherCodim<2> 
01142   {
01143     enum { codim = 2 };
01144     typedef ALU3dGridLevelIteratorWrapper<0,Dune::Ghost_Partition> GhostElementIteratorType;
01145   public:
01146     template <class GridImp> 
01147     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01148       : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {}
01149 
01150     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 
01151       : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
01152   };
01153   
01154   // the level ghost partition iterator 
01155   template <> 
01156   class ALU3dGridLevelIteratorWrapper<3,Dune::Ghost_Partition> 
01157     : public ALU3dGridGhostIteratorHigherCodim<3> 
01158   {
01159     enum { codim = 3 };
01160     typedef ALU3dGridLevelIteratorWrapper<0,Dune::Ghost_Partition> GhostElementIteratorType;
01161   public:
01162     template <class GridImp> 
01163     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01164       : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {}
01165 
01166     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 
01167       : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
01168   };
01169   
01170   // the all partition iterator 
01171   template <> 
01172   class ALU3dGridLeafIteratorWrapper<0,Dune::All_Partition> 
01173     : public IteratorWrapperInterface < IteratorElType<0>::val_t > 
01174   {
01175     enum { codim = 0 };
01176     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::InteriorBorder_Partition> InteriorIteratorType;
01177     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::Ghost_Partition> GhostIteratorType;
01178 
01179   public:  
01180     typedef IteratorElType<codim>::val_t val_t;
01181     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01182     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01183   private:
01184     IteratorType iter_;
01185   public:
01186     
01187     template <class GridImp> 
01188     ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01189       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01190                 GhostIteratorType    ( grid, level, nlinks ) )
01191     {
01192     }
01193     
01194     ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 
01195       : iter_ (org.iter_) {}
01196     
01197     int size  () { return iter_.size(); }
01198     void next () { iter_.next(); }
01199     void first() { iter_.first(); }
01200     int done () const {return iter_.done(); }
01201     val_t & item () const { assert( ! done() ); return iter_.item(); }
01202   };
01203 
01204   // the all partition iterator 
01205   template <> 
01206   class ALU3dGridLeafIteratorWrapper<1,Dune::All_Partition> 
01207     : public IteratorWrapperInterface < IteratorElType<1>::val_t > 
01208   {
01209     enum { codim = 1 };
01210     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::InteriorBorder_Partition> InteriorIteratorType;
01211     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::Ghost_Partition> GhostIteratorType;
01212 
01213   public:  
01214     typedef IteratorElType<codim>::val_t val_t;
01215     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01216     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01217   private:
01218     IteratorType iter_;
01219   public:
01220     
01221     template <class GridImp> 
01222     ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01223       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01224                 GhostIteratorType    ( grid, level, nlinks ) )
01225     {
01226     }
01227     
01228     ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 
01229       : iter_ (org.iter_) {}
01230     
01231     int size  () { return iter_.size(); }
01232     void next () { iter_.next(); }
01233     void first() { iter_.first(); }
01234     int done () const {return iter_.done(); }
01235     val_t & item () const { assert( ! done() ); return iter_.item(); }
01236   };
01237 
01238   // the all partition iterator 
01239   template <> 
01240   class ALU3dGridLeafIteratorWrapper<2,Dune::All_Partition> 
01241     : public IteratorWrapperInterface < IteratorElType<2>::val_t > 
01242   {
01243     enum { codim = 2 };
01244     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::InteriorBorder_Partition> InteriorIteratorType;
01245     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::Ghost_Partition> GhostIteratorType;
01246 
01247   public:  
01248     typedef IteratorElType<codim>::val_t val_t;
01249     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01250     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01251   private:
01252     IteratorType iter_;
01253   public:
01254     
01255     template <class GridImp> 
01256     ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01257       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01258                 GhostIteratorType    ( grid, level, nlinks ) )
01259     {
01260     }
01261     
01262     ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 
01263       : iter_ (org.iter_) {}
01264     
01265     int size  () { return iter_.size(); }
01266     void next () { iter_.next(); }
01267     void first() { iter_.first(); }
01268     int done () const {return iter_.done(); }
01269     val_t & item () const { assert( ! done() ); return iter_.item(); }
01270   };
01271 
01272   // the all partition iterator 
01273   template <> 
01274   class ALU3dGridLeafIteratorWrapper<3,Dune::All_Partition> 
01275     : public IteratorWrapperInterface < IteratorElType<3>::val_t > 
01276   {
01277     enum { codim = 3 };
01278     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::InteriorBorder_Partition> InteriorIteratorType;
01279     typedef ALU3dGridLeafIteratorWrapper<codim,Dune::Ghost_Partition> GhostIteratorType;
01280 
01281   public:  
01282     typedef IteratorElType<codim>::val_t val_t;
01283     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01284     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01285   private:
01286     IteratorType iter_;
01287   public:
01288     
01289     template <class GridImp> 
01290     ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01291       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01292                 GhostIteratorType    ( grid, level, nlinks ) )
01293     {
01294     }
01295     
01296     ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org ) 
01297       : iter_ (org.iter_) {}
01298     
01299     int size  () { return iter_.size(); }
01300     void next () { iter_.next(); }
01301     void first() { iter_.first(); }
01302     int done () const {return iter_.done(); }
01303     val_t & item () const { assert( ! done() ); return iter_.item(); }
01304   };
01305 
01306   // the all partition iterator 
01307   template <> 
01308   class ALU3dGridLevelIteratorWrapper<0,Dune::All_Partition> 
01309     : public IteratorWrapperInterface< LeafValType >
01310   {
01311     typedef ALU3dGridLevelIteratorWrapper<0,Dune::InteriorBorder_Partition> InteriorIteratorType;
01312     typedef ALU3dGridLevelIteratorWrapper<0,Dune::Ghost_Partition> GhostIteratorType;
01313 
01314   public:  
01315     typedef LeafValType val_t;
01316     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01317     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01318   private:
01319     IteratorType iter_;
01320   public:
01321     
01322     template <class GridImp> 
01323     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01324       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01325                 GhostIteratorType    ( grid, level, nlinks ) )
01326     {
01327     }
01328     
01329     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org) 
01330       : iter_(org.iter_) {}
01331     
01332     int size  () { return iter_.size(); }
01333     void next () { iter_.next(); }
01334     void first() { iter_.first(); }
01335     int done () const {return iter_.done(); }
01336     val_t & item () const { assert( ! done() ); return iter_.item(); }
01337   };
01338 #endif // end ALU3DGRID_PARALLEL
01339 
01340   // placed here because we need ALU3dGridLevelIteratorWrapper<0,Dune::All_Partition> here 
01341   // the edge level iterator 
01342   template <PartitionIteratorType pitype>
01343   class ALU3dGridLevelIteratorWrapper<2,pitype>
01344     : public IteratorWrapperInterface< typename IteratorElType<2>::val_t >
01345   {
01346   public:  
01347     typedef ALUHElementType<2>::ElementType ElType; 
01348     typedef ALU3DSPACE GEOEdgeT GEOEdgeType;
01349     
01350     typedef typename IteratorElType<2>::val_t val_t;
01351   private:
01352     mutable val_t elem_;
01353     const int level_;
01354 
01355     typedef Dune :: ALU3dGridItemListType ItemListType; 
01356     ItemListType & edgeList_;
01357 
01358     size_t count_ ;
01359     bool maxLevel_;
01360       
01361   public:  
01362     // constructor creating iterator 
01363     template <class GridImp> 
01364     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01365       : elem_(0,0)
01366       , level_(level) 
01367       , edgeList_( grid.getEdgeList(level) )
01368       , count_(0)
01369     {
01370       if( ! edgeList_.up2Date() )
01371         updateEdgeList(grid,level,nlinks);
01372     }
01373 
01374     // copy constructor 
01375     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
01376       : elem_(org.elem_) 
01377       , level_(org.level_)
01378       , edgeList_( org.edgeList_ )
01379       , count_(org.count_)
01380     {
01381     }
01382 
01383     int size  () { return edgeList_.getItemList().size(); }
01384     void next ()      
01385     { 
01386       ++count_;
01387     }
01388 
01389     void first()      
01390     { 
01391       count_ = 0;
01392     }
01393     
01394     int done () const { return ((count_ >= edgeList_.size()) ? 1: 0); }
01395     
01396     val_t & item () const 
01397     { 
01398       assert( ! done () );
01399       elem_.first = ( (ElType *) edgeList_.getItemList()[count_]);
01400 
01401       assert( elem_.first );
01402       return elem_; 
01403     }
01404   private: 
01405     template <class GridImp>
01406     void updateEdgeList(const GridImp & grid, int level, int nlinks) 
01407     {
01408       typedef ALU3dGridLevelIteratorWrapper<0,Dune::All_Partition> ElementLevelIterator;
01409       typedef typename ElementLevelIterator :: val_t el_val_t;
01410       ElementLevelIterator iter(grid,level,nlinks);
01411 
01412       edgeList_.getItemList().resize(0);
01413       map < int , int > visited; 
01414       
01415       for( iter.first(); ! iter.done(); iter.next() )
01416       {
01417         typedef typename Dune :: ALU3dImplTraits<GridImp::elementType>::GEOElementType GEOElementType;
01418         enum { numEdges = Dune :: EntityCount<GridImp::elementType>::numEdges };
01419         
01420         GEOElementType * elem = 0;
01421         el_val_t & item = iter.item();
01422         
01423         if( item.first )
01424           elem = static_cast<GEOElementType *> (item.first);
01425         else if( item.second )
01426           elem = static_cast<GEOElementType *> (item.second->getGhost().first);
01427 
01428         assert( elem );
01429         for(int e=0; e<numEdges; ++e) 
01430         {
01431           ElType * edge = elem->myhedge1(e);
01432           if( edge->isGhost() ) continue;
01433 
01434           int idx = edge->getIndex();
01435           if( visited.find(idx) == visited.end() )
01436           {
01437             edgeList_.getItemList().push_back( (void *) edge );
01438             visited[idx] = 1;
01439           }
01440         }
01441       }
01442       edgeList_.markAsUp2Date();
01443     }
01444   };
01445 
01446 #if ALU3DGRID_PARALLEL
01447   // the all partition iterator 
01448   template <> 
01449   class ALU3dGridLevelIteratorWrapper<1,Dune::All_Partition> 
01450     : public IteratorWrapperInterface < IteratorElType<1>::val_t > 
01451   {
01452     enum { codim = 1 };
01453     typedef ALU3dGridLevelIteratorWrapper<codim,Dune::InteriorBorder_Partition> InteriorIteratorType;
01454     typedef ALU3dGridLevelIteratorWrapper<codim,Dune::Ghost_Partition> GhostIteratorType;
01455 
01456   public:  
01457     typedef IteratorElType<codim>::val_t val_t;
01458     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01459     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01460   private:
01461     IteratorType iter_;
01462   public:
01463     
01464     template <class GridImp> 
01465     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01466       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01467                 GhostIteratorType    ( grid, level, nlinks ) )
01468     {
01469     }
01470     
01471     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 
01472       : iter_ (org.iter_) {}
01473     
01474     int size  () { return iter_.size(); }
01475     void next () { iter_.next(); }
01476     void first() { iter_.first(); }
01477     int done () const {return iter_.done(); }
01478     val_t & item () const { assert( ! done() ); return iter_.item(); }
01479   };
01480 
01481   // the all partition iterator 
01482   template <> 
01483   class ALU3dGridLevelIteratorWrapper<2,Dune::All_Partition> 
01484     : public IteratorWrapperInterface < IteratorElType<2>::val_t > 
01485   {
01486     enum { codim = 2 };
01487     typedef ALU3dGridLevelIteratorWrapper<codim,Dune::InteriorBorder_Partition> InteriorIteratorType;
01488     typedef ALU3dGridLevelIteratorWrapper<codim,Dune::Ghost_Partition> GhostIteratorType;
01489 
01490   public:  
01491     typedef IteratorElType<codim>::val_t val_t;
01492     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01493     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01494   private:
01495     IteratorType iter_;
01496   public:
01497     
01498     template <class GridImp> 
01499     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01500       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01501                 GhostIteratorType    ( grid, level, nlinks ) )
01502     {
01503     }
01504     
01505     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 
01506       : iter_ (org.iter_) {}
01507     
01508     int size  () { return iter_.size(); }
01509     void next () { iter_.next(); }
01510     void first() { iter_.first(); }
01511     int done () const {return iter_.done(); }
01512     val_t & item () const { assert( ! done() ); return iter_.item(); }
01513   };
01514 
01515   // the all partition iterator 
01516   template <> 
01517   class ALU3dGridLevelIteratorWrapper<3,Dune::All_Partition> 
01518     : public IteratorWrapperInterface < IteratorElType<3>::val_t > 
01519   {
01520     enum { codim = 3 };
01521     typedef ALU3dGridLevelIteratorWrapper<codim,Dune::InteriorBorder_Partition> InteriorIteratorType;
01522     typedef ALU3dGridLevelIteratorWrapper<codim,Dune::Ghost_Partition> GhostIteratorType;
01523 
01524   public:  
01525     typedef IteratorElType<codim>::val_t val_t;
01526     // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
01527     typedef AlignIterator< InteriorIteratorType, GhostIteratorType , val_t > IteratorType; 
01528   private:
01529     IteratorType iter_;
01530   public:
01531     
01532     template <class GridImp> 
01533     ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks ) 
01534       : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
01535                 GhostIteratorType    ( grid, level, nlinks ) )
01536     {
01537     }
01538     
01539     ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org ) 
01540       : iter_ (org.iter_) {}
01541     
01542     int size  () { return iter_.size(); }
01543     void next () { iter_.next(); }
01544     void first() { iter_.first(); }
01545     int done () const {return iter_.done(); }
01546     val_t & item () const { assert( ! done() ); return iter_.item(); }
01547   };
01548 #endif // end if ALU3DGRID_PARALLEL
01549 
01550   typedef PureElementLeafIterator < GitterType::helement_STI > BSLeafIteratorMaxLevel; 
01551 
01552 } //end namespace ALU3dGrid
01553 #endif

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