1
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
// vi: set et ts=8 sw=2 sts=2:
4
#ifndef DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
5
#define DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH
9
#include <dune/common/iteratorfacades.hh>
10
#include <dune/common/shared_ptr.hh>
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>
23
@brief Functions for VTK output on the skeleton
28
//! iterate over the GridViews boundary intersections
30
* This will visit all intersections for which boundary() is true and
31
* neighbor() is false.
34
class BoundaryIterator
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>
43
// reiterator the facades typedefs here
44
typedef BoundaryIterator<GV> DerivedType;
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
53
typedef ForwardIteratorFacade<DerivedType, Value, Reference,
54
DifferenceType> Facade;
58
shared_ptr<IntersectionIterator> iit;
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
69
void basic_increment() {
71
if(*iit == gv->iend(*eit)) {
74
if(eit != gv->template end<0>())
75
iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
80
Reference dereference() const {
83
bool equals(const DerivedType& other) const {
84
if(eit != other.eit) return false;
86
// this is a bit tricky, since we may not compare iit if we are
88
bool mePassedTheEnd = eit == gv->template end<0>();
89
bool otherPassedTheEnd = other.eit == other.gv->template end<0>();
91
// both passed-the-end => consider them equal
92
if(mePassedTheEnd && otherPassedTheEnd) return true;
94
// one passed the end => not equal
95
if(mePassedTheEnd || otherPassedTheEnd) return false;
97
// none passed-the-end => do their iit iterators match?
98
return *iit == *other.iit;
103
while(!valid()) basic_increment();
106
//! construct a BoundaryIterator
108
* The iterator will initially point to the intersection iit_. If that
109
* intersection is not valid, it will advance to the first valid one.
111
BoundaryIterator(const GV& gv_, const ElementIterator& eit_,
112
const IntersectionIterator& iit_)
113
: gv(&gv_), eit(eit_), iit(new IntersectionIterator(iit_))
115
while(!valid()) basic_increment();
117
//! construct a BoundaryIterator
119
* The iterator will initially point to eit_'s first intersection. If
120
* that intersection is not valid, it will advance to the first valid
123
BoundaryIterator(const GV& gv_, const ElementIterator& eit_)
124
: gv(&gv_), eit(eit_)
126
if(eit != gv->template end<0>())
127
iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
129
while(!valid()) basic_increment();
131
//! construct a BoundaryIterator
133
* If end == true, construct an end iterator for the given gridview.
134
* Otherwise, construct a begin iterator.
136
BoundaryIterator(const GV& gv_, bool end = false)
137
: gv(&gv_), eit(end ? gv->template end<0>() : gv->template begin<0>())
139
if(eit != gv->template end<0>())
140
iit.reset(new IntersectionIterator(gv->ibegin(*eit)));
142
while(!valid()) basic_increment();
146
template<typename ElementIndexSet>
147
class IntersectionIndexSet {
148
const ElementIndexSet& eis;
151
IntersectionIndexSet(const ElementIndexSet& eis_)
156
template<typename GV>
157
class NonConformingBoundaryIteratorFactory {
161
static const unsigned dimCell = GV::dimension-1;
163
typedef typename GV::Intersection Cell;
164
typedef BoundaryIterator<GV> CellIterator;
166
typedef VTK::Corner<Cell> Corner;
167
typedef VTK::CornerIterator<CellIterator> CornerIterator;
169
typedef Corner Point;
170
typedef CornerIterator PointIterator;
172
typedef NonConformingConnectivityWriter<Cell> ConnectivityWriter;
173
typedef typename GV::CollectiveCommunication CollectiveCommunication;
175
explicit NonConformingBoundaryIteratorFactory(const GV& gv_)
179
CellIterator beginCells() const {
180
return CellIterator(gv);
182
CellIterator endCells() const {
183
return CellIterator(gv, true);
186
CornerIterator beginCorners() const {
187
return CornerIterator(beginCells(), endCells());
189
CornerIterator endCorners() const {
190
return CornerIterator(endCells());
193
PointIterator beginPoints() const { return beginCorners(); }
194
PointIterator endPoints() const { return endCorners(); }
196
ConnectivityWriter makeConnectivity() const {
197
return ConnectivityWriter();
199
const CollectiveCommunication& comm() const {
210
#endif // DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH