Peano
Loading...
Searching...
No Matches
Lexicographic.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3"""!
4
5Legacy lexicographic Cartesian ordering helpers.
6
7This module provides the standard row-major lexicographic mapping that was
8used by an earlier version of the leaf distribution before the traversal was
9switched to Peano SFC order in `SplitTrees.py`.
10
11This strategy runs through the mesh bottom up. It first assigns all leaves
12on the finest level to partitions, then the leaves on the next coarser
13level, and so forth. This strategy is biased towards the finest mesh and
14particularly valuable for strategies which do more work on the finest level
15than on other cells. This holds for example for some p-multigrid solvers or
16ExaHyPE with limiter where the limiter typically kicks in on the finest
17mesh resolution only.
18
19We do assign indices per level along the Peano space filling curve. However,
20whenever we encounter an AMR transition, we stop assigning cells to a rank.
21That is, if there are 27 connected fine grid cells and each subtree should
22have 15 cells, then we assign the first 15 cells to tree 0. Tree 1 then
23get the remaining 27-15 cells. After that, we continue with tree 2. Through
24this, we avoid that AMR partitions become disconnected:
25
26@image html distribute_leaves_bottom_up.png
27
28The ordering itself is straightforward:
29- 2-D: `(x, y) -> x + y * size`
30- 3-D: `(x, y, z) -> x + y * size + z * size^2`
31
32This module keeps the legacy helpers isolated from the SFC utilities so the
33Peano-specific code can stay focused on SFC order.
34"""
35
36
37def Cartesian_to_lexicographic_2d(
38 coordinates: tuple[int, int],
39 size: int,
40):
41 """Map a 2-D Cartesian index to standard lexicographic order."""
42 result = 0
43 base = 1
44 for i in range(0, 2):
45 result += coordinates[i] * base
46 base *= size
47 return result
48
49
50def Cartesian_to_lexicographic_3d(
51 coordinates: tuple[int, int, int],
52 size: int,
53):
54 """Map a 3-D Cartesian index to standard lexicographic order."""
55 result = 0
56 base = 1
57 for i in range(0, 3):
58 result += coordinates[i] * base
59 base *= size
60 return result