dune-grid
2.1.1
|
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 #if HAVE_ALBERTA 00009 00010 namespace Dune 00011 { 00012 00013 // AlbertaGridHierarchicIterator 00014 // ----------------------------- 00015 00024 template< class GridImp > 00025 class AlbertaGridHierarchicIterator 00026 : public AlbertaGridEntityPointer< 0, GridImp > 00027 { 00028 typedef AlbertaGridHierarchicIterator< GridImp > This; 00029 typedef AlbertaGridEntityPointer< 0, GridImp > Base; 00030 00031 public: 00032 typedef typename GridImp::template Codim<0>::Entity Entity; 00033 typedef typename GridImp::ctype ctype; 00034 00035 typedef MakeableInterfaceObject< Entity > EntityObject; 00036 typedef typename EntityObject::ImplementationType EntityImp; 00037 00038 typedef typename Base::ElementInfo ElementInfo; 00039 00041 AlbertaGridHierarchicIterator ( const GridImp &grid, 00042 const ElementInfo &elementInfo, 00043 int maxLevel ); 00044 00046 AlbertaGridHierarchicIterator ( const GridImp &grid, int actLevel, int maxLevel ); 00047 00049 AlbertaGridHierarchicIterator ( const This &other ); 00050 00052 This &operator= ( const This &other ); 00053 00055 void increment(); 00056 00057 using Base::level; 00058 00059 protected: 00060 using Base::entityImp; 00061 00062 private: 00063 void increment ( ElementInfo elementInfo ); 00064 00065 // level on which the iterator was started 00066 int startLevel_; 00067 00068 // maximal level to go down to 00069 int maxlevel_; 00070 }; 00071 00072 00073 template< class GridImp > 00074 inline AlbertaGridHierarchicIterator< GridImp > 00075 ::AlbertaGridHierarchicIterator( const GridImp &grid, int actLevel, int maxLevel ) 00076 : Base( grid ), 00077 startLevel_( actLevel ), 00078 maxlevel_( maxLevel ) 00079 {} 00080 00081 00082 template< class GridImp > 00083 inline AlbertaGridHierarchicIterator< GridImp > 00084 ::AlbertaGridHierarchicIterator ( const GridImp &grid, 00085 const ElementInfo &elementInfo, 00086 int maxLevel ) 00087 : Base( grid ), 00088 startLevel_( elementInfo.level() ), 00089 maxlevel_( maxLevel ) 00090 { 00091 increment( elementInfo ); 00092 } 00093 00094 00095 template< class GridImp > 00096 inline AlbertaGridHierarchicIterator< GridImp > 00097 ::AlbertaGridHierarchicIterator( const This &other ) 00098 : Base( other ), 00099 startLevel_( other.startLevel_ ), 00100 maxlevel_( other.maxlevel_ ) 00101 {} 00102 00103 00104 template< class GridImp > 00105 inline typename AlbertaGridHierarchicIterator< GridImp >::This & 00106 AlbertaGridHierarchicIterator< GridImp >::operator= ( const This &other ) 00107 { 00108 Base::operator=( other ); 00109 00110 startLevel_ = other.startLevel_; 00111 maxlevel_ = other.maxlevel_; 00112 return *this; 00113 } 00114 00115 00116 template< class GridImp > 00117 inline void AlbertaGridHierarchicIterator< GridImp >::increment () 00118 { 00119 increment( entityImp().elementInfo() ); 00120 } 00121 00122 template< class GridImp > 00123 inline void AlbertaGridHierarchicIterator< GridImp > 00124 ::increment ( ElementInfo elementInfo ) 00125 { 00126 assert( !elementInfo == false ); 00127 if( (elementInfo.level() >= maxlevel_) || elementInfo.isLeaf() ) 00128 { 00129 while( (elementInfo.level() > startLevel_) && (elementInfo.indexInFather() == 1) ) 00130 elementInfo = elementInfo.father(); 00131 if( elementInfo.level() > startLevel_ ) 00132 entityImp().setElement( elementInfo.father().child( 1 ), 0 ); 00133 else 00134 entityImp().clearElement(); 00135 } 00136 else 00137 entityImp().setElement( elementInfo.child( 0 ), 0 ); 00138 } 00139 00140 } 00141 00142 #endif // #if HAVE_ALBERTA 00143 00144 #endif // #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH