3from toolbox.loadbalancing.api.strategies.SFC
import (
16 """Docstring example: (4, 2) with size=9 must map to 10."""
17 assert Cartesian_to_Peano_2d((4, 2), 9) == 10
21 """Inverse of docstring example: index 10 with size=9 must map to (4, 2)."""
22 assert Peano_to_Cartesian_2d(10, 9) == (4, 2)
30 assert Cartesian_to_Peano_2d((0, 0), 1) == 0
34 assert Peano_to_Cartesian_2d(0, 1) == (0, 0)
41@pytest.mark.parametrize("size", [3, 9])
43 """Every cell maps to a unique index in [0, size²)."""
47 idx = Cartesian_to_Peano_2d((x, y), size)
48 assert 0 <= idx < size * size, f
"Index {idx} out of range for ({x},{y})"
49 assert idx
not in seen, f
"Duplicate index {idx} for ({x},{y})"
51 assert len(seen) == size * size
54@pytest.mark.parametrize("size", [3, 9])
56 """Forward then inverse returns the original coordinates for all cells."""
59 idx = Cartesian_to_Peano_2d((x, y), size)
60 assert Peano_to_Cartesian_2d(idx, size) == (x, y), (
61 f
"Round-trip failed for ({x},{y}): got {Peano_to_Cartesian_2d(idx, size)}"
70 assert Cartesian_to_Peano_3d((0, 0, 0), 1) == 0
74 assert Peano_to_Cartesian_3d(0, 1) == (0, 0, 0)
81@pytest.mark.parametrize("size", [3])
83 """Every 3-D cell maps to a unique index in [0, size³)."""
88 idx = Cartesian_to_Peano_3d((x, y, z), size)
89 assert 0 <= idx < size ** 3, f
"Index {idx} out of range for ({x},{y},{z})"
90 assert idx
not in seen, f
"Duplicate index {idx} for ({x},{y},{z})"
92 assert len(seen) == size ** 3
95@pytest.mark.parametrize("size", [3])
97 """Forward then inverse returns the original coordinates for all 3-D cells."""
100 for z
in range(size):
101 idx = Cartesian_to_Peano_3d((x, y, z), size)
102 assert Peano_to_Cartesian_3d(idx, size) == (x, y, z), (
103 f
"Round-trip failed for ({x},{y},{z}): "
104 f
"got {Peano_to_Cartesian_3d(idx, size)}"
110 """Full bijection check for size=9 (729 cells); marked slow."""
113 for x
in range(size):
114 for y
in range(size):
115 for z
in range(size):
116 idx = Cartesian_to_Peano_3d((x, y, z), size)
117 assert 0 <= idx < size ** 3
118 assert idx
not in seen, f
"Duplicate index {idx} for ({x},{y},{z})"
120 assert len(seen) == size ** 3
125 """Round-trip check for size=9 (729 cells); marked slow."""
127 for x
in range(size):
128 for y
in range(size):
129 for z
in range(size):
130 idx = Cartesian_to_Peano_3d((x, y, z), size)
131 assert Peano_to_Cartesian_3d(idx, size) == (x, y, z)
141from toolbox.loadbalancing.api.strategies.SFC
import _children_in_traversal_order
145 """Read the lookup tables of zfor3 from src/peano4/utils/Loop.h"""
146 loop_header = os.path.join(
147 os.path.dirname(__file__),
"..",
"..",
"src",
"peano4",
"utils",
"Loop.h"
149 with open(loop_header)
as header:
151 children = 3**dimensions
153 "static const int lookupzfor3[{}][{}][{}]".format(2**dimensions, children, dimensions)
155 block = text[start : text.index(
"};", start)]
157 tuple(int(value)
for value
in entry.split(
","))
158 for entry
in re.findall(
r"\{(\d+(?:,\s*\d+)+)\}", block)
160 return [entries[i * children : (i + 1) * children]
for i
in range(2**dimensions)]
163@pytest.mark.parametrize("dimensions", [2, 3])
165 """The order of the 3^d children replicates peano4::utils::zfor3 for all loop directions."""
167 positive = tuple(bool(direction >> axis & 1)
for axis
in range(dimensions))
168 assert list(_children_in_traversal_order(positive)) == table
171@pytest.mark.parametrize("size", [3, 9, 27])
173 """Consecutive cells along the curve share a face, i.e. the curve has no jumps."""
174 cells = [Peano_to_Cartesian_2d(i, size)
for i
in range(size * size)]
175 for a, b
in zip(cells, cells[1:]):
176 assert abs(a[0] - b[0]) + abs(a[1] - b[1]) == 1, (a, b)
179@pytest.mark.parametrize("size", [3, 9])
181 """Consecutive cells along the curve share a face, i.e. the curve has no jumps."""
182 cells = [Peano_to_Cartesian_3d(i, size)
for i
in range(size**3)]
183 for a, b
in zip(cells, cells[1:]):
184 assert sum(abs(x - y)
for x, y
in zip(a, b)) == 1, (a, b)
test_peano_to_cartesian_2d_size1()
test_peano_to_cartesian_2d_round_trip(size)
Forward then inverse returns the original coordinates for all cells.
test_cartesian_to_peano_3d_bijection_size9()
Full bijection check for size=9 (729 cells); marked slow.
test_peano_to_cartesian_3d_size1()
test_peano_to_cartesian_3d_round_trip_size9()
Round-trip check for size=9 (729 cells); marked slow.
test_cartesian_to_peano_2d_bijection(size)
Every cell maps to a unique index in [0, size²).
test_cartesian_to_peano_3d_size1()
test_curve_2d_is_continuous(size)
Consecutive cells along the curve share a face, i.e.
test_cartesian_to_peano_3d_bijection(size)
Every 3-D cell maps to a unique index in [0, size³).
test_curve_3d_is_continuous(size)
Consecutive cells along the curve share a face, i.e.
_peano_zfor3_tables(dimensions)
Read the lookup tables of zfor3 from src/peano4/utils/Loop.h.
test_children_order_matches_peano_zfor3(dimensions)
The order of the 3^d children replicates peano4::utils::zfor3 for all loop directions.
test_cartesian_to_peano_2d_size1()
test_peano_to_cartesian_2d_docstring_example()
Inverse of docstring example: index 10 with size=9 must map to (4, 2).
test_peano_to_cartesian_3d_round_trip(size)
Forward then inverse returns the original coordinates for all 3-D cells.
test_cartesian_to_peano_2d_docstring_example()
Docstring example: (4, 2) with size=9 must map to 10.