4from .strategies.SFC
import Peano_to_Cartesian_2d
5from .strategies.SFC
import Peano_to_Cartesian_3d
10 Data structure for adaptive mesh trees in Peano load balancing.
12 This class represents adaptive mesh trees as sequences of grid levels,
13 where each level is stored as a 2D or 3D array. The tree structure is
14 designed to support offline decomposition and load balancing analysis.
16 ## Tree Structure Overview
18 The main content of this class is a series of 2D or 3D arrays with dimension sizes
19 of 3^(level+1), where level ranges from 1 to the maximum depth of the tree. Each entry
20 in the arrays is a tuple of 2 numbers:
22 - **Weight**: 1 if the cell exists, 0 if it doesn't (enables representation of adaptive meshes)
23 - **Subtree ID**: Integer indicating which compute resource/subtree owns the cell
25 ## Data Representation Examples
27 ### 2D Example: Uniform 2-level tree with 4 subtrees
38 {(1,0), (1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,1), (1,1),
39 (1,0), (1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,1), (1,1),
40 (1,0), (1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,1), (1,1),
41 (1,1), (1,1), (1,1), (1,1), (1,1), (1,1), (1,3), (1,3), (1,3),
42 (1,1), (1,1), (1,1), (1,1), (1,1), (1,1), (1,3), (1,3), (1,3),
43 (1,1), (1,1), (1,1), (1,1), (1,1), (1,1), (1,3), (1,3), (1,3),
44 (1,2), (1,2), (1,2), (1,2), (1,2), (1,2), (1,3), (1,3), (1,3),
45 (1,2), (1,2), (1,2), (1,2), (1,2), (1,2), (1,3), (1,3), (1,3),
46 (1,2), (1,2), (1,2), (1,2), (1,2), (1,2), (1,3), (1,3), (1,3)}
49 ### Adaptive Mesh Representation
51 For adaptive meshes where some regions are not refined, entries have weight 0:
53 Level 1: {(1,0), (0,0), (1,0) # Middle cell not refined
57 Level 2: Corresponding 9x9 array with zeros in the middle 3x3 block
62 - **Hierarchical Structure**: Each level refines the previous by factor of 3 in each dimension
63 - **Adaptive Support**: Zero weights represent non-existent cells in adaptive meshes
64 - **Load Balancing Ready**: Subtree IDs enable domain decomposition analysis
66 ## Usage in Load Balancing
68 This data structure supports various load balancing operations:
70 1. **Tree Analysis**: Count leaf nodes, analyze refinement patterns
71 2. **Splitting Strategies**: Redistribute subtree assignments for load balancing
72 3. **Visualization**: Generate spatial representations of tree structure
73 4. **Export**: Create YAML outputs for integration with Peano's hardcoded load balancer
77 - **2D**: Arrays use (a,b) indexing where a,b ∈ [0, 3^(level+1)-1]
78 - **3D**: Arrays use (a,b,c) indexing where a,b,c ∈ [0, 3^(level+1)-1]
79 - **Level Numbering**: Levels start from 0 (coarsest) to max_level-1 (finest)
80 - **Array Sizes**: Level k has size 3^(k+1) in each dimension
84 - The lowest level is 1 with size 3x3 (2D) or 3x3x3 (3D)
85 - All arrays are stored as numpy arrays with dtype=object for tuple storage
86 - Tree metadata (leaf count, split patterns) is automatically updated after modifications
87 - Domain offset and size define the physical coordinate mapping
91 This class works with:
92 - `GridPatchFileReader`: Reads Peano grid files into Tree format
93 - `RegularGridGenerator`: Creates artificial uniform trees for testing
94 - `SplitTrees`: Implements splitting algorithms for load balancing
95 - `TreeVisualizer`: Generates visual representations of tree structures
100 # Create a tree from artificial regular grid
101 tree = RegularGridGenerator("test", max_level=3, dimensions=2)
103 # Apply load balancing splitting
104 split_tree(tree, number_of_subtrees=3)
106 # Generate visualization
107 TreeVisualizer(tree, dimensions=2, filename="balanced_tree")
110 generate_tree_yaml(tree, "output.yaml")
114 def __init__(self, name, dimension, domain_offset, domain_size):
116 Initialize a new Tree object.
119 name (str): Descriptive name for the tree (e.g., "RegularGrid" or filename)
120 dimension (int): Spatial dimension (2 for 2D, 3 for 3D)
121 domain_offset (tuple): Physical coordinates of domain origin
122 domain_size (tuple): Physical size of domain in each dimension
153Peano Tree Structure From """ + self.
_name +
"""
190 new_level_array = np.empty((size, size), dtype=object)
191 for a
in range(size):
192 for b
in range(size):
193 new_level_array[a][b]=(0,0)
195 new_level_array = np.empty((size, size, size), dtype=object)
196 for a
in range(size):
197 for b
in range(size):
198 for c
in range(size):
199 new_level_array[a][b][c]=(0,0)
216 for a
in range(3**(level+1)):
217 for b
in range(3**(level+1)):
218 if input_level_arrays[a][b]==1:
219 self.
_tree_arrays[level][a][b] = (input_level_arrays[a][b], subtree_id)
221 for a
in range(3**(level+1)):
222 for b
in range(3**(level+1)):
223 for c
in range(3**(level+1)):
224 if input_level_arrays[a][b][c]==1:
225 self.
_tree_arrays[level][a][b][c] = (input_level_arrays[a][b][c], subtree_id)
246 for a
in range(3**(level+1)):
247 for b
in range(3**(level+1)):
256 for a
in range(3**(level+1)):
257 for b
in range(3**(level+1)):
258 for c
in range(3**(level+1)):
Data structure for adaptive mesh trees in Peano load balancing.
read_in_tree_from_artificial(self, input_artificial_arrays, max_level, weighted=False)
read_in_level_array(self, input_level_arrays, subtree_id, level)
read_in_tree_from_arrays(self, input_tree_arrays, max_level, weighted=False)
__init__(self, name, dimension, domain_offset, domain_size)
Initialize a new Tree object.
update_split_pattern(self)