dune-grid 2.8.0
Loading...
Searching...
No Matches
boundaryiterators.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
4#ifndef DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
5#define DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
6
7#include <iterator>
8#include <memory>
9
10#include <dune/common/iteratorfacades.hh>
11
15
16namespace Dune {
17
20
26 namespace VTK {
27
29
33 template<typename GV>
35 : public ForwardIteratorFacade
36 < BoundaryIterator<GV>,
37 const typename GV::Intersection,
38 const typename GV::Intersection&,
39 typename std::iterator_traits<typename GV::template Codim<0>::
40 Iterator>::difference_type>
41 {
42 public:
43 // reiterator the facades typedefs here
45 typedef const typename GV::Intersection Value;
46 typedef Value& Reference;
47 typedef typename GV::template Codim<0>::Iterator ElementIterator;
48 typedef typename GV::IntersectionIterator IntersectionIterator;
49 typedef typename std::iterator_traits<ElementIterator>::difference_type
51
52 private:
53 typedef ForwardIteratorFacade<DerivedType, Value, Reference,
54 DifferenceType> Facade;
55
56 const GV* gv;
58 std::shared_ptr<IntersectionIterator> iit;
59
60 bool valid() const {
61 // we're valid if we're passed-the-end
62 if(eit == gv->template end<0>()) return true;
63 // or if we're on a boundary
64 if((*iit)->boundary() && !(*iit)->neighbor()) return true;
65 // otherwise we're invalid
66 return false;
67 }
68
69 void basic_increment() {
70 ++*iit;
71 if(*iit == gv->iend(*eit)) {
72 iit.reset();
73 ++eit;
74 if(eit != gv->template end<0>())
75 iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
76 }
77 }
78
79 public:
81 return **iit;
82 }
83 bool equals(const DerivedType& other) const {
84 if(eit != other.eit) return false;
85
86 // this is a bit tricky, since we may not compare iit if we are
87 // passed-the-end
88 bool mePassedTheEnd = eit == gv->template end<0>();
89 bool otherPassedTheEnd = other.eit == other.gv->template end<0>();
90
91 // both passed-the-end => consider them equal
92 if(mePassedTheEnd && otherPassedTheEnd) return true;
93
94 // one passed the end => not equal
95 if(mePassedTheEnd || otherPassedTheEnd) return false;
96
97 // none passed-the-end => do their iit iterators match?
98 return *iit == *other.iit;
99 }
100
101 void increment() {
102 basic_increment();
103 while(!valid()) basic_increment();
104 }
105
107
111 BoundaryIterator(const GV& gv_, const ElementIterator& eit_,
112 const IntersectionIterator& iit_)
113 : gv(&gv_), eit(eit_), iit(new IntersectionIterator(iit_))
114 {
115 while(!valid()) basic_increment();
116 }
118
123 BoundaryIterator(const GV& gv_, const ElementIterator& eit_)
124 : gv(&gv_), eit(eit_)
125 {
126 if(eit != gv->template end<0>())
127 iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
128
129 while(!valid()) basic_increment();
130 }
132
136 BoundaryIterator(const GV& gv_, bool end = false)
137 : gv(&gv_), eit(end ? gv->template end<0>() : gv->template begin<0>())
138 {
139 if(eit != gv->template end<0>())
140 iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
141
142 while(!valid()) basic_increment();
143 }
144 };
145
146 template<typename ElementIndexSet>
148 const ElementIndexSet& eis;
149
150 public:
151 IntersectionIndexSet(const ElementIndexSet& eis_)
152 : eis(eis_)
153 { }
154 };
155
156 template<typename GV>
158 const GV& gv;
159
160 public:
161 static const unsigned dimCell = GV::dimension-1;
162
163 typedef typename GV::Intersection Cell;
165
168
169 typedef Corner Point;
171
173 typedef typename GV::CollectiveCommunication CollectiveCommunication;
174
176 : gv(gv_)
177 { }
178
180 return CellIterator(gv);
181 }
183 return CellIterator(gv, true);
184 }
185
188 }
190 return CornerIterator(endCells());
191 }
192
194 PointIterator endPoints() const { return endCorners(); }
195
197 return ConnectivityWriter();
198 }
200 return gv.comm();
201 }
202 };
203
204 } // namespace VTK
205
207
208} // namespace Dune
209
210#endif // DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
Include standard header files.
Definition: agrid.hh:58
iterate over the GridViews boundary intersections
Definition: boundaryiterators.hh:41
BoundaryIterator< GV > DerivedType
Definition: boundaryiterators.hh:44
BoundaryIterator(const GV &gv_, const ElementIterator &eit_)
construct a BoundaryIterator
Definition: boundaryiterators.hh:123
Reference dereference() const
Definition: boundaryiterators.hh:80
const GV::Intersection Value
Definition: boundaryiterators.hh:45
BoundaryIterator(const GV &gv_, bool end=false)
construct a BoundaryIterator
Definition: boundaryiterators.hh:136
BoundaryIterator(const GV &gv_, const ElementIterator &eit_, const IntersectionIterator &iit_)
construct a BoundaryIterator
Definition: boundaryiterators.hh:111
GV::template Codim< 0 >::Iterator ElementIterator
Definition: boundaryiterators.hh:47
Value & Reference
Definition: boundaryiterators.hh:46
GV::IntersectionIterator IntersectionIterator
Definition: boundaryiterators.hh:48
bool equals(const DerivedType &other) const
Definition: boundaryiterators.hh:83
std::iterator_traits< ElementIterator >::difference_type DifferenceType
Definition: boundaryiterators.hh:50
void increment()
Definition: boundaryiterators.hh:101
Definition: boundaryiterators.hh:147
IntersectionIndexSet(const ElementIndexSet &eis_)
Definition: boundaryiterators.hh:151
Definition: boundaryiterators.hh:157
PointIterator beginPoints() const
Definition: boundaryiterators.hh:193
ConnectivityWriter makeConnectivity() const
Definition: boundaryiterators.hh:196
const CollectiveCommunication & comm() const
Definition: boundaryiterators.hh:199
static const unsigned dimCell
Definition: boundaryiterators.hh:161
VTK::CornerIterator< CellIterator > CornerIterator
Definition: boundaryiterators.hh:167
BoundaryIterator< GV > CellIterator
Definition: boundaryiterators.hh:164
Corner Point
Definition: boundaryiterators.hh:169
CornerIterator beginCorners() const
Definition: boundaryiterators.hh:186
CellIterator beginCells() const
Definition: boundaryiterators.hh:179
NonConformingConnectivityWriter< Cell > ConnectivityWriter
Definition: boundaryiterators.hh:172
CornerIterator endCorners() const
Definition: boundaryiterators.hh:189
VTK::Corner< Cell > Corner
Definition: boundaryiterators.hh:166
GV::Intersection Cell
Definition: boundaryiterators.hh:163
CornerIterator PointIterator
Definition: boundaryiterators.hh:170
NonConformingBoundaryIteratorFactory(const GV &gv_)
Definition: boundaryiterators.hh:175
CellIterator endCells() const
Definition: boundaryiterators.hh:182
GV::CollectiveCommunication CollectiveCommunication
Definition: boundaryiterators.hh:173
PointIterator endPoints() const
Definition: boundaryiterators.hh:194
simple class representing a corner of a cell
Definition: corner.hh:23
iterate over the corners of some cell range
Definition: corneriterator.hh:37
writer for the connectivity array in nonconforming mode
Definition: functionwriter.hh:259