Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

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
6
11// Dune includes
12#include <dune/grid/common/gridenums.hh>
13
14namespace Dune
15{
16
21 template<int codim, PartitionIteratorType pitype, class GridImp, typename Enable = void>
23
24 template<int codim, PartitionIteratorType pitype, class GridImp>
26
30 template<PartitionIteratorType pitype, class GridImp>
31 class MMeshInterfaceGridLeafIteratorImp<0, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 2>>
32 {
33 private:
35 using HostGridLeafIterator = typename GridImp::HostGridType::Finite_faces_iterator;
37 using HostGridFacet = typename GridImp::MMeshType::FacetHandle;
38
39 public:
40 enum {codimension = 0};
41
42 typedef typename GridImp::template Codim<0>::Entity Entity;
43
45 mMesh_(nullptr)
46 {}
47
48 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh) :
49 mMesh_(mMesh),
50 hostLeafIterator_(pitype == Interior_Partition
51 ? mMesh->partitionHelper().leafInteriorBegin()
52 : mMesh->getHostGrid().finite_faces_begin()),
53 face_(0)
54 {
55 if( proceed() )
56 increment();
57 }
58
63 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh, bool endDummy) :
64 mMesh_(mMesh),
65 hostLeafIterator_(pitype == Interior_Partition
66 ? mMesh->partitionHelper().leafInteriorEnd()
67 : mMesh->getHostGrid().finite_faces_end()),
68 face_(0)
69 {}
70
72 void increment() {
73 do {
74 face_++;
75 if (face_ == 3)
76 {
77 ++hostLeafIterator_;
78 face_ = 0;
79 }
80 }
81 while( proceed() );
82 }
83
85 Entity dereference() const {
86 return Entity {{ mMesh_, HostGridFacet( hostLeafIterator_, face_ ) }};
87 }
88
91 return hostLeafIterator_ == i.hostLeafIterator_ && face_ == i.face_;
92 }
93
94 private:
96 bool proceed()
97 {
98 const auto endIterator = (pitype == Interior_Partition ? mMesh_->partitionHelper().leafInteriorEnd() : mMesh_->getHostGrid().finite_faces_end());
99 if (hostLeafIterator_ == endIterator)
100 return false;
101
102 HostGridFacet facet ( hostLeafIterator_, face_ );
103 if (!mMesh_->isInterface( facet ))
104 return true;
105
106 const auto mirrored = hostLeafIterator_->neighbor( face_ );
107 if ( hostLeafIterator_->info().insertionIndex > mirrored->info().insertionIndex )
108 return true;
109
110 return !mMesh_->partitionHelper().contains(pitype, dereference());
111 }
112
113 const GridImp* mMesh_;
114
115 HostGridLeafIterator hostLeafIterator_;
116 int face_;
117 };
118
119
120 template<PartitionIteratorType pitype, class GridImp>
121 class MMeshInterfaceGridLeafIteratorImp<1, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 2>>
122 {
123 private:
125 typedef typename GridImp::HostGridType::Vertex_iterator HostGridLeafIterator;
126
127 public:
128 enum {codimension = GridImp::dimension};
129
130 typedef typename GridImp::template Codim<codimension>::Entity Entity;
131
132 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh) :
133 mMesh_(mMesh),
134 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_begin()),
135 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end())
136 {
137 while( proceed() )
138 ++hostLeafIterator_;
139 }
140
145 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh, bool endDummy) :
146 mMesh_(mMesh),
147 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_end()),
148 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end())
149 {}
150
152 void increment() {
153 ++hostLeafIterator_;
154
155 while( proceed() )
156 ++hostLeafIterator_;
157 }
158
160 Entity dereference() const {
161 return Entity {{ mMesh_, hostLeafIterator_ }};
162 }
163
165 bool equals(const MMeshInterfaceGridLeafIteratorImp& i) const {
166 return hostLeafIterator_ == i.hostLeafIterator_;
167 }
168
169 private:
171 bool proceed()
172 {
173 if (hostLeafIterator_ == hostLeafIteratorEnd_)
174 return false;
175 if (!hostLeafIterator_->info().isInterface)
176 return true;
177 return !mMesh_->partitionHelper().contains(pitype, dereference());
178 }
179
180 const GridImp* mMesh_;
181
182 HostGridLeafIterator hostLeafIterator_;
183 HostGridLeafIterator hostLeafIteratorEnd_;
184 };
185
186
191 template<PartitionIteratorType pitype, class GridImp>
192 class MMeshInterfaceGridLeafIteratorImp<0, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 3>>
193 {
194 private:
196 using HostGridLeafIterator = typename GridImp::HostGridType::Finite_cells_iterator;
198 using HostGridFacet = typename GridImp::MMeshType::FacetHandle;
199
200 public:
201 enum {codimension = 0};
202
203 typedef typename GridImp::template Codim<0>::Entity Entity;
204
206 mMesh_(nullptr)
207 {}
208
209 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh) :
210 mMesh_(mMesh),
211 hostLeafIterator_(pitype == Interior_Partition
212 ? mMesh->partitionHelper().leafInteriorBegin()
213 : mMesh->getHostGrid().finite_cells_begin()),
214 face_(0)
215 {
216 if( proceed() )
217 increment();
218 }
219
224 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh, bool endDummy) :
225 mMesh_(mMesh),
226 hostLeafIterator_(pitype == Interior_Partition
227 ? mMesh->partitionHelper().leafInteriorEnd()
228 : mMesh->getHostGrid().finite_cells_end()),
229 face_(0)
230 {}
231
233 void increment() {
234 do {
235 face_++;
236 if (face_ == 4)
237 {
238 ++hostLeafIterator_;
239 face_ = 0;
240 }
241 }
242 while( proceed() );
243 }
244
246 Entity dereference() const {
247 return Entity {{ mMesh_, HostGridFacet( hostLeafIterator_, face_ ) }};
248 }
249
252 return hostLeafIterator_ == i.hostLeafIterator_ && face_ == i.face_;
253 }
254
255 private:
257 bool proceed()
258 {
259 const auto endIterator = (pitype == Interior_Partition ? mMesh_->partitionHelper().leafInteriorEnd() : mMesh_->getHostGrid().finite_cells_end());
260 if (hostLeafIterator_ == endIterator)
261 return false;
262
263 HostGridFacet facet ( hostLeafIterator_, face_ );
264 if (!mMesh_->isInterface( facet ))
265 return true;
266
267 const auto mirrored = hostLeafIterator_->neighbor( face_ );
268 if ( hostLeafIterator_->info().insertionIndex > mirrored->info().insertionIndex )
269 return true;
270
271 return !mMesh_->partitionHelper().contains(pitype, dereference());
272 }
273
274 const GridImp* mMesh_;
275
276 HostGridLeafIterator hostLeafIterator_;
277 int face_;
278 };
279
280 template<PartitionIteratorType pitype, class GridImp>
281 class MMeshInterfaceGridLeafIteratorImp<1, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 3>>
282 {
283 private:
285 using HostGridLeafIterator = typename GridImp::HostGridType::Finite_edges_iterator;
286
287 public:
288 enum {codimension = 1};
289
290 typedef typename GridImp::template Codim<1>::Entity Entity;
291
292 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh) :
293 mMesh_(mMesh),
294 hostLeafIterator_(mMesh->getHostGrid().finite_edges_begin()),
295 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_edges_end())
296 {
297 while( proceed() )
298 ++hostLeafIterator_;
299 }
300
305 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh, bool endDummy) :
306 mMesh_(mMesh),
307 hostLeafIterator_(mMesh->getHostGrid().finite_edges_end()),
308 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_edges_end())
309 {}
310
312 void increment() {
313 ++hostLeafIterator_;
314
315 while( proceed() )
316 ++hostLeafIterator_;
317 }
318
320 Entity dereference() const {
321 return Entity {{ mMesh_, *hostLeafIterator_ }};
322 }
323
325 bool equals(const MMeshInterfaceGridLeafIteratorImp& i) const {
326 return hostLeafIterator_ == i.hostLeafIterator_;
327 }
328
329 private:
331 bool proceed()
332 {
333 if (hostLeafIterator_ == hostLeafIteratorEnd_)
334 return false;
335 if (!mMesh_->isInterface( *hostLeafIterator_ ))
336 return true;
337 return !mMesh_->partitionHelper().contains(pitype, dereference());
338 }
339
340 const GridImp* mMesh_;
341
342 HostGridLeafIterator hostLeafIterator_;
343 HostGridLeafIterator hostLeafIteratorEnd_;
344 };
345
346 template<PartitionIteratorType pitype, class GridImp>
347 class MMeshInterfaceGridLeafIteratorImp<2, pitype, GridImp, std::enable_if_t<GridImp::dimensionworld == 3>>
348 {
349 private:
351 typedef typename GridImp::HostGridType::Vertex_iterator HostGridLeafIterator;
352
353 public:
354 enum {codimension = GridImp::dimension};
355
356 typedef typename GridImp::template Codim<codimension>::Entity Entity;
357
358 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh) :
359 mMesh_(mMesh),
360 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_begin()),
361 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end())
362 {
363 while( proceed() )
364 ++hostLeafIterator_;
365 }
366
371 explicit MMeshInterfaceGridLeafIteratorImp(const GridImp* mMesh, bool endDummy) :
372 mMesh_(mMesh),
373 hostLeafIterator_(mMesh->getHostGrid().finite_vertices_end()),
374 hostLeafIteratorEnd_(mMesh->getHostGrid().finite_vertices_end())
375 {}
376
378 void increment() {
379 ++hostLeafIterator_;
380
381 while( proceed() )
382 ++hostLeafIterator_;
383 }
384
386 Entity dereference() const {
387 return Entity {{ mMesh_, hostLeafIterator_ }};
388 }
389
391 bool equals(const MMeshInterfaceGridLeafIteratorImp& i) const {
392 return hostLeafIterator_ == i.hostLeafIterator_;
393 }
394
395 private:
397 bool proceed()
398 {
399 if (hostLeafIterator_ == hostLeafIteratorEnd_)
400 return false;
401 if (!hostLeafIterator_->info().isInterface)
402 return true;
403 return !mMesh_->partitionHelper().contains(pitype, dereference());
404 }
405
406 const GridImp* mMesh_;
407
408 HostGridLeafIterator hostLeafIterator_;
409 HostGridLeafIterator hostLeafIteratorEnd_;
410 };
411
412} // namespace Dune
413
414#endif
bool equals(const MMeshInterfaceGridLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:251
MMeshInterfaceGridLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:224
MMeshInterfaceGridLeafIteratorImp(const GridImp *mMesh, bool endDummy)
Constructor which creates the end iterator.
Definition: leafiterator.hh:63
bool equals(const MMeshInterfaceGridLeafIteratorImp &i) const
equality
Definition: leafiterator.hh:90
Iterator over all entities of a given codimension and level of a grid (2D).
Definition: leafiterator.hh:22
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 13, 22:42, 2025)