dune-foamgrid  2.8-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  static constexpr int dimworld = GridImp::dimensionworld;
26  static constexpr int dimgrid = GridImp::dimension;
27 
28  using EntityImpPointer = const FoamGridEntityImp<
29  dimgrid, dimgrid, dimworld, typename GridImp::ctype
30  >*;
31 
32 public:
33  using Entity = typename GridImp::template Codim<0>::Entity;
34 
36  enum { codimension = 0 };
37 
40  : maxLevel_(maxLevel)
41  {
42  // Load sons of target onto the iterator stack
43  stackChildren_(target);
44 
45  // Set entity target to the next child if exists
46  resetEntity_();
47  }
48 
51  : maxLevel_(maxLevel)
52  {
53  resetEntity_();
54  }
55 
57  void increment()
58  {
59  if (elemStack_.empty())
60  return;
61 
62  auto target = elemStack_.top();
63  elemStack_.pop();
64 
65  // Load sons of previous target onto the iterator stack
66  stackChildren_(target);
67 
68  // Set entity target to the next stacked element if exists
69  resetEntity_();
70  }
71 
73  const Entity& dereference() const { return virtualEntity_; }
74 
77  { return virtualEntity_ == other.virtualEntity_; }
78 
79 private:
80  void stackChildren_(EntityImpPointer target)
81  {
82  // Load sons of target onto the iterator stack
83  if (target->level() < maxLevel_ && !target->isLeaf())
84  for (std::size_t i = 0; i < target->nSons(); i++)
85  elemStack_.push(target->sons_[i]);
86  }
87 
88  void resetEntity_()
89  {
90  virtualEntity_.impl().setToTarget(
91  elemStack_.empty() ? nullptr : elemStack_.top()
92  );
93  }
94 
96  Entity virtualEntity_;
97 
99  int maxLevel_;
100 
102  std::stack<EntityImpPointer> elemStack_;
103 };
104 
105 
106 } // end namespace Dune
107 
108 #endif
Definition: dgffoam.cc:6
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:76
void increment()
Definition: foamgridhierarchiciterator.hh:57
@ codimension
Definition: foamgridhierarchiciterator.hh:36
FoamGridHierarchicIterator(int maxLevel)
Constructor without valid element (end iterator)
Definition: foamgridhierarchiciterator.hh:50
typename GridImp::template Codim< 0 >::Entity Entity
Definition: foamgridhierarchiciterator.hh:33
const Entity & dereference() const
dereferencing
Definition: foamgridhierarchiciterator.hh:73
FoamGridHierarchicIterator(EntityImpPointer target, int maxLevel)
Constructor with element impl (begin iterator)
Definition: foamgridhierarchiciterator.hh:39
The actual entity implementation.
Definition: foamgridvertex.hh:47