Peano
Loading...
Searching...
No Matches
FineGridCellLoadBalancingCostMetric.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.api.solversteps.ActionSet import ActionSet
4
5import dastgen2
7import jinja2
8
9
10
12 """!
13
14 Load balancing metric which assigns each cell a value
15
16 To use this metric, you have to do a couple of steps:
17
18 1. Create a new label via create_cell_label(). Capture the result object.
19 2. Create a new instance of this class.
20 3. Add the metric to the algorithmic step of your choice. A typical set is
21 ~~~~~~~~~~~~~~~~~~~~~
22 project.add_action_set_to_create_grid( load_balancing_action_set )
23 ~~~~~~~~~~~~~~~~~~~~~
24
25
26 So overall, a typical use looks similar to:
27
28
29 ~~~~~~~~~~~~~~~~~~~~~
30 load_balancing_cell_label = exahype2.grid.FineGridCellLoadBalancingCostMetric.create_cell_label(project)
31 load_balancing_action_set = exahype2.grid.FineGridCellLoadBalancingCostMetric(load_balancing_cell_label)
32 project.add_action_set_to_create_grid( load_balancing_action_set )
33 project.set_load_balancing(
34 "toolbox::loadbalancing::strategies::cascade::SpreadOut_SplitOversizedTree",
35 "new ::exahype2::LoadBalancingConfiguration(0.98, 1, " + str(args.trees) + "), new toolbox::loadbalancing::metrics::CustomCellWeight()",
36 )
37 ~~~~~~~~~~~~~~~~~~~~~
38
39 """
40 def __init__(self,
41 load_balancing_cell_label,
42 initialisation_weight = "1.0",
43 ):
44 super( FineGridCellLoadBalancingCostMetric, self ).__init__()
45 self.load_balancing_cell_label = load_balancing_cell_label
46 self.initialisation_weight = initialisation_weight
47
48
50 return __name__.replace(".py", "").replace(".", "_")
51
52
54 return False
55
56
57 def get_body_of_operation(self,operation_name):
58 result = "\n"
59 if operation_name==ActionSet.OPERATION_CREATE_CELL:
60 result += """
61 fineGridCell""" + self.load_balancing_cell_label.name + """.setWeight(
62 """ + self.initialisation_weight + """
63 );
64"""
65 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
66 result += """
67 if (not marker.willBeRefined()) {
68 toolbox::loadbalancing::metrics::CustomCellWeight::logCellWeight(
69 _treeNumber,
70 fineGridCell""" + self.load_balancing_cell_label.name + """.getWeight()
71 );
72 }
73"""
74 return result
75
76
77 def get_attributes(self):
78 return """
79 int _treeNumber;
80"""
81
82
84 return """
85 _treeNumber = treeNumber;
86"""
87
88
89 def get_includes(self):
90 return """
91#include "repositories/SolverRepository.h"
92#include "toolbox/loadbalancing/metrics/CustomCellWeight.h"
93"""
94
95
96 def create_cell_label(exahype2_project,
97 name="LoadBalancingCostMetric"):
98 """!
99
100 Create a cell label that's then used for the load balancing
101
102 """
103 result = peano4.api.datamodel.DaStGen2( name )
104
105 result.data.add_attribute( dastgen2.attributes.Double("Weight") )
106
107 result.peano4_mpi_and_storage_aspect.merge_implementation = """
108 switch (context) {
109 case ::peano4::grid::TraversalObserver::SendReceiveContext::BoundaryExchange:
110 assertionMsg( false, "cells should never be subject of a boundary exchange" );
111 break;
112 case ::peano4::grid::TraversalObserver::SendReceiveContext::ForkDomain:
113 *this = neighbour;
114 break;
115 default:
116 assertionMsg( false, "not implemented yet" );
117 }
118 """
119
120
121 exahype2_project._project.datamodel.add_cell(result)
122
123 exahype2_project.plot_solution.use_cell(result)
124 exahype2_project.init_grid.use_cell(result)
125 exahype2_project.perform_time_step.use_cell(result)
126 exahype2_project.create_grid.use_cell(result)
127 exahype2_project.create_grid_but_postpone_refinement.use_cell(result)
128 exahype2_project.create_grid_and_converge_lb.use_cell(result)
129
130 return result
cardinality is a string (you can thus use symbols as well as long as they will be defined at compile ...
Definition Double.py:6
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
Default superclass for any data model in Peano which is stored within the grid.
Definition DaStGen2.py:188
Action set (reactions to events)
Definition ActionSet.py:6