Peano
Loading...
Searching...
No Matches
create-dg-benchmark-executable-with-limiter.py
Go to the documentation of this file.
1"""
2
3 Simple, hard-coded version of the self-similarity test of the MNRAS
4 paper. A more elegant implementation of the solver via a proper subclass
5 can be found in the actual application folder.
6
7"""
8
9
10import os, sys
11import argparse
12import peano4
13import exahype2
14
15
16print( """
17
18ExaHyPE 2 Finite Volume version of the self-similarity tests of the MNRAS paper
19
20@author 2022 Han Zhang, Baojiu Li, Tobias Weinzierl
21
22""")
23
24parser = argparse.ArgumentParser(description='ExaHyPE 2 - Euler benchmarking script')
25parser.add_argument("-j", "--parallel-builds", dest="j", type=int, default=-1, help="Parallel builds" )
26parser.add_argument("-pd", "--peano-dir", dest="peanodir", default="../../../../", help="Peano4 directory" )
27parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose")
28parser.add_argument("-m", "--mode", dest="mode", choices=["release","stats","asserts"], required=True, help="Pick build type" )
29parser.add_argument("-t", "--type", dest="type", choices=["plot-0","plot-1","plot-2","plot-3","reg-0"], required=True, help="Pick scenario" )
30parser.add_argument( "--optimise-stateless", dest="optimise_stateless", action="store_true", default=False, help="Optimise stateless/side-effect free cells (required for GPU offloading)")
31parser.add_argument("-s", "--solver", dest="solver", choices=["dg1-rk1", "dg2-rk2", "dg3-rk3", "dg4-rk4"], required=True, help="Pick solver type" )
32args = parser.parse_args()
33
34
35
36
37
38#
39# Add the Finite Volumes solver
40#
41solver_name = "SelfSimilarInfall"
42dimensions = 3
43unknowns = {
44 "rho": 1,
45 "j": dimensions,
46 "E": 1,
47}
48number_of_unknowns = sum(unknowns.values())
49
50if args.type=="plot-0":
51 baseline_max_h = 0.05
52 baseline_min_h = 0.05
53 end_time = 4.0
54if args.type=="plot-1":
55 baseline_max_h = 0.005
56 baseline_min_h = 0.005
57 end_time = 4.0
58if args.type=="plot-2":
59 baseline_max_h = 0.5
60 baseline_min_h = 0.1
61 end_time = 64.0
62if args.type=="plot-3":
63 baseline_max_h = 0.5
64 baseline_min_h = 0.008
65 end_time = 4.0
66elif args.type=="reg-0":
67 baseline_max_h = 0.008
68 baseline_min_h = 0.008
69 end_time = 4.0
70
71#
72# For Finite Volumes, we use the same mesh size, as the mesh size
73# corresponds to volume sizes, and the patch size is, in principle,
74# only a way to organise the volumes. For DG, we really have to make
75# the cells coarser with increasing order (to fit into memory and
76# to remain reasonable by means of accuracy).
77#
78if "dg0-" in args.solver:
79 max_h = baseline_max_h
80 min_h = baseline_min_h
81if "dg1-" in args.solver:
82 max_h = baseline_max_h
83 min_h = baseline_min_h
84if "dg2-" in args.solver:
85 max_h = baseline_max_h * 3
86 min_h = baseline_min_h * 3
87elif "dg3-" in args.solver:
88 max_h = baseline_max_h * 4
89 min_h = baseline_min_h * 4
90elif "dg4-" in args.solver:
91 max_h = baseline_max_h * 5
92 min_h = baseline_min_h * 5
93
94
95
96auxiliary_variables = 0
97
98
99executable_name = "benchmark-" + args.type
100if args.optimise_stateless:
101 executable_name = executable_name + "-opt"
102else:
103 executable_name = executable_name + "-no-opt"
104
105
106if args.mode!="release":
107 executable_name = executable_name + "-" + args.mode
108
109
110
111space_order = int(args.solver[2])
112time_order = int(args.solver[6])
113executable_name = executable_name + "-RK" + str(time_order) + "DG" + str(space_order)
114
115
117 def __init__(self):
118 super(MyDGSolver,self).__init__(name = solver_name + "DG",
119 rk_order = time_order,
120 polynomials = exahype2.solvers.GaussLegendreBasis(space_order),
121 face_projections = exahype2.solvers.rkdg.FaceProjections.Solution,
122 unknowns = number_of_unknowns,
123 auxiliary_variables = auxiliary_variables,
124 min_cell_h = min_h,
125 max_cell_h = max_h,
126 time_step_relaxation = 0.1,
127 flux = exahype2.solvers.PDETerms.User_Defined_Implementation,
128 eigenvalues = exahype2.solvers.PDETerms.User_Defined_Implementation,
129 source_term = exahype2.solvers.PDETerms.User_Defined_Implementation,
130 refinement_criterion = exahype2.solvers.PDETerms.User_Defined_Implementation,
131 pde_terms_without_state = args.optimise_stateless
132 )
133
134 self._current_time_step.additional_load_and_store_arguments = [
135 ("repositories::DataRepository::_CellDataAlphaPoissonMarkerStack.getForPush( repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top()","celldata::AlphaPoissonMarker","alpha")
136 ]
137
138 #@todo I think this is wrong. It should not be in the generator, but directly on the patch data structure
139 self._current_time_step.generator.load_store_compute_flag = "::peano4::grid::constructLoadStoreComputeFlag({},{},{})".format(
140# @todo This is to be controlled via alpha marker later on
142 """
143(""" + self._current_time_step.generator.load_persistent_condition + """
144 and
145 (alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AnotB or alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AdeterminesB)
146 )
147 """,
148 """
149(""" + self._current_time_step.generator.store_persistent_condition + """
150 and
151 (alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AnotB or alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AdeterminesB)
152 )
153""")
154
155
156 # Bei compute bin ich mir echt unsicher
157
158# self._rhs_estimates = peano4.datamodel.Patch( (self.number_of_Runge_Kutta_steps()*(self._basis.dofs_per_axis),
159# self._linear_combination_of_estimates = peano4.datamodel.Patch( (self._basis.dofs_per_axis,
160
161
162
163
164dg_solver = MyDGSolver()
165
166patch_size = 2*space_order+1
167
169 patch_size = patch_size,
170 unknowns = number_of_unknowns,
171 auxiliary_variables = auxiliary_variables,
172 min_volume_h = min_h,
173 max_volume_h = max_h,
174 time_step_relaxation = 0.1,
175 flux = exahype2.solvers.PDETerms.User_Defined_Implementation,
176 eigenvalues = exahype2.solvers.PDETerms.User_Defined_Implementation,
177 source_term = exahype2.solvers.PDETerms.User_Defined_Implementation,
178 refinement_criterion = exahype2.solvers.PDETerms.User_Defined_Implementation,
179 pde_terms_without_state = args.optimise_stateless
180 )
181
182#
183# Get the global data accumulation in place. We do this only for the FV solver,
184# as we assume that the interesting stuff is all covered by the FV
185# discretisation.
186#
187fv_solver._action_set_postprocess_solution = exahype2.solvers.fv.actionsets.VolumeWisePostprocessSolution(fv_solver)
188fv_solver._action_set_postprocess_solution.guard = """
189repositories::{{SOLVER_INSTANCE}}.isLastGridSweepOfTimeStep()
190and
191not repositories::{{SOLVER_INSTANCE}}.patchCanUseStatelessPDETerms(marker.x(), marker.h(), timeStamp, timeStepSize)
192"""
193fv_solver._action_set_postprocess_solution.add_postprocessing_kernel( """
194 repositories::{{SOLVER_INSTANCE}}.addDensity(volumeX,volumeH,value[0]);
195 """ )
196
197#
198# Get the marker in place which switches between the solvers, i.e. lets the
199# FV solver overrule the DG solver.
200#
202 name = "Alpha",
203 plot = True)
204marker_solver.postprocess_updated_cell = """
205if ( not repositories::""" + fv_solver.get_name_of_global_instance() + """.patchCanUseStatelessPDETerms(
206 marker.x(),
207 marker.h(),
208 // it would be nicer to use fineGridCellSelfSimilarInfallFVCellLabel here I guess
209 repositories::""" + fv_solver.get_name_of_global_instance() + """.getMinTimeStamp(),
210 repositories::""" + fv_solver.get_name_of_global_instance() + """.getMinTimeStepSize()
211)) {
212 fineGridCell{{CELL_NAME}}.setValue(1.0);
213 fineGridCell{{CELL_NAME}}.setInvariant(true);
214}
215else {
216 fineGridCell{{CELL_NAME}}.setInvariant(false);
217}
218"""
219
220
221
222#
223# Configure plots and enable or disable dynamic AMR
224#
225fv_solver.plot_description = "rho,j_x,j_y,j_z,E,aux"
226dg_solver.plot_description = "rho,j_x,j_y,j_z,E,aux"
227if "dyn" in args.type:
228 fv_solver.add_solver_constants("static constexpr bool DynamicAMR = true;" )
229 dg_solver.add_solver_constants("static constexpr bool DynamicAMR = true;" )
230else:
231 fv_solver.add_solver_constants("static constexpr bool DynamicAMR = false;" )
232 dg_solver.add_solver_constants("static constexpr bool DynamicAMR = false;" )
233
234
235#
236# Create a project and configure it to end up in a subnamespace (and thus
237# subdirectory).
238#
239project = exahype2.Project( ["benchmarks", "exahype2", "euler", "sphericalaccretionupscaling"], "benchmark", ".", executable=executable_name )
240project.add_solver( marker_solver )
241project.add_solver( dg_solver )
242project.add_solver( fv_solver )
243
244
245
246
247#
248# Configure build
249#
250if args.mode=="release":
251 build_mode = peano4.output.CompileMode.Release
252if args.mode=="stats":
253 build_mode = peano4.output.CompileMode.Stats
254if args.mode=="asserts":
255 build_mode = peano4.output.CompileMode.Asserts
256
257if "plot" in args.type:
258 plot_interval = end_time / 20.0
259else:
260 plot_interval = 0.0
261
262
263cube_size = 1.0
264project.set_global_simulation_parameters(
265 dimensions = dimensions,
266 offset = [-cube_size/2.0, -cube_size/2.0, -cube_size/2.0],
267 size = [ cube_size, cube_size, cube_size],
268 min_end_time = end_time,
269 max_end_time = end_time,
270 first_plot_time_stamp = 0.0,
271 time_in_between_plots = plot_interval,
272 periodic_BC = [False, False, False]
273)
274
275
276project.set_load_balancing( "toolbox::loadbalancing::strategies::RecursiveBipartition", "new ::exahype2::LoadBalancingConfiguration()" )
277project.set_Peano4_installation( args.peanodir, build_mode )
278
279#
280# Generate code and then copy cpp file over main
281#
282peano4_project = project.generate_Peano4_project(args.verbose)
283
284
285peano4_project.output.makefile.add_cpp_file( "../../../../applications/exahype2/euler/spherical-accretion/MassAccumulator.cpp" )
286peano4_project.output.makefile.add_cpp_file( "../../../../applications/exahype2/euler/spherical-accretion/GravityModel.cpp" )
287peano4_project.output.makefile.add_header_search_path( "../../../../applications/exahype2/euler" )
288peano4_project.generate()
289
290os.system( "make clean" )
291if args.j>0:
292 os.system( "make -j{}".format(args.j) )
293else:
294 os.system( "make -j" )
295
296print("Done")
__init__(self)
Construct RKDG solver with adaptive global time step and enclave tasking.
ExaHyPE 2 project.
Definition Project.py:14
The Gauss-Legendre Basis is by construction the only basis which yields diagonal mass matrices.