entity.hh 12.5 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_ENTITY_HH
#define DUNE_CURVED_SURFACE_GRID_ENTITY_HH
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
5

6
#include <dune/common/std/optional.hh>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
7
8
9
#include <dune/geometry/referenceelements.hh>

#include <dune/grid/common/grid.hh>
10
#include <dune/curvedsurfacegrid/geometry.hh>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
11
12
13

namespace Dune
{
Praetorius, Simon's avatar
Praetorius, Simon committed
14
  namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
15
16
17
18
19
20
21
  {

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

    /** \class EntityBase
     *  \brief actual implementation of the entity
Praetorius, Simon's avatar
Praetorius, Simon committed
22
     *  \ingroup CurvedGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
23
24
25
26
     *
     *  \tparam  codim  codimension of the entity
     *  \tparam  Grid   CurvedSurfaceGrid, this entity belongs to
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
27
    template< int codim, class Grid >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
28
29
30
31
    class EntityBase;

    /** \class Entity
     *  \brief DUNE-conform implementation of the entity
Praetorius, Simon's avatar
Praetorius, Simon committed
32
     *  \ingroup CurvedGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
     *
     *  This class merely changes the template parameters of the entity to make
     *  DUNE happy. The actual implementation of the entity can be found in
     *  EntityBase.
     *
     *  \tparam  codim  codimension of the entity
     *  \tparam  dim    dimension of the Grid (redundant information)
     *  \tparam  Grid   CurvedSurfaceGrid, this entity belongs to
     */
    template< int codim, int dim, class Grid >
    class Entity;



    // External Forward Declarations
    // -----------------------------

    template< class Grid >
    class HierarchicIterator;

    template< class Grid, class HostIntersectionIterator >
    class IntersectionIterator;


57
    template< int codim, class G >
Praetorius, Simon's avatar
Praetorius, Simon committed
58
    class EntityBase
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
59
    {
60
      using Traits = typename std::remove_const_t<G>::Traits;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

    public:
      /** \name Attributes
       *  \{ */

      //! codimensioon of the entity
      static const int codimension = codim;
      //! dimension of the grid
      static const int dimension = Traits::dimension;
      //! dimension of the entity
      static const int mydimension = dimension - codimension;
      //! dimension of the world
      static const int dimensionworld = Traits::dimensionworld;

      /** \} */

      /** \name Types Required by DUNE
       *  \{ */

      //! coordinate type of the grid
Praetorius, Simon's avatar
Praetorius, Simon committed
81
      using ctype = typename Traits::ctype;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
82
83
84
85
86
87
88
89

      /** \} */

    public:
      /** \name Host Types
       *  \{ */

      //! type of corresponding entity seed
Praetorius, Simon's avatar
Praetorius, Simon committed
90
      using EntitySeed = typename Traits::template Codim<codimension>::EntitySeed;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
91

Praetorius, Simon's avatar
Praetorius, Simon committed
92
      /** \} */
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
93
94

    public:
95
96
97
98
99
      using Grid = typename Traits::Grid;
      using GridFunction = typename Traits::GridFunction;

      //! type of the host grid
      using HostGrid = typename Traits::HostGrid;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
100

101
102
103
104
105
106
107
      //! type of corresponding host entity
      using HostEntity = typename HostGrid::template Codim<codim>::Entity;

      //! type of host elements, i.e., of host entities of codimension 0
      using HostElement = typename HostGrid::template Codim<0>::Entity;

    public:
Praetorius, Simon's avatar
Praetorius, Simon committed
108
      EntityBase () = default;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
109

Praetorius, Simon's avatar
Praetorius, Simon committed
110
111
112
      // Construct the entity from an entity seed
      EntityBase (const Grid& grid, const EntitySeed& seed)
        : hostEntity_(grid.hostGrid().entity(seed.impl().hostEntitySeed()))
113
        , gridFunction_(&grid.gridFunction())
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
114
115
      {}

Praetorius, Simon's avatar
Praetorius, Simon committed
116
      // construct the entity from a subentity of a host-entity
117
      EntityBase (const GridFunction& gridFunction, const HostElement& hostElement, int i)
Praetorius, Simon's avatar
Praetorius, Simon committed
118
        : hostEntity_(hostElement.template subEntity<codim>(i))
119
        , gridFunction_(&gridFunction)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
120
121
      {}

Praetorius, Simon's avatar
Praetorius, Simon committed
122
      // construct the entity from a host-entity
123
      EntityBase (const GridFunction& gridFunction, const HostEntity& hostEntity)
Praetorius, Simon's avatar
Praetorius, Simon committed
124
        : hostEntity_(hostEntity)
125
        , gridFunction_(&gridFunction)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
126
127
      {}

Praetorius, Simon's avatar
Praetorius, Simon committed
128
      // construct the entity from a host-entity
129
      EntityBase (const GridFunction& gridFunction, HostEntity&& hostEntity)
Praetorius, Simon's avatar
Praetorius, Simon committed
130
        : hostEntity_(std::move(hostEntity))
131
        , gridFunction_(&gridFunction)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
132
133
      {}

Praetorius, Simon's avatar
Praetorius, Simon committed
134
135
      //! compare two entities
      bool equals (const EntityBase& other) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
136
137
138
139
140
141
142
143
      {
        return hostEntity_ == other.hostEntity_;
      }

    public:
      /** \name Methods Shared by Entities of All Codimensions
       *  \{ */

Praetorius, Simon's avatar
Praetorius, Simon committed
144
145
      //! obtain the name of the corresponding reference element
      /**
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
146
147
148
149
150
151
152
       *  This type can be used to access the DUNE reference element.
       */
      GeometryType type () const
      {
        return hostEntity().type();
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
153
      //! obtain the level of this entity
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
154
155
156
157
158
      int level () const
      {
        return hostEntity().level();
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
159
      //! obtain the partition type of this entity
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
160
161
162
163
164
      PartitionType partitionType () const
      {
        return hostEntity().partitionType();
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
165
166
      //! obtain number of sub-entities of the current entity
      unsigned int subEntities (unsigned int cc) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
167
      {
168
        return hostEntity().subEntities(cc);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
169
170
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
171
172
      //! return EntitySeed of host grid entity
      EntitySeed seed () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
173
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
174
        return typename EntitySeed::Implementation(hostEntity().seed());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
175
176
177
      }


Praetorius, Simon's avatar
Praetorius, Simon committed
178
      /** \name Methods Supporting the Grid Implementation
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
179
180
       *  \{ */

181
      const GridFunction& gridFunction () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
182
      {
183
        return *gridFunction_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
184
185
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
186
187
      //! return the wrapped host-entity
      const HostEntity& hostEntity () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
188
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
189
        return hostEntity_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
190
191
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
192
      /** \} */
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
193
194

    private:
195
196
197
198
199
200
201
202
203
204
205
206
207
      HostEntity hostEntity_;
      const GridFunction* gridFunction_ = nullptr;
    };



    template< int codim, class G >
    class EntityBaseGeometry
        : public EntityBase<codim, G>
    {
      using Super = EntityBase<codim, G>;
      using Traits = typename std::remove_const_t<G>::Traits;

208
209
210
211
      //! type of host elements, i.e., of host entities of codimension 0
      using HostElement = typename Traits::HostGrid::template Codim<0>::Entity;
      using GridFunction = typename Super::GridFunction;

212
213
214
    public:
      //! type of corresponding geometry
      using Geometry = typename Traits::template Codim<codim>::Geometry;
215
      using ctype = typename Geometry::ctype;
216
217
218
219

    public:
      using Super::Super;

220
221
222
223
224
225
226
      // construct the entity from a subentity of a host-entity
      EntityBaseGeometry (const GridFunction& gridFunction, const HostElement& hostElement, int i)
        : Super(gridFunction, hostElement, i)
        , hostElement_(hostElement)
        , subEntity_(i)
      {}

227
228
229
230
231
      //! obtain the geometry of this entity
      Geometry geometry () const
      {
        if (!geo_) {
          auto localFct = localFunction(Super::gridFunction());
232
233
234
235
236
237
238
239
240
241
          if (hostElement_) {
            localFct.bind(*hostElement_);

            auto refElem = referenceElement<ctype, Super::dimension>(hostElement_->type());
            auto localGeometry = refElem.template geometry<codim>(subEntity_);
            geo_ = std::make_shared<GeometryImpl>(Super::type(), localFct, localGeometry);
          }
          else {
            DUNE_THROW(Dune::NotImplemented, "Geometry of entities of codim!=0 not implemented");
          }
242
243
244
245
246
247
        }

        return Geometry(*geo_);
      }

    private:
248
249
250
      Std::optional<HostElement> hostElement_;
      int subEntity_ = -1;

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
      using GeometryImpl = typename Traits::template Codim<codim>::GeometryImpl;
      mutable std::shared_ptr<GeometryImpl> geo_;
    };


    template< class G >
    class EntityBaseGeometry<0, G>
        : public EntityBase<0, G>
    {
      using Super = EntityBase<0, G>;
      using Traits = typename std::remove_const_t<G>::Traits;

    public:
      //! type of corresponding geometry
      using Geometry = typename Traits::template Codim<0>::Geometry;

    public:
      using Super::Super;

      //! obtain the geometry of this entity
      /**
       *  Each DUNE entity encapsulates a geometry object, representing the map
       *  from the reference element to world coordinates. Wrapping the geometry
       *  is the main objective of the CurvedSurfaceGrid.
       *
       *  The CurvedSurfaceGrid provides geometries by parametrization with local basis
       *  functions, using the CurvedGeometry.
       *
       *  \returns a new curvedgeometry object
       */
      Geometry geometry () const
      {
        if (!geo_) {
          auto localFct = localFunction(Super::gridFunction());
          localFct.bind(Super::hostEntity());
286
287
          auto fakeDefaultGeometry = Dune::CGeo::Impl::DefaultLocalGeometry{};
          geo_ = std::make_shared<GeometryImpl>(Super::type(), localFct, fakeDefaultGeometry);
288
289
290
291
292
293
294
295
        }

        return Geometry(*geo_);
      }

    private:
      using GeometryImpl = typename Traits::template Codim<0>::GeometryImpl;
      mutable std::shared_ptr<GeometryImpl> geo_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
296
297
298
299
300
301
    };


    // Entity
    // ------

302
    template< int codim, int dim, class G >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
303
    class Entity
304
        : public EntityBaseGeometry<codim, G>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
305
    {
306
      using Super = EntityBaseGeometry<codim, G>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
307
308

    public:
Praetorius, Simon's avatar
Praetorius, Simon committed
309
310
      // import constructors from base class
      using Super::Super;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
311
312
313
314
315
316
    };


    // Entity for codimension 0
    // ------------------------

317
318
319
    template< int dim, class G >
    class Entity<0, dim, G>
        : public EntityBaseGeometry<0, G>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
320
    {
321
      using Super = EntityBaseGeometry<0, G>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
322

323
324
325
      using Traits = typename std::remove_const_t<G>::Traits;
      using Grid = typename Traits::Grid;
      using GridFunction = typename Grid::GridFunction;
Praetorius, Simon's avatar
Praetorius, Simon committed
326
      using HostGrid = typename Traits::HostGrid;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
327
328
329
330
331
332
333

    public:

      /** \name Types Required by DUNE
       *  \{ */

      //! type of corresponding local geometry
Praetorius, Simon's avatar
Praetorius, Simon committed
334
      using LocalGeometry = typename Traits::template Codim<0>::LocalGeometry;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
335

Praetorius, Simon's avatar
Praetorius, Simon committed
336
      //! facade type for entities
337
      using EntityFacade = Dune::Entity<0, dim, G, Dune::CGeo::Entity>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
338
339

      //! type of hierarchic iterator
Praetorius, Simon's avatar
Praetorius, Simon committed
340
341
      using HierarchicIterator = typename Traits::HierarchicIterator;

Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
342
      //! type of leaf intersection iterator
Praetorius, Simon's avatar
Praetorius, Simon committed
343
344
      using LeafIntersectionIterator = typename Traits::LeafIntersectionIterator;

Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
345
      //! type of level intersection iterator
Praetorius, Simon's avatar
Praetorius, Simon committed
346
      using LevelIntersectionIterator = typename Traits::LevelIntersectionIterator;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
347
348
349

      /** \} */

Praetorius, Simon's avatar
Praetorius, Simon committed
350
351
      // import constructors from base class
      using Super::Super;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
352
353

      template< int codim >
Praetorius, Simon's avatar
Praetorius, Simon committed
354
      typename Grid::template Codim<codim>::Entity subEntity (int i) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
355
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
356
        using EntityImpl = typename Traits::template Codim<codim>::EntityImpl;
357
        return EntityImpl(Super::gridFunction(), Super::hostEntity(), i);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
358
359
360
361
      }

      LevelIntersectionIterator ilevelbegin () const
      {
362
363
        using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
        return IteratorImpl(*this, Super::hostEntity().ilevelbegin());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
364
365
366
367
      }

      LevelIntersectionIterator ilevelend () const
      {
368
369
        using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
        return IteratorImpl(*this, Super::hostEntity().ilevelend());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
370
371
372
373
      }

      LeafIntersectionIterator ileafbegin () const
      {
374
375
        using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
        return IteratorImpl(*this, Super::hostEntity().ileafbegin());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
376
377
378
379
      }

      LeafIntersectionIterator ileafend () const
      {
380
381
        using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
        return IteratorImpl(*this, Super::hostEntity().ileafend());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
382
383
384
385
      }

      bool hasBoundaryIntersections () const
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
386
        return Super::hostEntity().hasBoundaryIntersections();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
387
388
389
390
      }

      bool isLeaf () const
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
391
        return Super::hostEntity().isLeaf();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
392
393
394
395
      }

      EntityFacade father () const
      {
396
        return Entity(Super::gridFunction(), Super::hostEntity().father());
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
397
398
399
400
      }

      bool hasFather () const
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
401
        return Super::hostEntity().hasFather();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
402
403
404
405
      }

      LocalGeometry geometryInFather () const
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
406
        return Super::hostEntity().geometryInFather();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
407
408
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
409
      HierarchicIterator hbegin (int maxLevel) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
410
      {
411
412
        using IteratorImpl = CGeo::HierarchicIterator<G>;
        return IteratorImpl(Super::gridFunction(), Super::hostEntity().hbegin(maxLevel));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
413
414
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
415
      HierarchicIterator hend (int maxLevel) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
416
      {
417
418
        using IteratorImpl = CGeo::HierarchicIterator<G>;
        return IteratorImpl(Super::gridFunction(), Super::hostEntity().hend(maxLevel));
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
419
420
421
422
      }

      bool isRegular () const
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
423
        return Super::hostEntity().isRegular();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
424
425
426
427
      }

      bool isNew () const
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
428
        return Super::hostEntity().isNew();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
429
430
431
432
      }

      bool mightVanish () const
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
433
        return Super::hostEntity().mightVanish();
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
434
435
436
      }
    };

Praetorius, Simon's avatar
Praetorius, Simon committed
437
  } // namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
438
439
} // namespace Dune

Praetorius, Simon's avatar
Praetorius, Simon committed
440
#endif // DUNE_CURVED_SURFACE_GRID_ENTITY_HH