dune-foamgrid  2.7-git
foamgridhierarchiciterator.hh
Go to the documentation of this file.
1 #ifndef DUNE_FOAMGRID_HIERARCHIC_ITERATOR_HH
2 #define DUNE_FOAMGRID_HIERARCHIC_ITERATOR_HH
3 
8 #include <stack>
9 
10 namespace Dune {
11 
12 
13 //**********************************************************************
14 //
22 template<class GridImp>
24 {
25  enum {dimworld = GridImp::dimensionworld};
26  enum {dimgrid = GridImp::dimension};
27 
28  friend class FoamGridEntity<0, dimgrid,GridImp>;
29 
31 
32 public:
33  using Entity = typename GridImp::template Codim<0>::Entity;
34 
36  enum { codimension = 0 };
37 
40  : maxlevel_(maxlevel)
41  {
42  virtualEntity_.impl().setToTarget(nullptr);
43  }
44 
46  void increment()
47  {
48  if (elemStack.empty())
49  return;
50 
51  StackEntry old_target = elemStack.top();
52  elemStack.pop();
53 
54  // Traverse the tree no deeper than maxlevel
55  if (old_target->level_ < maxlevel_) {
56 
57  // Load sons of old target onto the iterator stack
58  if (!old_target->isLeaf())
59  for (size_t i=0; i<old_target->nSons(); i++)
60  elemStack.push(old_target->sons_[i]);
61  }
62 
63  virtualEntity_.impl().setToTarget(elemStack.empty() ?
64  nullptr : elemStack.top());
65  }
66 
68  const Entity& dereference() const { return virtualEntity_; }
69 
71  bool equals(const FoamGridHierarchicIterator<GridImp>& other) const {
72  return virtualEntity_ == other.virtualEntity_;
73  }
74 
75 private:
77  Entity virtualEntity_;
78 
80  int maxlevel_;
81 
83  std::stack<StackEntry> elemStack;
84 };
85 
86 
87 } // end namespace Dune
88 
89 #endif
Definition: dgffoam.cc:6
The implementation of entities in a FoamGrid.
Definition: foamgridentity.hh:54
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: foamgridhierarchiciterator.hh:24
bool equals(const FoamGridHierarchicIterator< GridImp > &other) const
equality
Definition: foamgridhierarchiciterator.hh:71
void increment()
Definition: foamgridhierarchiciterator.hh:46
@ codimension
Definition: foamgridhierarchiciterator.hh:36
typename GridImp::template Codim< 0 >::Entity Entity
Definition: foamgridhierarchiciterator.hh:33
FoamGridHierarchicIterator(int maxlevel)
Constructor.
Definition: foamgridhierarchiciterator.hh:39
const Entity & dereference() const
dereferencing
Definition: foamgridhierarchiciterator.hh:68
The actual entity implementation.
Definition: foamgridvertex.hh:47