lagrangepoints.hh 18.9 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
#pragma once

#include <cassert>
#include <array>

#include <dune/common/exceptions.hh>
#include <dune/geometry/type.hh>
#include <dune/localfunctions/lagrange/equidistantpoints.hh>

namespace Dune {

namespace Impl {
  // forward declaration
  template <class K, unsigned int dim>
  class VtkLagrangePointSetBuilder;
}


/// \brief A set of lagrange points compatible with the numbering of VTK
/**
 * \tparam K    Field-type for the coordinates
 * \tparam dim  Dimension of the coordinates
 **/
template <class K, unsigned int dim>
class VtkLagrangePointSet
    : public EmptyPointSet<K, dim>
{
  using Super = EmptyPointSet<K, dim>;

public:
  static const unsigned int dimension = dim;

  VtkLagrangePointSet (std::size_t order)
    : Super(order)
  {
    assert(order > 0);
  }

  /// Fill the lagrange points for the given geometry type
  void build (GeometryType gt)
  {
    assert(gt.dim() == dimension);
    builder_(gt, order(), points_);
  }

  /// Fill the lagrange points for the given topology type `Topology`
  template <class Topology>
  bool build ()
  {
    build(GeometryType(Topology{}));
    return true;
  }

  /// Returns whether the point set support the given topology type `Topology` and can
  /// generate point for the given order.
  template <class Topology>
  static bool supports (std::size_t order)
  {
    return true;
  }

  using Super::order;

private:
  using Super::points_;
  Impl::VtkLagrangePointSetBuilder<K,dim> builder_;
};


namespace Impl {

// Build for lagrange point sets in different dimensions
// Specialized for dim=1,2,3
template <class K, unsigned int dim>
class VtkLagrangePointSetBuilder
{
public:
  template <class Points>
  void operator()(GeometryType, unsigned int, Points& points) const
  {
    DUNE_THROW(Dune::NotImplemented,
      "Lagrange points not yet implemented for this GeometryType.");
  }
};

/**
 *  The implementation of the point set builder is directly derived from VTK.
 *  Modification are a change in data-types and naming scheme. Additionally 
 *  a LocalKey is created to reflect the concept of a Dune PointSet.
 * 
 *  Included is the license of the BSD 3-clause License included in the VTK
 *  source code from 2020/04/13 in commit b90dad558ce28f6d321420e4a6b17e23f5227a1c
 *  of git repository https://gitlab.kitware.com/vtk/vtk.
 * 
    Program:   Visualization Toolkit
    Module:    Copyright.txt

    Copyright (c) 1993-2015 Ken Martin, Will Schroeder, Bill Lorensen
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.

    * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
      of any contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
    ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 **/

// Lagrange points on point geometries
template <class K>
class VtkLagrangePointSetBuilder<K,0>
{
  static constexpr int dim = 0;
  using LP = LagrangePoint<K,dim>;
  using Vec = typename LP::Vector;
  using Key = LocalKey;

public:
  template <class Points>
  void operator()(GeometryType gt, int /*order*/, Points& points) const
  {
    assert(gt.isVertex());
    points.push_back(LP{Vec{},Key{0,0,0}});
  }
};


// Lagrange points on line geometries
template <class K>
class VtkLagrangePointSetBuilder<K,1>
{
  static constexpr int dim = 1;
  using LP = LagrangePoint<K,dim>;
  using Vec = typename LP::Vector;
  using Key = LocalKey;

public:
  template <class Points>
  void operator()(GeometryType gt, int order, Points& points) const
  {
    assert(gt.isLine());

    // Vertex nodes
    points.push_back(LP{Vec{0.0}, Key{0,dim,0}});
    points.push_back(LP{Vec{1.0}, Key{1,dim,0}});

    if (order > 1) {
      // Inner nodes
      Vec p{0.0};
      for (unsigned int i = 0; i < order-1; i++)
      {
        p[0] += 1.0 / order;
        points.push_back(LP{p,Key{0,dim-1,i}});
      }
    }
  }
};


// Lagrange points on 2d geometries
template <class K>
class VtkLagrangePointSetBuilder<K,2>
{
  static constexpr int dim = 2;
  using LP = LagrangePoint<K,dim>;
  using Vec = typename LP::Vector;
  using Key = LocalKey;

  friend class VtkLagrangePointSetBuilder<K,3>;

public:
  template <class Points>
  void operator()(GeometryType gt, int order, Points& points) const
  {
    std::size_t nPoints = numLagrangePoints(gt.id(), dim, order);

    if (gt.isTriangle())
      buildTriangle(nPoints, order, points);
    else if (gt.isQuadrilateral())
      buildQuad(nPoints, order, points);
    else {
      DUNE_THROW(Dune::NotImplemented,
        "Lagrange points not yet implemented for this GeometryType.");
    }

    assert(points.size() == nPoints);
  }

private:
  // Construct the point set in a triangle element.
  // Loop from the outside to the inside
  template <class Points>
  void buildTriangle (std::size_t nPoints, int order, Points& points) const
  {
    points.reserve(nPoints);

    const int nVertexDOFs = 3;
    const int nEdgeDOFs = 3 * (order-1);

    static const unsigned int vertexPerm[3] = {0,1,2};
    static const unsigned int edgePerm[3]   = {0,2,1};

    auto calcKey = [&](int p) -> Key
    {
      if (p < nVertexDOFs) {
        return Key{vertexPerm[p], dim, 0};
      }
      else if (p < nVertexDOFs+nEdgeDOFs) {
        unsigned int entityIndex = (p - nVertexDOFs) / (order-1);
        unsigned int index = (p - nVertexDOFs) % (order-1);
        return Key{edgePerm[entityIndex], dim-1, index};
      }
      else {
        unsigned int index = p - (nVertexDOFs + nEdgeDOFs);
        return Key{0, dim-2, index};
      }
    };

    std::array<int,3> bindex;
    
    double order_d = double(order);
    for (std::size_t p = 0; p < nPoints; ++p) {
      barycentricIndex(p, bindex, order);
      Vec point{bindex[0] / order_d, bindex[1] / order_d};
      points.push_back(LP{point, calcKey(p)});
    }
  }

  // "Barycentric index" is a triplet of integers, each running from 0 to
  // <Order>. It is the index of a point on the triangle in barycentric
  // coordinates.
  static void barycentricIndex (int index, std::array<int,3>& bindex, int order)
  {
    int max = order;
    int min = 0;

    // scope into the correct triangle
    while (index != 0 && index >= 3 * order)
    {
      index -= 3 * order;
      max -= 2;
      min++;
      order -= 3;
    }

    // vertex DOFs
    if (index < 3)
    {
      bindex[index] = bindex[(index + 1) % 3] = min;
      bindex[(index + 2) % 3] = max;
    }
    // edge DOFs
    else
    {
      index -= 3;
      int dim = index / (order - 1);
      int offset = (index - dim * (order - 1));
      bindex[(dim + 1) % 3] = min;
      bindex[(dim + 2) % 3] = (max - 1) - offset;
      bindex[dim] = (min + 1) + offset;
    }
  }


  // Construct the point set in the quad element
  // 1. build equispaced points with index tuple (i,j)
  // 2. map index tuple to DOF index and LocalKey
  template <class Points>
  void buildQuad(std::size_t nPoints, int order, Points& points) const
  {
    points.resize(nPoints);

    std::array<int,2> orders{order, order};
    std::array<Vec,4> nodes{Vec{0., 0.}, Vec{1., 0.}, Vec{1., 1.}, Vec{0., 1.}};

    for (int n = 0; n <= orders[1]; ++n) {
      for (int m = 0; m <= orders[0]; ++m) {
        // int idx = pointIndexFromIJ(m,n,orders);

        const double r = double(m) / orders[0];
        const double s = double(n) / orders[1];
        Vec p = (1.0 - r) * (nodes[3] * s + nodes[0] * (1.0 - s)) +
                r *         (nodes[2] * s + nodes[1] * (1.0 - s));

        auto [idx,key] = calcQuadKey(m,n,orders);
        points[idx] = LP{p, key};
        // points[idx] = LP{p, calcQuadKey(n,m,orders)};
      }
    }
  }

  // Obtain the VTK DOF index of the node (i,j) in the quad element
  // and construct a LocalKey
  static std::pair<int,Key> calcQuadKey (int i, int j, std::array<int,2> order)
  {
    const bool ibdy = (i == 0 || i == order[0]);
    const bool jbdy = (j == 0 || j == order[1]);
    const int nbdy = (ibdy ? 1 : 0) + (jbdy ? 1 : 0); // How many boundaries do we lie on at once?
    
    int dof = 0;
    unsigned int entityIndex = 0;
    unsigned int index = 0;

    if (nbdy == 2) // Vertex DOF
    {
      dof = (i ? (j ? 2 : 1) : (j ? 3 : 0));
      entityIndex = (j ? (i ? 3 : 2) : (i ? 1 : 0));
      return std::make_pair(dof,Key{entityIndex, dim, 0});
    }

    int offset = 4;
    if (nbdy == 1) // Edge DOF
    {
      if (!ibdy) {
        dof = (i - 1) + (j ? order[0]-1 + order[1]-1 : 0) + offset;
        entityIndex = j ? 3 : 2;
        index = i-1;
      }
      else if (!jbdy) {
        dof = (j - 1) + (i ? order[0]-1 : 2 * (order[0]-1) + order[1]-1) + offset;
        entityIndex = i ? 1 : 0;
        index = j-1;
      }
      return std::make_pair(dof, Key{entityIndex, dim-1, index});
    }

    offset += 2 * (order[0]-1 + order[1]-1);

    // nbdy == 0: Face DOF
    dof = offset + (i - 1) + (order[0]-1) * ((j - 1));
    Key innerKey = VtkLagrangePointSetBuilder<K,2>::calcQuadKey(i-1,j-1,{order[0]-2, order[1]-2}).second;
    return std::make_pair(dof, Key{0, dim-2, innerKey.index()});
  }
};


// Lagrange points on 3d geometries
template <class K>
class VtkLagrangePointSetBuilder<K,3>
{
  static constexpr int dim = 3;
  using LP = LagrangePoint<K,dim>;
  using Vec = typename LP::Vector;
  using Key = LocalKey;

public:
  template <class Points>
  void operator() (GeometryType gt, unsigned int order, Points& points) const
  {
    std::size_t nPoints = numLagrangePoints(gt.id(), dim, order);

    if (gt.isTetrahedron())
      buildTetra(nPoints, order, points);
    else if (gt.isHexahedron())
      buildHex(nPoints, order, points);
    else {
      DUNE_THROW(Dune::NotImplemented,
        "Lagrange points not yet implemented for this GeometryType.");
    }

    assert(points.size() == nPoints);
  }

private:
  // Construct the point set in the tetrahedron element
  // 1. construct barycentric (index) coordinates
  // 2. obtains the DOF index, LocalKey and actual coordinate from barycentric index
  template <class Points>
  void buildTetra (std::size_t nPoints, int order, Points& points) const
  {
    points.reserve(nPoints);

    const int nVertexDOFs = 4;
    const int nEdgeDOFs = 6 * (order-1);
    const int nFaceDOFs = 4 * (order-1)*(order-2)/2;

    static const unsigned int vertexPerm[4] = {0,1,2,3};
    static const unsigned int edgePerm[6]   = {0,2,1,3,4,5};
    static const unsigned int facePerm[4]   = {1,2,0,3};

    auto calcKey = [&](int p) -> Key
    {
      if (p < nVertexDOFs) {
        return Key{vertexPerm[p], dim, 0};
      }
      else if (p < nVertexDOFs+nEdgeDOFs) {
        unsigned int entityIndex = (p - nVertexDOFs) / (order-1);
        unsigned int index = (p - nVertexDOFs) % (order-1);
        return Key{edgePerm[entityIndex], dim-1, index};
      }
      else if (p < nVertexDOFs+nEdgeDOFs+nFaceDOFs) {
        unsigned int index = (p - (nVertexDOFs + nEdgeDOFs)) % ((order-1)*(order-2)/2);
        unsigned int entityIndex = (p - (nVertexDOFs + nEdgeDOFs)) / ((order-1)*(order-2)/2);
        return Key{facePerm[entityIndex], dim-2, index};
      }
      else {
        unsigned int index = p - (nVertexDOFs + nEdgeDOFs + nFaceDOFs);
        return Key{0, dim-3, index};
      }
    };

    std::array<int,4> bindex;
    
    double order_d = double(order);
    for (std::size_t p = 0; p < nPoints; ++p) {
      barycentricIndex(p, bindex, order);
      Vec point{bindex[0] / order_d, bindex[1] / order_d, bindex[2] / order_d};
      points.push_back(LP{point, calcKey(p)});
    }
  }

  // "Barycentric index" is a set of 4 integers, each running from 0 to
  // <Order>. It is the index of a point in the tetrahedron in barycentric
  // coordinates.
  static void barycentricIndex (std::size_t p, std::array<int,4>& bindex, int order)
  {
    const int nVertexDOFs = 4;
    const int nEdgeDOFs = 6 * (order-1);

    static const int edgeVertices[6][2]   = {{0,1}, {1,2}, {2,0}, {0,3}, {1,3}, {2,3}};
    static const int linearVertices[4][4] = {{0,0,0,1}, {1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
    static const int vertexMaxCoords[4]   = {3,0,1,2};
    static const int faceBCoords[4][3]    = {{0,2,3}, {2,0,1}, {2,1,3}, {1,0,3}};
    static const int faceMinCoord[4]      = {1,3,0,2};

    int max = order;
    int min = 0;

    // scope into the correct tetra
    while (p >= 2 * (order * order + 1) && p != 0 && order > 3)
    {
      p -= 2 * (order * order + 1);
      max -= 3;
      min++;
      order -= 4;
    }

    // vertex DOFs
    if (p < nVertexDOFs)
    {
      for (int coord = 0; coord < 4; ++coord)
        bindex[coord] = (coord == vertexMaxCoords[p] ? max : min);
    }
    // edge DOFs
    else if (p < nVertexDOFs+nEdgeDOFs)
    {
      int edgeId = (p - nVertexDOFs) / (order-1);
      int vertexId = (p - nVertexDOFs) % (order-1);
      for (int coord = 0; coord < 4; ++coord)
      {
        bindex[coord] = min +
          (linearVertices[edgeVertices[edgeId][0]][coord] * (max - min - 1 - vertexId) +
            linearVertices[edgeVertices[edgeId][1]][coord] * (1 + vertexId));
      }
    }
    // face DOFs
    else
    {
      int faceId = (p - (nVertexDOFs+nEdgeDOFs)) / ((order-2)*(order-1)/2);
      int vertexId = (p - (nVertexDOFs+nEdgeDOFs)) % ((order-2)*(order-1)/2);

      std::array<int,3> projectedBIndex;
      if (order == 3)
        projectedBIndex[0] = projectedBIndex[1] = projectedBIndex[2] = 0;
      else
        VtkLagrangePointSetBuilder<K,2>::barycentricIndex(vertexId, projectedBIndex, order-3);

      for (int i = 0; i < 3; i++)
        bindex[faceBCoords[faceId][i]] = (min + 1 + projectedBIndex[i]);
        
      bindex[faceMinCoord[faceId]] = min;
    }
  }

private:
  // Construct the point set in the heyhedral element
  // 1. build equispaced points with index tuple (i,j,k)
  // 2. map index tuple to DOF index and LocalKey
  template <class Points>
  void buildHex (std::size_t nPoints, int order, Points& points) const
  {
    points.resize(nPoints);

    std::array<int,3> orders{order, order, order};
    std::array<Vec,8> nodes{Vec{0., 0., 0.}, Vec{1., 0., 0.}, Vec{1., 1., 0.}, Vec{0., 1., 0.}, 
                            Vec{0., 0., 1.}, Vec{1., 0., 1.}, Vec{1., 1., 1.}, Vec{0., 1., 1.}};

    for (int p = 0; p <= orders[2]; ++p) {
      for (int n = 0; n <= orders[1]; ++n) {
        for (int m = 0; m <= orders[0]; ++m) {
          const double r = double(m) / orders[0];
          const double s = double(n) / orders[1];
          const double t = double(p) / orders[2];
          Vec point = (1.0-r) * ((nodes[3] * (1.0-t) + nodes[7] * t) * s + (nodes[0] * (1.0-t) + nodes[4] * t) * (1.0-s)) +
                      r *       ((nodes[2] * (1.0-t) + nodes[6] * t) * s + (nodes[1] * (1.0-t) + nodes[5] * t) * (1.0-s));

          auto [idx,key] = calcHexKey(m,n,p,orders);
          points[idx] = LP{point, key};
        }
      }
    }
  }

  // Obtain the VTK DOF index of the node (i,j,k) in the hexahedral element
  static std::pair<int,Key> calcHexKey (int i, int j, int k, std::array<int,3> order)
  {
    const bool ibdy = (i == 0 || i == order[0]);
    const bool jbdy = (j == 0 || j == order[1]);
    const bool kbdy = (k == 0 || k == order[2]);
    const int nbdy = (ibdy ? 1 : 0) + (jbdy ? 1 : 0) + (kbdy ? 1 : 0); // How many boundaries do we lie on at once?

    int dof = 0;
    unsigned int entityIndex = 0;
    unsigned int index = 0;

    if (nbdy == 3) // Vertex DOF
    {
      dof = (i ? (j ? 2 : 1) : (j ? 3 : 0)) + (k ? 4 : 0);
      entityIndex = (i ? 1 : 0) + (j ? 2 : 0) + (k ? 4 : 0);
      return std::make_pair(dof, Key{entityIndex, dim, 0});
    }

    int offset = 8;
    if (nbdy == 2) // Edge DOF
    {
      entityIndex = (k ? 8 : 4);
      if (!ibdy)
      { // On i axis
        dof = (i - 1) + (j ? order[0]-1 + order[1]-1 : 0) + (k ? 2 * (order[0]-1 + order[1]-1) : 0) + offset;
        index = i;
        entityIndex += (i ? 1 : 0);
      }
      else if (!jbdy)
      { // On j axis
        dof = (j - 1) + (i ? order[0]-1 : 2 * (order[0]-1) + order[1]-1) + (k ? 2 * (order[0]-1 + order[1]-1) : 0) + offset;
        index = j;
        entityIndex += (j ? 3 : 2);
      }
      else 
      { // !kbdy, On k axis
        offset += 4 * (order[0]-1) + 4 * (order[1]-1);
        dof = (k - 1) + (order[2]-1) * (i ? (j ? 3 : 1) : (j ? 2 : 0)) + offset;
        index = k;
        entityIndex = (i ? 1 : 0) + (j ? 2 : 0);
      }
      return std::make_pair(dof, Key{entityIndex, dim-1, index});
    }

    offset += 4 * (order[0]-1 + order[1]-1 + order[2]-1);
    if (nbdy == 1) // Face DOF
    {
      Key faceKey;
      if (ibdy) // On i-normal face
      {
        dof = (j - 1) + ((order[1]-1) * (k - 1)) + (i ? (order[1]-1) * (order[2]-1) : 0) + offset;
        entityIndex = (i ? 1 : 0);
        faceKey = VtkLagrangePointSetBuilder<K,2>::calcQuadKey(j-1,k-1,{order[1]-2, order[2]-2}).second;
      }
      else {
        offset += 2 * (order[1] - 1) * (order[2] - 1);
        if (jbdy) // On j-normal face
        {
          dof = (i - 1) + ((order[0]-1) * (k - 1)) + (j ? (order[2]-1) * (order[0]-1) : 0) + offset;
          entityIndex = (j ? 3 : 2);
          faceKey = VtkLagrangePointSetBuilder<K,2>::calcQuadKey(i-1,k-1,{order[0]-2, order[2]-2}).second;
        }
        else 
        { // kbdy, On k-normal face
          offset += 2 * (order[2]-1) * (order[0]-1);
          dof = (i - 1) + ((order[0]-1) * (j - 1)) + (k ? (order[0]-1) * (order[1]-1) : 0) + offset;
          entityIndex = (k ? 5 : 4);
          faceKey = VtkLagrangePointSetBuilder<K,2>::calcQuadKey(i-1,j-1,{order[0]-2, order[1]-2}).second;
        }
      }
      return std::make_pair(dof, Key{entityIndex, dim-2, faceKey.index()});
    }

    // nbdy == 0: Body DOF
    offset += 2 * ((order[1]-1) * (order[2]-1) + (order[2]-1) * (order[0]-1) + (order[0]-1) * (order[1]-1));
    dof = offset + (i - 1) + (order[0]-1) * ((j - 1) + (order[1]-1) * ((k - 1)));
    Key innerKey = VtkLagrangePointSetBuilder<K,3>::calcHexKey(i-1,j-1,k-1,{order[0]-2, order[1]-2, order[2]-2}).second;
    return std::make_pair(dof, Key{0, dim-3, innerKey.index()});
  }
};

}} // end namespace Dune::Impl