gridview.hh 7.57 KB
Newer Older
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
1
2
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
Praetorius, Simon's avatar
Praetorius, Simon committed
3
4
#ifndef DUNE_CURVED_SURFACE_GRID_GRIDVIEW_HH
#define DUNE_CURVED_SURFACE_GRID_GRIDVIEW_HH
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#include <dune/common/typetraits.hh>
#include <dune/common/exceptions.hh>

#include <dune/grid/common/capabilities.hh>
#include <dune/grid/common/gridview.hh>
#include <dune/curvedsurfacegrid/datahandle.hh>
#include <dune/curvedsurfacegrid/indexsets.hh>
#include <dune/curvedsurfacegrid/intersection.hh>
#include <dune/curvedsurfacegrid/intersectioniterator.hh>
#include <dune/curvedsurfacegrid/iterator.hh>

namespace Dune
{
Praetorius, Simon's avatar
Praetorius, Simon committed
19
  namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
20
21
22
23
24
  {

    // Internal Forward Declarations
    // -----------------------------

25
    template< class HGV, class CF, int order, class Allocator >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
26
27
28
29
30
31
    class GridView;


    // GridViewTraits
    // --------------

32
    template< class HGV, class CF, int order, class Allocator >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
33
34
    class GridViewTraits
    {
35
      friend class GridView<HGV, CF, order, Allocator>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
36

Praetorius, Simon's avatar
Praetorius, Simon committed
37
      using HostGridView = HGV;
38
      using CoordFunction = CF;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
39

Praetorius, Simon's avatar
Praetorius, Simon committed
40
41
42
      using HostGrid = typename HostGridView::Grid;
      using HostIntersection = typename HostGridView::Intersection;
      using HostIntersectionIterator = typename HostGridView::IntersectionIterator;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
43
44

    public:
45
46
      using GridViewImp = GridView<HostGridView, CoordFunction, order, Allocator>;
      using Grid = Dune::CurvedSurfaceGrid<HostGrid, CoordFunction, order, Allocator>;
Praetorius, Simon's avatar
Praetorius, Simon committed
47
      using IndexSet = CGeo::IndexSet<const Grid, typename HostGridView::IndexSet>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
48

Praetorius, Simon's avatar
Praetorius, Simon committed
49
      using Intersection = Dune::Intersection<const Grid, CGeo::Intersection<const Grid, HostIntersection> >;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
50

Praetorius, Simon's avatar
Praetorius, Simon committed
51
52
      using IntersectionIterator
        = Dune::IntersectionIterator<const Grid, CGeo::IntersectionIterator<const Grid, HostIntersectionIterator>, CGeo::Intersection<const Grid, HostIntersection> >;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
53

Praetorius, Simon's avatar
Praetorius, Simon committed
54
      using CollectiveCommunication = typename HostGridView::CollectiveCommunication;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
55
56
57
58

      template< int codim >
      struct Codim
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
59
60
        using IteratorImp = CGeo::Iterator<HostGridView, codim, All_Partition, const Grid>;
        using Iterator = Dune::EntityIterator<codim, const Grid, IteratorImp>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
61

Praetorius, Simon's avatar
Praetorius, Simon committed
62
        using Entity = typename Grid::Traits::template Codim<codim>::Entity;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
63

Praetorius, Simon's avatar
Praetorius, Simon committed
64
65
        using Geometry = typename Grid::template Codim<codim>::Geometry;
        using LocalGeometry = typename Grid::template Codim<codim>::LocalGeometry;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
66
67
68
69

        template< PartitionIteratorType pit >
        struct Partition
        {
Praetorius, Simon's avatar
Praetorius, Simon committed
70
71
          using IteratorImp = CGeo::Iterator<HostGridView, codim, pit, const Grid>;
          using Iterator = Dune::EntityIterator<codim, const Grid, IteratorImp>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
72
73
74
75
76
77
78
79
80
81
82
        };
      };

      static const bool conforming = HostGridView::conforming;
    };



    // GridView
    // --------

83
    template< class HGV, class CF, int order, class Allocator >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
84
85
    class GridView
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
86
      using Self = GridView;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
87
88

    public:
89
      using Traits = GridViewTraits<HGV, CF, order, Allocator>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
90

Praetorius, Simon's avatar
Praetorius, Simon committed
91
92
93
94
95
96
      using HostGridView = typename Traits::HostGridView;
      using Grid = typename Traits::Grid;
      using IndexSet = typename Traits::IndexSet;
      using Intersection = typename Traits::Intersection;
      using IntersectionIterator = typename Traits::IntersectionIterator;
      using CollectiveCommunication = typename Traits::CollectiveCommunication;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
97
98
99

      template< int codim >
      struct Codim
Praetorius, Simon's avatar
Praetorius, Simon committed
100
        : public Traits::template Codim<codim>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
101
102
103
104
      {};

      static const bool conforming = Traits::conforming;

Praetorius, Simon's avatar
Praetorius, Simon committed
105
106
107
108
109
    public:
      // construct from a host-gridview
      GridView (const Grid& grid, const HostGridView& hostGridView)
        : grid_(&grid)
        , hostGridView_(hostGridView)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
110
111
      {}

112
113
114
115
116
117
118
119
120
121
122
      //! copy constructor. Only copies grid and hostGridView
      GridView (const Self& other)
        : grid_(other.grid_)
        , hostGridView_(other.hostGridView_)
      {}

      //! move constructor. Only moves grid and hostGridView
      GridView (Self&& other)
        : grid_(other.grid_)
        , hostGridView_(std::move(other.hostGridView_))
      {}
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
123

Praetorius, Simon's avatar
Praetorius, Simon committed
124
125
      //! copy-assignment operator
      Self& operator= (const Self& other)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
126
127
128
      {
        grid_ = other.grid_;
        hostGridView_ = other.hostGridView_;
Praetorius, Simon's avatar
Praetorius, Simon committed
129
130
        if (indexSet_)
          indexSet_.reset(hostGridView().indexSet());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
131
132
133
        return *this;
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
134
135
      //! move-assignment operator
      Self& operator= (Self&& other)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
136
137
      {
        grid_ = other.grid_;
Praetorius, Simon's avatar
Praetorius, Simon committed
138
139
140
        hostGridView_ = std::move(other.hostGridView_);
        if (indexSet_)
          indexSet_.reset(hostGridView().indexSet()); // TODO: find a better way for copy and move!
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
141
142
143
        return *this;
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
144
      const Grid& grid () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
145
146
147
148
149
      {
        assert( grid_ );
        return *grid_;
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
150
      const IndexSet& indexSet () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
151
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
152
        indexSet_.reset(hostGridView().indexSet());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
153
154
155
        return indexSet_;
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
156
      int size (int codim) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
157
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
158
        return hostGridView().size(codim);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
159
160
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
161
      int size (const GeometryType& type) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
162
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
163
        return hostGridView().size(type);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
164
165
166
      }

      template< int codim >
Praetorius, Simon's avatar
Praetorius, Simon committed
167
      typename Codim<codim>::Iterator begin () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
168
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
169
        return begin<codim, All_Partition>();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
170
171
172
      }

      template< int codim, PartitionIteratorType pit >
Praetorius, Simon's avatar
Praetorius, Simon committed
173
      typename Codim<codim>::template Partition<pit>::Iterator begin () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
174
      {
175
        using IteratorImp = typename Traits::template Codim<codim>::template Partition<pit>::IteratorImp;
Praetorius, Simon's avatar
Praetorius, Simon committed
176
        return IteratorImp::begin(grid(), hostGridView());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
177
178
179
      }

      template< int codim >
Praetorius, Simon's avatar
Praetorius, Simon committed
180
      typename Codim<codim>::Iterator end () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
181
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
182
        return end<codim, All_Partition>();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
183
184
185
      }

      template< int codim, PartitionIteratorType pit >
Praetorius, Simon's avatar
Praetorius, Simon committed
186
      typename Codim<codim>::template Partition<pit>::Iterator end () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
187
      {
188
        using IteratorImp = typename Traits::template Codim<codim>::template Partition<pit>::IteratorImp;
Praetorius, Simon's avatar
Praetorius, Simon committed
189
        return IteratorImp::end(grid(), hostGridView());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
190
191
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
192
      IntersectionIterator ibegin (const typename Codim<0>::Entity& entity) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
193
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
194
195
        using IntersectionIteratorImpl = CGeo::IntersectionIterator<const Grid, typename HostGridView::IntersectionIterator>;
        return IntersectionIteratorImpl(entity, hostGridView().ibegin(entity.impl().hostEntity()));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
196
197
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
198
      IntersectionIterator iend (const typename Codim<0>::Entity& entity) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
199
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
200
201
        using IntersectionIteratorImpl = CGeo::IntersectionIterator<const Grid, typename HostGridView::IntersectionIterator>;
        return IntersectionIteratorImpl(entity, hostGridView().iend(entity.impl().hostEntity()));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
202
203
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
204
      const CollectiveCommunication& comm () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
205
206
207
208
      {
        return hostGridView().comm();
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
209
      int overlapSize (int codim) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
210
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
211
        return hostGridView().overlapSize(codim);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
212
213
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
214
      int ghostSize (int codim) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
215
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
216
        return hostGridView().ghostSize(codim);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
217
218
219
      }

      template< class DataHandle, class Data >
Praetorius, Simon's avatar
Praetorius, Simon committed
220
221
222
      void communicate (CommDataHandleIF<DataHandle, Data>& dataHandle,
                        InterfaceType interface,
                        CommunicationDirection direction) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
223
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
224
225
        using DataHandleIF = CommDataHandleIF<DataHandle, Data>;
        using WrappedDataHandle = CGeo::CommDataHandle<Grid, DataHandleIF>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
226

Praetorius, Simon's avatar
Praetorius, Simon committed
227
228
        WrappedDataHandle wrappedDataHandle(grid(), dataHandle);
        hostGridView().communicate(wrappedDataHandle, interface, direction);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
229
230
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
231
      const HostGridView& hostGridView () const { return hostGridView_; }
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
232
233
234
235
236
237
238

    private:
      const Grid *grid_;
      HostGridView hostGridView_;
      mutable IndexSet indexSet_;
    };

Praetorius, Simon's avatar
Praetorius, Simon committed
239
  } // namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
240
241
} // namespace Dune

Praetorius, Simon's avatar
Praetorius, Simon committed
242
#endif // DUNE_CURVED_SURFACE_GRID_GRIDVIEW_HH