alugrid/2d/iterator.hh

Go to the documentation of this file.
00001 #ifndef DUNE_ALU2DGRID_ITERATOR_HH
00002 #define DUNE_ALU2DGRID_ITERATOR_HH
00003 
00004 // System includes
00005 #include <stack>
00006 #include <utility>
00007 
00008 // Dune includes
00009 #include <dune/grid/common/grid.hh>
00010 #include <dune/grid/alugrid/common/intersectioniteratorwrapper.hh>
00011 
00012 // Local includes 
00013 #include "entity.hh"
00014 
00015 namespace Dune {
00016   // Forward declarations
00017   template<int cd, int dim, class GridImp> 
00018   class ALU2dGridEntity;
00019   template<int cd, PartitionIteratorType pitype, class GridImp >
00020   class ALU2dGridLevelIterator;
00021   template<int cd, class GridImp > 
00022   class ALU2dGridEntityPointer;
00023   template<int mydim, int coorddim, class GridImp>
00024   class ALU2dGridGeometry;
00025   template<class GridImp> 
00026   class ALU2dGridHierarchicIterator;
00027   template<class GridImp>
00028   class ALU2dGridIntersectionBase;
00029   template<class GridImp>
00030   class ALU2dGridLeafIntersectionIterator;
00031   template<class GridImp>
00032   class ALU2dGridLevelIntersectionIterator;
00033   template<int codim, PartitionIteratorType pitype, class GridImp>
00034   class ALU2dGridLeafIterator;
00035   template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
00036   class ALU2dGrid;
00037   
00038  
00039 //********************************************************************
00040 //  --ALU2dGridLeafIterator
00041 //  --LeafIterator   
00042 //  --for codim = 0,2
00043 //
00044 //********************************************************************
00045 
00046 template<int cdim, PartitionIteratorType pitype, class GridImp>
00047 class ALU2dGridLeafIterator
00048 : public ALU2dGridEntityPointer<cdim,GridImp>
00049   // public LeafIteratorDefaultImplementation<cdim, pitype, GridImp, ALU2dGridLeafIterator> 
00050 {
00051   static const int dim = GridImp::dimension;
00052   static const int dimworld  = GridImp::dimensionworld;
00053   static const ALU2DSPACE ElementType eltype = GridImp::elementType;
00054   static const int codim = cdim;
00055 
00056   friend class ALU2dGridEntity<0,dimworld,GridImp>;
00057   friend class ALU2dGridEntity<1,dimworld,GridImp>;
00058   friend class ALU2dGridEntity<dim,dimworld,GridImp>;  
00059   friend class ALU2dGrid< dim, dimworld, eltype >;
00060     
00061   typedef ALU2dGridEntityPointer<cdim,GridImp> EntityPointerType;  
00062   typedef ALU2dGridEntity<cdim,dim,GridImp> EntityImp;      
00063 
00064   typedef ALU2dGridLeafIterator<cdim, pitype, GridImp> ThisType;
00065  
00066   typedef typename GridImp :: ALU2dGridLeafMarkerVectorType LeafMarkerVectorType;
00067 
00068   // default impl for elements 
00069   template <class ElementImp, class MarkerVectorImp, int codim> 
00070   struct GetLevel
00071   {
00072     // return level of element 
00073     static int level(const ElementImp & elem, const MarkerVectorImp& marker)
00074     {
00075       return elem.level();
00076     }
00077   };
00078  
00079   // specialization for vertices 
00080   template <class ElementImp, class MarkerVectorImp> 
00081   struct GetLevel<ElementImp,MarkerVectorImp,2>
00082   {
00083     // return level of leaf vertex 
00084     static int level(const ElementImp & elem, const MarkerVectorImp& marker)
00085     {
00086       return marker.levelOfVertex(elem.getIndex()); 
00087     }
00088   };
00089  
00090  public:
00091   typedef typename GridImp :: GridObjectFactoryType  FactoryType;
00092 
00094   typedef typename GridImp::template Codim<cdim>::Entity Entity;
00095   typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<cdim>::InterfaceType ElementType;  
00096 
00098   ALU2dGridLeafIterator(const FactoryType& factory, bool end);
00099   
00101   ALU2dGridLeafIterator(const ThisType & org);
00102 
00104   void increment ();
00105 
00107   ThisType & operator = (const ThisType & org);
00108 
00109 private:
00111   bool endIter_;
00113   int level_;    
00114   ElementType * elem_;   
00115   typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
00116   // Listwalkptr, behaves like a proxy for Leafwalk and Levelwalk Ptrs
00117   IteratorType iter_;
00118   
00119   // for the codim 2 case
00120   LeafMarkerVectorType & marker_;
00121 };  // end ALU2dGridLeafIterator
00122 
00123 
00124 //********************************************************************
00125 //  --ALU2dGridLeafIterator
00126 //  --LeafIterator   
00127 //  --specialized for codim = 1
00128 //
00129 //********************************************************************
00130 
00131 template<PartitionIteratorType pitype, class GridImp>
00132 class ALU2dGridLeafIterator<1,pitype,GridImp>
00133 : public ALU2dGridEntityPointer<1,GridImp>
00134   // public LeafIteratorDefaultImplementation<1, pitype, GridImp, ALU2dGridLeafIterator> 
00135 {
00136   static const int dim = GridImp::dimension;
00137   static const int dimworld  = GridImp::dimensionworld;
00138   static const ALU2DSPACE ElementType eltype = GridImp::elementType;
00139   static const int codim = 1;
00140 
00141   friend class ALU2dGridEntity<0,dimworld,GridImp>;
00142   friend class ALU2dGridEntity<1,dimworld,GridImp>;
00143   friend class ALU2dGridEntity<dim,dimworld,GridImp>;  
00144   friend class ALU2dGrid< dim, dimworld, eltype >;
00145     
00146   typedef ALU2dGridEntityPointer<1,GridImp> EntityPointerType;  
00147   typedef ALU2dGridEntity<1,dim,GridImp> EntityImp;      
00148 
00149   typedef ALU2dGridLeafIterator<1, pitype, GridImp> ThisType;
00150 
00151   typedef typename GridImp :: ALU2dGridLeafMarkerVectorType LeafMarkerVectorType;
00152  
00153  public:
00154   typedef typename GridImp :: GridObjectFactoryType  FactoryType;
00155 
00157   typedef typename GridImp::template Codim<1>::Entity Entity;
00158   typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<1>::InterfaceType ElementType;  
00159 
00161   ALU2dGridLeafIterator(const FactoryType& factory, bool end);
00162   
00164   ALU2dGridLeafIterator(const ThisType & org);
00165 
00167   void increment ();
00168 
00170   ThisType & operator = (const ThisType & org);
00171 
00172 private:  
00173   int goNextElement();
00174 
00176   bool endIter_;
00178   int level_; 
00180   int face_;  
00181     
00183   ElementType * elem_;
00184    
00185   typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
00186 
00187   // Listwalkptr, behaves like a proxy for Leafwalk and Levelwalk Ptrs
00188   IteratorType iter_;
00189 
00190   // for the codim 1 case
00191   LeafMarkerVectorType & marker_;
00192 
00193 };  // end ALU2dGridLeafIterator
00194 
00195 //**********************************************************************
00196 //
00197 // --ALU2dGridLevelIterator
00198 // --LevelIterator, specialized for cd=0
00199 //**********************************************************************
00200 
00201 template<PartitionIteratorType pitype, class GridImp>
00202 class ALU2dGridLevelIterator<0, pitype, GridImp>
00203 : public ALU2dGridEntityPointer<0,GridImp>
00204   // public LevelIteratorDefaultImplementation <0, pitype, GridImp, ALU2dGridLevelIterator>
00205 {
00206   static const int dim = GridImp::dimension;
00207   static const int dimworld  = GridImp::dimensionworld;
00208   static const ALU2DSPACE ElementType eltype = GridImp::elementType;
00209   static const int codim = 0;
00210   
00211   friend class ALU2dGridEntity<dim,dimworld,GridImp>;
00212   friend class ALU2dGridEntity<1,dimworld,GridImp>;
00213   friend class ALU2dGridEntity<0,dimworld,GridImp>;
00214   friend class ALU2dGrid< dim, dimworld, eltype >;
00215   
00216   typedef ALU2dGridEntityPointer<codim,GridImp> EntityPointerType; 
00217   typedef ALU2dGridEntity<codim,dim,GridImp> EntityImp;      
00218   
00219   typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType;
00220   typedef ALU2dGridLevelIterator<0,pitype,GridImp> ThisType; 
00221   
00222 public:  
00223   typedef typename GridImp :: GridObjectFactoryType  FactoryType;
00224 
00225   typedef typename GridImp::template Codim<codim>::Entity Entity;
00226  
00228   ALU2dGridLevelIterator(const FactoryType& factory, int level, bool end);  
00229     
00231   ALU2dGridLevelIterator(const ThisType & org);      
00232   
00234   void increment ();
00235 
00237   ThisType & operator = (const ThisType & org);
00238 
00239 private:
00241   bool endIter_;
00243   int level_; 
00244   
00246   HElementType * item_;  
00247   
00249   typedef typename Dune::ALU2dImplTraits< dimworld, eltype  >::template Codim<0>::InterfaceType ElementType;   
00250   typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
00251   IteratorType iter_;  
00252   
00253 }; 
00254 
00255 //**********************************************************************
00256 //
00257 // --ALU2dGridLevelIterator
00258 // --LevelIterator, specialized for cd=1
00259 //**********************************************************************
00260 
00261 template<PartitionIteratorType pitype, class GridImp>
00262 class ALU2dGridLevelIterator<1, pitype, GridImp>
00263 : public ALU2dGridEntityPointer<1,GridImp> 
00264   // public LevelIteratorDefaultImplementation <1, pitype, GridImp, ALU2dGridLevelIterator>
00265 {
00266   static const int dim = GridImp::dimension;
00267   static const int dimworld  = GridImp::dimensionworld;
00268   static const ALU2DSPACE ElementType eltype = GridImp::elementType;
00269   static const int codim = 1;
00270   
00271   friend class ALU2dGridEntity<dim,dimworld,GridImp>;
00272   friend class ALU2dGridEntity<1,dimworld,GridImp>;
00273   friend class ALU2dGridEntity<0,dimworld,GridImp>;
00274   friend class ALU2dGrid< dim, dimworld, eltype >;
00275   
00276   typedef ALU2dGridEntityPointer<codim,GridImp> EntityPointerType; 
00277   typedef ALU2dGridEntity<codim,dim,GridImp> EntityImp;      
00278   
00279   typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType;
00280   
00281   typedef ALU2dGridLevelIterator<1,pitype,GridImp> ThisType; 
00282 public:  
00283   typedef typename GridImp :: GridObjectFactoryType  FactoryType;
00284 
00285   typedef typename GridImp::template Codim<codim>::Entity Entity;
00286  
00288   ALU2dGridLevelIterator(const FactoryType& factroy, int level, bool end);  
00289     
00291   ALU2dGridLevelIterator(const ThisType & org);      
00292   
00293   ~ALU2dGridLevelIterator();      
00294   
00296   void increment ();
00297 
00299   ThisType & operator = (const ThisType & org);
00300 
00301 private:
00303   bool endIter_;
00305   int level_; 
00307   int myFace_;  
00308 
00309   // current item 
00310   HElementType * item_;  
00312   typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<1>::InterfaceType ElementType;  
00313   ElementType * elem_;
00314   // Listwalkptr is a proxy for iterator pointers 
00315   typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
00316 
00317   IteratorType iter_;  
00318   
00319   ALU2dGridMarkerVector * marker_;
00320 
00321   ALU2dGridMarkerVector & marker() 
00322   { 
00323     assert( marker_ );
00324     return *marker_; 
00325   }
00326 }; 
00327 
00328 //**********************************************************************
00329 //
00330 // --ALU2dGridLevelIterator
00331 // --LevelIterator, specialized for cd=2
00332 //**********************************************************************
00333 
00334 template<PartitionIteratorType pitype, class GridImp>
00335 class ALU2dGridLevelIterator<2, pitype, GridImp>
00336 : public ALU2dGridEntityPointer<2,GridImp>
00337   // public LevelIteratorDefaultImplementation <2, pitype, GridImp, ALU2dGridLevelIterator>
00338 {
00339   static const int dim = GridImp::dimension;
00340   static const int dimworld  = GridImp::dimensionworld;
00341   static const ALU2DSPACE ElementType eltype = GridImp::elementType;
00342   static const int codim = 2;
00343   
00344   friend class ALU2dGridEntity<dim,dimworld,GridImp>;
00345   friend class ALU2dGridEntity<1,dimworld,GridImp>;
00346   friend class ALU2dGridEntity<0,dimworld,GridImp>;
00347   friend class ALU2dGrid< dim, dimworld, eltype >;
00348   
00349   typedef ALU2dGridEntityPointer<codim,GridImp> EntityPointerType; 
00350   typedef ALU2dGridEntity<codim,dim,GridImp> EntityImp;      
00351   
00352   typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
00353   typedef ALU2dGridLevelIterator<2,pitype,GridImp> ThisType; 
00354   
00355 public:  
00356   typedef typename GridImp :: GridObjectFactoryType  FactoryType;
00357 
00358   typedef typename GridImp::template Codim<codim>::Entity Entity;
00359  
00361   ALU2dGridLevelIterator(const FactoryType& factory, int level, bool end);  
00362     
00364   ALU2dGridLevelIterator(const ThisType & org);      
00365   
00366   ~ALU2dGridLevelIterator();      
00367   
00369   void increment ();
00370 
00372   ThisType & operator = (const ThisType & org);
00373 
00374 private:
00376   bool endIter_;
00378   int level_; 
00380   int myFace_;  
00382     
00384   typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<0>::InterfaceType ElementType;
00385   typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<2>::InterfaceType VertexType;
00386 
00387   HElementType * item_;
00388   VertexType * vertex_;
00389   
00390  
00391   typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
00392   IteratorType iter_;  
00393   
00394   // marker vector to tell on which element vertex is visited 
00395   ALU2dGridMarkerVector * marker_;
00396   ALU2dGridMarkerVector & marker() 
00397   { 
00398     assert( marker_ );
00399     return *marker_; 
00400   }
00401 }; 
00402 
00403 //***************************************************************
00404 //
00405 // - HierarchicIteraror
00406 // --HierarchicIterator
00407 //***************************************************************
00408 
00410 template<class GridImp>
00411 class ALU2dGridHierarchicIterator
00412 : public ALU2dGridEntityPointer<0,GridImp>
00413   // public HierarchicIteratorDefaultImplementation <GridImp,ALU2dGridHierarchicIterator>
00414 {
00415   typedef ALU2dGridHierarchicIterator<GridImp> ThisType;
00416 
00417   static const int dim = GridImp::dimension;
00418   static const int dimworld  = GridImp::dimensionworld;
00419   static const ALU2DSPACE ElementType eltype = GridImp::elementType;
00420   static const int codim = 2;
00421   
00422   typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
00423   
00424 public:
00425   typedef typename GridImp :: GridObjectFactoryType  FactoryType;
00426 
00428   typedef typename GridImp::template Codim<0>::Entity Entity;
00430   typedef typename GridImp::ctype ctype;
00432   typedef ALU2dGridEntity<0,dim,GridImp> EntityImp;
00433 
00435   ALU2dGridHierarchicIterator(const FactoryType& factory, 
00436                               const HElementType & elem, int maxlevel, bool end=false);
00437   
00439   ALU2dGridHierarchicIterator(const ALU2dGridHierarchicIterator<GridImp> &org);
00440     
00442   void increment();
00443   
00445   ThisType & operator = (const ALU2dGridHierarchicIterator<GridImp> &org)
00446   {
00447     ALU2dGridEntityPointer<0,GridImp> :: operator = (org);
00448     elem_ = org.elem_;
00449     maxlevel_= org.maxlevel_;
00450     endIter_ = org.endIter_;
00451     return *this;
00452   };
00453   
00454 private:
00455 
00457   HElementType * goNextElement (HElementType * oldEl);
00458     
00460   const HElementType * elem_;
00461      
00463   int maxlevel_;
00465   bool endIter_;
00466 };  // end ALU2dHierarchicIterator 
00467 
00468 } // end namespace Dune
00469 
00470 #include "iterator_imp.cc"
00471 
00472 #endif // #ifndef DUNE_ALU2DGRID_ITERATOR_HH

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].