Dune Core Modules (2.4.1)

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 public YaspEntityPointer<0,GridImp>
19 {
20 enum { dim=GridImp::dimension };
21
22 typedef YaspEntity<0,GridImp::dimension,GridImp> YaspEntityImp;
23
24 public:
25 // types used from grids
26 typedef typename GridImp::YGridLevelIterator YGLI;
27 typedef typename GridImp::YGrid::Iterator I;
28 typedef typename GridImp::template Codim<0>::Entity Entity;
29
31 YaspHierarchicIterator (const YGLI& g, const I& it, int maxlevel) :
32 YaspEntityPointer<0,GridImp>(g,it)
33 {
34 // store reference to entity implementation for better readability
35 YaspEntityImp& entity = entityImplementation();
36 // now iterator points to current cell
37 StackElem se(entity._g);
38 std::copy(entity._it.coord().begin(), entity._it.coord().end(), se.coord.begin());
39 stack.push(se);
40
41 // determine maximum level
42 _maxlevel = std::min(maxlevel,entity._g->mg->maxLevel());
43
44 // if maxlevel not reached then push yourself and sons
45 if (entity._g->level()<_maxlevel)
46 {
47 push_sons();
48 }
49
50 // and make iterator point to first son if stack is not empty
51 if (!stack.empty())
52 pop_tos();
53 }
54
57 YaspEntityPointer<0,GridImp>(it),
58 _maxlevel(it._maxlevel), stack(it.stack)
59 {}
60
62 void increment ()
63 {
64 // sanity check: do nothing when stack is empty
65 if (stack.empty()) return;
66
67 // if maxlevel not reached then push sons
68 if (entityImplementation()._g->level()<_maxlevel)
69 push_sons();
70
71 // in any case pop one element
72 pop_tos();
73 }
74
75 void print (std::ostream& s) const
76 {
77 // store reference to entity implementation for better readability
78 YaspEntityImp& entity = entityImplementation();
79 s << "HIER: " << "level=" << entity._g.level()
80 << " position=" << entity._it.coord()
81 << " superindex=" << entity._it.superindex()
82 << " maxlevel=" << entity._maxlevel
83 << " stacksize=" << stack.size()
84 << std::endl;
85 }
86
87 private:
88 int _maxlevel;
89
90 struct StackElem {
91 YGLI g; // grid level of the element
92 array<int,dim> coord; // and the coordinates
93 StackElem(YGLI gg) : g(gg) {}
94 };
95 std::stack<StackElem> stack;
96
97 // push sons of current element on the stack
98 void push_sons ()
99 {
100 // store reference to entity implementation for better readability
101 YaspEntityImp& entity = entityImplementation();
102
103 // yes, process all 1<<dim sons
104 YGLI finer = entity._g;
105 ++finer;
106 StackElem se(finer);
107 for (int i=0; i<(1<<dim); i++)
108 {
109 for (int k=0; k<dim; k++)
110 if (i&(1<<k))
111 se.coord[k] = entity._it.coord(k)*2+1;
112 else
113 se.coord[k] = entity._it.coord(k)*2;
114 // not all entities have 2^d subentities due to refineOptions with keep_ovlp==false
115 bool exists = true;
116 for (int k=0; k<dim; k++)
117 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)))
118 exists = false;
119 if (exists)
120 stack.push(se);
121 }
122 }
123
124 YaspEntityImp& entityImplementation()
125 {
126 return GridImp::getRealImplementation(this->_entity);
127 }
128
129 // make TOS the current element
130 void pop_tos ()
131 {
132 StackElem se = stack.top();
133 stack.pop();
134 entityImplementation()._g = se.g;
135 entityImplementation()._it.reinit(entityImplementation()._g->overlap[0],se.coord);
136 }
137 };
138
139} // namespace Dune
140
141#endif // DUNE_GRID_YASPGRIDHIERARCHICITERATOR_HH
A pointer to a YaspGrid::Entity.
Definition: yaspgridentitypointer.hh:16
Entity _entity
use default assignment operator
Definition: yaspgridentitypointer.hh:85
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition: yaspgridhierarchiciterator.hh:19
YaspHierarchicIterator(const YaspHierarchicIterator &it)
constructor
Definition: yaspgridhierarchiciterator.hh:56
void increment()
increment
Definition: yaspgridhierarchiciterator.hh:62
YaspHierarchicIterator(const YGLI &g, const I &it, int maxlevel)
constructor
Definition: yaspgridhierarchiciterator.hh:31
Dune namespace.
Definition: alignment.hh:10
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 (Dec 22, 23:30, 2024)