FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
cell_to_dof_helper.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
9#include <kernel/geometry/index_set.hpp>
10#include <kernel/shape.hpp>
11
12#include <algorithm>
13
14namespace FEAT
15{
16 namespace VoxelAssembly
17 {
18 namespace Intern
19 {
21 template<typename SpaceType_, int target_dim_>
22 struct DofHelper;
23
24 template<int target_dim>
25 struct DofHelper<VoxelAssembly::Q2StandardQuad, target_dim>
26 {
27 static constexpr int dof_per_entity = 1;
28 };
29
30 template<int target_dim>
31 struct DofHelper<VoxelAssembly::Q2StandardHexa, target_dim>
32 {
33 static constexpr int dof_per_entity = 1;
34 };
35
36 template<int num_indices>
38 {
40 Index* begin = tmp.indices;
41 Index* end = tmp.indices + num_indices;
42 std::sort(begin, end);
43 return tmp;
44 }
45 }
46
52 template<typename Space_, typename IT_, int tar_dim = 0, int prior_ents = 0>
53 void fill_cell_to_dof(IT_* ctd, const Space_& space, IT_ offset = 0)
54 {
55 constexpr int dim = Space_::shape_dim;
56 constexpr int dof_per_cell = Space_::DofMappingType::dof_count;
57 //get index_set dim -> tar_dim
58 const auto& mesh = space.get_mesh();
59 const auto& index_set = mesh.template get_index_set<dim, tar_dim>();
62 constexpr int dof_per_entity = Intern::DofHelper<Space_, tar_dim>::dof_per_entity;
63 for(Index ent = 0; ent < index_set.get_num_entities(); ++ent)
64 {
65 const auto ind_arr = index_set[ent];
66 IT_* tmp_ctd = ctd + ent * dof_per_cell;
67 for(Index i = 0; i < ind_arr.num_indices; ++i)
68 {
69 for(IT_ j = 0; j < IT_(dof_per_entity); ++j)
70 {
71 tmp_ctd[i*IT_(dof_per_entity) + j + IT_(prior_ents)] = offset + IT_(dof_per_entity) * IT_(ind_arr[int(i)]) + j;
72 }
73 }
74 }
75 offset += IT_(mesh.get_num_entities(tar_dim)*dof_per_entity);
76 if constexpr(tar_dim < (dim-1))
77 {
78 constexpr int new_prior_ents = prior_ents + num_indices*dof_per_entity;
79 fill_cell_to_dof<Space_, IT_, tar_dim+1, new_prior_ents>(ctd, space, offset);
80 }
81 else if constexpr(tar_dim == (dim-1))
82 {
83 constexpr int shape_dim_dofs_per = Intern::DofHelper<Space_, dim>::dof_per_entity;
84 for(Index ent = 0; ent < index_set.get_num_entities(); ++ent)
85 {
86 IT_* tmp_ctd = ctd + (ent+1)*dof_per_cell - shape_dim_dofs_per;
87 for(int j = 0; j < shape_dim_dofs_per; ++j)
88 tmp_ctd[j] = IT_(ent)*IT_(shape_dim_dofs_per) + IT_(j) + offset;
89 }
90 }
91 else
92 {
93 XABORTM("Thou shallt not arrive here!");
94 }
95 }
96
97 template<typename Space_, typename IT_>
98 void fill_sorter(IT_* sorter, const IT_* mapping, const Space_& space)
99 {
100 constexpr int num_loc_dofs = Space_::DofMappingType::dof_count;
101 for(Index cell = 0; cell < space.get_mesh().get_num_entities(Space_::world_dim); ++cell)
102 {
103 //fill up local range
104 const Index begin = cell*num_loc_dofs;
105 const Index end = (cell+1)*num_loc_dofs;
106 const IT_* loc_map = mapping + begin;
107 std::generate(sorter+begin, sorter+end, [n=0]() mutable{return n++;});
108 std::sort(sorter+begin, sorter+end, [loc_map](IT_ va, IT_ vb){return loc_map[va] < loc_map[vb];});
109 }
110
111 /* For testing...
112 for(Index cell = 0; cell < space.get_mesh().get_num_entities(Space_::world_dim); ++cell)
113 {
114 //fill up local range
115 const Index begin = cell*num_loc_dofs;
116 const Index end = (cell+1)*num_loc_dofs;
117 const Index* loc_map = mapping + begin;
118 std::cout << "Mapping at cell " << cell << "\n";
119 for(Index i = begin; i < end; ++i)
120 {
121 std::cout << loc_map[i] << " ";
122 }
123 std::cout << "\n";
124 for(Index i = begin; i < end; ++i)
125 {
126 std::cout << sorter[i] << " ";
127 }
128 std::cout << "\n";
129 } //*/
130 }
131 }
132}
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
FEAT Kernel base header.
Standard Lagrange-2 Finite-Element space class template.
Definition: element.hpp:39
void fill_cell_to_dof(IT_ *ctd, const Space_ &space, IT_ offset=0)
Computes a sequentialized dof mapping for the given space.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.
Index Tuple class template.
Definition: index_set.hpp:35
Index indices[num_indices]
indices array
Definition: index_set.hpp:42
Face traits tag struct template.
Definition: shape.hpp:106
Prescribes the number of dofs per dimension for a given space.