Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
dof_policy.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22// Author: Pedro Peixoto <ppeixoto@usp.br>
23
24#ifndef VULPES_FE_DOF_POLICY_HPP_
25#define VULPES_FE_DOF_POLICY_HPP_
26
27#include <algorithm>
28#include <cassert>
29#include <cstddef>
30#include <cstdint>
31#include <iostream>
32#include <stdexcept>
33#include <utility>
34#include <vector>
35
43
44namespace vulpes {
45namespace fe {
46
57template <std::size_t Dim, typename DofPolicy>
59 explicit DofPolicyBase(std::size_t order) : m_order(order) {}
60
65 static std::array<std::size_t, Dim + 1> buildDofSubdimEntity(
66 std::size_t order) {
67 return DofPolicy::buildDofSubdimEntity(order);
68 }
69
72 static constexpr bool dofsInteractionDistance() {
73 return DofPolicy::dofsInteractionDistance();
74 };
75
76 template <typename MeshType>
77 constexpr MeshType::index_t dofToCellDof(
78 const MeshType& mesh,
79 MeshType::index_t cell_id,
80 MeshType::index_t owning_enty_id,
81 MeshType::index_t enty_dim,
82 MeshType::index_t enty_multiplicity) const {
83 static_assert(Dim == MeshType::self_dim);
84 return self().dofToCellDof(
85 mesh, cell_id, owning_enty_id, enty_dim, enty_multiplicity);
86 }
87
88 protected:
89 const auto& self() const { return static_cast<const DofPolicy&>(*this); }
90 auto& self() { return static_cast<DofPolicy&>(*this); }
92 std::size_t m_order;
93};
94
99template <std::size_t Dim>
100struct DofPolicyFeSpaceCQ : public DofPolicyBase<Dim, DofPolicyFeSpaceCQ<Dim>> {
101 using ConvexCartIndexValue = uint16_t;
102 using ConvexCartIndex = std::array<ConvexCartIndexValue, 1 << Dim>;
103
104 explicit DofPolicyFeSpaceCQ(std::size_t order)
105 : DofPolicyBase<Dim, DofPolicyFeSpaceCQ<Dim>>(order) {
107 }
108
113 static std::array<std::size_t, Dim + 1> buildDofSubdimEntity(
114 std::size_t order) {
115 std::array<std::size_t, Dim + 1> ndofs;
116 ndofs[0] = 1;
117 for (std::size_t d = 1; d < Dim + 1; ++d) {
118 ndofs[d] = ndofs[d - 1] * (order - 1);
119 }
120 return ndofs;
121 }
122
125 inline static constexpr bool dofsInteractionDistance() { return false; };
126
131 size_t getLocalDof(const ConvexCartIndex& convex_id) const {
132 // TODO: an unordered_map could be faster here?
133 const auto it = std::lower_bound(m_dofs.begin(), m_dofs.end(), convex_id);
134 assert((it != m_dofs.end()) && (*it == convex_id));
135 const auto d = std::distance(m_dofs.begin(), it);
136 return m_dofs_perm[d];
137 }
138
192 template <typename MeshType>
193 constexpr MeshType::index_t dofToCellDof(
194 const MeshType& mesh,
195 MeshType::index_t cell_id,
196 MeshType::index_t owning_enty_id,
197 MeshType::index_t enty_dim,
198 MeshType::index_t enty_multiplicity) const {
199 static_assert(Dim > 0 && Dim <= 3);
200 using index_t = MeshType::index_t;
201 index_t owning_enty_id_local = owning_enty_id;
202 if constexpr (MeshType::parallel()) {
203 owning_enty_id_local = mesh.globalToLocal(enty_dim).at(owning_enty_id);
204 }
205 if (enty_dim == 0) {
206 const auto& cell_vtxs = mesh.getCellToVtxGlobalMap();
207 ConvexCartIndex loc_vtx_id = {0};
208 std::size_t lvid = 0;
209 for (const auto& vtx_id : cell_vtxs[cell_id]) {
210 if (vtx_id == owning_enty_id) {
211 loc_vtx_id[lvid] = m_max_rescaling_dim;
212 break;
213 }
214 lvid++;
215 }
216 const auto loc_id = getLocalDof(loc_vtx_id);
217 return loc_id;
218 } else if (enty_dim == 1) {
219 if constexpr (Dim == 1) {
220 assert(cell_id == owning_enty_id_local);
221 return enty_multiplicity + 1;
222 }
223 using EdgeToVtxMapType = std::conditional_t<
224 Dim == 2, typename MeshType::FacetToVtxMap,
225 typename MeshType::EdgeToVtxMap>;
226 const EdgeToVtxMapType* edge_to_vtx_map;
227 if constexpr (Dim == 2) {
228 edge_to_vtx_map = &mesh.getFacetToVtxGlobalMap();
229 }
230 if constexpr (Dim == 3) {
231 edge_to_vtx_map = &mesh.getEdgeToVtxGlobalMap();
232 }
233 const auto cell_vtxs = mesh.getCellToVtxGlobalMap()[cell_id];
234 const auto edge_vtxs = (*edge_to_vtx_map)[owning_enty_id_local];
235 std::array<index_t, 2> loc_edge_vtx_id = {0};
236 for (std::size_t i = 0; i < (1 << Dim); ++i) {
237 loc_edge_vtx_id[0] += i * (edge_vtxs[0] == cell_vtxs[i]);
238 loc_edge_vtx_id[1] += i * (edge_vtxs[1] == cell_vtxs[i]);
239 }
240 ConvexCartIndex loc_vtx_id = {0};
241 assert(loc_edge_vtx_id[0] < index_t(loc_vtx_id.size()));
242 assert(loc_edge_vtx_id[1] < index_t(loc_vtx_id.size()));
243 loc_vtx_id[loc_edge_vtx_id[0]] = this->m_order - enty_multiplicity - 1;
244 loc_vtx_id[loc_edge_vtx_id[1]] = enty_multiplicity + 1;
245 loc_vtx_id[loc_edge_vtx_id[0]] *= m_max_rescaling_dim_1;
246 loc_vtx_id[loc_edge_vtx_id[1]] *= m_max_rescaling_dim_1;
247 const auto loc_id = getLocalDof(loc_vtx_id);
248 return loc_id;
249 } else if (enty_dim == 2) {
250 if constexpr (Dim == 2) {
251 return m_internal_dofs[enty_multiplicity];
252 }
253 if constexpr (Dim == 3) {
254 // The idea here (like above) is the following.
255 // I put this comment here since it is the most complex case but the
256 // procedure generalizes to the other cases.
257 // We recover the global vertices that define the face and write it
258 // as a convex combination of them. In this way we have a unique
259 // representation of the dof that does not depend on the frame of
260 // reference. The global vtx id of the face are
261 // `face_to_vtx_map[owning_enty_id_local]`. Their coefficient are
262 // `m_face_dofs[enty_multiplicity]` (up to a rescaling factor, since the
263 // rescaling is order^Dim and m_face_dofs are computed in 2D).
264 // Then, we can write this convex combination with respect to the local
265 // dofs of the cells since it has all the four vertices needed.
266 // Thus we find which are the position of these four global vertices
267 // in local enumeration (of the 8 vertices that define the cell),
268 // so we can write the dof as a ConvexCartIndex
269 std::array<ConvexCartIndexValue, 4> loc_face_vtx_id = {0};
270 const auto& face_to_vtx_map = mesh.getFacetToVtxGlobalMap();
271 const auto cell_vtxs = mesh.getCellToVtxGlobalMap()[cell_id];
272 for (std::size_t i = 0; i < 8; ++i) {
273 for (std::size_t j = 0; j < 4; ++j) {
274 if (face_to_vtx_map[owning_enty_id_local][j] == cell_vtxs[i]) {
275 loc_face_vtx_id[j] += i;
276 }
277 }
278 }
279 ConvexCartIndex loc_vtx_id = {0};
280 for (std::size_t i = 0; i < 4; ++i) {
281 loc_vtx_id[loc_face_vtx_id[i]] =
282 m_face_dofs[enty_multiplicity][i] * this->m_order;
283 }
284 return getLocalDof(loc_vtx_id);
285 }
286 } else if (enty_dim == 3) {
287 if constexpr (Dim == 3) {
288 return m_internal_dofs[enty_multiplicity];
289 }
290 }
291 throw std::logic_error("DofPolicy: invalid entity dimension");
292 }
293
295 const auto n_pts = this->m_order + 1;
296 // list the local dofs
297 for (std::size_t j = 0; j < vmath::pow(n_pts, Dim); ++j) {
298 // compute the cartesian index (x, y, z)
299 std::array<std::size_t, Dim> cart_dof_id;
300 std::size_t idx = j;
301 for (std::size_t d = 0; d < Dim; ++d) {
302 cart_dof_id[d] = idx % n_pts;
303 idx /= n_pts;
304 }
305 // convert to convex combination of vertices
306 ConvexCartIndex convx_cart_dof;
307 convx_cart_dof.fill(1);
308 // for each vertex of the hyper-cube
309 for (std::size_t covx_id = 0; covx_id < (1 << Dim); ++covx_id) {
310 for (std::size_t d = 0; d < Dim; ++d) {
311 const auto i = (covx_id & (1 << d)) > 0;
312 convx_cart_dof[covx_id] *=
313 (i * cart_dof_id[d] + (1 - i) * (this->m_order - cart_dof_id[d]));
314 }
315 }
316 // apply the permutation to go from the `covx_id` enumeration
317 // to our enumeration.
318 if constexpr (Dim == 2) {
319 // covx_id covx_id binary our convention (the CCW)
320 // 2-3 10-11 3-2
321 // | | = | | => | |
322 // 0-1 00-01 0-1
323 std::swap(convx_cart_dof[2], convx_cart_dof[3]);
324 } else if constexpr (Dim == 3) {
325 // y y y
326 // ^ z ^ z ^ z
327 // | / | / | /
328 // | 6-------7 | 110----111 | 7--------6
329 // | /| / /| | /| / /| | /| / /|
330 // |/ | / / | |/ | / / | |/ | / / |
331 // 2--------3 | 010----011 | 4--------5 |
332 // | |/ | | = | |/ | | => | |/ | |
333 // | 4-----|--5 | 100---|101 | 3-----|--2
334 // | / | / | / | / | / | /
335 // |/ |/ |/ |/ |/ |/
336 // 0--------1---->x 000----001---->x 0--------1---->x
337 // 0 1 2 3 4 5 6 7
338 std::swap(convx_cart_dof[6], convx_cart_dof[7]); // 0 1 2 3 4 5 7 6
339 std::swap(convx_cart_dof[2], convx_cart_dof[4]); // 0 1 4 3 2 5 6 7
340 std::swap(convx_cart_dof[2], convx_cart_dof[3]); // 0 1 3 4 2 5 6 7
341 std::swap(convx_cart_dof[2], convx_cart_dof[5]); // 0 1 5 4 2 3 7 6
342 } else if constexpr (Dim > 3) {
343 static_assert(Dim * 0 && "NotImplemented");
344 }
345 m_dofs.push_back(convx_cart_dof);
346 }
347 // sort the dofs to speed up search
348 m_dofs_perm.resize(m_dofs.size());
349 std::iota(m_dofs_perm.begin(), m_dofs_perm.end(), 0);
350 std::sort(m_dofs_perm.begin(), m_dofs_perm.end(), [this](auto a, auto b) {
351 return this->m_dofs[a] < this->m_dofs[b];
352 });
353 const auto dofs_perm = m_dofs_perm;
354 const auto dofs = m_dofs;
355 for (std::size_t i = 0; i < m_dofs_perm.size(); ++i) {
356 m_dofs[i] = dofs[dofs_perm[i]];
357 }
358
360 m_max_rescaling_dim_1 = vmath::pow(this->m_order, Dim - 1);
361
362 // create a table for finding the local index of internal dofs
363 // and facet dofs in 3D
364 for (std::size_t i = 0; i < m_dofs.size(); ++i) {
365 if ((*std::min_element(m_dofs[i].begin(), m_dofs[i].end())) > 0) {
366 m_internal_dofs.push_back(m_dofs_perm[i]);
367 }
368 }
369
370 if constexpr (Dim == 3) {
371 for (std::size_t j = 0; j < vmath::pow(n_pts, Dim - 1); ++j) {
372 // compute the cartesian index (x, y, z)
373 std::array<std::size_t, Dim - 1> cart_dof_id;
374 std::size_t idx = j;
375 for (std::size_t d = 0; d < Dim - 1; ++d) {
376 cart_dof_id[d] = idx % n_pts;
377 idx /= n_pts;
378 }
379 // convert to convex combination of vertices
380 ConvexCartFaceIndex convx_dof;
381 convx_dof.fill(1);
382 // for each vertex of the hyper-cube
383 for (std::size_t covx_id = 0; covx_id < 4; ++covx_id) {
384 for (std::size_t d = 0; d < Dim - 1; ++d) {
385 const auto i = (covx_id & (1 << d)) > 0;
386 convx_dof[covx_id] *=
387 (i * cart_dof_id[d] +
388 (1 - i) * (this->m_order - cart_dof_id[d]));
389 }
390 }
391 // fix the convex convention (use CCW, see above)
392 std::swap(convx_dof[2], convx_dof[3]);
393 if ((*std::min_element(convx_dof.begin(), convx_dof.end())) > 0) {
394 m_face_dofs.push_back(convx_dof);
395 }
396 }
397 }
398 }
399
402 // List of dofs in local cartesian enumeration, that is,
403 // in convex combination of vertices of the hyper-cube.
404 // The dofs are sorted lexicographycally.
405 // The coordinates are rescaled by a factor order^Dim so
406 // to be integers for any point with components of the type
407 // q/order in [0, 1]^Dim
408 std::vector<ConvexCartIndex> m_dofs = {};
409 // inverse permutation vector to have lexicographycally sorted cartesian dofs
410 std::vector<std::size_t> m_dofs_perm;
411 // these dofs are internal so we can do whatever we want (as numbering goes)
412 std::vector<std::size_t> m_internal_dofs;
413
414 // convex index type for the dofs on a face
415 using ConvexCartFaceIndex = std::array<ConvexCartIndexValue, 1 << (Dim - 1)>;
416 // ordered list of dofs internal to a facet (all ids are greater than zero)
417 std::vector<ConvexCartFaceIndex> m_face_dofs;
418};
419
428template <std::size_t Dim>
429struct DofPolicyFeSpaceCP : public DofPolicyBase<Dim, DofPolicyFeSpaceCP<Dim>> {
430 using CartDofIndexType = int8_t;
431 explicit DofPolicyFeSpaceCP(std::size_t order)
432 : DofPolicyBase<Dim, DofPolicyFeSpaceCP<Dim>>(order) {
434 }
435
440 static std::array<std::size_t, Dim + 1> buildDofSubdimEntity(
441 std::size_t order) {
442 std::array<std::size_t, Dim + 1> ndofs;
443 ndofs[0] = 1;
444 for (std::size_t d = 1; d < Dim + 1; ++d) {
445 ndofs[d] = ndofs[d - 1] * (order - d) / d;
446 }
447 return ndofs;
448 }
449
453 inline static constexpr bool dofsInteractionDistance() { return false; };
454
474 template <typename MeshType>
475 constexpr MeshType::index_t dofToCellDof(
476 const MeshType& mesh,
477 MeshType::index_t cell_id,
478 MeshType::index_t owning_enty_id,
479 MeshType::index_t enty_dim,
480 MeshType::index_t enty_multiplicity) const {
481 using index_t = MeshType::index_t;
482 index_t owning_enty_id_local = owning_enty_id;
483 if constexpr (MeshType::parallel()) {
484 owning_enty_id_local = mesh.globalToLocal(enty_dim).at(owning_enty_id);
485 }
486 if (enty_dim == 0) {
487 const auto& cell_vtxs = mesh.getCellToVtxGlobalMap();
488 index_t loc_vtx_id = 0;
489 for (const auto& vtx_id : cell_vtxs[cell_id]) {
490 if (vtx_id == owning_enty_id) {
491 break;
492 }
493 loc_vtx_id++;
494 }
495 std::array<CartDofIndexType, Dim + 1> cart_dof = {0};
496 assert(loc_vtx_id < index_t(cart_dof.size()));
497 cart_dof[loc_vtx_id] = this->m_order;
498 const auto dof_it =
499 std::lower_bound(m_dofs.begin(), m_dofs.end(), cart_dof);
500 assert((dof_it < m_dofs.end()) && ((*dof_it) == cart_dof));
501 const auto dist = std::distance(m_dofs.begin(), dof_it);
502 return m_dofs_perm[dist];
503 } else if (enty_dim == 1) {
504 if constexpr (Dim == 1) {
505 assert(cell_id == owning_enty_id_local);
506 return enty_multiplicity + 1;
507 }
508 static_assert(Dim > 0 && Dim <= 3);
509 using EdgeToVtxMapType = std::conditional_t<
510 Dim == 2, typename MeshType::FacetToVtxMap,
511 typename MeshType::EdgeToVtxMap>;
512 const EdgeToVtxMapType* edge_to_vtx_map;
513 if constexpr (Dim == 2) {
514 edge_to_vtx_map = &mesh.getFacetToVtxGlobalMap();
515 }
516 if constexpr (Dim == 3) {
517 edge_to_vtx_map = &mesh.getEdgeToVtxGlobalMap();
518 }
519 const auto cell_vtxs = mesh.getCellToVtxGlobalMap()[cell_id];
520 std::array<index_t, 2> loc_edge_vtx_id = {0};
521 for (std::size_t i = 0; i < Dim + 1; ++i) {
522 const auto edge_vtxs = (*edge_to_vtx_map)[owning_enty_id_local];
523 loc_edge_vtx_id[0] += i * (edge_vtxs[0] == cell_vtxs[i]);
524 loc_edge_vtx_id[1] += i * (edge_vtxs[1] == cell_vtxs[i]);
525 }
526 std::array<CartDofIndexType, Dim + 1> cart_dof = {0};
527 assert(loc_edge_vtx_id[0] < index_t(cart_dof.size()));
528 assert(loc_edge_vtx_id[1] < index_t(cart_dof.size()));
529 cart_dof[loc_edge_vtx_id[0]] = this->m_order - enty_multiplicity - 1;
530 cart_dof[loc_edge_vtx_id[1]] = enty_multiplicity + 1;
531 const auto dof_it =
532 std::lower_bound(m_dofs.begin(), m_dofs.end(), cart_dof);
533 assert((dof_it < m_dofs.end()) && ((*dof_it) == cart_dof));
534 const auto dist = std::distance(m_dofs.begin(), dof_it);
535 return m_dofs_perm[dist];
536 } else if (enty_dim == 2) {
537 std::array<index_t, 3> loc_face_vtx_id = {0};
538 if constexpr (Dim == 2) {
539 loc_face_vtx_id = {0, 1, 2};
540 }
541 if constexpr (Dim == 3) {
542 const auto& face_to_vtx_map = mesh.getFacetToVtxGlobalMap();
543 const auto cell_vtxs = mesh.getCellToVtxGlobalMap()[cell_id];
544 for (std::size_t i = 0; i < Dim + 1; ++i) {
545 for (std::size_t j = 0; j < 3; ++j) {
546 loc_face_vtx_id[j] +=
547 i * (face_to_vtx_map[owning_enty_id_local][j] == cell_vtxs[i]);
548 }
549 }
550 }
551 const auto cart_idx_xy =
553 std::array<CartDofIndexType, Dim + 1> cart_dof = {0};
554 cart_dof[loc_face_vtx_id[1]] = cart_idx_xy[0] + 1;
555 cart_dof[loc_face_vtx_id[2]] = cart_idx_xy[1] + 1;
556 cart_dof[loc_face_vtx_id[0]] =
557 this->m_order - 2 - cart_idx_xy[0] - cart_idx_xy[1];
558 const auto dof_it =
559 std::lower_bound(m_dofs.begin(), m_dofs.end(), cart_dof);
560 assert((dof_it < m_dofs.end()) && ((*dof_it) == cart_dof));
561 const auto dist = std::distance(m_dofs.begin(), dof_it);
562 return m_dofs_perm[dist];
563 } else if (enty_dim == 3) {
564 if constexpr (Dim > 2) {
565 const auto cart_idx_xyz =
567 std::array<CartDofIndexType, Dim + 1> cart_dof = {0};
568 cart_dof[0] = this->m_order;
569 for (std::size_t d = 0; d < 3; ++d) {
570 cart_dof[d + 1] = cart_idx_xyz[d] + 1;
571 cart_dof[0] -= cart_dof[d + 1];
572 }
573 const auto dof_it =
574 std::lower_bound(m_dofs.begin(), m_dofs.end(), cart_dof);
575 assert((dof_it < m_dofs.end()) && ((*dof_it) == cart_dof));
576 const auto dist = std::distance(m_dofs.begin(), dof_it);
577 return m_dofs_perm[dist];
578 }
579 }
580 throw std::logic_error("DofPolicy: invalid entity dimension");
581 }
582
587 const auto n_pts = this->m_order + 1;
588 for (std::size_t j = 0; j < vmath::pow(n_pts, Dim); ++j) {
589 std::array<CartDofIndexType, Dim + 1> cart_dof_id;
590 std::size_t idx = j;
591 std::size_t idx_sum = 0;
592 for (std::size_t d = 0; d < Dim; ++d) {
593 const auto idx_d = idx % n_pts;
594 idx_sum += idx_d;
595 cart_dof_id[d + 1] = idx_d;
596 idx /= n_pts;
597 }
598 if (idx_sum > this->m_order) {
599 continue;
600 }
601 cart_dof_id[0] = this->m_order - idx_sum;
602 m_dofs.push_back(cart_dof_id);
603 }
604 m_dofs_perm.resize(m_dofs.size());
605 std::iota(m_dofs_perm.begin(), m_dofs_perm.end(), 0);
606 std::sort(m_dofs_perm.begin(), m_dofs_perm.end(), [this](auto a, auto b) {
607 return this->m_dofs[a] < this->m_dofs[b];
608 });
609 const auto dofs_perm = m_dofs_perm;
610 const auto dofs = m_dofs;
611 for (std::size_t i = 0; i < m_dofs_perm.size(); ++i) {
612 m_dofs[i] = dofs[dofs_perm[i]];
613 }
614 }
615
616 // list of dofs in local cartesian enumeration
617 // that is in convex combination of vertices of the simplex
618 // the dofs are sorted
619 std::vector<std::array<CartDofIndexType, Dim + 1>> m_dofs;
620 // inverse permutation vector to have lexicographycally sorted cartesian dofs
621 std::vector<std::size_t> m_dofs_perm;
622};
623
628template <std::size_t Dim>
629struct DofPolicyFeSpaceDQ : public DofPolicyBase<Dim, DofPolicyFeSpaceDQ<Dim>> {
630 explicit DofPolicyFeSpaceDQ(std::size_t order)
631 : DofPolicyBase<Dim, DofPolicyFeSpaceDQ<Dim>>(order) {}
632 static std::array<std::size_t, Dim + 1> buildDofSubdimEntity(
633 std::size_t order) {
634 std::array<std::size_t, Dim + 1> ndofs = {0};
635 ndofs[Dim] = vmath::pow(order + 1, Dim);
636 return ndofs;
637 }
638 inline static constexpr bool dofsInteractionDistance() { return true; };
639
640 template <typename MeshType>
641 constexpr MeshType::index_t dofToCellDof(
642#ifndef NDEBUG
643 const MeshType& mesh,
644 MeshType::index_t cell_id,
645 MeshType::index_t owning_enty_id,
646 MeshType::index_t enty_dim,
647#else
648 const MeshType&,
649 MeshType::index_t,
650 MeshType::index_t,
651 MeshType::index_t,
652#endif
653 MeshType::index_t enty_multiplicity) const {
654 assert(enty_dim == Dim);
655#ifndef NDEBUG
656 if constexpr (MeshType::parallel()) {
657 owning_enty_id = mesh.globalToLocal(enty_dim).at(owning_enty_id);
658 }
659 assert(cell_id == owning_enty_id);
660#endif
661
662 return enty_multiplicity;
663 }
664};
665
670template <std::size_t Dim>
671struct DofPolicyFeSpaceDP : public DofPolicyBase<Dim, DofPolicyFeSpaceDP<Dim>> {
672 explicit DofPolicyFeSpaceDP(std::size_t order)
673 : DofPolicyBase<Dim, DofPolicyFeSpaceDP<Dim>>(order) {}
674 static std::array<std::size_t, Dim + 1> buildDofSubdimEntity(
675 std::size_t order) {
676 std::array<std::size_t, Dim + 1> ndofs = {0};
677 ndofs[Dim] = vmath::binomial(order + Dim, Dim);
678 return ndofs;
679 }
680 inline static constexpr bool dofsInteractionDistance() { return true; };
681
682 template <typename MeshType>
683 constexpr MeshType::index_t dofToCellDof(
684#ifndef NDEBUG
685 const MeshType& mesh,
686 MeshType::index_t cell_id,
687 MeshType::index_t owning_enty_id,
688 MeshType::index_t enty_dim,
689#else
690 const MeshType&,
691 MeshType::index_t,
692 MeshType::index_t,
693 MeshType::index_t,
694#endif
695 MeshType::index_t enty_multiplicity) const {
696 assert(enty_dim == Dim);
697#ifndef NDEBUG
698 if constexpr (MeshType::parallel()) {
699 owning_enty_id = mesh.globalToLocal(enty_dim).at(owning_enty_id);
700 }
701 assert(cell_id == owning_enty_id);
702#endif
703 return enty_multiplicity;
704 }
705};
706
707} // namespace fe
708} // namespace vulpes
709
710#endif // VULPES_FE_DOF_POLICY_HPP_
Definition dof_handler.hpp:50
Definition dof_policy.hpp:45
std::array< T, 2 > getMonomial2D(std::size_t n)
Computes the 2D monomial exponents for a given linear index.
Definition monomial.hpp:132
std::array< T, 3 > getMonomial3D(std::size_t n)
Computes the 3D monomial exponents for a given linear index.
Definition monomial.hpp:177
constexpr T binomial(T n, T k)
Definition vmath.hpp:386
constexpr U pow(U base, V exp, U result=U(1))
Computes the power of a number.
Definition vmath.hpp:171
Definition cell_manager.hpp:38
constexpr MeshType::index_t dofToCellDof(const MeshType &mesh, MeshType::index_t cell_id, MeshType::index_t owning_enty_id, MeshType::index_t enty_dim, MeshType::index_t enty_multiplicity) const
Definition dof_policy.hpp:77
auto & self()
Definition dof_policy.hpp:90
std::size_t m_order
Polynomial order of the finite element space.
Definition dof_policy.hpp:92
DofPolicyBase(std::size_t order)
Definition dof_policy.hpp:59
static std::array< std::size_t, Dim+1 > buildDofSubdimEntity(std::size_t order)
Returns the number of dofs associated to each sub-dimensional entity.
Definition dof_policy.hpp:65
static constexpr bool dofsInteractionDistance()
Returns the distance of interaction of dofs in different cells.
Definition dof_policy.hpp:72
const auto & self() const
Definition dof_policy.hpp:89
std::vector< std::array< CartDofIndexType, Dim+1 > > m_dofs
Definition dof_policy.hpp:619
static std::array< std::size_t, Dim+1 > buildDofSubdimEntity(std::size_t order)
Returns the number of dofs associated to each sub-dimensional entity.
Definition dof_policy.hpp:440
static constexpr bool dofsInteractionDistance()
Returns the distance of interaction of dofs in different cells.
Definition dof_policy.hpp:453
int8_t CartDofIndexType
Definition dof_policy.hpp:430
void buildDofTable()
Build the table of dofs in cartesian enumeration.
Definition dof_policy.hpp:586
constexpr MeshType::index_t dofToCellDof(const MeshType &mesh, MeshType::index_t cell_id, MeshType::index_t owning_enty_id, MeshType::index_t enty_dim, MeshType::index_t enty_multiplicity) const
Returns the index of the dof in cell enumeration given geometrical information.
Definition dof_policy.hpp:475
std::vector< std::size_t > m_dofs_perm
Definition dof_policy.hpp:621
DofPolicyFeSpaceCP(std::size_t order)
Definition dof_policy.hpp:431
std::vector< ConvexCartFaceIndex > m_face_dofs
Definition dof_policy.hpp:417
std::vector< std::size_t > m_dofs_perm
Definition dof_policy.hpp:410
DofPolicyFeSpaceCQ(std::size_t order)
Definition dof_policy.hpp:104
std::vector< std::size_t > m_internal_dofs
Definition dof_policy.hpp:412
static constexpr bool dofsInteractionDistance()
Returns the distance of interaction of dofs in different cells.
Definition dof_policy.hpp:125
ConvexCartIndexValue m_max_rescaling_dim_1
Definition dof_policy.hpp:401
size_t getLocalDof(const ConvexCartIndex &convex_id) const
Given the convex combination of vertices of the hyper-cube representing the local dof,...
Definition dof_policy.hpp:131
std::vector< ConvexCartIndex > m_dofs
Definition dof_policy.hpp:408
uint16_t ConvexCartIndexValue
Definition dof_policy.hpp:101
std::array< ConvexCartIndexValue, 1<<(Dim - 1)> ConvexCartFaceIndex
Definition dof_policy.hpp:415
void buildDofTable()
Definition dof_policy.hpp:294
std::array< ConvexCartIndexValue, 1<< Dim > ConvexCartIndex
Definition dof_policy.hpp:102
ConvexCartIndexValue m_max_rescaling_dim
Definition dof_policy.hpp:400
static std::array< std::size_t, Dim+1 > buildDofSubdimEntity(std::size_t order)
Returns the number of dofs associated to each sub-dimensional entity.
Definition dof_policy.hpp:113
constexpr MeshType::index_t dofToCellDof(const MeshType &mesh, MeshType::index_t cell_id, MeshType::index_t owning_enty_id, MeshType::index_t enty_dim, MeshType::index_t enty_multiplicity) const
Returns the index of the dof in cell enumeration given geometrical information.
Definition dof_policy.hpp:193
DofPolicyFeSpaceDP(std::size_t order)
Definition dof_policy.hpp:672
constexpr MeshType::index_t dofToCellDof(const MeshType &mesh, MeshType::index_t cell_id, MeshType::index_t owning_enty_id, MeshType::index_t enty_dim, MeshType::index_t enty_multiplicity) const
Definition dof_policy.hpp:683
static constexpr bool dofsInteractionDistance()
Definition dof_policy.hpp:680
static std::array< std::size_t, Dim+1 > buildDofSubdimEntity(std::size_t order)
Definition dof_policy.hpp:674
constexpr MeshType::index_t dofToCellDof(const MeshType &mesh, MeshType::index_t cell_id, MeshType::index_t owning_enty_id, MeshType::index_t enty_dim, MeshType::index_t enty_multiplicity) const
Definition dof_policy.hpp:641
static std::array< std::size_t, Dim+1 > buildDofSubdimEntity(std::size_t order)
Definition dof_policy.hpp:632
DofPolicyFeSpaceDQ(std::size_t order)
Definition dof_policy.hpp:630
static constexpr bool dofsInteractionDistance()
Definition dof_policy.hpp:638