entity.hh 12.6 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
      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;

267
268
269
      //! type of corresponding local geometry
      using LocalGeometry = typename Traits::template Codim<0>::LocalGeometry;

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    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());
289
          auto fakeDefaultGeometry = Dune::DefaultLocalGeometry<typename Super::ctype, Super::mydimension, Super::mydimension>{};
290
          geo_ = std::make_shared<GeometryImpl>(Super::type(), localFct, fakeDefaultGeometry);
291
292
293
294
295
296
297
298
        }

        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
299
300
301
302
303
304
    };


    // Entity
    // ------

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

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


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

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

326
327
328
      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
329
      using HostGrid = typename Traits::HostGrid;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
330
331
332
333
334
335
336

    public:

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

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

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

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

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

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

      /** \} */

Praetorius, Simon's avatar
Praetorius, Simon committed
353
354
      // import constructors from base class
      using Super::Super;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
355
356

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Praetorius, Simon's avatar
Praetorius, Simon committed
440
  } // namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
441
442
} // namespace Dune

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