Peano
Loading...
Searching...
No Matches
api.Tree.Tree Class Reference

Data structure for adaptive mesh trees in Peano load balancing. More...

Inheritance diagram for api.Tree.Tree:
Collaboration diagram for api.Tree.Tree:

Public Member Functions

 __init__ (self, name, dimension, domain_offset, domain_size)
 Initialize a new Tree object.
 
 number_of_subtrees (self)
 
 number_of_leaves (self)
 
 __str__ (self)
 
 read_in_tree_from_arrays (self, input_tree_arrays, max_level, weighted=False)
 
 read_in_level_array (self, input_level_arrays, subtree_id, level)
 
 read_in_tree_from_artificial (self, input_artificial_arrays, max_level, weighted=False)
 
 update_split_pattern (self)
 
 update_weight (self)
 

Protected Attributes

 _name
 
 _dimension
 
 _domain_offset
 
 _domain_size
 
 _tree_arrays
 
 _leaf_count
 
 _subtree_count
 
 _split_pattern
 
 _max_level
 
 _weighted
 

Detailed Description

Data structure for adaptive mesh trees in Peano load balancing.

This class represents adaptive mesh trees as sequences of grid levels, where each level is stored as a 2D or 3D array. The tree structure is designed to support offline decomposition and load balancing analysis.

Tree Structure Overview

The main content of this class is a series of 2D or 3D arrays with dimension sizes of 3^(level+1), where level ranges from 1 to the maximum depth of the tree. Each entry in the arrays is a tuple of 2 numbers:

  • Weight: 1 if the cell exists, 0 if it doesn't (enables representation of adaptive meshes)
  • Subtree ID: Integer indicating which compute resource/subtree owns the cell

Data Representation Examples

2D Example: Uniform 2-level tree with 4 subtrees

Level 1 (3x3 array):

{(1,0), (1,0), (1,1)
(1,1), (1,1), (1,3)
(1,2), (1,2), (1,3)}

Level 2 (9x9 array):

{(1,0), (1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,1), (1,1),
(1,0), (1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,1), (1,1),
(1,0), (1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,1), (1,1),
(1,1), (1,1), (1,1), (1,1), (1,1), (1,1), (1,3), (1,3), (1,3),
(1,1), (1,1), (1,1), (1,1), (1,1), (1,1), (1,3), (1,3), (1,3),
(1,1), (1,1), (1,1), (1,1), (1,1), (1,1), (1,3), (1,3), (1,3),
(1,2), (1,2), (1,2), (1,2), (1,2), (1,2), (1,3), (1,3), (1,3),
(1,2), (1,2), (1,2), (1,2), (1,2), (1,2), (1,3), (1,3), (1,3),
(1,2), (1,2), (1,2), (1,2), (1,2), (1,2), (1,3), (1,3), (1,3)}

Adaptive Mesh Representation

For adaptive meshes where some regions are not refined, entries have weight 0:

Level 1: {(1,0), (0,0), (1,0) # Middle cell not refined
(1,0), (1,0), (1,0)
(1,0), (1,0), (1,0)}
Level 2: Corresponding 9x9 array with zeros in the middle 3x3 block

Key Properties

  • Hierarchical Structure: Each level refines the previous by factor of 3 in each dimension
  • Adaptive Support: Zero weights represent non-existent cells in adaptive meshes
  • Load Balancing Ready: Subtree IDs enable domain decomposition analysis

Usage in Load Balancing

This data structure supports various load balancing operations:

  1. Tree Analysis: Count leaf nodes, analyze refinement patterns
  2. Splitting Strategies: Redistribute subtree assignments for load balancing
  3. Visualization: Generate spatial representations of tree structure
  4. Export: Create YAML outputs for integration with Peano's hardcoded load balancer

Coordinate System

  • 2D: Arrays use (a,b) indexing where a,b ∈ [0, 3^(level+1)-1]
  • 3D: Arrays use (a,b,c) indexing where a,b,c ∈ [0, 3^(level+1)-1]
  • Level Numbering: Levels start from 0 (coarsest) to max_level-1 (finest)
  • Array Sizes: Level k has size 3^(k+1) in each dimension

Important Notes

  • The lowest level is 1 with size 3x3 (2D) or 3x3x3 (3D)
  • All arrays are stored as numpy arrays with dtype=object for tuple storage
  • Tree metadata (leaf count, split patterns) is automatically updated after modifications
  • Domain offset and size define the physical coordinate mapping

Related Components

This class works with:

  • GridPatchFileReader: Reads Peano grid files into Tree format
  • RegularGridGenerator: Creates artificial uniform trees for testing
  • SplitTrees: Implements splitting algorithms for load balancing
  • TreeVisualizer: Generates visual representations of tree structures

Example Usage

# Create a tree from artificial regular grid
tree = RegularGridGenerator("test", max_level=3, dimensions=2)
# Apply load balancing splitting
split_tree(tree, number_of_subtrees=3)
# Generate visualization
TreeVisualizer(tree, dimensions=2, filename="balanced_tree")
# Export to YAML
generate_tree_yaml(tree, "output.yaml")

Definition at line 8 of file Tree.py.

Constructor & Destructor Documentation

◆ __init__()

api.Tree.Tree.__init__ (   self,
  name,
  dimension,
  domain_offset,
  domain_size 
)

Initialize a new Tree object.

Args: name (str): Descriptive name for the tree (e.g., "RegularGrid" or filename) dimension (int): Spatial dimension (2 for 2D, 3 for 3D) domain_offset (tuple): Physical coordinates of domain origin domain_size (tuple): Physical size of domain in each dimension

Definition at line 114 of file Tree.py.

Member Function Documentation

◆ __str__()

api.Tree.Tree.__str__ (   self)

Definition at line 150 of file Tree.py.

References api.Tree.Tree._dimension, exahype2.api.Project.Project._domain_offset, exaparty.api.Project.Project._domain_offset, api.Project.Project._domain_offset, api.Tree.Tree._domain_offset, exahype2.api.Project.Project._domain_size, exaparty.api.Project.Project._domain_size, api.Project.Project._domain_size, api.Tree.Tree._domain_size, scenarios.acoustic_planar_waves.AcousticPlanarWaves._domain_size, scenarios.elastic_planar_waves.ElasticPlanarWaves._domain_size, scenarios.euler_gaussian_bell.EulerGaussianBell._domain_size, scenarios.euler_isotropic_vortex.EulerIsotropicVortex._domain_size, scenarios.scenario.Scenario._domain_size, scenarios.swe_radial_dam_break.SWERadialDamBreak._domain_size, scenarios.swe_resting_lake.SWERestingLake._domain_size, api.Tree.Tree._leaf_count, api.Tree.Tree._max_level, solvers.aderdg.ADERDG.ADERDG._name, solvers.elliptic.AMRMarker.AMRMarker._name, solvers.elliptic.ConstrainedPoissonEquationForMarkerOnCells.ConstrainedPoissonEquationForMarkerOnCells._name, solvers.fv.EnclaveTasking.EnclaveTasking._name, solvers.fv.FV.FV._name, solvers.limiting.PosterioriLimiting.PosterioriLimiting._name, solvers.limiting.StaticLimiting.StaticLimiting._name, solvers.rkdg.RungeKuttaDG.RungeKuttaDG._name, solvers.rkdg.SeparateSweeps.SeparateSweeps._name, solvers.rkdg.SeparateSweepsWithEnclaveTasking.SeparateSweepsWithEnclaveTasking._name, dastgen2.attributes.Attribute.Attribute._name, dastgen2.attributes.BooleanArray.BooleanArray._name, dastgen2.attributes.Enumeration.Enumeration._name, exahype2.api.dslhype.SyntaxTree.MemoryAllocation._name, exahype2.api.dslhype.SyntaxTree.MemoryDeallocation._name, exahype2.api.dslhype.SyntaxTree.Construction._name, exahype2.api.dslhype.SyntaxTree.DataBlockConstructionFromExisting._name, exahype2.api.dslhype.SyntaxTree.DataBlockConstructionFromOperation._name, exahype2.api.dslhype.SyntaxTree.DataBlockConstructionFromMatrixVectorProduct._name, exahype2.api.dslhype.SyntaxTree.DataBlockConstructionFromDotProduct._name, exahype2.api.dslhype.SyntaxTree.DataBlockConstructionFromFunction._name, exahype2.api.Solver.Solver._name, solvers.api.Solver.Solver._name, mghype::matrixfree::solvers::Solver._name, api.solvers.Solver.Solver._name, peano4.api.dastgen2.Peano4DoubleArray.Peano4DoubleArray._name, peano4.api.dastgen2.Peano4IntegerArray.Peano4IntegerArray._name, peano4.api.dastgen2.Peano4SmartPointerDoubleArray.Peano4SmartPointerDoubleArray._name, peano4::RunMultipleSteps._name, tarch::services::ServiceRepository::ServiceEntry._name, api.Tree.Tree._name, api.Tree.Tree._split_pattern, and api.Tree.Tree._subtree_count.

Referenced by peano4.api.toolbox.particles.postprocessing.ParticleVTUReader.VTUParticleSet.__repr__().

Here is the caller graph for this function:

◆ number_of_leaves()

api.Tree.Tree.number_of_leaves (   self)

Definition at line 147 of file Tree.py.

References api.Tree.Tree._leaf_count.

◆ number_of_subtrees()

api.Tree.Tree.number_of_subtrees (   self)

Definition at line 143 of file Tree.py.

References api.Tree.Tree._subtree_count.

◆ read_in_level_array()

api.Tree.Tree.read_in_level_array (   self,
  input_level_arrays,
  subtree_id,
  level 
)

Definition at line 214 of file Tree.py.

References api.Tree.Tree._dimension, and api.Tree.Tree._tree_arrays.

Referenced by api.Tree.Tree.read_in_tree_from_arrays().

Here is the caller graph for this function:

◆ read_in_tree_from_arrays()

api.Tree.Tree.read_in_tree_from_arrays (   self,
  input_tree_arrays,
  max_level,
  weighted = False 
)

◆ read_in_tree_from_artificial()

api.Tree.Tree.read_in_tree_from_artificial (   self,
  input_artificial_arrays,
  max_level,
  weighted = False 
)

◆ update_split_pattern()

api.Tree.Tree.update_split_pattern (   self)

◆ update_weight()

api.Tree.Tree.update_weight (   self)

Definition at line 268 of file Tree.py.

Referenced by api.Tree.Tree.read_in_tree_from_arrays(), and api.Tree.Tree.read_in_tree_from_artificial().

Here is the caller graph for this function:

Field Documentation

◆ _dimension

◆ _domain_offset

◆ _domain_size

◆ _leaf_count

api.Tree.Tree._leaf_count
protected

◆ _max_level

◆ _name

api.Tree.Tree._name
protected

Definition at line 124 of file Tree.py.

Referenced by solvers.aderdg.ADERDG.ADERDG.__str__(), solvers.elliptic.AMRMarker.AMRMarker.__str__(), solvers.elliptic.ConstrainedPoissonEquationForMarkerOnCells.ConstrainedPoissonEquationForMarkerOnCells.__str__(), solvers.fv.FV.FV.__str__(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG.__str__(), exahype2.api.Solver.Solver.__str__(), solvers.api.Solver.Solver.__str__(), api.Tree.Tree.__str__(), solvers.fv.EnclaveTasking.EnclaveTasking._enclave_task_name(), dastgen2.attributes.Enumeration.Enumeration._enum_name(), solvers.aderdg.ADERDG.ADERDG._generate_kernels(), solvers.aderdg.ADERDG.ADERDG._init_dictionary_with_default_parameters(), solvers.fv.FV.FV._init_dictionary_with_default_parameters(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._init_dictionary_with_default_parameters(), solvers.aderdg.ADERDG.ADERDG._interpolate_face_data_default_guard(), solvers.aderdg.SingleSweep.SingleSweep._interpolate_face_data_default_guard(), solvers.aderdg.ADERDG.ADERDG._load_cell_data_default_guard(), solvers.fv.FV.FV._load_cell_data_default_guard(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._load_cell_data_default_guard(), solvers.aderdg.ADERDG.ADERDG._load_face_data_default_guard(), solvers.fv.FV.FV._load_face_data_default_guard(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._load_face_data_default_guard(), solvers.aderdg.ADERDG.ADERDG._provide_cell_data_to_compute_kernels_default_guard(), solvers.fv.FV.FV._provide_cell_data_to_compute_kernels_default_guard(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._provide_cell_data_to_compute_kernels_default_guard(), solvers.aderdg.ADERDG.ADERDG._provide_face_data_to_compute_kernels_default_guard(), solvers.fv.FV.FV._provide_face_data_to_compute_kernels_default_guard(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._provide_face_data_to_compute_kernels_default_guard(), solvers.aderdg.SingleSweep.SingleSweep._restrict_face_data_default_guard(), solvers.aderdg.ADERDG.ADERDG._store_boundary_data_default_guard(), solvers.aderdg.ADERDG.ADERDG._store_cell_data_default_guard(), solvers.fv.FV.FV._store_cell_data_default_guard(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._store_cell_data_default_guard(), solvers.aderdg.ADERDG.ADERDG._store_face_data_default_guard(), solvers.fv.FV.FV._store_face_data_default_guard(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._store_face_data_default_guard(), solvers.aderdg.ADERDG.ADERDG._unknown_identifier(), solvers.elliptic.AMRMarker.AMRMarker._unknown_identifier(), solvers.elliptic.ConstrainedPoissonEquationForMarkerOnCells.ConstrainedPoissonEquationForMarkerOnCells._unknown_identifier(), solvers.fv.FV.FV._unknown_identifier(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG._unknown_identifier(), exahype2.api.Solver.Solver._unknown_identifier(), solvers.fv.FV.FV.add_actions_to_checkpoint_solution(), solvers.fv.EnclaveTasking.EnclaveTasking.add_actions_to_create_grid(), solvers.fv.EnclaveTasking.EnclaveTasking.add_actions_to_init_grid(), solvers.aderdg.ADERDG.ADERDG.add_actions_to_plot_solution(), solvers.elliptic.ConstrainedPoissonEquationForMarkerOnCells.ConstrainedPoissonEquationForMarkerOnCells.add_actions_to_plot_solution(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG.add_actions_to_plot_solution(), solvers.fv.FV.FV.add_actions_to_plot_solution(), solvers.fv.EnclaveTasking.EnclaveTasking.add_entries_to_text_replacement_dictionary(), solvers.rkdg.SeparateSweepsWithEnclaveTasking.SeparateSweepsWithEnclaveTasking.add_entries_to_text_replacement_dictionary(), solvers.aderdg.ADERDG.ADERDG.add_implementation_files_to_project(), solvers.elliptic.AMRMarker.AMRMarker.add_to_Peano4_datamodel(), solvers.elliptic.ConstrainedPoissonEquationForMarkerOnCells.ConstrainedPoissonEquationForMarkerOnCells.add_to_Peano4_datamodel(), api.solvers.CollocatedLowOrderDiscretisation.CollocatedLowOrderDiscretisation.add_to_plot(), solvers.aderdg.SingleSweep.SingleSweep.create_action_sets(), solvers.fv.rusanov.LocalTimeStepWithEnclaveTasking.LocalTimeStepWithEnclaveTasking.create_action_sets(), solvers.fv.rusanov.SubcyclingAdaptiveTimeStepWithEnclaveTasking.SubcyclingAdaptiveTimeStepWithEnclaveTasking.create_action_sets(), solvers.fv.rusanov.SubcyclingFixedTimeStep.SubcyclingFixedTimeStep.create_action_sets(), solvers.fv.rusanov.SubcyclingFixedTimeStepWithEnclaveTasking.SubcyclingFixedTimeStepWithEnclaveTasking.create_action_sets(), solvers.rkdg.SeparateSweeps.SeparateSweeps.create_action_sets(), solvers.fv.SingleSweep.SingleSweep.create_data_structures(), dastgen2.attributes.Attribute.Attribute.get_accessor_name(), dastgen2.attributes.BooleanArray.BooleanArray.get_constructor_arguments(), peano4.api.dastgen2.Peano4DoubleArray.Peano4DoubleArray.get_constructor_arguments(), peano4.api.dastgen2.Peano4IntegerArray.Peano4IntegerArray.get_constructor_arguments(), peano4.api.dastgen2.Peano4SmartPointerDoubleArray.Peano4SmartPointerDoubleArray.get_constructor_arguments(), dastgen2.attributes.BooleanArray.BooleanArray.get_first_plain_C_attribute(), dastgen2.attributes.DoubleArray.DoubleArray.get_first_plain_C_attribute(), dastgen2.attributes.IntegerArray.IntegerArray.get_first_plain_C_attribute(), peano4.api.dastgen2.Peano4DoubleArray.Peano4DoubleArray.get_first_plain_C_attribute(), peano4.api.dastgen2.Peano4IntegerArray.Peano4IntegerArray.get_first_plain_C_attribute(), peano4.api.dastgen2.Peano4SmartPointerDoubleArray.Peano4SmartPointerDoubleArray.get_first_plain_C_attribute(), dastgen2.attributes.Boolean.Boolean.get_method_body(), dastgen2.attributes.BooleanArray.BooleanArray.get_method_body(), dastgen2.attributes.Double.Double.get_method_body(), dastgen2.attributes.DoubleArray.DoubleArray.get_method_body(), dastgen2.attributes.DoublePointer.DoublePointer.get_method_body(), dastgen2.attributes.Enumeration.Enumeration.get_method_body(), dastgen2.attributes.Integer.Integer.get_method_body(), dastgen2.attributes.IntegerArray.IntegerArray.get_method_body(), dastgen2.attributes.String.String.get_method_body(), dastgen2.attributes.UserDefinedType.UserDefinedType.get_method_body(), peano4.api.dastgen2.Peano4DoubleArray.Peano4DoubleArray.get_method_body(), peano4.api.dastgen2.Peano4IntegerArray.Peano4IntegerArray.get_method_body(), peano4.api.dastgen2.Peano4SmartPointerDoubleArray.Peano4SmartPointerDoubleArray.get_method_body(), dastgen2.attributes.BooleanArray.BooleanArray.get_methods(), dastgen2.attributes.DoubleArray.DoubleArray.get_methods(), dastgen2.attributes.IntegerArray.IntegerArray.get_methods(), peano4.api.dastgen2.Peano4DoubleArray.Peano4DoubleArray.get_methods(), peano4.api.dastgen2.Peano4IntegerArray.Peano4IntegerArray.get_methods(), peano4.api.dastgen2.Peano4SmartPointerDoubleArray.Peano4SmartPointerDoubleArray.get_methods(), solvers.aderdg.ADERDG.ADERDG.get_name_of_global_instance(), solvers.elliptic.AMRMarker.AMRMarker.get_name_of_global_instance(), solvers.elliptic.ConstrainedPoissonEquationForMarkerOnCells.ConstrainedPoissonEquationForMarkerOnCells.get_name_of_global_instance(), solvers.fv.FV.FV.get_name_of_global_instance(), solvers.rkdg.RungeKuttaDG.RungeKuttaDG.get_name_of_global_instance(), exahype2.api.Solver.Solver.get_name_of_global_instance(), exahype2.api.Solver.Solver.get_name_of_solver_class(), dastgen2.attributes.Boolean.Boolean.get_plain_C_attributes(), dastgen2.attributes.BooleanArray.BooleanArray.get_plain_C_attributes(), dastgen2.attributes.Double.Double.get_plain_C_attributes(), dastgen2.attributes.DoubleArray.DoubleArray.get_plain_C_attributes(), dastgen2.attributes.DoublePointer.DoublePointer.get_plain_C_attributes(), dastgen2.attributes.Integer.Integer.get_plain_C_attributes(), dastgen2.attributes.IntegerArray.IntegerArray.get_plain_C_attributes(), dastgen2.attributes.String.String.get_plain_C_attributes(), dastgen2.attributes.UserDefinedType.UserDefinedType.get_plain_C_attributes(), peano4.api.dastgen2.Peano4DoubleArray.Peano4DoubleArray.get_plain_C_attributes(), peano4.api.dastgen2.Peano4IntegerArray.Peano4IntegerArray.get_plain_C_attributes(), dastgen2.attributes.String.String.get_setter_getter_name(), dastgen2.attributes.Boolean.Boolean.get_to_string(), dastgen2.attributes.BooleanArray.BooleanArray.get_to_string(), dastgen2.attributes.Double.Double.get_to_string(), dastgen2.attributes.DoubleArray.DoubleArray.get_to_string(), dastgen2.attributes.DoublePointer.DoublePointer.get_to_string(), dastgen2.attributes.Enumeration.Enumeration.get_to_string(), dastgen2.attributes.Integer.Integer.get_to_string(), dastgen2.attributes.IntegerArray.IntegerArray.get_to_string(), dastgen2.attributes.UserDefinedType.UserDefinedType.get_to_string(), peano4.api.dastgen2.Peano4DoubleArray.Peano4DoubleArray.get_to_string(), peano4.api.dastgen2.Peano4IntegerArray.Peano4IntegerArray.get_to_string(), peano4.api.dastgen2.Peano4SmartPointerDoubleArray.Peano4SmartPointerDoubleArray.get_to_string(), solvers.elliptic.ConstrainedPoissonEquationForMarkerOnCells.ConstrainedPoissonEquationForMarkerOnCells.name(), solvers.fv.FV.FV.name(), dastgen2.attributes.Attribute.Attribute.name(), exahype2.api.Solver.Solver.name(), solvers.api.Solver.Solver.name(), api.solvers.Solver.Solver.name(), solvers.api.Solver.Solver.typename(), and api.solvers.Solver.Solver.typename().

◆ _split_pattern

api.Tree.Tree._split_pattern
protected

Definition at line 136 of file Tree.py.

Referenced by api.Tree.Tree.__str__(), and api.Tree.Tree.update_split_pattern().

◆ _subtree_count

◆ _tree_arrays

◆ _weighted

api.Tree.Tree._weighted
protected

The documentation for this class was generated from the following file: