dune-grid  2.7.0
hierarchiciterator.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH
4 #define DUNE_ALBERTA_HIERARCHICITERATOR_HH
5 
8 
9 #if HAVE_ALBERTA
10 
11 namespace Dune
12 {
13 
14  // AlbertaGridHierarchicIterator
15  // -----------------------------
16 
25  template< class GridImp >
26  class AlbertaGridHierarchicIterator
27  {
28  typedef AlbertaGridHierarchicIterator< GridImp > This;
29 
30  public:
31  typedef typename GridImp::template Codim<0>::Entity Entity;
32  typedef typename GridImp::ctype ctype;
33 
34  typedef MakeableInterfaceObject< Entity > EntityObject;
35  typedef typename EntityObject::ImplementationType EntityImp;
36 
37  typedef typename EntityImp::ElementInfo ElementInfo;
38 
39  AlbertaGridHierarchicIterator ()
40  {}
41 
43  AlbertaGridHierarchicIterator ( const GridImp &grid,
44  const ElementInfo &elementInfo,
45  int maxLevel );
46 
48  AlbertaGridHierarchicIterator ( const GridImp &grid, int actLevel, int maxLevel );
49 
51  AlbertaGridHierarchicIterator ( const This &other );
52 
54  This &operator= ( const This &other );
55 
57  void increment();
58 
60  bool equals ( const This &other ) const
61  {
62  return entity_.impl().equals( other.entity_.impl() );
63  }
64 
66  Entity &dereference () const
67  {
68  return entity_;
69  }
70 
72  int level () const
73  {
74  return entity_.impl().level();
75  }
76 
77  protected:
79  const GridImp &grid () const
80  {
81  return entity_.impl().grid();
82  }
83 
84  private:
85  void increment ( ElementInfo elementInfo );
86 
87  mutable Entity entity_;
88 
89  // level on which the iterator was started
90  int startLevel_;
91 
92  // maximal level to go down to
93  int maxlevel_;
94  };
95 
96 
97  template< class GridImp >
98  inline AlbertaGridHierarchicIterator< GridImp >
99  ::AlbertaGridHierarchicIterator( const GridImp &grid, int actLevel, int maxLevel )
100  : entity_( EntityImp( grid ) ),
101  startLevel_( actLevel ),
102  maxlevel_( maxLevel )
103  {}
104 
105 
106  template< class GridImp >
107  inline AlbertaGridHierarchicIterator< GridImp >
108  ::AlbertaGridHierarchicIterator ( const GridImp &grid,
109  const ElementInfo &elementInfo,
110  int maxLevel )
111  : entity_( EntityImp( grid ) ),
112  startLevel_( elementInfo.level() ),
113  maxlevel_( maxLevel )
114  {
115  increment( elementInfo );
116  }
117 
118 
119  template< class GridImp >
120  inline AlbertaGridHierarchicIterator< GridImp >
121  ::AlbertaGridHierarchicIterator( const This &other )
122  : entity_( other.entity_ ),
123  startLevel_( other.startLevel_ ),
124  maxlevel_( other.maxlevel_ )
125  {}
126 
127 
128  template< class GridImp >
129  inline typename AlbertaGridHierarchicIterator< GridImp >::This &
130  AlbertaGridHierarchicIterator< GridImp >::operator= ( const This &other )
131  {
132  entity_ = other.entity_;
133  startLevel_ = other.startLevel_;
134  maxlevel_ = other.maxlevel_;
135  return *this;
136  }
137 
138 
139  template< class GridImp >
140  inline void AlbertaGridHierarchicIterator< GridImp >::increment ()
141  {
142  increment( entity_.impl().elementInfo() );
143  }
144 
145  template< class GridImp >
146  inline void AlbertaGridHierarchicIterator< GridImp >
147  ::increment ( ElementInfo elementInfo )
148  {
149  assert( !elementInfo == false );
150  if( (elementInfo.level() >= maxlevel_) || elementInfo.isLeaf() )
151  {
152  while( (elementInfo.level() > startLevel_) && (elementInfo.indexInFather() == 1) )
153  elementInfo = elementInfo.father();
154  if( elementInfo.level() > startLevel_ )
155  entity_.impl().setElement( elementInfo.father().child( 1 ), 0 );
156  else
157  entity_.impl().clearElement();
158  }
159  else
160  entity_.impl().setElement( elementInfo.child( 0 ), 0 );
161  }
162 
163 }
164 
165 #endif // #if HAVE_ALBERTA
166 
167 #endif // #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH
elementinfo.hh
provides a wrapper for ALBERTA's el_info structure
entityiterator.hh
Dune
Include standard header files.
Definition: agrid.hh:58