Dune Core Modules (2.3.1)

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
11
12#include <dune/grid/io/file/vtk/corner.hh>
13#include <dune/grid/io/file/vtk/corneriterator.hh>
14#include <dune/grid/io/file/vtk/functionwriter.hh>
15
16namespace Dune {
17
20
26 namespace VTK {
27
29
33 template<typename GV>
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
50 DifferenceType;
51
52 private:
53 typedef ForwardIteratorFacade<DerivedType, Value, Reference,
54 DifferenceType> Facade;
55
56 const GV* gv;
57 ElementIterator eit;
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:
80 Reference dereference() const {
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>
147 class IntersectionIndexSet {
148 const ElementIndexSet& eis;
149
150 public:
151 IntersectionIndexSet(const ElementIndexSet& eis_)
152 : eis(eis_)
153 { }
154 };
155
156 template<typename GV>
157 class NonConformingBoundaryIteratorFactory {
158 const GV& gv;
159
160 public:
161 static const unsigned dimCell = GV::dimension-1;
162
163 typedef typename GV::Intersection Cell;
164 typedef BoundaryIterator<GV> CellIterator;
165
166 typedef VTK::Corner<Cell> Corner;
167 typedef VTK::CornerIterator<CellIterator> CornerIterator;
168
169 typedef Corner Point;
170 typedef CornerIterator PointIterator;
171
172 typedef NonConformingConnectivityWriter<Cell> ConnectivityWriter;
173 typedef typename GV::CollectiveCommunication CollectiveCommunication;
174
175 explicit NonConformingBoundaryIteratorFactory(const GV& gv_)
176 : gv(gv_)
177 { }
178
179 CellIterator beginCells() const {
180 return CellIterator(gv);
181 }
182 CellIterator endCells() const {
183 return CellIterator(gv, true);
184 }
185
186 CornerIterator beginCorners() const {
187 return CornerIterator(beginCells(), endCells());
188 }
189 CornerIterator endCorners() const {
190 return CornerIterator(endCells());
191 }
192
193 PointIterator beginPoints() const { return beginCorners(); }
194 PointIterator endPoints() const { return endCorners(); }
195
196 ConnectivityWriter makeConnectivity() const {
197 return ConnectivityWriter();
198 }
199 const CollectiveCommunication& comm() const {
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
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:142
iterate over the GridViews boundary intersections
Definition: boundaryiterators.hh:41
BoundaryIterator(const GV &gv_, const ElementIterator &eit_)
construct a BoundaryIterator
Definition: boundaryiterators.hh:123
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
void reset()
Decrease the reference count by one and free the memory if the reference count has reached 0.
Definition: shared_ptr.hh:354
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignment.hh:14
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)