FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
struct_index_coding.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
8// includes, FEAT
10
11namespace FEAT
12{
13 namespace Geometry
14 {
16 namespace Intern
17 {
18 template<int shape_dim_, int cell_dim_>
19 struct StructIndexCoding;
20
21 // 1D vertices
22 template<>
23 struct StructIndexCoding<1, 0>
24 {
25 // n[0] = number of slices in X
26 // v[0] = x-index of vertex <= n[0]
27 static Index encode(const Index v[], const Index /*n*/[])
28 {
29 return v[0];
30 }
31
32 static void decode(Index v[], const Index i, const Index /*n*/[])
33 {
34 v[0] = i;
35 }
36 };
37
38 // 2D vertices
39 template<>
40 struct StructIndexCoding<2, 0>
41 {
42 // n[0] = number of slices in X
43 // n[1] = number of slices in Y
44 // v[0] = x-index of vertex <= n[0]
45 // v[1] = y-index of vertex <= n[1]
46 static Index encode(const Index v[], const Index n[])
47 {
48 return v[0] + (n[0] + Index(1)) * v[1];
49 }
50
51 static void decode(Index v[], const Index i, const Index n[])
52 {
53 v[0] = i % (n[0] + Index(1));
54 v[1] = i / (n[0] + Index(1));
55 }
56 };
57
58 // 3D vertices
59 template<>
60 struct StructIndexCoding<3, 0>
61 {
62 // n[0] = number of slices in X
63 // n[1] = number of slices in Y
64 // n[2] = number of slices in Z
65 // v[0] = x-index of vertex <= n[0]
66 // v[1] = y-index of vertex <= n[1]
67 // v[2] = z-index of vertex <= n[2]
68 static Index encode(const Index v[], const Index n[])
69 {
70 return v[0] + (n[0] + Index(1)) * (v[1] + (n[1] + Index(1)) * v[2]);
71 }
72
73 static void decode(Index v[], const Index i, const Index n[])
74 {
75 v[0] = i % ((n[0] + Index(1)) * (n[1] + Index(1)));
76 v[1] = (i / (n[0] + Index(1))) % (n[1] + Index(1));
77 v[2] = i / ((n[0] + Index(1)) * (n[1] + Index(1)));
78 }
79 };
80
81 // 1D edges
82 template<>
83 struct StructIndexCoding<1, 1>
84 {
85 // n[0] = number of slices in X
86 // v[1] = x-index of edge < n[0]
87 static Index encode(const Index v[], const Index /*n*/[])
88 {
89 return v[0];
90 }
91
92 static void decode(Index v[], const Index i, const Index /*n*/[])
93 {
94 v[0] = i;
95 }
96 };
97
98 // 2D edges
99 template<>
100 struct StructIndexCoding<2, 1>
101 {
102 // n[0] = number of slices in X
103 // n[1] = number of slices in Y
104 // v[0] = x-index of edge < n[0] (+1)
105 // v[1] = y-index of edge < n[1] (+1)
106 // v[2] = {0 = horz edge, 1 = vert edge}
107 static Index encode(const Index v[], const Index n[])
108 {
109 if(v[2] == 0) // horizontal edge
110 return v[0] + n[0] * v[1];
111 else // vertical edge
112 return v[1] + n[1] * v[0] + n[0]*(n[1]+Index(1));
113 }
114
115 static void decode(Index v[], const Index i, const Index n[])
116 {
117 if(i < n[0] * (n[1] + Index(1)))
118 {
119 // horizontal edge
120 v[0] = i % n[0];
121 v[1] = i / n[0];
122 v[2] = 0;
123 }
124 else
125 {
126 // vertical edge
127 const Index j = (i - n[0] * (n[1] + Index(1)));
128 v[0] = j / n[1];
129 v[1] = j % n[1];
130 v[2] = 1;
131 }
132 }
133 };
134
136
137 // 2D quads
138 template<>
139 struct StructIndexCoding<2, 2>
140 {
141 // n[0] = number of slices in X
142 // n[1] = number of slices in Y
143 // v[0] = x-index of quad < n[0]
144 // v[1] = y-index of quad < n[1]
145 static Index encode(const Index v[], const Index n[])
146 {
147 return v[0] + n[0] * v[1];
148 }
149
150 static void decode(Index v[], const Index i, const Index n[])
151 {
152 v[0] = i % n[0];
153 v[1] = i / n[0];
154 }
155 };
156
158
159 // 3D hexas
160 template<>
161 struct StructIndexCoding<3, 3>
162 {
163 // n[0] = number of slices in X
164 // n[1] = number of slices in Y
165 // n[2] = number of slices in Z
166 // v[0] = x-index of hexa < n[0]
167 // v[1] = y-index of hexa < n[1]
168 // v[2] = z-index of hexa < n[2]
169 static Index encode(const Index v[], const Index n[])
170 {
171 return v[0] + n[0] * (v[1] + n[1] * v[2]);
172 }
173
174 static void decode(Index v[], const Index i, const Index n[])
175 {
176 v[0] = i % (n[0] * n[1]);
177 v[1] = (i / n[0]) % (n[1]);
178 v[2] = i / (n[0] * n[1]);
179 }
180 };
181 } // namespace Intern
183 } // namespace Geometry
184} // namespace FEAT
FEAT Kernel base header.
std::size_t encode(void *buf, const T_ *src, const std::size_t buf_size, const std::size_t count, const Pack::Type pack_type, bool swap_bytes, double tolerance)
Encodes an array into a packed buffer.
Definition: pack.cpp:566
std::size_t decode(T_ *dst, void *buf, const std::size_t count, const std::size_t buf_size, const Pack::Type pack_type, bool swap_bytes)
Decodes an array from a packed buffer.
Definition: pack.cpp:680
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.