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_INTERFACE_MMESHLEAFITERATOR_HH
4#define DUNE_MMESH_INTERFACE_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>
26
30template <PartitionIteratorType pitype, class GridImp>
32 0, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 2>> {
33 private:
35 using HostGridLeafIterator =
36 typename GridImp::HostGridType::Finite_faces_iterator;
38 using HostGridFacet = typename GridImp::MMeshType::FacetHandle;
39
40 public:
41 enum { codimension = 0 };
42
43 typedef typename GridImp::template Codim<0>::Entity Entity;
44
45 explicit MMeshInterfaceGridLeafIteratorImp() : mMesh_(nullptr) {}
46
47 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh)
48 : mMesh_(mMesh),
49 hostLeafIterator_(pitype == Interior_Partition
50 ? mMesh->partitionHelper().leafInteriorBegin()
51 : mMesh->getHostGrid().finite_faces_begin()),
52 face_(0) {
53 if (proceed()) increment();
54 }
55
60 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh,
61 bool endDummy)
62 : mMesh_(mMesh),
63 hostLeafIterator_(pitype == Interior_Partition
64 ? mMesh->partitionHelper().leafInteriorEnd()
65 : mMesh->getHostGrid().finite_faces_end()),
66 face_(0) {}
67
69 void increment() {
70 do {
71 face_++;
72 if (face_ == 3) {
73 ++hostLeafIterator_;
74 face_ = 0;
75 }
76 } while (proceed());
77 }
78
80 Entity dereference() const {
81 return Entity{{mMesh_, HostGridFacet(hostLeafIterator_, face_)}};
82 }
83
86 return hostLeafIterator_ == i.hostLeafIterator_ && face_ == i.face_;
87 }
88
89 private:
91 bool proceed() {
92 const auto endIterator = (pitype == Interior_Partition
93 ? mMesh_->partitionHelper().leafInteriorEnd()
94 : mMesh_->getHostGrid().finite_faces_end());
95 if (hostLeafIterator_ == endIterator) return false;
96
97 HostGridFacet facet(hostLeafIterator_, face_);
98 if (!mMesh_->isInterface(facet)) return true;
99
100 const auto mirrored = hostLeafIterator_->neighbor(face_);
101 if (hostLeafIterator_->info().insertionIndex >
102 mirrored->info().insertionIndex)
103 return true;
104
105 return !mMesh_->partitionHelper().contains(pitype, dereference());
106 }
107
108 const GridImp* mMesh_;
109
110 HostGridLeafIterator hostLeafIterator_;
111 int face_;
112};
113
114template <PartitionIteratorType pitype, class GridImp>
115class MMeshInterfaceGridLeafIteratorImp<
116 1, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 2>> {
117 private:
119 typedef typename GridImp::HostGridType::Vertex_iterator HostGridLeafIterator;
120
121 public:
122 enum { codimension = GridImp::dimension };
123
124 typedef typename GridImp::template Codim<codimension>::Entity Entity;
125
126 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh)
127 : mMesh_(mMesh),
128 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_begin()),
129 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end()) {
130 while (proceed()) ++hostLeafIterator_;
131 }
132
137 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh,
138 bool endDummy)
139 : mMesh_(mMesh),
140 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_end()),
141 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end()) {}
142
144 void increment() {
145 ++hostLeafIterator_;
146
147 while (proceed()) ++hostLeafIterator_;
148 }
149
151 Entity dereference() const { return Entity{{mMesh_, hostLeafIterator_}}; }
152
154 bool equals(const MMeshInterfaceGridLeafIteratorImp& i) const {
155 return hostLeafIterator_ == i.hostLeafIterator_;
156 }
157
158 private:
160 bool proceed() {
161 if (hostLeafIterator_ == hostLeafIteratorEnd_) return false;
162 if (!hostLeafIterator_->info().isInterface) return true;
163 return !mMesh_->partitionHelper().contains(pitype, dereference());
164 }
165
166 const GridImp* mMesh_;
167
168 HostGridLeafIterator hostLeafIterator_;
169 HostGridLeafIterator hostLeafIteratorEnd_;
170};
171
176template <PartitionIteratorType pitype, class GridImp>
178 0, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 3>> {
179 private:
181 using HostGridLeafIterator =
182 typename GridImp::HostGridType::Finite_cells_iterator;
184 using HostGridFacet = typename GridImp::MMeshType::FacetHandle;
185
186 public:
187 enum { codimension = 0 };
188
189 typedef typename GridImp::template Codim<0>::Entity Entity;
190
191 explicit MMeshInterfaceGridLeafIteratorImp() : mMesh_(nullptr) {}
192
193 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh)
194 : mMesh_(mMesh),
195 hostLeafIterator_(pitype == Interior_Partition
196 ? mMesh->partitionHelper().leafInteriorBegin()
197 : mMesh->getHostGrid().finite_cells_begin()),
198 face_(0) {
199 if (proceed()) increment();
200 }
201
206 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh,
207 bool endDummy)
208 : mMesh_(mMesh),
209 hostLeafIterator_(pitype == Interior_Partition
210 ? mMesh->partitionHelper().leafInteriorEnd()
211 : mMesh->getHostGrid().finite_cells_end()),
212 face_(0) {}
213
215 void increment() {
216 do {
217 face_++;
218 if (face_ == 4) {
219 ++hostLeafIterator_;
220 face_ = 0;
221 }
222 } while (proceed());
223 }
224
226 Entity dereference() const {
227 return Entity{{mMesh_, HostGridFacet(hostLeafIterator_, face_)}};
228 }
229
232 return hostLeafIterator_ == i.hostLeafIterator_ && face_ == i.face_;
233 }
234
235 private:
237 bool proceed() {
238 const auto endIterator = (pitype == Interior_Partition
239 ? mMesh_->partitionHelper().leafInteriorEnd()
240 : mMesh_->getHostGrid().finite_cells_end());
241 if (hostLeafIterator_ == endIterator) return false;
242
243 HostGridFacet facet(hostLeafIterator_, face_);
244 if (!mMesh_->isInterface(facet)) return true;
245
246 const auto mirrored = hostLeafIterator_->neighbor(face_);
247 if (hostLeafIterator_->info().insertionIndex >
248 mirrored->info().insertionIndex)
249 return true;
250
251 return !mMesh_->partitionHelper().contains(pitype, dereference());
252 }
253
254 const GridImp* mMesh_;
255
256 HostGridLeafIterator hostLeafIterator_;
257 int face_;
258};
259
260template <PartitionIteratorType pitype, class GridImp>
261class MMeshInterfaceGridLeafIteratorImp<
262 1, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 3>> {
263 private:
265 using HostGridLeafIterator =
266 typename GridImp::HostGridType::Finite_edges_iterator;
267
268 public:
269 enum { codimension = 1 };
270
271 typedef typename GridImp::template Codim<1>::Entity Entity;
272
273 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh)
274 : mMesh_(mMesh),
275 hostLeafIterator_(mMesh->getHostGrid().finite_edges_begin()),
276 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_edges_end()) {
277 while (proceed()) ++hostLeafIterator_;
278 }
279
284 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh,
285 bool endDummy)
286 : mMesh_(mMesh),
287 hostLeafIterator_(mMesh->getHostGrid().finite_edges_end()),
288 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_edges_end()) {}
289
291 void increment() {
292 ++hostLeafIterator_;
293
294 while (proceed()) ++hostLeafIterator_;
295 }
296
298 Entity dereference() const { return Entity{{mMesh_, *hostLeafIterator_}}; }
299
301 bool equals(const MMeshInterfaceGridLeafIteratorImp& i) const {
302 return hostLeafIterator_ == i.hostLeafIterator_;
303 }
304
305 private:
307 bool proceed() {
308 if (hostLeafIterator_ == hostLeafIteratorEnd_) return false;
309 if (!mMesh_->isInterface(*hostLeafIterator_)) return true;
310 return !mMesh_->partitionHelper().contains(pitype, dereference());
311 }
312
313 const GridImp* mMesh_;
314
315 HostGridLeafIterator hostLeafIterator_;
316 HostGridLeafIterator hostLeafIteratorEnd_;
317};
318
319template <PartitionIteratorType pitype, class GridImp>
320class MMeshInterfaceGridLeafIteratorImp<
321 2, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 3>> {
322 private:
324 typedef typename GridImp::HostGridType::Vertex_iterator HostGridLeafIterator;
325
326 public:
327 enum { codimension = GridImp::dimension };
328
329 typedef typename GridImp::template Codim<codimension>::Entity Entity;
330
331 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh)
332 : mMesh_(mMesh),
333 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_begin()),
334 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end()) {
335 while (proceed()) ++hostLeafIterator_;
336 }
337
342 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh,
343 bool endDummy)
344 : mMesh_(mMesh),
345 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_end()),
346 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end()) {}
347
349 void increment() {
350 ++hostLeafIterator_;
351
352 while (proceed()) ++hostLeafIterator_;
353 }
354
356 Entity dereference() const { return Entity{{mMesh_, hostLeafIterator_}}; }
357
359 bool equals(const MMeshInterfaceGridLeafIteratorImp& i) const {
360 return hostLeafIterator_ == i.hostLeafIterator_;
361 }
362
363 private:
365 bool proceed() {
366 if (hostLeafIterator_ == hostLeafIteratorEnd_) return false;
367 if (!hostLeafIterator_->info().isInterface) return true;
368 return !mMesh_->partitionHelper().contains(pitype, dereference());
369 }
370
371 const GridImp* mMesh_;
372
373 HostGridLeafIterator hostLeafIterator_;
374 HostGridLeafIterator hostLeafIteratorEnd_;
375};
376
377} // namespace Dune
378
379#endif
bool equals(const MMeshInterfaceGridLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:231
MMeshInterfaceGridLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:206
MMeshInterfaceGridLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:60
bool equals(const MMeshInterfaceGridLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:85
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 (Sep 4, 22:38, 2025)