dune-vtk 2.12
Loading...
Searching...
No Matches
lagrangepoints.impl.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-FileCopyrightText: Copyright (c) 1993-2015 Ken Martin, Will Schroeder, Bill Lorensen
3// SPDX-License-Identifier: BSD-3-Clause AND (LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later)
4#pragma once
5
6#include <cassert>
7#include <array>
8
12#include <dune/geometry/type.hh>
14
15namespace Dune::Vtk {
16namespace Impl {
17
65template <class K>
66 template <class Points>
67void LagrangePointSetBuilder<K,0>::operator() (GeometryType gt, int /*order*/, Points& points) const
68{
69 assert(gt.isVertex());
70 points.push_back(LP{Vec{},Key{0,0,0}});
71}
72
73
74template <class K>
75 template <class Points>
76void LagrangePointSetBuilder<K,1>::operator() (GeometryType gt, int order, Points& points) const
77{
78 assert(gt.isLine());
79
80 if (order == 0) {
81 auto refElem = Dune::referenceElement<K,1>(gt);
82 points.push_back(LP{refElem.position(0,0), Key{0,0,0}});
83 return;
84 }
85
86 // Vertex nodes
87 points.push_back(LP{Vec{0.0}, Key{0,dim,0}});
88 points.push_back(LP{Vec{1.0}, Key{1,dim,0}});
89
90 if (order > 1) {
91 // Inner nodes
92 Vec p{0.0};
93 for (int i = 0; i < order-1; i++)
94 {
95 p[0] += 1.0 / order;
96 points.push_back(LP{p,Key{0,dim-1,(unsigned int)(i)}});
97 }
98 }
99}
100
101
102template <class K>
103 template <class Points>
104void LagrangePointSetBuilder<K,2>::operator() (GeometryType gt, int order, Points& points) const
105{
106 if (order == 0) {
107 auto refElem = Dune::referenceElement<K,2>(gt);
108 points.push_back(LP{refElem.position(0,0), Key{0,0,0}});
109 return;
110 }
111
112 if (gt.isTriangle())
113 buildTriangle(order, points);
114 else if (gt.isQuadrilateral())
115 buildQuad(order, order, points);
116 else {
118 "Lagrange points not yet implemented for this GeometryType.");
119 }
120
121 [[maybe_unused]] std::size_t nPoints = numLagrangePoints(gt, order);
122 assert(points.size() == nPoints);
123}
124
125
126// Construct the point set in a triangle element.
127// Loop from the outside to the inside
128template <class K>
129 template <class Points>
130void LagrangePointSetBuilder<K,2>::buildTriangle (int order, Points& points) const
131{
132 std::size_t nPoints = numLagrangePoints(GeometryTypes::simplex(2), order);
133 points.reserve(nPoints);
134
135 const int nVertexDOFs = 3;
136 const int nEdgeDOFs = 3 * (order-1);
137
138 static const unsigned int vertexPerm[3] = {0,1,2};
139 static const unsigned int edgePerm[3] = {0,2,1};
140
141 auto calcKey = [&](int p) -> Key
142 {
143 if (p < nVertexDOFs) {
144 return Key{vertexPerm[p], dim, 0};
145 }
146 else if (p < nVertexDOFs+nEdgeDOFs) {
147 unsigned int entityIndex = (p - nVertexDOFs) / (order-1);
148 unsigned int index = (p - nVertexDOFs) % (order-1);
149 return Key{edgePerm[entityIndex], dim-1, index};
150 }
151 else {
152 unsigned int index = p - (nVertexDOFs + nEdgeDOFs);
153 return Key{0, dim-2, index};
154 }
155 };
156
157 std::array<int,3> bindex;
158
159 K order_d = K(order);
160 for (std::size_t p = 0; p < nPoints; ++p) {
161 barycentricIndex(p, bindex, order);
162 Vec point{bindex[0] / order_d, bindex[1] / order_d};
163 points.push_back(LP{point, calcKey(p)});
164 }
165}
166
167
168// "Barycentric index" is a triplet of integers, each running from 0 to
169// <Order>. It is the index of a point on the triangle in barycentric
170// coordinates.
171template <class K>
172void LagrangePointSetBuilder<K,2>::barycentricIndex (int index, std::array<int,3>& bindex, int order)
173{
174 int max = order;
175 int min = 0;
176
177 // scope into the correct triangle
178 while (index != 0 && index >= 3 * order)
179 {
180 index -= 3 * order;
181 max -= 2;
182 min++;
183 order -= 3;
184 }
185
186 // vertex DOFs
187 if (index < 3)
188 {
189 bindex[index] = bindex[(index + 1) % 3] = min;
190 bindex[(index + 2) % 3] = max;
191 }
192 // edge DOFs
193 else
194 {
195 index -= 3;
196 int dim = index / (order - 1);
197 int offset = (index - dim * (order - 1));
198 bindex[(dim + 1) % 3] = min;
199 bindex[(dim + 2) % 3] = (max - 1) - offset;
200 bindex[dim] = (min + 1) + offset;
201 }
202}
203
204
205// Construct the point set in the quad element
206// 1. build equispaced points with index tuple (i,j)
207// 2. map index tuple to DOF index and LocalKey
208template <class K>
209 template <class Points>
210void LagrangePointSetBuilder<K,2>::buildQuad(int orderx, int ordery, Points& points) const
211{
212 if (orderx == 0 && ordery == 0) {
213 points.push_back(LP{Vec{0.5, 0.5}});
214 return;
215 }
216 else if (orderx == 0) {
218 LagrangePointSetBuilder<K,1>{}(GeometryTypes::line, ordery, linePoints);
219 points.reserve(linePoints.size());
220 for (auto& p : linePoints)
221 points.push_back(LP{Vec{0.5, p.point()[0]}});
222 return;
223 }
224 else if (ordery == 0) {
226 LagrangePointSetBuilder<K,1>{}(GeometryTypes::line, orderx, linePoints);
227 points.reserve(linePoints.size());
228 for (auto& p : linePoints)
229 points.push_back(LP{Vec{p.point()[0], 0.5}});
230 return;
231 }
232
233 std::size_t nPoints = numLagrangePoints(GeometryTypes::line, orderx);
234 nPoints *= numLagrangePoints(GeometryTypes::line, ordery);
235 points.resize(nPoints);
236
237 assert(orderx > 0 && ordery > 0);
238 std::array<int,2> orders{orderx, ordery};
239 std::array<Vec,4> nodes{Vec{0., 0.}, Vec{1., 0.}, Vec{1., 1.}, Vec{0., 1.}};
240
241 for (int n = 0; n <= orders[1]; ++n) {
242 for (int m = 0; m <= orders[0]; ++m) {
243 // int idx = pointIndexFromIJ(m,n,orders);
244
245 const K r = K(m) / orders[0];
246 const K s = K(n) / orders[1];
247 Vec p = K(1.0-r) * (nodes[3] * s + nodes[0] * K(1.0 - s)) +
248 r * (nodes[2] * s + nodes[1] * K(1.0 - s));
249
250 auto [idx,key] = calcQuadKey(m,n,orders);
251 points[idx] = LP{p, key};
252 // points[idx] = LP{p, calcQuadKey(n,m,orders)};
253 }
254 }
255}
256
257
258// Obtain the VTK DOF index of the node (i,j) in the quad element
259// and construct a LocalKey
260template <class K>
262LagrangePointSetBuilder<K,2>::calcQuadKey (int i, int j, std::array<int,2> order)
263{
264 const bool ibdy = (i == 0 || i == order[0]);
265 const bool jbdy = (j == 0 || j == order[1]);
266 const int nbdy = (ibdy ? 1 : 0) + (jbdy ? 1 : 0); // How many boundaries do we lie on at once?
267
268 int dof = 0;
269 unsigned int entityIndex = 0;
270 unsigned int index = 0;
271
272 if (nbdy == 2) // Vertex DOF
273 {
274 dof = (i ? (j ? 2 : 1) : (j ? 3 : 0));
275 entityIndex = (j ? (i ? 3 : 2) : (i ? 1 : 0));
276 return std::make_pair(dof,Key{entityIndex, dim, 0});
277 }
278
279 int offset = 4;
280 if (nbdy == 1) // Edge DOF
281 {
282 if (!ibdy) {
283 dof = (i - 1) + (j ? order[0]-1 + order[1]-1 : 0) + offset;
284 entityIndex = j ? 3 : 2;
285 index = i-1;
286 }
287 else if (!jbdy) {
288 dof = (j - 1) + (i ? order[0]-1 : 2 * (order[0]-1) + order[1]-1) + offset;
289 entityIndex = i ? 1 : 0;
290 index = j-1;
291 }
292 return std::make_pair(dof, Key{entityIndex, dim-1, index});
293 }
294
295 offset += 2 * (order[0]-1 + order[1]-1);
296
297 // nbdy == 0: Face DOF
298 dof = offset + (i - 1) + (order[0]-1) * ((j - 1));
299 Key innerKey = LagrangePointSetBuilder<K,2>::calcQuadKey(i-1,j-1,{order[0]-2, order[1]-2}).second;
300 return std::make_pair(dof, Key{0, dim-2, innerKey.index()});
301}
302
303
304// Lagrange points on 3d geometries
305template <class K>
306 template <class Points>
307void LagrangePointSetBuilder<K,3>::operator() (GeometryType gt, unsigned int order, Points& points) const
308{
309 if (order == 0) {
310 auto refElem = Dune::referenceElement<K,3>(gt);
311 points.push_back(LP{refElem.position(0,0), Key{0,0,0}});
312 return;
313 }
314
315 if (gt.isTetrahedron())
316 buildTetra(order, points);
317 else if (gt.isHexahedron())
318 buildHex(order, points);
319 else if (gt.isPrism())
320 buildWedge(order, order, points);
321 else {
323 "Lagrange points not yet implemented for this GeometryType.");
324 }
325
326 [[maybe_unused]] std::size_t nPoints = numLagrangePoints(gt, order);
327 assert(points.size() == nPoints);
328}
329
330
331// Construct the point set in the tetrahedron element
332// 1. construct barycentric (index) coordinates
333// 2. obtains the DOF index, LocalKey and actual coordinate from barycentric index
334template <class K>
335 template <class Points>
336void LagrangePointSetBuilder<K,3>::buildTetra (int order, Points& points) const
337{
338 std::size_t nPoints = numLagrangePoints(GeometryTypes::simplex(3), order);
339 points.reserve(nPoints);
340
341 const int nVertexDOFs = 4;
342 const int nEdgeDOFs = 6 * (order-1);
343 const int nFaceDOFs = 4 * (order-1)*(order-2)/2;
344
345 static const unsigned int vertexPerm[4] = {0,1,2,3};
346 static const unsigned int edgePerm[6] = {0,2,1,3,4,5};
347 static const unsigned int facePerm[4] = {1,2,0,3};
348
349 auto calcKey = [&](int p) -> Key
350 {
351 if (p < nVertexDOFs) {
352 return Key{vertexPerm[p], dim, 0};
353 }
354 else if (p < nVertexDOFs+nEdgeDOFs) {
355 unsigned int entityIndex = (p - nVertexDOFs) / (order-1);
356 unsigned int index = (p - nVertexDOFs) % (order-1);
357 return Key{edgePerm[entityIndex], dim-1, index};
358 }
359 else if (p < nVertexDOFs+nEdgeDOFs+nFaceDOFs) {
360 unsigned int index = (p - (nVertexDOFs + nEdgeDOFs)) % ((order-1)*(order-2)/2);
361 unsigned int entityIndex = (p - (nVertexDOFs + nEdgeDOFs)) / ((order-1)*(order-2)/2);
362 return Key{facePerm[entityIndex], dim-2, index};
363 }
364 else {
365 unsigned int index = p - (nVertexDOFs + nEdgeDOFs + nFaceDOFs);
366 return Key{0, dim-3, index};
367 }
368 };
369
370 std::array<int,4> bindex;
371
372 K order_d = K(order);
373 for (std::size_t p = 0; p < nPoints; ++p) {
374 barycentricIndex(p, bindex, order);
375 Vec point{bindex[0] / order_d, bindex[1] / order_d, bindex[2] / order_d};
376 points.push_back(LP{point, calcKey(p)});
377 }
378}
379
380
381// "Barycentric index" is a set of 4 integers, each running from 0 to
382// <Order>. It is the index of a point in the tetrahedron in barycentric
383// coordinates.
384template <class K>
385void LagrangePointSetBuilder<K,3>::barycentricIndex (int p, std::array<int,4>& bindex, int order)
386{
387 const int nVertexDOFs = 4;
388 const int nEdgeDOFs = 6 * (order-1);
389
390 static const int edgeVertices[6][2] = {{0,1}, {1,2}, {2,0}, {0,3}, {1,3}, {2,3}};
391 static const int linearVertices[4][4] = {{0,0,0,1}, {1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
392 static const int vertexMaxCoords[4] = {3,0,1,2};
393 static const int faceBCoords[4][3] = {{0,2,3}, {2,0,1}, {2,1,3}, {1,0,3}};
394 static const int faceMinCoord[4] = {1,3,0,2};
395
396 int max = order;
397 int min = 0;
398
399 // scope into the correct tetra
400 while (p >= 2 * (order * order + 1) && p != 0 && order > 3)
401 {
402 p -= 2 * (order * order + 1);
403 max -= 3;
404 min++;
405 order -= 4;
406 }
407
408 // vertex DOFs
409 if (p < nVertexDOFs)
410 {
411 for (int coord = 0; coord < 4; ++coord)
412 bindex[coord] = (coord == vertexMaxCoords[p] ? max : min);
413 }
414 // edge DOFs
415 else if (p < nVertexDOFs+nEdgeDOFs)
416 {
417 int edgeId = (p - nVertexDOFs) / (order-1);
418 int vertexId = (p - nVertexDOFs) % (order-1);
419 for (int coord = 0; coord < 4; ++coord)
420 {
421 bindex[coord] = min +
422 (linearVertices[edgeVertices[edgeId][0]][coord] * (max - min - 1 - vertexId) +
423 linearVertices[edgeVertices[edgeId][1]][coord] * (1 + vertexId));
424 }
425 }
426 // face DOFs
427 else
428 {
429 int faceId = (p - (nVertexDOFs+nEdgeDOFs)) / ((order-2)*(order-1)/2);
430 int vertexId = (p - (nVertexDOFs+nEdgeDOFs)) % ((order-2)*(order-1)/2);
431
432 std::array<int,3> projectedBIndex;
433 if (order == 3)
434 projectedBIndex[0] = projectedBIndex[1] = projectedBIndex[2] = 0;
435 else
436 LagrangePointSetBuilder<K,2>::barycentricIndex(vertexId, projectedBIndex, order-3);
437
438 for (int i = 0; i < 3; i++)
439 bindex[faceBCoords[faceId][i]] = (min + 1 + projectedBIndex[i]);
440
441 bindex[faceMinCoord[faceId]] = min;
442 }
443}
444
445
446// Construct the point set in the hexahedral element
447// 1. build equispaced points with index tuple (i,j,k)
448// 2. map index tuple to DOF index and LocalKey
449template <class K>
450 template <class Points>
451void LagrangePointSetBuilder<K,3>::buildHex (int order, Points& points) const
452{
453 std::size_t nPoints = numLagrangePoints(GeometryTypes::cube(3), order);
454 points.resize(nPoints);
455
456 std::array<int,3> orders{order, order, order};
457 std::array<Vec,8> nodes{Vec{0., 0., 0.}, Vec{1., 0., 0.}, Vec{1., 1., 0.}, Vec{0., 1., 0.},
458 Vec{0., 0., 1.}, Vec{1., 0., 1.}, Vec{1., 1., 1.}, Vec{0., 1., 1.}};
459
460 for (int p = 0; p <= orders[2]; ++p) {
461 for (int n = 0; n <= orders[1]; ++n) {
462 for (int m = 0; m <= orders[0]; ++m) {
463 const K r = K(m) / orders[0];
464 const K s = K(n) / orders[1];
465 const K t = K(p) / orders[2];
466 Vec point = K(1.0-r) * ((nodes[3] * K(1.0-t) + nodes[7] * t) * s + (nodes[0] * K(1.0-t) + nodes[4] * t) * K(1.0-s)) +
467 r * ((nodes[2] * K(1.0-t) + nodes[6] * t) * s + (nodes[1] * K(1.0-t) + nodes[5] * t) * K(1.0-s));
468
469 auto [idx,key] = calcHexKey(m,n,p,orders);
470 points[idx] = LP{point, key};
471 }
472 }
473 }
474}
475
476
477// Obtain the VTK DOF index of the node (i,j,k) in the hexahedral element
478template <class K>
480LagrangePointSetBuilder<K,3>::calcHexKey (int i, int j, int k, std::array<int,3> order)
481{
482 const bool ibdy = (i == 0 || i == order[0]);
483 const bool jbdy = (j == 0 || j == order[1]);
484 const bool kbdy = (k == 0 || k == order[2]);
485 const int nbdy = (ibdy ? 1 : 0) + (jbdy ? 1 : 0) + (kbdy ? 1 : 0); // How many boundaries do we lie on at once?
486
487 int dof = 0;
488 unsigned int entityIndex = 0;
489 unsigned int index = 0;
490
491 if (nbdy == 3) // Vertex DOF
492 {
493 dof = (i ? (j ? 2 : 1) : (j ? 3 : 0)) + (k ? 4 : 0);
494 entityIndex = (i ? 1 : 0) + (j ? 2 : 0) + (k ? 4 : 0);
495 return std::make_pair(dof, Key{entityIndex, dim, 0});
496 }
497
498 int offset = 8;
499 if (nbdy == 2) // Edge DOF
500 {
501 entityIndex = (k ? 8 : 4);
502 if (!ibdy)
503 { // On i axis
504 dof = (i - 1) + (j ? order[0]-1 + order[1]-1 : 0) + (k ? 2 * (order[0]-1 + order[1]-1) : 0) + offset;
505 index = i;
506 entityIndex += (i ? 1 : 0);
507 }
508 else if (!jbdy)
509 { // On j axis
510 dof = (j - 1) + (i ? order[0]-1 : 2 * (order[0]-1) + order[1]-1) + (k ? 2 * (order[0]-1 + order[1]-1) : 0) + offset;
511 index = j;
512 entityIndex += (j ? 3 : 2);
513 }
514 else
515 { // !kbdy, On k axis
516 offset += 4 * (order[0]-1) + 4 * (order[1]-1);
517 dof = (k - 1) + (order[2]-1) * (i ? (j ? 3 : 1) : (j ? 2 : 0)) + offset;
518 index = k;
519 entityIndex = (i ? 1 : 0) + (j ? 2 : 0);
520 }
521 return std::make_pair(dof, Key{entityIndex, dim-1, index});
522 }
523
524 offset += 4 * (order[0]-1 + order[1]-1 + order[2]-1);
525 if (nbdy == 1) // Face DOF
526 {
527 Key faceKey;
528 if (ibdy) // On i-normal face
529 {
530 dof = (j - 1) + ((order[1]-1) * (k - 1)) + (i ? (order[1]-1) * (order[2]-1) : 0) + offset;
531 entityIndex = (i ? 1 : 0);
532 faceKey = LagrangePointSetBuilder<K,2>::calcQuadKey(j-1,k-1,{order[1]-2, order[2]-2}).second;
533 }
534 else {
535 offset += 2 * (order[1] - 1) * (order[2] - 1);
536 if (jbdy) // On j-normal face
537 {
538 dof = (i - 1) + ((order[0]-1) * (k - 1)) + (j ? (order[2]-1) * (order[0]-1) : 0) + offset;
539 entityIndex = (j ? 3 : 2);
540 faceKey = LagrangePointSetBuilder<K,2>::calcQuadKey(i-1,k-1,{order[0]-2, order[2]-2}).second;
541 }
542 else
543 { // kbdy, On k-normal face
544 offset += 2 * (order[2]-1) * (order[0]-1);
545 dof = (i - 1) + ((order[0]-1) * (j - 1)) + (k ? (order[0]-1) * (order[1]-1) : 0) + offset;
546 entityIndex = (k ? 5 : 4);
547 faceKey = LagrangePointSetBuilder<K,2>::calcQuadKey(i-1,j-1,{order[0]-2, order[1]-2}).second;
548 }
549 }
550 return std::make_pair(dof, Key{entityIndex, dim-2, faceKey.index()});
551 }
552
553 // nbdy == 0: Body DOF
554 offset += 2 * ((order[1]-1) * (order[2]-1) + (order[2]-1) * (order[0]-1) + (order[0]-1) * (order[1]-1));
555 dof = offset + (i - 1) + (order[0]-1) * ((j - 1) + (order[1]-1) * ((k - 1)));
556 Key innerKey = LagrangePointSetBuilder<K,3>::calcHexKey(i-1,j-1,k-1,{order[0]-2, order[1]-2, order[2]-2}).second;
557 return std::make_pair(dof, Key{0, dim-3, innerKey.index()});
558}
559
560template <class K>
561 template <class Points>
562void LagrangePointSetBuilder<K,3>::buildWedge (int order_tri, int order_quad, Points& points) const
563{
564 auto refElem = Dune::referenceElement<K,3>(GeometryTypes::prism);
565
566 // flip the y-axis
567 auto flip = [](auto x) { x[1] = 1-x[1]; return x; };
568
569 // transform the coordinates by shifting and scaling
570 auto shrink_linexy = [order_tri](auto x) { x *= (1-K(2)/order_tri); x += decltype(x)(K(1)/order_tri); return x; };
571 auto shrink_linez = [order_quad](auto x) { x *= (1-K(2)/order_quad); x += decltype(x)(K(1)/order_quad); return x; };
572 auto shrink_tri = [order_tri](auto x) { x *= (1-K(3)/order_tri); x += decltype(x)(K(1)/order_tri); return x; };
573 auto shrink_quad = [order_tri,order_quad](auto x) {
574 x[0] *= (1-K(2)/order_tri);
575 x[1] *= (1-K(2)/order_quad);
576 x += decltype(x){K(1)/order_tri, K(1)/order_quad};
577 return x;
578 };
579 auto shrink_prism = [order_tri,order_quad](auto x) {
580 x[0] *= (1-K(3)/order_tri);
581 x[1] *= (1-K(3)/order_tri);
582 x[2] *= (1-K(2)/order_quad);
583 x += decltype(x){K(1)/order_tri, K(1)/order_tri, K(1)/order_quad};
584 return x;
585 };
586
587 // embed the point set into a sub-area of a subentity of the prism element
588 auto embed = [&](auto const& entityPoints, auto const& perm, auto codim, auto shrink) {
589 for (int p : perm) {
590 unsigned int s = std::abs(p);
591 constexpr unsigned int c = codim.value;
592 auto geo = refElem.template geometry<c>(s);
593
594 unsigned int i = 0;
595 for (auto& lp : entityPoints) {
596 if (p < 0)
597 points.push_back(LP{Vec{flip(geo.global(shrink(lp.point())))}, Key{s,c,i}});
598 else
599 points.push_back(LP{Vec{geo.global(shrink(lp.point()))}, Key{s,c,i}});
600 i++;
601 }
602 }
603 };
604
605 std::size_t nPoints = numLagrangePoints(GeometryTypes::simplex(2), order_tri);
606 nPoints *= numLagrangePoints(GeometryTypes::line, order_quad);
607 points.reserve(nPoints);
608
609 if (order_tri >= 0 && order_quad >= 0) {
610 // 1. vertex and inner DOFs
612 LagrangePointSetBuilder<K,2>{}(GeometryTypes::simplex(2), std::min(order_tri,1), triPoints);
613
615 LagrangePointSetBuilder<K,1>{}(GeometryTypes::line, std::min(order_quad,1), linePoints);
616
617 unsigned int i = 0;
618 for (auto& p0 : linePoints)
619 for (auto& p1 : triPoints)
620 points.push_back(LP{Vec{p1.point()[0], p1.point()[1], p0.point()[0]},Key{i++,3,0}});
621 }
622
623 if (order_tri > 1) {
624 // 2. edge DOFs on horizontal
626 LexicographicPointSetBuilder<K,1>::buildLine(order_tri-2, linePoints);
627 embed(linePoints, std::array{3,5,-4,6,8,-7}, Codim<2>{}, shrink_linexy);
628 }
629
630 if (order_quad > 1) {
631 // 2. edge DOFs on vertical edges
633 LexicographicPointSetBuilder<K,1>::buildLine(order_quad-2, linePoints);
634 if (order_tri == 0)
635 embed(linePoints, std::array{0}, Codim<2>{}, shrink_linez);
636 else
637 embed(linePoints, std::array{0,1,2}, Codim<2>{}, shrink_linez);
638 }
639
640 if (order_tri > 2) {
641 // 3. triangular face DOFs
643 LagrangePointSetBuilder<K,2>{}(GeometryTypes::simplex(2), order_tri-3, triPoints);
644 embed(triPoints, std::array{3,4}, Codim<1>{}, shrink_tri);
645 }
646
647 if (order_tri > 1 && order_quad > 1) {
648 // 4. quad face DOFs
650 LexicographicPointSetBuilder<K,2>::buildQuad(order_tri-2, order_quad-2, quadPoints);
651 embed(quadPoints, std::array{0,2,-1}, Codim<1>{}, shrink_quad);
652 }
653
654 if (order_tri >= 3 && order_quad >= 2) {
655 // 5. volume DOFs
657 buildWedge(order_tri-3, order_quad-2, prismPoints);
658 embed(prismPoints, std::array{0}, Codim<0>{}, shrink_prism);
659 }
660}
661
662
663template <class K, unsigned int dim>
664 template <class Points>
665void LexicographicPointSetBuilder<K,dim>::buildLine (int a, Points& points)
666{
667 static_assert(dim == 1);
668 using Point = typename Points::value_type;
669 using Vec = typename Point::Vector;
670 using Key = Dune::LocalKey;
671
672 auto coord = [a](int i) { return a == 0 ? K(0.5) : K(i)/a; };
673
674 for (int i = 0; i < a+1; ++i) {
675 auto key = (i == 0 || i == a)
676 ? Key(0u + (i > 0), 1, 0) // vertex
677 : Key(0, 0, i-1); // edge
678 points.push_back(Point{Vec{coord(i)}, key});
679 }
680}
681
682
683template <class K, unsigned int dim>
684 template <class Points>
685void LexicographicPointSetBuilder<K,dim>::buildQuad (int a, int b, Points& points)
686{
687 static_assert(dim == 2);
688 using Point = typename Points::value_type;
689 using Vec = typename Point::Vector;
690 using Key = Dune::LocalKey;
691
692 auto coord_a = [a](int i) { return a == 0 ? K(0.5) : K(i)/a; };
693 auto coord_b = [b](int i) { return b == 0 ? K(0.5) : K(i)/b; };
694
695 for (int j = 0; j < b+1; ++j) {
696 for (int i = 0; i < a+1; ++i) {
697 auto key = ((i == 0 || i == a) && (j == 0 || j == b))
698 ? Key((i > 0) + 2u * (j > 0), 2, 0) // vertex
699 : (i == 0 || i == a) ? Key(0u + (i > 0), 1, j-1) // left/right edge
700 : (j == 0 || j == b) ? Key(2u + (j > 0), 1, i-1) // bottom/top edge
701 : Key(0, 0, i-1); // face
702
703 points.push_back(Point{Vec{coord_a(i), coord_b(j)}, key});
704 }
705 }
706}
707
708
709template <class K, unsigned int dim>
710 template <class Points>
711void LexicographicPointSetBuilder<K,dim>::buildHex (int a, int b, int c, Points& points)
712{
713 static_assert(dim == 3);
714 using Point = typename Points::value_type;
715 using Vec = typename Point::Vector;
716 using Key = Dune::LocalKey;
717
718 auto coord_a = [a](int i) { return a == 0 ? K(0.5) : K(i)/a; };
719 auto coord_b = [b](int i) { return b == 0 ? K(0.5) : K(i)/b; };
720 auto coord_c = [c](int i) { return c == 0 ? K(0.5) : K(i)/c; };
721
722 for (int k = 0; k < c+1; ++k) {
723 for (int j = 0; j < b+1; ++j) {
724 for (int i = 0; i < a+1; ++i) {
725 auto key = ((i == 0 || i == a) && (j == 0 || j == b) && (k == 0 | k == c))
726 ? Key((i > 0) + 2u * (j > 0) + 4u * (k > 0), 3, 0) // vertex
727 : (i == 0 || i == a) ? Key(0u + (i > 0), 2, (k-1)*(b-1) + (j-1)) // left/right face
728 : (j == 0 || j == b) ? Key(2u + (j > 0), 2, (k-1)*(a-1) + (i-1)) // front/rear face
729 : (k == 0 || k == c) ? Key(4u + (k > 0), 2, (j-1)*(a-1) + (i-1)) // bottom/top face
730 : (i == 0 && j == 0) ? Key(0,1,k-1) // edge 0
731 : (i == a && j == 0) ? Key(1,1,k-1) // edge 1
732 : (i == 0 && j == b) ? Key(2,1,k-1)
733 : (i == a && j == b) ? Key(3,1,k-1)
734 : (i == 0 && k == 0) ? Key(4,1,j-1)
735 : (i == a && k == 0) ? Key(5,1,j-1)
736 : (j == 0 && k == 0) ? Key(6,1,i-1)
737 : (j == b && k == 0) ? Key(7,1,i-1)
738 : (i == 0 && k == c) ? Key(8,1,j-1)
739 : (i == a && k == c) ? Key(9,1,j-1)
740 : (j == 0 && k == c) ? Key(10,1,i-1)
741 : (j == b && k == c) ? Key(11,1,i-1) // edge 11
742 : Key(0, 0, (k-1)*(b-1)*(a-1) + (j-1)*(a-1) + (i-1)); // cell
743
744 points.push_back(Point{Vec{coord_a(i), coord_b(j), coord_c(k)}, key});
745 }
746 }
747 }
748}
749
750}} // end namespace Dune::Vtk::Impl
Definition datacollector.hh:19
constexpr auto max
constexpr auto min
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon=DefaultEpsilon< T, style >::value())
size_type dim() const
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
constexpr std::integer_sequence< T, II..., T(IN)> push_back(std::integer_sequence< T, II... >, std::integral_constant< T, IN >={})
T make_pair(T... args)
T min(T... args)
T reserve(T... args)
T size(T... args)