dune-grid  2.2.1
albertagrid/hierarchiciterator.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH
2 #define DUNE_ALBERTA_HIERARCHICITERATOR_HH
3 
5 
7 
8 #if HAVE_ALBERTA
9 
10 namespace Dune
11 {
12 
13  // AlbertaGridHierarchicIterator
14  // -----------------------------
15 
24  template< class GridImp >
25  class AlbertaGridHierarchicIterator
26  : public AlbertaGridEntityPointer< 0, GridImp >
27  {
28  typedef AlbertaGridHierarchicIterator< GridImp > This;
29  typedef AlbertaGridEntityPointer< 0, GridImp > Base;
30 
31  public:
32  typedef typename GridImp::template Codim<0>::Entity Entity;
33  typedef typename GridImp::ctype ctype;
34 
37 
38  typedef typename Base::ElementInfo ElementInfo;
39 
41  AlbertaGridHierarchicIterator ( const GridImp &grid,
42  const ElementInfo &elementInfo,
43  int maxLevel );
44 
46  AlbertaGridHierarchicIterator ( const GridImp &grid, int actLevel, int maxLevel );
47 
49  AlbertaGridHierarchicIterator ( const This &other );
50 
52  This &operator= ( const This &other );
53 
55  void increment();
56 
57  using Base::level;
58 
59  protected:
60  using Base::entityImp;
61 
62  private:
63  void increment ( ElementInfo elementInfo );
64 
65  // level on which the iterator was started
66  int startLevel_;
67 
68  // maximal level to go down to
69  int maxlevel_;
70  };
71 
72 
73  template< class GridImp >
75  ::AlbertaGridHierarchicIterator( const GridImp &grid, int actLevel, int maxLevel )
76  : Base( grid ),
77  startLevel_( actLevel ),
78  maxlevel_( maxLevel )
79  {}
80 
81 
82  template< class GridImp >
84  ::AlbertaGridHierarchicIterator ( const GridImp &grid,
85  const ElementInfo &elementInfo,
86  int maxLevel )
87  : Base( grid ),
88  startLevel_( elementInfo.level() ),
89  maxlevel_( maxLevel )
90  {
91  increment( elementInfo );
92  }
93 
94 
95  template< class GridImp >
98  : Base( other ),
99  startLevel_( other.startLevel_ ),
100  maxlevel_( other.maxlevel_ )
101  {}
102 
103 
104  template< class GridImp >
107  {
108  Base::operator=( other );
109 
110  startLevel_ = other.startLevel_;
111  maxlevel_ = other.maxlevel_;
112  return *this;
113  }
114 
115 
116  template< class GridImp >
118  {
119  increment( entityImp().elementInfo() );
120  }
121 
122  template< class GridImp >
124  ::increment ( ElementInfo elementInfo )
125  {
126  assert( !elementInfo == false );
127  if( (elementInfo.level() >= maxlevel_) || elementInfo.isLeaf() )
128  {
129  while( (elementInfo.level() > startLevel_) && (elementInfo.indexInFather() == 1) )
130  elementInfo = elementInfo.father();
131  if( elementInfo.level() > startLevel_ )
132  entityImp().setElement( elementInfo.father().child( 1 ), 0 );
133  else
134  entityImp().clearElement();
135  }
136  else
137  entityImp().setElement( elementInfo.child( 0 ), 0 );
138  }
139 
140 }
141 
142 #endif // #if HAVE_ALBERTA
143 
144 #endif // #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH