24#ifndef VULPES_FE_DOF_POLICY_HPP_
25#define VULPES_FE_DOF_POLICY_HPP_
57template <std::
size_t Dim,
typename DofPolicy>
67 return DofPolicy::buildDofSubdimEntity(order);
73 return DofPolicy::dofsInteractionDistance();
76 template <
typename MeshType>
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);
89 const auto&
self()
const {
return static_cast<const DofPolicy&
>(*this); }
90 auto&
self() {
return static_cast<DofPolicy&
>(*this); }
99template <std::
size_t Dim>
115 std::array<std::size_t, Dim + 1> ndofs;
117 for (std::size_t d = 1; d < Dim + 1; ++d) {
118 ndofs[d] = ndofs[d - 1] * (order - 1);
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);
192 template <
typename MeshType>
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);
206 const auto& cell_vtxs = mesh.getCellToVtxGlobalMap();
208 std::size_t lvid = 0;
209 for (
const auto& vtx_id : cell_vtxs[cell_id]) {
210 if (vtx_id == owning_enty_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;
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();
230 if constexpr (Dim == 3) {
231 edge_to_vtx_map = &mesh.getEdgeToVtxGlobalMap();
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]);
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;
249 }
else if (enty_dim == 2) {
250 if constexpr (Dim == 2) {
253 if constexpr (Dim == 3) {
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;
280 for (std::size_t i = 0; i < 4; ++i) {
281 loc_vtx_id[loc_face_vtx_id[i]] =
286 }
else if (enty_dim == 3) {
287 if constexpr (Dim == 3) {
291 throw std::logic_error(
"DofPolicy: invalid entity dimension");
295 const auto n_pts = this->
m_order + 1;
297 for (std::size_t j = 0; j <
vmath::pow(n_pts, Dim); ++j) {
299 std::array<std::size_t, Dim> cart_dof_id;
301 for (std::size_t d = 0; d < Dim; ++d) {
302 cart_dof_id[d] = idx % n_pts;
307 convx_cart_dof.fill(1);
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]));
318 if constexpr (Dim == 2) {
323 std::swap(convx_cart_dof[2], convx_cart_dof[3]);
324 }
else if constexpr (Dim == 3) {
338 std::swap(convx_cart_dof[6], convx_cart_dof[7]);
339 std::swap(convx_cart_dof[2], convx_cart_dof[4]);
340 std::swap(convx_cart_dof[2], convx_cart_dof[3]);
341 std::swap(convx_cart_dof[2], convx_cart_dof[5]);
342 }
else if constexpr (Dim > 3) {
343 static_assert(Dim * 0 &&
"NotImplemented");
345 m_dofs.push_back(convx_cart_dof);
351 return this->m_dofs[a] < this->m_dofs[b];
355 for (std::size_t i = 0; i <
m_dofs_perm.size(); ++i) {
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) {
370 if constexpr (Dim == 3) {
371 for (std::size_t j = 0; j <
vmath::pow(n_pts, Dim - 1); ++j) {
373 std::array<std::size_t, Dim - 1> cart_dof_id;
375 for (std::size_t d = 0; d < Dim - 1; ++d) {
376 cart_dof_id[d] = idx % n_pts;
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]));
392 std::swap(convx_dof[2], convx_dof[3]);
393 if ((*std::min_element(convx_dof.begin(), convx_dof.end())) > 0) {
408 std::vector<ConvexCartIndex>
m_dofs = {};
428template <std::
size_t Dim>
442 std::array<std::size_t, Dim + 1> ndofs;
444 for (std::size_t d = 1; d < Dim + 1; ++d) {
445 ndofs[d] = ndofs[d - 1] * (order - d) / d;
474 template <
typename MeshType>
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);
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) {
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;
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);
503 }
else if (enty_dim == 1) {
504 if constexpr (Dim == 1) {
505 assert(cell_id == owning_enty_id_local);
506 return enty_multiplicity + 1;
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();
516 if constexpr (Dim == 3) {
517 edge_to_vtx_map = &mesh.getEdgeToVtxGlobalMap();
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]);
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;
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);
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};
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]);
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];
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);
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};
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];
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);
580 throw std::logic_error(
"DofPolicy: invalid entity dimension");
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;
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;
595 cart_dof_id[d + 1] = idx_d;
601 cart_dof_id[0] = this->
m_order - idx_sum;
602 m_dofs.push_back(cart_dof_id);
607 return this->m_dofs[a] < this->m_dofs[b];
611 for (std::size_t i = 0; i <
m_dofs_perm.size(); ++i) {
619 std::vector<std::array<CartDofIndexType, Dim + 1>>
m_dofs;
628template <std::
size_t Dim>
634 std::array<std::size_t, Dim + 1> ndofs = {0};
640 template <
typename MeshType>
643 const MeshType& mesh,
644 MeshType::index_t cell_id,
645 MeshType::index_t owning_enty_id,
646 MeshType::index_t enty_dim,
653 MeshType::index_t enty_multiplicity)
const {
654 assert(enty_dim == Dim);
656 if constexpr (MeshType::parallel()) {
657 owning_enty_id = mesh.globalToLocal(enty_dim).at(owning_enty_id);
659 assert(cell_id == owning_enty_id);
662 return enty_multiplicity;
670template <std::
size_t Dim>
676 std::array<std::size_t, Dim + 1> ndofs = {0};
682 template <
typename MeshType>
685 const MeshType& mesh,
686 MeshType::index_t cell_id,
687 MeshType::index_t owning_enty_id,
688 MeshType::index_t enty_dim,
695 MeshType::index_t enty_multiplicity)
const {
696 assert(enty_dim == Dim);
698 if constexpr (MeshType::parallel()) {
699 owning_enty_id = mesh.globalToLocal(enty_dim).at(owning_enty_id);
701 assert(cell_id == owning_enty_id);
703 return enty_multiplicity;
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