~ubuntu-branches/ubuntu/trusty/dune-grid/trusty

« back to all changes in this revision

Viewing changes to dune/grid/io/file/vtk/boundaryiterators.hh

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2012-04-06 11:31:20 UTC
  • Revision ID: package-import@ubuntu.com-20120406113120-x0z4e0qqgfhmaj2a
Tags: upstream-2.2~svn7982
Import upstream version 2.2~svn7982

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=8 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
 
 
9
#include <dune/common/iteratorfacades.hh>
 
10
#include <dune/common/shared_ptr.hh>
 
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
 
 
16
namespace Dune {
 
17
 
 
18
  //! \addtogroup VTK
 
19
  //! \{
 
20
 
 
21
  /** @file
 
22
      @author Jö Fahlke
 
23
      @brief Functions for VTK output on the skeleton
 
24
  */
 
25
 
 
26
  namespace VTK {
 
27
 
 
28
    //! iterate over the GridViews boundary intersections
 
29
    /**
 
30
     * This will visit all intersections for which boundary() is true and
 
31
     * neighbor() is false.
 
32
     */
 
33
    template<typename GV>
 
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>
 
41
    {
 
42
    public:
 
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
 
50
              DifferenceType;
 
51
 
 
52
    private:
 
53
      typedef ForwardIteratorFacade<DerivedType, Value, Reference,
 
54
                                    DifferenceType> Facade;
 
55
 
 
56
      const GV* gv;
 
57
      ElementIterator eit;
 
58
      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:
 
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
 
 
106
      //! construct a BoundaryIterator
 
107
      /**
 
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.
 
110
       */
 
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
      }
 
117
      //! construct a BoundaryIterator
 
118
      /**
 
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
 
121
       * one.
 
122
       */
 
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
      }
 
131
      //! construct a BoundaryIterator
 
132
      /**
 
133
       * If end == true, construct an end iterator for the given gridview.
 
134
       * Otherwise, construct a begin iterator.
 
135
       */
 
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
 
 
206
  //! \} group VTK
 
207
 
 
208
} // namespace Dune
 
209
 
 
210
#endif // DUNE_GRID_IO_FILE_VTK_BOUNDARYITERATORS_HH