dune-grid 2.9.0
boundaryiterators.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
7#define DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
8
9#include <iterator>
10#include <memory>
11
12#include <dune/common/iteratorfacades.hh>
13
17
18namespace Dune {
19
22
28 namespace VTK {
29
31
35 template<typename GV>
37 : public ForwardIteratorFacade
38 < BoundaryIterator<GV>,
39 const typename GV::Intersection,
40 const typename GV::Intersection&,
41 typename std::iterator_traits<typename GV::template Codim<0>::
42 Iterator>::difference_type>
43 {
44 public:
45 // reiterator the facades typedefs here
47 typedef const typename GV::Intersection Value;
48 typedef Value& Reference;
49 typedef typename GV::template Codim<0>::Iterator ElementIterator;
50 typedef typename GV::IntersectionIterator IntersectionIterator;
51 typedef typename std::iterator_traits<ElementIterator>::difference_type
53
54 private:
55 typedef ForwardIteratorFacade<DerivedType, Value, Reference,
56 DifferenceType> Facade;
57
58 const GV* gv;
60 std::shared_ptr<IntersectionIterator> iit;
61
62 bool valid() const {
63 // we're valid if we're passed-the-end
64 if(eit == gv->template end<0>()) return true;
65 // or if we're on a boundary
66 if((*iit)->boundary() && !(*iit)->neighbor()) return true;
67 // otherwise we're invalid
68 return false;
69 }
70
71 void basic_increment() {
72 ++*iit;
73 if(*iit == gv->iend(*eit)) {
74 iit.reset();
75 ++eit;
76 if(eit != gv->template end<0>())
77 iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
78 }
79 }
80
81 public:
83 return **iit;
84 }
85 bool equals(const DerivedType& other) const {
86 if(eit != other.eit) return false;
87
88 // this is a bit tricky, since we may not compare iit if we are
89 // passed-the-end
90 bool mePassedTheEnd = eit == gv->template end<0>();
91 bool otherPassedTheEnd = other.eit == other.gv->template end<0>();
92
93 // both passed-the-end => consider them equal
94 if(mePassedTheEnd && otherPassedTheEnd) return true;
95
96 // one passed the end => not equal
97 if(mePassedTheEnd || otherPassedTheEnd) return false;
98
99 // none passed-the-end => do their iit iterators match?
100 return *iit == *other.iit;
101 }
102
103 void increment() {
104 basic_increment();
105 while(!valid()) basic_increment();
106 }
107
109
113 BoundaryIterator(const GV& gv_, const ElementIterator& eit_,
114 const IntersectionIterator& iit_)
115 : gv(&gv_), eit(eit_), iit(new IntersectionIterator(iit_))
116 {
117 while(!valid()) basic_increment();
118 }
120
125 BoundaryIterator(const GV& gv_, const ElementIterator& eit_)
126 : gv(&gv_), eit(eit_)
127 {
128 if(eit != gv->template end<0>())
129 iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
130
131 while(!valid()) basic_increment();
132 }
134
138 BoundaryIterator(const GV& gv_, bool end = false)
139 : gv(&gv_), eit(end ? gv->template end<0>() : gv->template begin<0>())
140 {
141 if(eit != gv->template end<0>())
142 iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
143
144 while(!valid()) basic_increment();
145 }
146 };
147
148 template<typename ElementIndexSet>
150 const ElementIndexSet& eis;
151
152 public:
153 IntersectionIndexSet(const ElementIndexSet& eis_)
154 : eis(eis_)
155 { }
156 };
157
158 template<typename GV>
160 const GV& gv;
161
162 public:
163 static const unsigned dimCell = GV::dimension-1;
164
165 typedef typename GV::Intersection Cell;
167
170
171 typedef Corner Point;
173
175 typedef typename GV::Communication Communication;
176
178 : gv(gv_)
179 { }
180
182 return CellIterator(gv);
183 }
185 return CellIterator(gv, true);
186 }
187
190 }
192 return CornerIterator(endCells());
193 }
194
196 PointIterator endPoints() const { return endCorners(); }
197
199 return ConnectivityWriter();
200 }
201 const Communication& comm() const {
202 return gv.comm();
203 }
204 };
205
206 } // namespace VTK
207
209
210} // namespace Dune
211
212#endif // DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
Include standard header files.
Definition: agrid.hh:60
iterate over the GridViews boundary intersections
Definition: boundaryiterators.hh:43
BoundaryIterator< GV > DerivedType
Definition: boundaryiterators.hh:46
BoundaryIterator(const GV &gv_, const ElementIterator &eit_)
construct a BoundaryIterator
Definition: boundaryiterators.hh:125
Reference dereference() const
Definition: boundaryiterators.hh:82
const GV::Intersection Value
Definition: boundaryiterators.hh:47
BoundaryIterator(const GV &gv_, bool end=false)
construct a BoundaryIterator
Definition: boundaryiterators.hh:138
BoundaryIterator(const GV &gv_, const ElementIterator &eit_, const IntersectionIterator &iit_)
construct a BoundaryIterator
Definition: boundaryiterators.hh:113
GV::template Codim< 0 >::Iterator ElementIterator
Definition: boundaryiterators.hh:49
Value & Reference
Definition: boundaryiterators.hh:48
GV::IntersectionIterator IntersectionIterator
Definition: boundaryiterators.hh:50
bool equals(const DerivedType &other) const
Definition: boundaryiterators.hh:85
std::iterator_traits< ElementIterator >::difference_type DifferenceType
Definition: boundaryiterators.hh:52
void increment()
Definition: boundaryiterators.hh:103
Definition: boundaryiterators.hh:149
IntersectionIndexSet(const ElementIndexSet &eis_)
Definition: boundaryiterators.hh:153
Definition: boundaryiterators.hh:159
PointIterator beginPoints() const
Definition: boundaryiterators.hh:195
ConnectivityWriter makeConnectivity() const
Definition: boundaryiterators.hh:198
GV::Communication Communication
Definition: boundaryiterators.hh:175
static const unsigned dimCell
Definition: boundaryiterators.hh:163
VTK::CornerIterator< CellIterator > CornerIterator
Definition: boundaryiterators.hh:169
BoundaryIterator< GV > CellIterator
Definition: boundaryiterators.hh:166
Corner Point
Definition: boundaryiterators.hh:171
CornerIterator beginCorners() const
Definition: boundaryiterators.hh:188
CellIterator beginCells() const
Definition: boundaryiterators.hh:181
NonConformingConnectivityWriter< Cell > ConnectivityWriter
Definition: boundaryiterators.hh:174
CornerIterator endCorners() const
Definition: boundaryiterators.hh:191
VTK::Corner< Cell > Corner
Definition: boundaryiterators.hh:168
GV::Intersection Cell
Definition: boundaryiterators.hh:165
CornerIterator PointIterator
Definition: boundaryiterators.hh:172
NonConformingBoundaryIteratorFactory(const GV &gv_)
Definition: boundaryiterators.hh:177
CellIterator endCells() const
Definition: boundaryiterators.hh:184
const Communication & comm() const
Definition: boundaryiterators.hh:201
PointIterator endPoints() const
Definition: boundaryiterators.hh:196
simple class representing a corner of a cell
Definition: corner.hh:25
iterate over the corners of some cell range
Definition: corneriterator.hh:39
writer for the connectivity array in nonconforming mode
Definition: functionwriter.hh:261