dune-grid  2.6-git
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 
36 
37  typedef typename EntityImp::ElementInfo ElementInfo;
38 
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 entityImp().equals( other.entityImp() );
63  }
64 
66  Entity &dereference () const
67  {
68  return entity_;
69  }
70 
72  int level () const
73  {
74  return entityImp().level();
75  }
76 
77  protected:
79  EntityImp &entityImp ()
80  {
81  return GridImp::getRealImplementation( entity_ );
82  }
83 
85  const EntityImp &entityImp () const
86  {
87  return GridImp::getRealImplementation( entity_ );
88  }
89 
91  const GridImp &grid () const
92  {
93  return entityImp().grid();
94  }
95 
96  private:
97  void increment ( ElementInfo elementInfo );
98 
99  mutable Entity entity_;
100 
101  // level on which the iterator was started
102  int startLevel_;
103 
104  // maximal level to go down to
105  int maxlevel_;
106  };
107 
108 
109  template< class GridImp >
111  ::AlbertaGridHierarchicIterator( const GridImp &grid, int actLevel, int maxLevel )
112  : entity_( EntityImp( grid ) ),
113  startLevel_( actLevel ),
114  maxlevel_( maxLevel )
115  {}
116 
117 
118  template< class GridImp >
121  const ElementInfo &elementInfo,
122  int maxLevel )
123  : entity_( EntityImp( grid ) ),
124  startLevel_( elementInfo.level() ),
125  maxlevel_( maxLevel )
126  {
127  increment( elementInfo );
128  }
129 
130 
131  template< class GridImp >
134  : entity_( other.entity_ ),
135  startLevel_( other.startLevel_ ),
136  maxlevel_( other.maxlevel_ )
137  {}
138 
139 
140  template< class GridImp >
143  {
144  entity_ = other.entity_;
145  startLevel_ = other.startLevel_;
146  maxlevel_ = other.maxlevel_;
147  return *this;
148  }
149 
150 
151  template< class GridImp >
153  {
154  increment( entityImp().elementInfo() );
155  }
156 
157  template< class GridImp >
159  ::increment ( ElementInfo elementInfo )
160  {
161  assert( !elementInfo == false );
162  if( (elementInfo.level() >= maxlevel_) || elementInfo.isLeaf() )
163  {
164  while( (elementInfo.level() > startLevel_) && (elementInfo.indexInFather() == 1) )
165  elementInfo = elementInfo.father();
166  if( elementInfo.level() > startLevel_ )
167  entityImp().setElement( elementInfo.father().child( 1 ), 0 );
168  else
169  entityImp().clearElement();
170  }
171  else
172  entityImp().setElement( elementInfo.child( 0 ), 0 );
173  }
174 
175 }
176 
177 #endif // #if HAVE_ALBERTA
178 
179 #endif // #ifndef DUNE_ALBERTA_HIERARCHICITERATOR_HH
Include standard header files.
Definition: agrid.hh:58
const GridImp & grid() const
obtain a reference to the grid
Definition: hierarchiciterator.hh:91
This & operator=(const This &other)
assignment operator
Definition: hierarchiciterator.hh:142
MakeableInterfaceObject< Entity > EntityObject
Definition: hierarchiciterator.hh:34
const EntityImp & entityImp() const
obtain const reference to internal entity implementation
Definition: hierarchiciterator.hh:85
EntityImp & entityImp()
obtain reference to internal entity implementation
Definition: hierarchiciterator.hh:79
EntityObject::ImplementationType EntityImp
Definition: hierarchiciterator.hh:35
Entity & dereference() const
dereferencing
Definition: hierarchiciterator.hh:66
int level() const
ask for level of entities
Definition: hierarchiciterator.hh:72
Entity ::Implementation ImplementationType
Definition: common/grid.hh:1173
provides a wrapper for ALBERTA&#39;s el_info structure
void increment()
increment
Definition: hierarchiciterator.hh:152
GridImp::ctype ctype
Definition: hierarchiciterator.hh:32
Definition: albertagrid/entity.hh:24
EntityImp::ElementInfo ElementInfo
Definition: hierarchiciterator.hh:37
bool equals(const This &other) const
equality
Definition: hierarchiciterator.hh:60
GridImp::template Codim< 0 >::Entity Entity
Definition: hierarchiciterator.hh:31
AlbertaGridHierarchicIterator()
Definition: hierarchiciterator.hh:39