albertagrid/hierarchiciterator.hh
00001 #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH
00002 #define DUNE_ALBERTA_HIERARCHICITERATOR_HH
00003
00004 #include <dune/grid/common/hierarchiciterator.hh>
00005
00006 #include <dune/grid/albertagrid/entitypointer.hh>
00007
00008 namespace Dune
00009 {
00010
00011
00012
00013
00022 template< class GridImp >
00023 class AlbertaGridHierarchicIterator
00024 : public AlbertaGridEntityPointer< 0, GridImp >
00025 {
00026 typedef AlbertaGridHierarchicIterator< GridImp > This;
00027 typedef AlbertaGridEntityPointer< 0, GridImp > Base;
00028
00029 public:
00030 typedef typename GridImp::template Codim<0>::Entity Entity;
00031 typedef typename GridImp::ctype ctype;
00032
00033 typedef MakeableInterfaceObject< Entity > EntityObject;
00034 typedef typename EntityObject::ImplementationType EntityImp;
00035
00036 typedef typename Base::ElementInfo ElementInfo;
00037
00039 AlbertaGridHierarchicIterator ( const GridImp &grid,
00040 const ElementInfo &elementInfo,
00041 int maxLevel );
00042
00044 AlbertaGridHierarchicIterator ( const GridImp &grid, int actLevel, int maxLevel );
00045
00047 AlbertaGridHierarchicIterator ( const This &other );
00048
00050 This &operator= ( const This &other );
00051
00053 void increment();
00054
00055 using Base::level;
00056
00057 protected:
00058 using Base::entityImp;
00059
00060 private:
00061 void increment ( ElementInfo elementInfo );
00062
00063
00064 int startLevel_;
00065
00066
00067 int maxlevel_;
00068 };
00069
00070
00071 template< class GridImp >
00072 inline AlbertaGridHierarchicIterator< GridImp >
00073 ::AlbertaGridHierarchicIterator( const GridImp &grid, int actLevel, int maxLevel )
00074 : Base( grid ),
00075 startLevel_( actLevel ),
00076 maxlevel_( maxLevel )
00077 {}
00078
00079
00080 template< class GridImp >
00081 inline AlbertaGridHierarchicIterator< GridImp >
00082 ::AlbertaGridHierarchicIterator ( const GridImp &grid,
00083 const ElementInfo &elementInfo,
00084 int maxLevel )
00085 : Base( grid ),
00086 startLevel_( elementInfo.level() ),
00087 maxlevel_( maxLevel )
00088 {
00089 increment( elementInfo );
00090 }
00091
00092
00093 template< class GridImp >
00094 inline AlbertaGridHierarchicIterator< GridImp >
00095 ::AlbertaGridHierarchicIterator( const This &other )
00096 : Base( other ),
00097 startLevel_( other.startLevel_ ),
00098 maxlevel_( other.maxlevel_ )
00099 {}
00100
00101
00102 template< class GridImp >
00103 inline typename AlbertaGridHierarchicIterator< GridImp >::This &
00104 AlbertaGridHierarchicIterator< GridImp >::operator= ( const This &other )
00105 {
00106 Base::operator=( other );
00107
00108 startLevel_ = other.startLevel_;
00109 maxlevel_ = other.maxlevel_;
00110 return *this;
00111 }
00112
00113
00114 template< class GridImp >
00115 inline void AlbertaGridHierarchicIterator< GridImp >::increment ()
00116 {
00117 increment( entityImp().elementInfo() );
00118 }
00119
00120 template< class GridImp >
00121 inline void AlbertaGridHierarchicIterator< GridImp >
00122 ::increment ( ElementInfo elementInfo )
00123 {
00124 assert( !elementInfo == false );
00125 if( (elementInfo.level() >= maxlevel_) || elementInfo.isLeaf() )
00126 {
00127 while( (elementInfo.level() > startLevel_) && (elementInfo.indexInFather() == 1) )
00128 elementInfo = elementInfo.father();
00129 if( elementInfo.level() > startLevel_ )
00130 entityImp().setElement( elementInfo.father().child( 1 ), 0 );
00131 else
00132 entityImp().clearElement();
00133 }
00134 else
00135 entityImp().setElement( elementInfo.child( 0 ), 0 );
00136 }
00137
00138 }
00139
00140 #endif