LoAdSG
ListOfDepthOrderedGrids.h
1/****************************
2 * Test for ordered grids
3 ***************************/
4
5#ifndef LISTOFORDEREDGRIDS_H
6#define LISTOFORDEREDGRIDS_H
7
8#include <list>
9#include <vector>
10#include <iostream>
11
12
32private:
33 class IndexPlusi {
34 public:
35 IndexPlusi(IndexDimension I_, unsigned long i_) : I(I_), i(i_) {}
36
37 IndexDimension I;
38 unsigned long i;
39
40 bool operator==(IndexPlusi vergleich) {
41 if (I == vergleich.I) return true;
42 if (i == vergleich.i) return true;
43 return false;
44
45 }
46
47 void print() {
48 I.Print();
49 }
50 };
51
52public:
53 SubgridFixedDepth(Depth &T_);
54
55
61 SubgridFixedDepth(Depth &T_, IndexDimension p, unsigned long i);
62
63
64 Depth getT() { return T; }
65
69 bool addPoint(IndexDimension &p, unsigned long i);
70
71 bool isOccupied(IndexDimension &p, unsigned long i);
72
73
82 class iterator {
83 public:
84 iterator(SubgridFixedDepth &dataStructure_);
85
86 void gotobegin();
87
88 bool next();
89
90 bool empty();
91
92 IndexDimension getPoint() {
93
94 return (*it).I;
95 }
96
97 unsigned long geti() {
98
99 return it->i;
100 }
101
102 private:
103 SubgridFixedDepth *dataStructure;
104 std::list<SubgridFixedDepth::IndexPlusi>::iterator it;
105 };
106
107private:
108 Depth T;
109 std::list<SubgridFixedDepth::IndexPlusi> listPoints;
110};
111
116public:
118
120
121 ListOfDepthOrderedSubgrids(AdaptiveSparseGrid_Base &grid, bool *restrictions);
122
123
124 void addPoint(IndexDimension &p, unsigned long i);
125
126
127 class iterator {
128 public:
129 iterator(ListOfDepthOrderedSubgrids &dataStructure_);
130
131 void gotoBegin();
132
133 void gotoEnd();
134
135 bool previous();
136
137 bool next();
138
139 bool empty();
140
141
142 int get_t() { return t; };
143
144 Depth getDepth() {
145 return (*it).getT();
146 }
147
148 SubgridFixedDepth *getSubgrid() { return &(*it); }
149
150 private:
151 ListOfDepthOrderedSubgrids *dataStructure;
152 std::list<SubgridFixedDepth>::iterator it;
153 int t;
154 };
155
156
157 bool isIncluded(Depth &T);
158
159 inline void sortDepths(bool *Restrictions);
160
161 inline void SortiereTiefenBoundary(bool *Restrictions);
162
163
164 SubgridFixedDepth *getSubgrid(Depth T) {
165 iterator iter(*this);
166 iter.gotoBegin();
167 do {
168 Depth Tlocal = iter.getSubgrid()->getT();
169 if (Tlocal == T) return iter.getSubgrid();
170 } while (iter.next());
171
172 cout << "error no subgrid of required depth" << endl;
173 return iter.getSubgrid();
174
175 };
176
177 std::list<Depth> *getSortierteTiefen() { return &SortierteTiefen; }
178
179private:
180 std::vector<std::list<SubgridFixedDepth>> TiefeVector;
181 std::list<Depth> SortierteTiefen;
182 int MaximalDepth[DimensionSparseGrid];
183
184 inline void recursiveDepth(bool *Restrictions, bool checkProlongation, int d, Depth *T);
185
186 inline void recursiveDepthBoundary(bool *Restrictions, bool checkProlongation, int d, Depth *T);
187
188 void recursiveDepthCoarse(int d, Depth *T);
189};
190
191
193void ListOfDepthOrderedSubgrids::sortDepths(bool *Restrictions) {
194
195 SortierteTiefen.clear();
196 Depth T(0);
197 recursiveDepth(Restrictions, true, DimensionSparseGrid - 1, &T);
198
199}
200
201
202inline void ListOfDepthOrderedSubgrids::SortiereTiefenBoundary(bool *Restrictions) {
203
204 SortierteTiefen.clear();
205 Depth T(0);
206 recursiveDepthBoundary(Restrictions, true, DimensionSparseGrid - 1, &T);
207
208}
209
210
211inline void ListOfDepthOrderedSubgrids::recursiveDepth(bool *Restrictions, bool checkProlongation, int d, Depth *T) {
212 if (checkProlongation && d > 0) {
213 if (!Restrictions[d]) {
214 for (int t = 1; t <= MaximalDepth[d]; t++) {
215 T->set(t, d);
216 recursiveDepth(Restrictions, checkProlongation, d - 1, T);
217 }
218 } else {
219 recursiveDepth(Restrictions, checkProlongation, d - 1, T);
220 }
221 }
222
223 if (checkProlongation && d == 0) {
224 if (!Restrictions[d]) {
225 for (int t = 1; t <= MaximalDepth[d]; t++) {
226 T->set(t, d);
227 recursiveDepth(Restrictions, false, DimensionSparseGrid - 1, T);
228 }
229 } else {
230 recursiveDepth(Restrictions, false, DimensionSparseGrid - 1, T);
231 }
232 }
233
234 if ((!checkProlongation) && d >= 0) {
235 if (Restrictions[d]) {
236 for (int t = MaximalDepth[d]; t > 1; t--) {
237 T->set(t, d);
238 recursiveDepth(Restrictions, checkProlongation, d - 1, T);
239 }
240 } else {
241 recursiveDepth(Restrictions, checkProlongation, d - 1, T);
242 }
243 }
244
245 if (d < 0 && isIncluded(*T)) {
246 SortierteTiefen.push_back(*T);
247 }
248
249}
250
251
252inline void
253ListOfDepthOrderedSubgrids::recursiveDepthBoundary(bool *Restrictions, bool checkProlongation, int d, Depth *T) {
254
255 if (checkProlongation && d > 0) {
256 if (!Restrictions[d]) {
257 for (int t = 0; t <= MaximalDepth[d]; t++) {
258 T->set(t, d);
259 recursiveDepthBoundary(Restrictions, checkProlongation, d - 1, T);
260 }
261 } else {
262 recursiveDepthBoundary(Restrictions, checkProlongation, d - 1, T);
263 }
264 }
265
266 if (checkProlongation && d == 0) {
267 if (!Restrictions[d]) {
268 for (int t = 0; t <= MaximalDepth[d]; t++) {
269 T->set(t, d);
270 recursiveDepthBoundary(Restrictions, false, DimensionSparseGrid - 1, T);
271 }
272 } else {
273 recursiveDepthBoundary(Restrictions, false, DimensionSparseGrid - 1, T);
274 }
275 }
276
277 if ((!checkProlongation) && d >= 0) {
278 if (Restrictions[d]) {
279 for (int t = MaximalDepth[d]; t >= 1; t--) {
280 T->set(t, d);
281 recursiveDepthBoundary(Restrictions, checkProlongation, d - 1, T);
282 }
283 } else {
284 recursiveDepthBoundary(Restrictions, checkProlongation, d - 1, T);
285 }
286 }
287
288 if (d < 0 && isIncluded(*T)) {
289 SortierteTiefen.push_back(*T);
290 }
291
292}
293
294#endif
Definition sparseGrid.h:86
Definition ListOfDepthOrderedGrids.h:115
Definition ListOfDepthOrderedGrids.h:82
Definition ListOfDepthOrderedGrids.h:31
bool addPoint(IndexDimension &p, unsigned long i)
Definition ListOfDepthOrderedGrids.cc:32