Peano
Loading...
Searching...
No Matches
create-benchmark-executable.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.api
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
24
25parser = argparse.ArgumentParser(description='ExaHyPE 2 - Euler benchmarking script')
26parser.add_argument("-j", "--parallel-builds", dest="j", type=int, default=-1, help="Parallel builds" )
27parser.add_argument("-pd", "--peano-dir", dest="peanodir", default="../../../../", help="Peano4 directory" )
28parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose")
29parser.add_argument("-m", "--mode", dest="mode", choices=peano4.api.output.CompileModes, default=peano4.api.output.CompileModes[0], help="|".join(peano4.api.output.CompileModes) )
30parser.add_argument("-t", "--type", dest="type", choices=["plot-0","plot-1","plot-2","plot-3","reg-0"], required=True, help="Pick scenario" )
31parser.add_argument( "--optimise-stateless", dest="optimise_stateless", action="store_true", default=False, help="Optimise stateless/side-effect free cells (required for GPU offloading)")
32parser.add_argument("-s", "--solver", dest="solver", choices=["fv-4", "fv-6", "fv-8", "dg1-rk1", "dg2-rk2", "dg3-rk3", "dg4-rk4", "fd4-rk1", "fd4-rk4"], required=True, help="Pick solver type. For the Finite Volume (fv) solvers, the second index is the patch/block size. For DG, you can pick different Runge-Kutta time integration orders" )
33args = parser.parse_args()
34
35
36
37
38
39#
40# Add the Finite Volumes solver
41#
42solver_name = "SelfSimilarInfall"
43dimensions = 3
44unknowns = {
45 "rho": 1,
46 "j": dimensions,
47 "E": 1,
48}
49number_of_unknowns = sum(unknowns.values())
50
51if args.type=="plot-0":
52 baseline_max_h = 0.05
53 baseline_min_h = 0.05
54 end_time = 4.0
55if args.type=="plot-1":
56 baseline_max_h = 0.005
57 baseline_min_h = 0.005
58 end_time = 4.0
59if args.type=="plot-2":
60 baseline_max_h = 0.5
61 baseline_min_h = 0.1
62 end_time = 64.0
63if args.type=="plot-3":
64 baseline_max_h = 0.5
65 baseline_min_h = 0.008
66 end_time = 4.0
67elif args.type=="reg-0":
68 baseline_max_h = 0.008
69 baseline_min_h = 0.008
70 end_time = 4.0
71
72#
73# For Finite Volumes, we use the same mesh size, as the mesh size
74# corresponds to volume sizes, and the patch size is, in principle,
75# only a way to organise the volumes. For DG, we really have to make
76# the cells coarser with increasing order (to fit into memory and
77# to remain reasonable by means of accuracy).
78#
79if "dg0-" in args.solver:
80 max_h = baseline_max_h
81 min_h = baseline_min_h
82if "dg1-" in args.solver:
83 max_h = baseline_max_h
84 min_h = baseline_min_h
85if "dg2-" in args.solver:
86 max_h = baseline_max_h * 3
87 min_h = baseline_min_h * 3
88elif "dg3-" in args.solver:
89 max_h = baseline_max_h * 4
90 min_h = baseline_min_h * 4
91elif "dg4-" in args.solver:
92 max_h = baseline_max_h * 5
93 min_h = baseline_min_h * 5
94elif "fd4-" in args.solver:
95 max_h = baseline_max_h
96 min_h = baseline_min_h
97elif "fv-" in args.solver:
98 max_h = baseline_max_h
99 min_h = baseline_min_h
100
101
102
103auxiliary_variables = 0
104
105
106executable_name = "benchmark-" + args.type
107if args.optimise_stateless:
108 executable_name = executable_name + "-opt"
109else:
110 executable_name = executable_name + "-no-opt"
111
112
113if args.mode!="release":
114 executable_name = executable_name + "-" + args.mode
115
116
117
118if "fv" in args.solver:
119 patch_size = int(args.solver[-1])
120 thesolver = exahype2.solvers.fv.rusanov.GlobalAdaptiveTimeStepWithEnclaveTasking(name = solver_name + "FV",
121 patch_size = patch_size,
122 unknowns = number_of_unknowns,
123 auxiliary_variables = auxiliary_variables,
124 min_volume_h = min_h,
125 max_volume_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 executable_name = executable_name + "-FV-" + str(patch_size)
134
135 thesolver._action_set_postprocess_solution = exahype2.solvers.fv.actionsets.VolumeWisePostprocessSolution(thesolver)
136 thesolver._action_set_postprocess_solution.guard = """
137repositories::{{SOLVER_INSTANCE}}.isLastGridSweepOfTimeStep()
138and
139not repositories::{{SOLVER_INSTANCE}}.patchCanUseStatelessPDETerms(marker.x(), marker.h(), timeStamp, timeStepSize)
140"""
141 thesolver._action_set_postprocess_solution.add_postprocessing_kernel( """
142 repositories::{{SOLVER_INSTANCE}}.addDensity(volumeX,volumeH,value[0]);
143 """ )
144if "fd4" in args.solver:
145 patch_size = 5
146 time_order = int(args.solver[6])
147 thesolver = exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepWithEnclaveTasking(name = solver_name + "FD4",
148 #thesolver = exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStep(name = solver_name + "FD4",
149 patch_size = patch_size,
150 rk_order = time_order,
151 unknowns = number_of_unknowns,
152 auxiliary_variables = auxiliary_variables,
153 min_meshcell_h = min_h,
154 max_meshcell_h = max_h,
155 time_step_relaxation = 0.1,
156 flux = exahype2.solvers.PDETerms.User_Defined_Implementation,
157 eigenvalues = exahype2.solvers.PDETerms.User_Defined_Implementation,
158 source_term = exahype2.solvers.PDETerms.User_Defined_Implementation,
159 refinement_criterion = exahype2.solvers.PDETerms.User_Defined_Implementation,
160# pde_terms_without_state = args.optimise_stateless
161 )
162 executable_name = executable_name + "-FD4-" + str(patch_size)
163
164 thesolver._action_set_postprocess_solution = exahype2.solvers.rkfd.actionsets.CellWisePostprocessSolution(thesolver)
165 thesolver._action_set_postprocess_solution.guard = """
166repositories::{{SOLVER_INSTANCE}}.isLastGridSweepOfTimeStep()
167//and
168//not repositories::{{SOLVER_INSTANCE}}.patchCanUseStatelessPDETerms(marker.x(), marker.h(), timeStamp, timeStepSize)
169"""
170 thesolver._action_set_postprocess_solution.add_postprocessing_kernel( """
171 repositories::{{SOLVER_INSTANCE}}.addDensity(volumeX,volumeH,value[0]);
172 """ )
173
174 exahype2.solvers.rkfd.fd4.switch_to_FD4_tensor_product_interpolation( thesolver, "TP_constant" )
175 exahype2.solvers.rkfd.fd4.switch_to_FD4_tensor_product_restriction( thesolver, "TP_inject_normal_extrap" )
176if "rk" in args.solver and "dg" in args.solver:
177 space_order = int(args.solver[2])
178 time_order = int(args.solver[6])
179 thesolver = exahype2.solvers.rkdg.rusanov.GlobalAdaptiveTimeStepWithEnclaveTasking(name = solver_name + "DG",
180 rk_order = time_order,
181 polynomials = exahype2.solvers.GaussLegendreBasis(space_order),
182 face_projections = exahype2.solvers.rkdg.FaceProjections.Solution,
183 unknowns = number_of_unknowns,
184 auxiliary_variables = auxiliary_variables,
185 min_cell_h = min_h,
186 max_cell_h = max_h,
187 time_step_relaxation = 0.1,
188 flux = exahype2.solvers.PDETerms.User_Defined_Implementation,
189 eigenvalues = exahype2.solvers.PDETerms.User_Defined_Implementation,
190 source_term = exahype2.solvers.PDETerms.User_Defined_Implementation,
191 refinement_criterion = exahype2.solvers.PDETerms.User_Defined_Implementation,
192 pde_terms_without_state = args.optimise_stateless
193 )
194 executable_name = executable_name + "-RK" + str(time_order) + "DG" + str(space_order)
195
196 thesolver._action_set_postprocess_solution = exahype2.solvers.rkdg.actionsets.DoFWisePostprocessSolution(thesolver)
197 thesolver._action_set_postprocess_solution.guard = """
198repositories::{{SOLVER_INSTANCE}}.isLastGridSweepOfTimeStep()
199and
200not repositories::{{SOLVER_INSTANCE}}.cellCanUseStatelessPDETerms(marker.x(), marker.h(), timeStamp, timeStepSize)
201"""
202 thesolver._action_set_postprocess_solution.add_postprocessing_kernel( """
203 repositories::{{SOLVER_INSTANCE}}.addDensity(x, marker.h(), index, values[0]);
204 """ )
205
206
207#
208# Configure plots and enable or disable dynamic AMR
209#
210thesolver.plot_description = "rho,j_x,j_y,j_z,E,aux"
211if "dyn" in args.type:
212 thesolver.add_solver_constants("static constexpr bool DynamicAMR = true;" )
213else:
214 thesolver.add_solver_constants("static constexpr bool DynamicAMR = false;" )
215
216
217#
218# Create a project and configure it to end up in a subnamespace (and thus
219# subdirectory).
220#
221project = exahype2.Project( ["benchmarks", "exahype2", "euler", "sphericalaccretionupscaling"], "benchmark", ".", executable=executable_name )
222project.add_solver( thesolver )
223
224
225#
226# Configure build
227#
228if "plot" in args.type:
229 plot_interval = end_time / 20.0
230else:
231 plot_interval = 0.0
232
233
234cube_size = 1.0
235project.set_global_simulation_parameters(
236 dimensions = dimensions,
237 offset = [-cube_size/2.0, -cube_size/2.0, -cube_size/2.0],
238 size = [ cube_size, cube_size, cube_size],
239 min_end_time = end_time,
240 max_end_time = end_time,
241 first_plot_time_stamp = 0.0,
242 time_in_between_plots = plot_interval,
243 periodic_BC = [False, False, False]
244)
245
246
247project.set_load_balancing( "toolbox::loadbalancing::strategies::RecursiveBipartition", "new ::exahype2::LoadBalancingConfiguration()" )
248project.set_Peano4_installation( args.peanodir, peano4.api.output.string_to_mode(args.mode) )
249
250#
251# Generate code and then copy cpp file over main
252#
253peano4_project = project.generate_Peano4_project(args.verbose)
254
255
256peano4_project.output.makefile.add_cpp_file( "../../../../applications/exahype2/euler/spherical-accretion/MassAccumulator.cpp" )
257peano4_project.output.makefile.add_cpp_file( "../../../../applications/exahype2/euler/spherical-accretion/GravityModel.cpp" )
258peano4_project.output.makefile.add_header_search_path( "../../../../applications/exahype2/euler" )
259peano4_project.generate()
260
261os.system( "make clean" )
262if args.j>0:
263 os.system( "make -j{}".format(args.j) )
264else:
265 os.system( "make -j" )
266
267print("Done")