Loading...
Searching...
No Matches
tree_constants.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#include "tree_constants.hpp"
26#include "morton.hpp"
27
28#include <algorithm>
29#include <cassert>
30
31namespace bitpit {
32
33// =================================================================================== //
34// CLASS IMPLEMENTATION //
35// =================================================================================== //
36
40const TreeConstants &
42 assert(dim == 2 || dim == 3);
43 return instances()[dim];
44}
45
48const TreeConstants::Instances &
50 // It is possible to instance only 2D and 3D trees, therefore constants
51 // will be initialized only for these two dimensions.
52 static TreeConstants::Instances instances = {{
57 }};
58
59 return instances;
60}
61
65TreeConstants::TreeConstants(uint8_t dim) {
66 initialize(dim);
67}
68
72void
73TreeConstants::initialize(uint8_t dim) {
74
75 maxLevel = PABLO::computeMaximumLevel(dim);
76
77 nChildren = uint8_t(1)<<dim;
78 nFaces = 2*dim;
79 nNodes = uint8_t(1)<<dim;
80 nEdges = (dim-2)*12;
81 nNodesPerFace = uint8_t(1)<<(dim-1);
82
83 oppositeFace[0] = 1;
84 oppositeFace[1] = 0;
85 oppositeFace[2] = 3;
86 oppositeFace[3] = 2;
87 oppositeFace[4] = 5;
88 oppositeFace[5] = 4;
89
90 nodeFace[0][0] = 0;
91 nodeFace[0][1] = 2;
92 nodeFace[0][2] = 4;
93 nodeFace[1][0] = 1;
94 nodeFace[1][1] = 2;
95 nodeFace[1][2] = 4;
96 nodeFace[2][0] = 0;
97 nodeFace[2][1] = 3;
98 nodeFace[2][2] = 4;
99 nodeFace[3][0] = 1;
100 nodeFace[3][1] = 3;
101 nodeFace[3][2] = 4;
102 nodeFace[4][0] = 0;
103 nodeFace[4][1] = 2;
104 nodeFace[4][2] = 5;
105 nodeFace[5][0] = 1;
106 nodeFace[5][1] = 2;
107 nodeFace[5][2] = 5;
108 nodeFace[6][0] = 0;
109 nodeFace[6][1] = 3;
110 nodeFace[6][2] = 5;
111 nodeFace[7][0] = 1;
112 nodeFace[7][1] = 3;
113 nodeFace[7][2] = 5;
114
115 nodeEdge[0][0] = 0;
116 nodeEdge[0][1] = 2;
117 nodeEdge[0][2] = 4;
118 nodeEdge[1][0] = 1;
119 nodeEdge[1][1] = 2;
120 nodeEdge[1][2] = 5;
121 nodeEdge[2][0] = 0;
122 nodeEdge[2][1] = 3;
123 nodeEdge[2][2] = 6;
124 nodeEdge[3][0] = 1;
125 nodeEdge[3][1] = 3;
126 nodeEdge[3][2] = 7;
127 nodeEdge[4][0] = 4;
128 nodeEdge[4][1] = 8;
129 nodeEdge[4][2] = 10;
130 nodeEdge[5][0] = 5;
131 nodeEdge[5][1] = 9;
132 nodeEdge[5][2] = 10;
133 nodeEdge[6][0] = 6;
134 nodeEdge[6][1] = 8;
135 nodeEdge[6][2] = 11;
136 nodeEdge[7][0] = 7;
137 nodeEdge[7][1] = 9;
138 nodeEdge[7][2] = 11;
139
140 edgeNode[0][0] = 0;
141 edgeNode[0][1] = 2;
142 edgeNode[1][0] = 1;
143 edgeNode[1][1] = 3;
144 edgeNode[2][0] = 0;
145 edgeNode[2][1] = 1;
146 edgeNode[3][0] = 2;
147 edgeNode[3][1] = 3;
148 edgeNode[4][0] = 0;
149 edgeNode[4][1] = 4;
150 edgeNode[5][0] = 1;
151 edgeNode[5][1] = 5;
152 edgeNode[6][0] = 2;
153 edgeNode[6][1] = 6;
154 edgeNode[7][0] = 3;
155 edgeNode[7][1] = 7;
156 edgeNode[8][0] = 4;
157 edgeNode[8][1] = 6;
158 edgeNode[9][0] = 5;
159 edgeNode[9][1] = 7;
160 edgeNode[10][0] = 4;
161 edgeNode[10][1] = 5;
162 edgeNode[11][0] = 6;
163 edgeNode[11][1] = 7;
164
165 faceNode[0][0] = 0;
166 faceNode[0][1] = 2;
167 faceNode[0][2] = 4;
168 faceNode[0][3] = 6;
169 faceNode[1][0] = 1;
170 faceNode[1][1] = 3;
171 faceNode[1][2] = 5;
172 faceNode[1][3] = 7;
173 faceNode[2][0] = 0;
174 faceNode[2][1] = 1;
175 faceNode[2][2] = 4;
176 faceNode[2][3] = 5;
177 faceNode[3][0] = 2;
178 faceNode[3][1] = 3;
179 faceNode[3][2] = 6;
180 faceNode[3][3] = 7;
181 faceNode[4][0] = 0;
182 faceNode[4][1] = 1;
183 faceNode[4][2] = 2;
184 faceNode[4][3] = 3;
185 faceNode[5][0] = 4;
186 faceNode[5][1] = 5;
187 faceNode[5][2] = 6;
188 faceNode[5][3] = 7;
189
190 edgeFace[0][0] = 0;
191 edgeFace[0][1] = 4;
192 edgeFace[1][0] = 1;
193 edgeFace[1][1] = 4;
194 edgeFace[2][0] = 2;
195 edgeFace[2][1] = 4;
196 edgeFace[3][0] = 3;
197 edgeFace[3][1] = 4;
198 edgeFace[4][0] = 0;
199 edgeFace[4][1] = 2;
200 edgeFace[5][0] = 1;
201 edgeFace[5][1] = 2;
202 edgeFace[6][0] = 0;
203 edgeFace[6][1] = 3;
204 edgeFace[7][0] = 1;
205 edgeFace[7][1] = 3;
206 edgeFace[8][0] = 0;
207 edgeFace[8][1] = 5;
208 edgeFace[9][0] = 1;
209 edgeFace[9][1] = 5;
210 edgeFace[10][0] = 2;
211 edgeFace[10][1] = 5;
212 edgeFace[11][0] = 3;
213 edgeFace[11][1] = 5;
214
215 normals[0][0] = -1;
216 normals[0][1] = 0;
217 normals[0][2] = 0;
218 normals[1][0] = 1;
219 normals[1][1] = 0;
220 normals[1][2] = 0;
221 normals[2][0] = 0;
222 normals[2][1] = -1;
223 normals[2][2] = 0;
224 normals[3][0] = 0;
225 normals[3][1] = 1;
226 normals[3][2] = 0;
227 normals[4][0] = 0;
228 normals[4][1] = 0;
229 normals[4][2] = -1;
230 normals[5][0] = 0;
231 normals[5][1] = 0;
232 normals[5][2] = 1;
233
234 edgeCoeffs[0][0] = -1;
235 edgeCoeffs[0][1] = 0;
236 edgeCoeffs[0][2] = -1;
237 edgeCoeffs[1][0] = 1;
238 edgeCoeffs[1][1] = 0;
239 edgeCoeffs[1][2] = -1;
240 edgeCoeffs[2][0] = 0;
241 edgeCoeffs[2][1] = -1;
242 edgeCoeffs[2][2] = -1;
243 edgeCoeffs[3][0] = 0;
244 edgeCoeffs[3][1] = 1;
245 edgeCoeffs[3][2] = -1;
246 edgeCoeffs[4][0] = -1;
247 edgeCoeffs[4][1] = -1;
248 edgeCoeffs[4][2] = 0;
249 edgeCoeffs[5][0] = 1;
250 edgeCoeffs[5][1] = -1;
251 edgeCoeffs[5][2] = 0;
252 edgeCoeffs[6][0] = -1;
253 edgeCoeffs[6][1] = 1;
254 edgeCoeffs[6][2] = 0;
255 edgeCoeffs[7][0] = 1;
256 edgeCoeffs[7][1] = 1;
257 edgeCoeffs[7][2] = 0;
258 edgeCoeffs[8][0] = -1;
259 edgeCoeffs[8][1] = 0;
260 edgeCoeffs[8][2] = 1;
261 edgeCoeffs[9][0] = 1;
262 edgeCoeffs[9][1] = 0;
263 edgeCoeffs[9][2] = 1;
264 edgeCoeffs[10][0] = 0;
265 edgeCoeffs[10][1] = -1;
266 edgeCoeffs[10][2] = 1;
267 edgeCoeffs[11][0] = 0;
268 edgeCoeffs[11][1] = 1;
269 edgeCoeffs[11][2] = 1;
270
271 nodeCoeffs[0][0] = -1;
272 nodeCoeffs[0][1] = -1;
273 nodeCoeffs[0][2] = -1;
274 nodeCoeffs[1][0] = 1;
275 nodeCoeffs[1][1] = -1;
276 nodeCoeffs[1][2] = -1;
277 nodeCoeffs[2][0] = -1;
278 nodeCoeffs[2][1] = 1;
279 nodeCoeffs[2][2] = -1;
280 nodeCoeffs[3][0] = 1;
281 nodeCoeffs[3][1] = 1;
282 nodeCoeffs[3][2] = -1;
283 nodeCoeffs[4][0] = -1;
284 nodeCoeffs[4][1] = -1;
285 nodeCoeffs[4][2] = 1;
286 nodeCoeffs[5][0] = 1;
287 nodeCoeffs[5][1] = -1;
288 nodeCoeffs[5][2] = 1;
289 nodeCoeffs[6][0] = -1;
290 nodeCoeffs[6][1] = 1;
291 nodeCoeffs[6][2] = 1;
292 nodeCoeffs[7][0] = 1;
293 nodeCoeffs[7][1] = 1;
294 nodeCoeffs[7][2] = 1;
295
296 parallelEdges[0][0] = 1;
297 parallelEdges[0][1] = 8;
298 parallelEdges[0][2] = 9;
299 parallelEdges[1][0] = 0;
300 parallelEdges[1][1] = 8;
301 parallelEdges[1][2] = 9;
302 parallelEdges[2][0] = 3;
303 parallelEdges[2][1] = 10;
304 parallelEdges[2][2] = 11;
305 parallelEdges[3][0] = 2;
306 parallelEdges[3][1] = 10;
307 parallelEdges[3][2] = 11;
308 parallelEdges[4][0] = 5;
309 parallelEdges[4][1] = 6;
310 parallelEdges[4][2] = 7;
311 parallelEdges[5][0] = 4;
312 parallelEdges[5][1] = 6;
313 parallelEdges[5][2] = 7;
314 parallelEdges[6][0] = 4;
315 parallelEdges[6][1] = 5;
316 parallelEdges[6][2] = 7;
317 parallelEdges[7][0] = 4;
318 parallelEdges[7][1] = 5;
319 parallelEdges[7][2] = 6;
320 parallelEdges[8][0] = 0;
321 parallelEdges[8][1] = 1;
322 parallelEdges[8][2] = 9;
323 parallelEdges[9][0] = 0;
324 parallelEdges[9][1] = 1;
325 parallelEdges[9][2] = 8;
326 parallelEdges[10][0] = 2;
327 parallelEdges[10][1] = 3;
328 parallelEdges[10][2] = 11;
329 parallelEdges[11][0] = 2;
330 parallelEdges[11][1] = 3;
331 parallelEdges[11][2] = 10;
332
333 nodeCoordinates[0][0] = 0;
334 nodeCoordinates[0][1] = 0;
335 nodeCoordinates[0][2] = 0;
336 nodeCoordinates[1][0] = 1;
337 nodeCoordinates[1][1] = 0;
338 nodeCoordinates[1][2] = 0;
339 nodeCoordinates[2][0] = 0;
340 nodeCoordinates[2][1] = 1;
341 nodeCoordinates[2][2] = 0;
342 nodeCoordinates[3][0] = 1;
343 nodeCoordinates[3][1] = 1;
344 nodeCoordinates[3][2] = 0;
345 nodeCoordinates[4][0] = 0;
346 nodeCoordinates[4][1] = 0;
347 nodeCoordinates[4][2] = 1;
348 nodeCoordinates[5][0] = 1;
349 nodeCoordinates[5][1] = 0;
350 nodeCoordinates[5][2] = 1;
351 nodeCoordinates[6][0] = 0;
352 nodeCoordinates[6][1] = 1;
353 nodeCoordinates[6][2] = 1;
354 nodeCoordinates[7][0] = 1;
355 nodeCoordinates[7][1] = 1;
356 nodeCoordinates[7][2] = 1;
357
358 edgeDisplacements[0][0] = 0;
359 edgeDisplacements[0][1] = 1;
360 edgeDisplacements[0][2] = 0;
361 edgeDisplacements[1][0] = 2;
362 edgeDisplacements[1][1] = 1;
363 edgeDisplacements[1][2] = 0;
364 edgeDisplacements[2][0] = 1;
365 edgeDisplacements[2][1] = 0;
366 edgeDisplacements[2][2] = 0;
367 edgeDisplacements[3][0] = 1;
368 edgeDisplacements[3][1] = 2;
369 edgeDisplacements[3][2] = 0;
370 edgeDisplacements[4][0] = 0;
371 edgeDisplacements[4][1] = 0;
372 edgeDisplacements[4][2] = 1;
373 edgeDisplacements[5][0] = 2;
374 edgeDisplacements[5][1] = 0;
375 edgeDisplacements[5][2] = 1;
376 edgeDisplacements[6][0] = 0;
377 edgeDisplacements[6][1] = 2;
378 edgeDisplacements[6][2] = 1;
379 edgeDisplacements[7][0] = 2;
380 edgeDisplacements[7][1] = 2;
381 edgeDisplacements[7][2] = 1;
382 edgeDisplacements[8][0] = 0;
383 edgeDisplacements[8][1] = 1;
384 edgeDisplacements[8][2] = 2;
385 edgeDisplacements[9][0] = 2;
386 edgeDisplacements[9][1] = 1;
387 edgeDisplacements[9][2] = 2;
388 edgeDisplacements[10][0] = 1;
389 edgeDisplacements[10][1] = 0;
390 edgeDisplacements[10][2] = 2;
391 edgeDisplacements[11][0] = 1;
392 edgeDisplacements[11][1] = 2;
393 edgeDisplacements[11][2] = 2;
394
395 faceDisplacements[0][0] = 0;
396 faceDisplacements[0][1] = 1;
397 faceDisplacements[0][2] = 1;
398 faceDisplacements[1][0] = 2;
399 faceDisplacements[1][1] = 1;
400 faceDisplacements[1][2] = 1;
401 faceDisplacements[2][0] = 1;
402 faceDisplacements[2][1] = 0;
403 faceDisplacements[2][2] = 1;
404 faceDisplacements[3][0] = 1;
405 faceDisplacements[3][1] = 2;
406 faceDisplacements[3][2] = 1;
407 faceDisplacements[4][0] = 1;
408 faceDisplacements[4][1] = 1;
409 faceDisplacements[4][2] = 0;
410 faceDisplacements[5][0] = 1;
411 faceDisplacements[5][1] = 1;
412 faceDisplacements[5][2] = 2;
413
414 nodeFromCoordinates[0][0][0] = 0;
415 nodeFromCoordinates[1][0][0] = 1;
416 nodeFromCoordinates[0][1][0] = 2;
417 nodeFromCoordinates[1][1][0] = 3;
418 nodeFromCoordinates[0][0][1] = 4;
419 nodeFromCoordinates[1][0][1] = 5;
420 nodeFromCoordinates[0][1][1] = 6;
421 nodeFromCoordinates[1][1][1] = 7;
422
423 lengths.resize(maxLevel + 1);
424 areas.resize(maxLevel + 1);
425 volumes.resize(maxLevel + 1);
426 for (int level = 0; level <= maxLevel; ++level) {
427 lengths[level] = uint32_t(1) << (maxLevel - level);
428 areas[level] = uint64_t(1) << ((dim - 1) * (maxLevel - level));
429 volumes[level] = uint64_t(1) << (dim * (maxLevel - level));
430 }
431
432}
433
434// =================================================================================== //
435
436}
Global constants associated to a PABLO tree.
uint8_t edgeDisplacements[12][3]
std::vector< uint64_t > volumes
uint8_t faceDisplacements[6][3]
static BITPIT_PUBLIC_API const Instances & instances()
uint8_t parallelEdges[12][3]
std::vector< uint32_t > lengths
uint8_t nodeFromCoordinates[2][2][2]
static BITPIT_PUBLIC_API const TreeConstants & instance(uint8_t dim)
std::vector< uint64_t > areas
uint8_t nodeCoordinates[8][3]
--- layout: doxygen_footer ---