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 self._current_time_step.generator.load_store_compute_flag = "::peano4::grid::constructLoadStoreComputeFlag({},{},{})".format(
139# @todo This is to be controlled via alpha marker later on
141 """
142(""" + self._current_time_step.generator.load_persistent_condition + """
143 and
144 (alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AnotB or alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AdeterminesB)
145 )
146 """,
147 """
148(""" + self._current_time_step.generator.store_persistent_condition + """
149 and
150 (alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AnotB or alpha.getMarker()==celldata::AlphaPoissonMarker::Marker::AdeterminesB)
151 )
152""")
153
154
155 # Bei compute bin ich mir echt unsicher
156
157# self._rhs_estimates = peano4.datamodel.Patch( (self.number_of_Runge_Kutta_steps()*(self._basis.dofs_per_axis),
158# self._linear_combination_of_estimates = peano4.datamodel.Patch( (self._basis.dofs_per_axis,
159
160
161
162
163dg_solver = MyDGSolver()
164
165patch_size = 2*space_order+1
166
168 patch_size = patch_size,
169 unknowns = number_of_unknowns,
170 auxiliary_variables = auxiliary_variables,
171 min_volume_h = min_h,
172 max_volume_h = max_h,
173 time_step_relaxation = 0.1,
174 flux = exahype2.solvers.PDETerms.User_Defined_Implementation,
175 eigenvalues = exahype2.solvers.PDETerms.User_Defined_Implementation,
176 source_term = exahype2.solvers.PDETerms.User_Defined_Implementation,
177 refinement_criterion = exahype2.solvers.PDETerms.User_Defined_Implementation,
178 pde_terms_without_state = args.optimise_stateless
179 )
180
181#
182# Get the global data accumulation in place. We do this only for the FV solver,
183# as we assume that the interesting stuff is all covered by the FV
184# discretisation.
185#
186fv_solver._action_set_postprocess_solution = exahype2.solvers.fv.actionsets.VolumeWisePostprocessSolution(fv_solver)
187fv_solver._action_set_postprocess_solution.guard = """
188repositories::{{SOLVER_INSTANCE}}.isLastGridSweepOfTimeStep()
189and
190not repositories::{{SOLVER_INSTANCE}}.patchCanUseStatelessPDETerms(marker.x(), marker.h(), timeStamp, timeStepSize)
191"""
192fv_solver._action_set_postprocess_solution.add_postprocessing_kernel( """
193 repositories::{{SOLVER_INSTANCE}}.addDensity(volumeX,volumeH,value[0]);
194 """ )
195
196#
197# Get the marker in place which switches between the solvers, i.e. lets the
198# FV solver overrule the DG solver.
199#
201 name = "Alpha",
202 plot = True)
203marker_solver.postprocess_updated_cell = """
204if ( not repositories::""" + fv_solver.get_name_of_global_instance() + """.patchCanUseStatelessPDETerms(
205 marker.x(),
206 marker.h(),
207 // it would be nicer to use fineGridCellSelfSimilarInfallFVCellLabel here I guess
208 repositories::""" + fv_solver.get_name_of_global_instance() + """.getMinTimeStamp(),
209 repositories::""" + fv_solver.get_name_of_global_instance() + """.getMinTimeStepSize()
210)) {
211 fineGridCell{{CELL_NAME}}.setValue(1.0);
212 fineGridCell{{CELL_NAME}}.setInvariant(true);
213}
214else {
215 fineGridCell{{CELL_NAME}}.setInvariant(false);
216}
217"""
218
219
220
221#
222# Configure plots and enable or disable dynamic AMR
223#
224fv_solver.plot_description = "rho,j_x,j_y,j_z,E,aux"
225dg_solver.plot_description = "rho,j_x,j_y,j_z,E,aux"
226if "dyn" in args.type:
227 fv_solver.add_solver_constants("static constexpr bool DynamicAMR = true;" )
228 dg_solver.add_solver_constants("static constexpr bool DynamicAMR = true;" )
229else:
230 fv_solver.add_solver_constants("static constexpr bool DynamicAMR = false;" )
231 dg_solver.add_solver_constants("static constexpr bool DynamicAMR = false;" )
232
233
234#
235# Create a project and configure it to end up in a subnamespace (and thus
236# subdirectory).
237#
238project = exahype2.Project( ["benchmarks", "exahype2", "euler", "sphericalaccretionupscaling"], "benchmark", ".", executable=executable_name )
239project.add_solver( marker_solver )
240project.add_solver( dg_solver )
241project.add_solver( fv_solver )
242
243
244
245
246#
247# Configure build
248#
249if args.mode=="release":
250 build_mode = peano4.output.CompileMode.Release
251if args.mode=="stats":
252 build_mode = peano4.output.CompileMode.Stats
253if args.mode=="asserts":
254 build_mode = peano4.output.CompileMode.Asserts
255
256if "plot" in args.type:
257 plot_interval = end_time / 20.0
258else:
259 plot_interval = 0.0
260
261
262cube_size = 1.0
263project.set_global_simulation_parameters(
264 dimensions = dimensions,
265 offset = [-cube_size/2.0, -cube_size/2.0, -cube_size/2.0],
266 size = [ cube_size, cube_size, cube_size],
267 min_end_time = end_time,
268 max_end_time = end_time,
269 first_plot_time_stamp = 0.0,
270 time_in_between_plots = plot_interval,
271 periodic_BC = [False, False, False]
272)
273
274
275project.set_load_balancing( "toolbox::loadbalancing::strategies::RecursiveBipartition", "new ::exahype2::LoadBalancingConfiguration()" )
276project.set_Peano4_installation( args.peanodir, build_mode )
277
278#
279# Generate code and then copy cpp file over main
280#
281peano4_project = project.generate_Peano4_project(args.verbose)
282
283
284peano4_project.output.makefile.add_cpp_file( "../../../../applications/exahype2/euler/spherical-accretion/MassAccumulator.cpp" )
285peano4_project.output.makefile.add_cpp_file( "../../../../applications/exahype2/euler/spherical-accretion/GravityModel.cpp" )
286peano4_project.output.makefile.add_header_search_path( "../../../../applications/exahype2/euler" )
287peano4_project.generate()
288
289os.system( "make clean" )
290if args.j>0:
291 os.system( "make -j{}".format(args.j) )
292else:
293 os.system( "make -j" )
294
295print("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.