dune-mmesh (unstable)

leafiterator.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_MMESH_GRID_MMESHLEAFITERATOR_HH
4#define DUNE_MMESH_GRID_MMESHLEAFITERATOR_HH
5
10// Dune includes
11#include <dune/grid/common/gridenums.hh>
12
13namespace Dune {
14
19template <int codim, PartitionIteratorType pitype, class GridImp,
20 typename Enable = void>
22
23template <int codim, PartitionIteratorType pitype, class GridImp>
25
29template <PartitionIteratorType pitype, class GridImp>
30class MMeshLeafIteratorImp<0, pitype, GridImp,
31 std::enable_if_t<GridImp::dimension == 2>> {
32 public:
35 typename GridImp::HostGridType::Finite_faces_iterator;
36 enum { codimension = 0 };
37
38 typedef typename GridImp::template Codim<0>::Entity Entity;
39
40 explicit MMeshLeafIteratorImp() : mMesh_(nullptr) {}
41
42 explicit MMeshLeafIteratorImp(const GridImp* mMesh)
43 : mMesh_(mMesh),
44 hostLeafIterator_(pitype == Interior_Partition
45 ? mMesh->partitionHelper().leafInteriorBegin()
46 : mMesh->getHostGrid().finite_faces_begin()) {
47 while (proceed()) increment();
48 }
49
54 explicit MMeshLeafIteratorImp(const GridImp* mMesh, bool endDummy)
55 : mMesh_(mMesh),
56 hostLeafIterator_(pitype == Interior_Partition
57 ? mMesh->partitionHelper().leafInteriorEnd()
58 : mMesh->getHostGrid().finite_faces_end()) {}
59
61 void increment() {
62 do {
63 ++hostLeafIterator_;
64 } while (proceed());
65 }
66
68 Entity dereference() const { return Entity{{mMesh_, hostLeafIterator_}}; }
69
71 bool equals(const MMeshLeafIteratorImp& i) const {
72 return hostLeafIterator_ == i.hostLeafIterator_;
73 }
74
75 private:
77 bool proceed() {
78 const auto endIterator = (pitype == Interior_Partition
79 ? mMesh_->partitionHelper().leafInteriorEnd()
80 : mMesh_->getHostGrid().finite_faces_end());
81 if (hostLeafIterator_ == endIterator) return false;
82 return !mMesh_->partitionHelper().contains(
83 pitype, hostLeafIterator_->info().partition);
84 }
85
86 const GridImp* mMesh_;
87 HostGridLeafIterator hostLeafIterator_;
88};
89
90template <PartitionIteratorType pitype, class GridImp>
91class MMeshLeafIteratorImp<1, pitype, GridImp,
92 std::enable_if_t<GridImp::dimension == 2>> {
93 private:
95 using HostGridLeafIterator =
96 typename GridImp::HostGridType::Finite_edges_iterator;
97
98 public:
99 enum { codimension = 1 };
100
101 typedef typename GridImp::template Codim<1>::Entity Entity;
102
103 explicit MMeshLeafIteratorImp(const GridImp* mMesh)
104 : mMesh_(mMesh),
105 hostLeafIterator_(mMesh->getHostGrid().finite_edges_begin()) {
106 while (proceed()) increment();
107 }
108
113 explicit MMeshLeafIteratorImp(const GridImp* mMesh, bool endDummy)
114 : mMesh_(mMesh),
115 hostLeafIterator_(mMesh->getHostGrid().finite_edges_end()) {}
116
118 void increment() {
119 do {
120 ++hostLeafIterator_;
121 } while (proceed());
122 }
123
125 Entity dereference() const { return Entity{{mMesh_, *hostLeafIterator_}}; }
126
128 bool equals(const MMeshLeafIteratorImp& i) const {
129 return hostLeafIterator_ == i.hostLeafIterator_;
130 }
131
132 private:
134 bool proceed() {
135 if (hostLeafIterator_ == mMesh_->getHostGrid().finite_edges_end())
136 return false;
137 return !mMesh_->partitionHelper().contains(pitype, dereference());
138 }
139 const GridImp* mMesh_;
140
141 HostGridLeafIterator hostLeafIterator_;
142};
143
144template <PartitionIteratorType pitype, class GridImp>
145class MMeshLeafIteratorImp<2, pitype, GridImp,
146 std::enable_if_t<GridImp::dimension == 2>> {
147 private:
149 using HostGridLeafIterator =
150 typename GridImp::HostGridType::Finite_vertices_iterator;
151
152 public:
153 enum { codimension = GridImp::dimension };
154
155 typedef typename GridImp::template Codim<codimension>::Entity Entity;
156
157 explicit MMeshLeafIteratorImp(const GridImp* mMesh)
158 : mMesh_(mMesh),
159 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_begin()) {
160 while (proceed()) increment();
161 }
162
167 explicit MMeshLeafIteratorImp(const GridImp* mMesh, bool endDummy)
168 : mMesh_(mMesh),
169 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_end()) {}
170
172 void increment() {
173 do {
174 ++hostLeafIterator_;
175 } while (proceed());
176 }
177
179 Entity dereference() const { return Entity{{mMesh_, hostLeafIterator_}}; }
180
182 bool equals(const MMeshLeafIteratorImp& i) const {
183 return hostLeafIterator_ == i.hostLeafIterator_;
184 }
185
186 private:
188 bool proceed() {
189 if (hostLeafIterator_ == mMesh_->getHostGrid().finite_vertices_end())
190 return false;
191 return !mMesh_->partitionHelper().contains(
192 pitype, hostLeafIterator_->info().partition);
193 }
194
195 const GridImp* mMesh_;
196 HostGridLeafIterator hostLeafIterator_;
197};
198
204template <PartitionIteratorType pitype, class GridImp>
205class MMeshLeafIteratorImp<0, pitype, GridImp,
206 std::enable_if_t<GridImp::dimension == 3>> {
207 public:
210 typename GridImp::HostGridType::Finite_cells_iterator;
211
212 enum { codimension = 0 };
213
214 typedef typename GridImp::template Codim<0>::Entity Entity;
215
216 explicit MMeshLeafIteratorImp() : mMesh_(nullptr) {}
217
218 explicit MMeshLeafIteratorImp(const GridImp* mMesh)
219 : mMesh_(mMesh),
220 hostLeafIterator_(pitype == Interior_Partition
221 ? mMesh->partitionHelper().leafInteriorBegin()
222 : mMesh->getHostGrid().finite_cells_begin()) {
223 while (proceed()) increment();
224 }
225
230 explicit MMeshLeafIteratorImp(const GridImp* mMesh, bool endDummy)
231 : mMesh_(mMesh),
232 hostLeafIterator_(pitype == Interior_Partition
233 ? mMesh->partitionHelper().leafInteriorEnd()
234 : mMesh->getHostGrid().finite_cells_end()) {}
235
237 void increment() {
238 do {
239 ++hostLeafIterator_;
240 } while (proceed());
241 }
242
244 Entity dereference() const { return Entity{{mMesh_, hostLeafIterator_}}; }
245
247 bool equals(const MMeshLeafIteratorImp& i) const {
248 return hostLeafIterator_ == i.hostLeafIterator_;
249 }
250
251 private:
253 bool proceed() {
254 const auto endIterator = (pitype == Interior_Partition
255 ? mMesh_->partitionHelper().leafInteriorEnd()
256 : mMesh_->getHostGrid().finite_cells_end());
257 if (hostLeafIterator_ == endIterator) return false;
258 return !mMesh_->partitionHelper().contains(
259 pitype, hostLeafIterator_->info().partition);
260 }
261
262 const GridImp* mMesh_;
263 HostGridLeafIterator hostLeafIterator_;
264};
265
267template <PartitionIteratorType pitype, class GridImp>
268class MMeshLeafIteratorImp<1, pitype, GridImp,
269 std::enable_if_t<GridImp::dimension == 3>> {
270 private:
272 using HostGridLeafIterator =
273 typename GridImp::HostGridType::Finite_facets_iterator;
274
275 public:
276 enum { codimension = 1 };
277
278 typedef typename GridImp::template Codim<1>::Entity Entity;
279
280 explicit MMeshLeafIteratorImp(const GridImp* mMesh)
281 : mMesh_(mMesh),
282 hostLeafIterator_(mMesh->getHostGrid().finite_facets_begin()) {
283 while (proceed()) increment();
284 }
285
290 explicit MMeshLeafIteratorImp(const GridImp* mMesh, bool endDummy)
291 : mMesh_(mMesh),
292 hostLeafIterator_(mMesh->getHostGrid().finite_facets_end()) {}
293
295 void increment() {
296 do {
297 ++hostLeafIterator_;
298 } while (proceed());
299 }
300
302 Entity dereference() const { return Entity{{mMesh_, *hostLeafIterator_}}; }
303
305 bool equals(const MMeshLeafIteratorImp& i) const {
306 return hostLeafIterator_ == i.hostLeafIterator_;
307 }
308
309 private:
311 bool proceed() {
312 if (hostLeafIterator_ == mMesh_->getHostGrid().finite_facets_end())
313 return false;
314 return !mMesh_->partitionHelper().contains(pitype, dereference());
315 }
316
317 const GridImp* mMesh_;
318 HostGridLeafIterator hostLeafIterator_;
319};
320
322template <PartitionIteratorType pitype, class GridImp>
323class MMeshLeafIteratorImp<2, pitype, GridImp,
324 std::enable_if_t<GridImp::dimension == 3>> {
325 private:
327 using HostGridLeafIterator =
328 typename GridImp::HostGridType::Finite_edges_iterator;
329
330 public:
331 enum { codimension = 2 };
332
333 typedef typename GridImp::template Codim<2>::Entity Entity;
334
335 explicit MMeshLeafIteratorImp(const GridImp* mMesh)
336 : mMesh_(mMesh),
337 hostLeafIterator_(mMesh->getHostGrid().finite_edges_begin()) {
338 while (proceed()) increment();
339 }
340
345 explicit MMeshLeafIteratorImp(const GridImp* mMesh, bool endDummy)
346 : mMesh_(mMesh),
347 hostLeafIterator_(mMesh->getHostGrid().finite_edges_end()) {}
348
350 void increment() {
351 do {
352 ++hostLeafIterator_;
353 } while (proceed());
354 }
355
357 Entity dereference() const { return Entity{{mMesh_, *hostLeafIterator_}}; }
358
360 bool equals(const MMeshLeafIteratorImp& i) const {
361 return hostLeafIterator_ == i.hostLeafIterator_;
362 }
363
364 private:
366 bool proceed() {
367 if (hostLeafIterator_ == mMesh_->getHostGrid().finite_edges_end())
368 return false;
369 return !mMesh_->partitionHelper().contains(pitype, dereference());
370 }
371
372 const GridImp* mMesh_;
373 HostGridLeafIterator hostLeafIterator_;
374};
375
377template <PartitionIteratorType pitype, class GridImp>
378class MMeshLeafIteratorImp<3, pitype, GridImp,
379 std::enable_if_t<GridImp::dimension == 3>> {
380 private:
382 typedef typename GridImp::HostGridType::Vertex_iterator HostGridLeafIterator;
383
384 public:
385 enum { codimension = GridImp::dimension };
386
387 typedef typename GridImp::template Codim<codimension>::Entity Entity;
388
389 explicit MMeshLeafIteratorImp(const GridImp* mMesh)
390 : mMesh_(mMesh),
391 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_begin()) {
392 while (proceed()) increment();
393 }
394
399 explicit MMeshLeafIteratorImp(const GridImp* mMesh, bool endDummy)
400 : mMesh_(mMesh),
401 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_end()) {}
402
404 void increment() {
405 do {
406 ++hostLeafIterator_;
407 } while (proceed());
408 }
409
411 Entity dereference() const { return Entity{{mMesh_, hostLeafIterator_}}; }
412
414 bool equals(const MMeshLeafIteratorImp& i) const {
415 return hostLeafIterator_ == i.hostLeafIterator_;
416 }
417
418 private:
420 bool proceed() {
421 if (hostLeafIterator_ ==
422 HostGridLeafIterator(mMesh_->getHostGrid().finite_vertices_end()))
423 return false;
424 if (hostLeafIterator_ == mMesh_->getHostGrid().infinite_vertex())
425 return true;
426 return !mMesh_->partitionHelper().contains(
427 pitype, hostLeafIterator_->info().partition);
428 }
429
430 const GridImp* mMesh_;
431 HostGridLeafIterator hostLeafIterator_;
432};
433
434} // namespace Dune
435
436#endif
bool equals(const MMeshLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:71
MMeshLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:54
typename GridImp::HostGridType::Finite_faces_iterator HostGridLeafIterator
The type of the underlying entities.
Definition: leafiterator.hh:35
Entity dereference() const
dereferencing
Definition: leafiterator.hh:244
typename GridImp::HostGridType::Finite_cells_iterator HostGridLeafIterator
The type of the underlying entities.
Definition: leafiterator.hh:210
bool equals(const MMeshLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:247
MMeshLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:230
bool equals(const MMeshLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:305
MMeshLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:290
Entity dereference() const
dereferencing
Definition: leafiterator.hh:302
bool equals(const MMeshLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:360
Entity dereference() const
dereferencing
Definition: leafiterator.hh:357
MMeshLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:345
Entity dereference() const
dereferencing
Definition: leafiterator.hh:411
bool equals(const MMeshLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:414
MMeshLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which create the end iterator.
Definition: leafiterator.hh:399
Iterator over all entities of a given codimension and level of a grid (2D).
Definition: leafiterator.hh:21
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 17, 23:30, 2025)