grid.hh 17.3 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_GRID_HH
#define DUNE_CURVED_SURFACE_GRID_GRID_HH
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
5
6
7
8
9
10
11
12

#include <dune/common/deprecated.hh>

#include <dune/grid/common/grid.hh>

#include <dune/curvedsurfacegrid/gridfamily.hh>
#include <dune/curvedsurfacegrid/backuprestore.hh>
#include <dune/curvedsurfacegrid/datahandle.hh>
13
#include <dune/curvedsurfacegrid/gridfunction/gridfunction.hh>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
14
15
16
17
18
19
#include <dune/grid/geometrygrid/identity.hh>
#include <dune/grid/geometrygrid/persistentcontainer.hh>
#include <dune/grid/geometrygrid/grid.hh>

namespace Dune
{
20
21
22
23
24
  namespace Impl
  {
    template< class GridFunction, int order >
    struct CurvedSurfaceGridBase
    {
25
      using HG = GridOf_t<GridFunction>;
26
27
28
29
30
31
32
33
34
35
36

      using type = GridDefaultImplementation<
        HG::dimension, CGeo::DimRange<GridFunction>::value, typename HG::ctype,
        CGeo::GridFamily<GridFunction,order>
      >;
    };
  }

  template< class GridFunction, int order >
  using CurvedSurfaceGridBase = typename Impl::CurvedSurfaceGridBase<GridFunction,order>::type;

Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
37
38
39
40
41
42

  // CurvedSurfaceGrid
  // -----------------

  /** \class CurvedSurfaceGrid
   *  \brief grid wrapper replacing the geometries
Praetorius, Simon's avatar
Praetorius, Simon committed
43
   *  \ingroup CurvedGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
44
   *
Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
   *  CurvedSurfaceGrid wraps another DUNE grid and replaces its geometry by an implementation
   *  of a CurvedGeometry.
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
47
   *
48
49
50
   *  \tparam GF     GridViewFunction defined on a (flat) hostgrid
   *  \tparam order  Polynomial order of local lagrange basis functions to use when approximating
   *                 the curved geometry. [optional]
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
51
52
53
   *
   *  \nosubgrouping
   */
54
  template< class GF, int order = -1 >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
55
  class CurvedSurfaceGrid
56
57
      : public CurvedSurfaceGridBase<GF,order>
      , public CGeo::BackupRestoreFacilities<CurvedSurfaceGrid<GF,order> >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
58
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
59
    using Self = CurvedSurfaceGrid;
60
    using Super = CurvedSurfaceGridBase<GF,order>;
Praetorius, Simon's avatar
Praetorius, Simon committed
61
62
63
64

    // friend declarations
    template< class, class > friend class CGeo::IdSet;
    template< class, class > friend class CGeo::IndexSet;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
65
66

  public:
67
68
    using GridFunction = GF;
    using GridFamily = CGeo::GridFamily<GF,order>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
69
70
71
72
73

    /** \name Traits
     *  \{ */

    //! type of the grid traits
Praetorius, Simon's avatar
Praetorius, Simon committed
74
    using Traits = typename GridFamily::Traits;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
75

76
77
    using HostGrid = typename Traits::HostGrid;

Praetorius, Simon's avatar
Praetorius, Simon committed
78
79
    //! traits structure containing types for a codimension
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
80
81
82
83
84
85
86
87
88
89
90
91
92
     *  \tparam codim  codimension
     *
     *  \nosubgrouping
     */
    template< int codim >
    struct Codim;

    /** \} */

    /** \name Iterator Types
     *  \{ */

    //! iterator over the grid hierarchy
Praetorius, Simon's avatar
Praetorius, Simon committed
93
94
    using HierarchicIterator = typename Traits::HierarchicIterator;

Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
95
    //! iterator over intersections with other entities on the leaf level
Praetorius, Simon's avatar
Praetorius, Simon committed
96
97
    using LeafIntersectionIterator = typename Traits::LeafIntersectionIterator;

Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
98
    //! iterator over intersections with other entities on the same level
Praetorius, Simon's avatar
Praetorius, Simon committed
99
    using LevelIntersectionIterator = typename Traits::LevelIntersectionIterator;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
100
101
102

    /** \} */

Praetorius, Simon's avatar
Praetorius, Simon committed
103

Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
104
105
106
    /** \name Grid View Types
     *  \{ */

Praetorius, Simon's avatar
Praetorius, Simon committed
107
108
109
110
111
    //! type of view for leaf grid
    using LeafGridView = typename GridFamily::Traits::LeafGridView;

    //! type of view for level grid
    using LevelGridView = typename GridFamily::Traits::LevelGridView;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

    /** \} */


    /** \name Index and Id Set Types
     *  \{ */

    /** \brief type of leaf index set
     *
     *  The index set assigns consecutive indices to the entities of the
     *  leaf grid. The indices are of integral type and can be used to access
     *  arrays.
     *
     *  The leaf index set is a model of Dune::IndexSet.
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
127
    using LeafIndexSet = typename Traits::LeafIndexSet;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
128
129
130
131
132
133
134
135
136

    /** \brief type of level index set
     *
     *  The index set assigns consecutive indices to the entities of a grid
     *  level. The indices are of integral type and can be used to access
     *  arrays.
     *
     *  The level index set is a model of Dune::IndexSet.
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
137
    using LevelIndexSet = typename Traits::LevelIndexSet;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
138
139
140
141
142
143
144
145
146
147
148

    /** \brief type of global id set
     *
     *  The id set assigns a unique identifier to each entity within the
     *  grid. This identifier is unique over all processes sharing this grid.
     *
     *  \note Id's are neither consecutive nor necessarily of an integral
     *        type.
     *
     *  The global id set is a model of Dune::IdSet.
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
149
    using GlobalIdSet = typename Traits::GlobalIdSet;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

    /** \brief type of local id set
     *
     *  The id set assigns a unique identifier to each entity within the
     *  grid. This identifier needs only to be unique over this process.
     *
     *  Though the local id set may be identical to the global id set, it is
     *  often implemented more efficiently.
     *
     *  \note Ids are neither consecutive nor necessarily of an integral
     *        type.
     *  \note Local ids need not be compatible with global ids. Also, no
     *        mapping from local ids to global ones needs to exist.
     *
     *  The global id set is a model of Dune::IdSet.
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
166
    using LocalIdSet = typename Traits::LocalIdSet;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
167
168
169
170
171
172
173

    /** \} */

    /** \name Miscellaneous Types
     * \{ */

    //! type of vector coordinates (e.g., double)
Praetorius, Simon's avatar
Praetorius, Simon committed
174
    using ctype = typename Traits::ctype;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
175
176

    //! communicator with all other processes having some part of the grid
Praetorius, Simon's avatar
Praetorius, Simon committed
177
    using CollectiveCommunication = typename Traits::CollectiveCommunication;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
178
179
180
181
182
183

    /** \} */

    /** \name Construction and Destruction
     *  \{ */

Praetorius, Simon's avatar
Praetorius, Simon committed
184
185
186
    //! constructor for host-grid given by reference
    /**
     *  The references to host grid is stored in the grid. It must be valid until this grid
187
     *  wrapper is destroyed.
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
188
     *
Praetorius, Simon's avatar
Praetorius, Simon committed
189
190
191
192
     *  \param[in]  hostGrid   reference to the grid to wrap
     *  \param[in]  param      mapping from global coordinates in the host geometry
     *                         to global coordinates in the curved geometry
     *  \param[in]  allocator  storage allocator
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
193
     */
194
195
196
197
    CurvedSurfaceGrid (HostGrid& hostGrid, const GridFunction& gridFunction)
      : hostGrid_(hostGrid)
      , gridFunction_(gridFunction)
      , levelIndexSets_(hostGrid_.maxLevel()+1, nullptr)
Praetorius, Simon's avatar
Praetorius, Simon committed
198
    {}
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
199
200


Praetorius, Simon's avatar
Praetorius, Simon committed
201
    //! destructor
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
202
203
    ~CurvedSurfaceGrid ()
    {
204
      for (unsigned int i = 0; i < levelIndexSets_.size(); ++i)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
205
      {
206
207
        if (levelIndexSets_[i])
          delete (levelIndexSets_[i]);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
208
209
210
211
212
213
214
215
      }
    }

    /** \} */

    /** \name Size Methods
     *  \{ */

Praetorius, Simon's avatar
Praetorius, Simon committed
216
217
    //! obtain maximal grid level
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
218
219
220
221
222
223
224
225
226
227
     *  Grid levels are numbered 0, ..., L, where L is the value returned by
     *  this method.
     *
     *  \returns maximal grid level
     */
    int maxLevel () const
    {
      return hostGrid().maxLevel();
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
228
229
    //! obtain number of entites on a level
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
230
231
232
     *  \param[in]  level  level to consider
     *  \param[in]  codim  codimension to consider
     *
Praetorius, Simon's avatar
Praetorius, Simon committed
233
     *  \returns number of entities of codimension `codim` on grid level `level`.
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
234
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
235
    int size (int level, int codim) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
236
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
237
      return levelGridView(level).size(codim);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
238
239
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
240
241
    //! obtain number of leaf entities
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
242
243
244
245
     *  \param[in]  codim  codimension to consider
     *
     *  \returns number of leaf entities of codimension \em codim
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
246
    int size (int codim) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
247
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
248
      return leafGridView().size(codim);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
249
250
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
251
252
    //! obtain number of entites on a level
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
253
254
255
     *  \param[in]  level  level to consider
     *  \param[in]  type   geometry type to consider
     *
Praetorius, Simon's avatar
Praetorius, Simon committed
256
     *  \returns number of entities with a geometry of type `type` on grid level `level`.
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
257
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
258
    int size (int level, GeometryType type) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
259
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
260
      return levelGridView(level).size(type);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
261
262
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
263
264
265
    //! obtain number of leaf entities
    /**
     *  \returns number of leaf entities with a geometry of type `type`
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
266
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
267
    int size (GeometryType type) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
268
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
269
      return leafGridView().size(type);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
270
271
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
272
273
    //! returns the number of boundary segments within the macro grid
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
274
275
     *  \returns number of boundary segments within the macro grid
     */
276
    std::size_t numBoundarySegments () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
277
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
278
      return hostGrid().numBoundarySegments();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
279
280
281
    }
    /** \} */

Praetorius, Simon's avatar
Praetorius, Simon committed
282
    const GlobalIdSet& globalIdSet () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
283
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
284
285
286
      if (!globalIdSet_)
        globalIdSet_ = GlobalIdSet(hostGrid().globalIdSet());
      assert(globalIdSet_);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
287
288
289
      return globalIdSet_;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
290
    const LocalIdSet& localIdSet () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
291
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
292
293
294
      if (!localIdSet_)
        localIdSet_ = LocalIdSet(hostGrid().localIdSet());
      assert(localIdSet_);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
295
296
297
      return localIdSet_;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
298
    const LevelIndexSet& levelIndexSet (int level) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
299
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
300
      assert(levelIndexSets_.size() == (size_t)(maxLevel()+1));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
301

Praetorius, Simon's avatar
Praetorius, Simon committed
302
303
      if ((level < 0) || (level > maxLevel()))
        DUNE_THROW(GridError, "LevelIndexSet for nonexisting level " << level << " requested.");
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
304

Praetorius, Simon's avatar
Praetorius, Simon committed
305
306
307
308
      LevelIndexSet*& levelIndexSet = levelIndexSets_[level];
      if (!levelIndexSet)
        levelIndexSet = new LevelIndexSet(hostGrid().levelIndexSet(level));
      assert(levelIndexSet);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
309
310
311
      return *levelIndexSet;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
312
    const LeafIndexSet& leafIndexSet () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
313
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
314
315
316
      if (!leafIndexSet_)
        leafIndexSet_.reset(hostGrid().leafIndexSet());
      assert(leafIndexSet_);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
317
318
319
      return leafIndexSet_;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
320
    void globalRefine (int refCount)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
321
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
322
      hostGrid().globalRefine(refCount);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
323
324
325
      update();
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
326
    bool mark (int refCount, const typename Codim<0>::Entity& entity)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
327
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
328
      return hostGrid().mark(refCount, getHostEntity<0>(entity));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
329
330
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
331
    int getMark (const typename Codim<0>::Entity& entity) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
332
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
333
      return hostGrid().getMark(getHostEntity<0>(entity));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
    }

    bool preAdapt ()
    {
      return hostGrid().preAdapt();
    }

    bool adapt ()
    {
      bool ret = hostGrid().adapt();
      update();
      return ret;
    }

    void postAdapt ()
    {
      hostGrid().postAdapt();
    }

    /** \name Parallel Data Distribution and Communication Methods
     *  \{ */

Praetorius, Simon's avatar
Praetorius, Simon committed
356
357
    //! obtain CollectiveCommunication object
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
358
359
360
361
362
363
     *  The CollectiveCommunication object should be used to globally
     *  communicate information between all processes sharing this grid.
     *
     *  \note The CollectiveCommunication object returned is identical to the
     *        one returned by the host grid.
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
364
    const CollectiveCommunication& comm () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
365
366
367
368
369
370
    {
      return hostGrid().comm();
    }

    // data handle interface different between geo and interface

Praetorius, Simon's avatar
Praetorius, Simon committed
371
372
    //! rebalance the load each process has to handle
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
373
374
375
376
377
378
379
380
381
     *  A parallel grid is redistributed such that each process has about
     *  the same load (e.g., the same number of leaf entites).
     *
     *  \note DUNE does not specify, how the load is measured.
     *
     *  \returns \b true, if the grid has changed.
     */
    bool loadBalance ()
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
382
383
      const bool gridChanged = hostGrid().loadBalance();
      if (gridChanged)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
384
385
386
387
        update();
      return gridChanged;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
388
389
    //! rebalance the load each process has to handle
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
     *  A parallel grid is redistributed such that each process has about
     *  the same load (e.g., the same number of leaf entites).
     *
     *  The data handle is used to communicate the data associated with
     *  entities that move from one process to another.
     *
     *  \note DUNE does not specify, how the load is measured.
     *
     *  \param  datahandle  communication data handle (user defined)
     *
     *  \returns \b true, if the grid has changed.
     */

    template< class DataHandle, class Data >
Praetorius, Simon's avatar
Praetorius, Simon committed
404
    bool loadBalance (CommDataHandleIF<DataHandle, Data>& datahandle)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
405
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
406
      using DataHandleIF = CommDataHandleIF<DataHandle, Data>;
407
      using WrappedDataHandle = CGeo::CommDataHandle<Self, DataHandleIF>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
408

Praetorius, Simon's avatar
Praetorius, Simon committed
409
410
411
      WrappedDataHandle wrappedDataHandle(*this, datahandle);
      const bool gridChanged = hostGrid().loadBalance(wrappedDataHandle);
      if (gridChanged)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
412
413
414
415
        update();
      return gridChanged;
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
416
417
    //! obtain Entity from EntitySeed
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
418
     *  EntitySeed survives to a grid modification which only changes the grid coordinates.
Praetorius, Simon's avatar
Praetorius, Simon committed
419
420
     *  Therefore it is consistent to use an EntitySeed to rebuild an Entity after this kind
     *  of grid modification.
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
421
422
     */
    template< class EntitySeed >
Praetorius, Simon's avatar
Praetorius, Simon committed
423
    typename Traits::template Codim<EntitySeed::codimension>::Entity entity (const EntitySeed& seed) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
424
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
425
426
      using EntityImpl = typename Traits::template Codim<EntitySeed::codimension>::EntityImpl;
      return EntityImpl(*this, seed);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
427
428
429
430
431
432
433
    }

    /** \} */

    /** \name Grid Views
     *  \{ */

Praetorius, Simon's avatar
Praetorius, Simon committed
434
435
    //! View for a grid level
    LevelGridView levelGridView (int level) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
436
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
437
438
      using ViewImp = typename LevelGridView::GridViewImp;
      return LevelGridView(ViewImp(*this, hostGrid().levelGridView(level)));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
439
440
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
441
    //! View for the leaf grid
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
442
443
    LeafGridView leafGridView () const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
444
445
      using ViewImp = typename LeafGridView::GridViewImp;
      return LeafGridView(ViewImp(*this, hostGrid().leafGridView()));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
446
447
448
449
450
451
452
    }

    /** \} */

    /** \name Miscellaneous Methods
     *  \{ */

Praetorius, Simon's avatar
Praetorius, Simon committed
453
454
    //! obtain constant reference to the host grid
    const HostGrid& hostGrid () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
455
    {
456
      return hostGrid_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
457
458
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
459
460
    //! obtain mutable reference to the host grid
    HostGrid& hostGrid ()
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
461
    {
462
      return hostGrid_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
463
464
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
465
466
    //! update grid caches
    /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
467
468
469
470
471
472
473
474
475
     *  This method has to be called whenever the underlying host grid changes.
     *
     *  \note If you adapt the host grid through this geometry grid's
     *        adaptation or load balancing methods, update is automatically
     *        called.
     */
    void update ()
    {
      // adapt the coordinate function
476
      // GeoGrid::AdaptCoordFunction<typename CoordFunction::Interface>::adapt(coordFunction());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
477
478
479
480

      const int newNumLevels = maxLevel()+1;
      const int oldNumLevels = levelIndexSets_.size();

Praetorius, Simon's avatar
Praetorius, Simon committed
481
      for (int i = newNumLevels; i < oldNumLevels; ++i)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
482
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
483
484
        if (levelIndexSets_[i])
          delete levelIndexSets_[i];
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
485
      }
Praetorius, Simon's avatar
Praetorius, Simon committed
486
      levelIndexSets_.resize(newNumLevels, nullptr);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
487
488
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
489
    //! obtain constant reference to the coordinate function
490
    GridFunction const& gridFunction () const { return gridFunction_; }
491
492
493
494
495
496
497
498
499
500

    bool useGeometryCaching () const
    {
      return useGeometryCaching_;
    }

    void setGeometryCaching (bool cache)
    {
      useGeometryCaching_ = cache;
    }
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
501
502
503
504
505

    /** \} */

  protected:
    template< int codim >
Praetorius, Simon's avatar
Praetorius, Simon committed
506
507
    static const typename HostGrid::template Codim<codim>::Entity&
    getHostEntity(const typename Codim<codim>::Entity& entity)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
508
    {
509
      return entity.impl().hostEntity();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
510
511
512
    }

  private:
513
514
    HostGrid& hostGrid_;
    GridFunction gridFunction_;
Praetorius, Simon's avatar
Praetorius, Simon committed
515

516
    bool useGeometryCaching_ = false;
Praetorius, Simon's avatar
Praetorius, Simon committed
517

518
    mutable std::vector<LevelIndexSet*> levelIndexSets_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
519
520
521
522
    mutable LeafIndexSet leafIndexSet_;
    mutable GlobalIdSet globalIdSet_;
    mutable LocalIdSet localIdSet_;

Praetorius, Simon's avatar
Praetorius, Simon committed
523
524
525
526
527
528
529
530
531
532
  private:
    template <class Indices>
    struct GeometryCache;

    template <int... codims>
    struct GeometryCache<std::integer_sequence<int,codims...>>
    {
      using type = std::tuple<
        std::map<
          typename HostGrid::Traits::LocalIdSet::IdType,
533
          typename Traits::template Codim<codims>::GeometryImpl
Praetorius, Simon's avatar
Praetorius, Simon committed
534
535
536
537
        >...
      >;
    };

538
    mutable typename GeometryCache<std::make_integer_sequence<int,Traits::dimension+1>>::type geometryCache_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
539
540
541
542
543
544
  };


  // CurvedSurfaceGrid::Codim
  // ------------------------

545
  template< class GridFunction, int order >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
546
  template< int codim >
547
  struct CurvedSurfaceGrid<GridFunction,order>::Codim
548
    : public Super::template Codim< codim >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
549
550
551
552
553
554
555
556
  {
    /** \name Entity types
     *  \{ */

    /** \brief type of entity
     *
     *  The entity is a model of Dune::Entity.
     */
557
    using Entity = typename Traits::template Codim< codim >::Entity;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
558
559
560
561
562
563
564
565
566
567
568
569
570
571

    /** \} */

    /** \name Geometry Types
     *  \{ */

    /** \brief type of world geometry
     *
     *  Models the geomtry mapping of the entity, i.e., the mapping from the
     *  reference element into world coordinates.
     *
     *  The geometry is a model of Dune::Geometry, implemented through the
     *  generic geometries provided by dune-grid.
     */
572
    using Geometry = typename Traits::template Codim< codim >::Geometry;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
573
574
575
576
577
578
579
580
581

    /** \brief type of local geometry
     *
     *  Models the geomtry mapping into the reference element of dimension
     *  \em dimension.
     *
     *  The local geometry is a model of Dune::Geometry, implemented through
     *  the generic geometries provided by dune-grid.
     */
582
    using LocalGeometry = typename Traits::template Codim< codim >::LocalGeometry;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
583
584
585
586
587
588
589
590
591

    /** \} */

    /** \name Iterator Types
     *  \{ */

    template< PartitionIteratorType pitype >
    struct Partition
    {
592
593
594
595
      using LeafIterator
        = typename Traits::template Codim<codim>::template Partition< pitype >::LeafIterator;
      using LevelIterator
        = typename Traits::template Codim<codim>::template Partition< pitype >::LevelIterator;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
596
597
598
599
600
601
602
603
604
    };

    /** \brief type of leaf iterator
     *
     *  This iterator enumerates the entites of codimension \em codim of a
     *  grid level.
     *
     *  The level iterator is a model of Dune::LevelIterator.
     */
605
    using LeafIterator = typename Partition< All_Partition >::LeafIterator;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
606
607
608
609
610
611
612
613

    /** \brief type of level iterator
     *
     *  This iterator enumerates the entites of codimension \em codim of the
     *  leaf grid.
     *
     *  The leaf iterator is a model of Dune::LeafIterator.
     */
614
    using LevelIterator = typename Partition< All_Partition >::LevelIterator;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
615
616
617
618
619
620

    /** \} */
  };

} // namespace Dune

Praetorius, Simon's avatar
Praetorius, Simon committed
621
#endif // DUNE_CURVED_SURFACE_GRID_GRID_HH