treeiterator.hh
00001 #ifndef DUNE_ALBERTA_TREEITERATOR_HH
00002 #define DUNE_ALBERTA_TREEITERATOR_HH
00003
00004 #include <dune/grid/albertagrid/meshpointer.hh>
00005 #include <dune/grid/albertagrid/entitypointer.hh>
00006
00007 namespace Dune
00008 {
00009
00010
00011
00012
00021 template< int dim, int dimworld >
00022 class AlbertaMarkerVector
00023 {
00024 typedef AlbertaMarkerVector< dim, dimworld > This;
00025
00026 typedef AlbertaGrid< dim, dimworld > Grid;
00027
00028
00029
00030 static const int dimension = Grid::dimension;
00031
00032 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
00033 typedef Alberta::ElementInfo< dimension > ElementInfo;
00034
00035 template< bool >
00036 struct NoMarkSubEntities;
00037 template< bool >
00038 struct MarkSubEntities;
00039
00040 public:
00042 explicit AlbertaMarkerVector ( const DofNumbering &dofNumbering )
00043 : dofNumbering_( dofNumbering )
00044 {
00045 for( int codim = 0; codim <= dimension; ++codim )
00046 marker_[ codim ] = 0;
00047 }
00048
00049 AlbertaMarkerVector ( const This &other )
00050 : dofNumbering_( other.dofNumbering_ )
00051 {
00052 for( int codim = 0; codim <= dimension; ++codim )
00053 marker_[ codim ] = 0;
00054 }
00055
00056 ~AlbertaMarkerVector ()
00057 {
00058 clear();
00059 }
00060
00061 private:
00062 This &operator= ( const This & );
00063
00064 public:
00066 template< int codim >
00067 bool subEntityOnElement ( const ElementInfo &elementInfo, int subEntity ) const;
00068
00069 template< int firstCodim, class Iterator >
00070 void markSubEntities ( const Iterator &begin, const Iterator &end );
00071
00072 void clear ()
00073 {
00074 for( int codim = 0; codim <= dimension; ++codim )
00075 {
00076 if( marker_[ codim ] != 0 )
00077 delete[] marker_[ codim ];
00078 marker_[ codim ] = 0;
00079 }
00080 }
00081
00083 bool up2Date () const
00084 {
00085 return (marker_[ dimension ] != 0);
00086 }
00087
00089 void print ( std::ostream &out = std::cout ) const;
00090
00091 private:
00092 const DofNumbering &dofNumbering_;
00093 int *marker_[ dimension+1 ];
00094 };
00095
00096
00097
00098
00099
00100
00104 template< int codim, class GridImp, bool leafIterator >
00105 class AlbertaGridTreeIterator
00106 : public AlbertaGridEntityPointer< codim, GridImp >
00107 {
00108 typedef AlbertaGridTreeIterator< codim, GridImp, leafIterator > This;
00109 typedef AlbertaGridEntityPointer< codim, GridImp > Base;
00110
00111 public:
00112 static const int dimension = GridImp::dimension;
00113 static const int codimension = codim;
00114 static const int dimensionworld = GridImp::dimensionworld;
00115
00116 private:
00117 friend class AlbertaGrid< dimension, dimensionworld >;
00118
00119 static const int numSubEntities
00120 = Alberta::NumSubEntities< dimension, codimension >::value;
00121
00122 public:
00123 typedef typename Base::ElementInfo ElementInfo;
00124 typedef Alberta::MeshPointer< dimension > MeshPointer;
00125 typedef typename MeshPointer::MacroIterator MacroIterator;
00126
00127 typedef typename GridImp::template Codim< codim >::Entity Entity;
00128 typedef MakeableInterfaceObject< Entity > EntityObject;
00129 typedef typename EntityObject::ImplementationType EntityImp;
00130
00131 typedef AlbertaMarkerVector< dimension, dimensionworld > MarkerVector;
00132
00134 AlbertaGridTreeIterator ( const This &other );
00135
00137 This &operator= ( const This &other );
00138
00140 AlbertaGridTreeIterator ( const GridImp &grid, int travLevel );
00141
00143 AlbertaGridTreeIterator ( const GridImp &grid,
00144 const MarkerVector *marker,
00145 int travLevel );
00146
00148 void increment();
00149
00150 protected:
00151 using Base::entityImp;
00152 using Base::grid;
00153
00154 private:
00155 void nextElement ( ElementInfo &elementInfo );
00156 void nextElementStop (ElementInfo &elementInfo );
00157 bool stopAtElement ( const ElementInfo &elementInfo ) const;
00158
00159 void goNext ( ElementInfo &elementInfo );
00160 void goNext ( const Int2Type< 0 > cdVariable, ElementInfo &elementInfo );
00161 void goNext ( const Int2Type< 1 > cdVariable, ElementInfo &elementInfo );
00162 template< int cd >
00163 void goNext ( const Int2Type< cd > cdVariable, ElementInfo &elementInfo );
00164
00166 int level_;
00167
00169 int subEntity_;
00170
00171 MacroIterator macroIterator_;
00172
00173
00174 const MarkerVector *marker_;
00175 };
00176
00177 }
00178
00179 #endif