Dune Core Modules (2.8.0)

yaspgridhierarchiciterator.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_GRID_YASPGRIDHIERARCHICITERATOR_HH
4#define DUNE_GRID_YASPGRIDHIERARCHICITERATOR_HH
5
12namespace Dune {
13
16 template<class GridImp>
18 {
19 enum { dim=GridImp::dimension };
20
21 typedef YaspEntity<0,GridImp::dimension,GridImp> YaspEntityImp;
22
23 public:
24 // types used from grids
25 typedef typename GridImp::YGridLevelIterator YGLI;
26 typedef typename GridImp::YGrid::Iterator I;
27 typedef typename GridImp::template Codim<0>::Entity Entity;
28
30 YaspHierarchicIterator () : _entity(), _maxlevel(-1), stack() {}
31
33 YaspHierarchicIterator (const YGLI& g, const I& it, int maxlevel) :
34 _entity(YaspEntity<0, dim, GridImp>(g,it))
35 {
36 // store reference to entity implementation for better readability
37 YaspEntityImp& entity = _entity.impl();
38 // now iterator points to current cell
39 StackElem se(entity._g);
40 std::copy(entity._it.coord().begin(), entity._it.coord().end(), se.coord.begin());
41 stack.push(se);
42
43 // determine maximum level
44 _maxlevel = std::min(maxlevel,entity._g->mg->maxLevel());
45
46 // if maxlevel not reached then push yourself and sons
47 if (entity._g->level()<_maxlevel)
48 {
49 push_sons();
50 }
51
52 // and make iterator point to first son if stack is not empty
53 if (!stack.empty())
54 pop_tos();
55 }
56
58 void increment ()
59 {
60 // sanity check: do nothing when stack is empty
61 if (stack.empty()) return;
62
63 // if maxlevel not reached then push sons
64 if (_entity.impl()._g->level()<_maxlevel)
65 push_sons();
66
67 // in any case pop one element
68 pop_tos();
69 }
70
72 bool equals (const YaspHierarchicIterator& rhs) const
73 {
74 return (_entity == rhs._entity);
75 }
76
78 const Entity& dereference() const
79 {
80 return _entity;
81 }
82
83 void print (std::ostream& s) const
84 {
85 // store reference to entity implementation for better readability
86 YaspEntityImp& entity = _entity.impl();
87 s << "HIER: " << "level=" << entity._g.level()
88 << " position=" << entity._it.coord()
89 << " superindex=" << entity._it.superindex()
90 << " maxlevel=" << entity._maxlevel
91 << " stacksize=" << stack.size()
92 << std::endl;
93 }
94
95 private:
96 Entity _entity;
97
98 int _maxlevel;
99
100 struct StackElem {
101 YGLI g; // grid level of the element
102 std::array<int,dim> coord; // and the coordinates
103 StackElem(YGLI gg) : g(gg) {}
104 };
105 std::stack<StackElem> stack;
106
107 // push sons of current element on the stack
108 void push_sons ()
109 {
110 // store reference to entity implementation for better readability
111 YaspEntityImp& entity = _entity.impl();
112
113 // yes, process all 1<<dim sons
114 YGLI finer = entity._g;
115 ++finer;
116 StackElem se(finer);
117 for (int i=0; i<(1<<dim); i++)
118 {
119 for (int k=0; k<dim; k++)
120 if (i&(1<<k))
121 se.coord[k] = entity._it.coord(k)*2+1;
122 else
123 se.coord[k] = entity._it.coord(k)*2;
124 // not all entities have 2^d subentities due to refineOptions with keep_ovlp==false
125 bool exists = true;
126 for (int k=0; k<dim; k++)
127 if ((se.coord[k] < finer->overlap[0].dataBegin()->origin(k)) || (se.coord[k] >= finer->overlap[0].dataBegin()->origin(k)+finer->overlap[0].dataBegin()->size(k)))
128 exists = false;
129 if (exists)
130 stack.push(se);
131 }
132 }
133
134 // make TOS the current element
135 void pop_tos ()
136 {
137 StackElem se = stack.top();
138 stack.pop();
139 YaspEntityImp& entity = _entity.impl();
140 entity._g = se.g;
141 entity._it.reinit(entity._g->overlap[0],se.coord);
142 }
143 };
144
145} // namespace Dune
146
147#endif // DUNE_GRID_YASPGRIDHIERARCHICITERATOR_HH
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition: yaspgridhierarchiciterator.hh:18
YaspHierarchicIterator()
default constructor creating empty iterator
Definition: yaspgridhierarchiciterator.hh:30
const Entity & dereference() const
dereferencing
Definition: yaspgridhierarchiciterator.hh:78
void increment()
increment
Definition: yaspgridhierarchiciterator.hh:58
bool equals(const YaspHierarchicIterator &rhs) const
equality
Definition: yaspgridhierarchiciterator.hh:72
YaspHierarchicIterator(const YGLI &g, const I &it, int maxlevel)
constructor
Definition: yaspgridhierarchiciterator.hh:33
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
Dune namespace.
Definition: alignedallocator.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)