121 parser = argparse.ArgumentParser(
122 description=
"Single Schwarzschild black hole with ExaGRyPE",
123 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
126 scheme = parser.add_argument_group(
"numerical scheme")
129 choices=[
"fv",
"fd4"],
131 help=
"fv: Rusanov Finite Volumes with explicit Euler. fd4: fourth-order Finite Differences with Runge-Kutta.",
136 choices=[1, 2, 3, 4],
138 help=
"Order of the Runge-Kutta time integrator (fd4 only).",
144 help=
"Scaling of the Kreiss-Oliger dissipation (fd4 only). 0 switches the dissipation off.",
152 help=
"Indices of the unknowns which are damped by the Kreiss-Oliger dissipation. Default: all.",
157 help=
"Discretise the advection terms along the shift with lop-sided stencils (fd4 only). "
158 "Without it, the solver adds them with central differences.",
161 "--enforce-constraints",
162 choices=list(EnforceModes),
164 help=
"When to push the solution back onto the algebraic CCZ4 constraints.",
167 mesh = parser.add_argument_group(
"domain and mesh")
172 help=
"Edge length of the domain. Default: depends on --variant.",
178 help=
"Maximum size of a volume or grid cell. The mesh is a regular 3-adic grid, i.e. the actual size is smaller. Default: depends on --variant.",
184 help=
"Number of additional mesh refinement levels (factor 3 each) around the black hole. 0 yields the regular mesh.",
190 help=
"Radius around the puncture within which the mesh is refined to the finest level.",
196 help=
"Volumes/grid cells per axis per mesh cell. Has to be even, so no volume centre hits the puncture.",
198 mesh.add_argument(
"--mass", type=float, default=1.0, help=
"Mass of the black hole.")
200 time = parser.add_argument_group(
"time and checkpoints")
205 help=
"Final time. Default: depends on --variant.",
208 "--checkpoint-interval",
211 help=
"Time between two binary checkpoints. 0 switches checkpointing off.",
217 help=
"Time between two visualisation snapshots. 0 switches the snapshots off.",
220 "--first-checkpoint",
223 help=
"Time stamp of the first checkpoint and of the first snapshot.",
226 "--checkpoint-precision",
229 help=
"Significant digits per value in the visualisation snapshots. Checkpoints are lossless.",
232 balancing = parser.add_argument_group(
"load balancing")
233 balancing.add_argument(
235 choices=[
"hardcoded",
"spread-out"],
237 help=
"hardcoded: decomposition of the regular mesh, computed offline. spread-out: SpreadOutOnceGridStagnates decides at runtime.",
239 balancing.add_argument(
241 choices=[
"equidistant",
"quantised"],
242 default=
"equidistant",
243 help=
"Chunk sizes of the hardcoded load balancing. equidistant: every tree gets the same number of cells. quantised: chunk sizes are multiples of 3^(k*d) cells, i.e. trees hold (almost) complete subtrees and few virtual cells, but they might be imbalanced.",
245 balancing.add_argument(
247 choices=[
"bottom-up",
"top-down",
"inferred"],
249 help=
"How Peano picks the cells of a split (hardcoded load balancing only).",
251 balancing.add_argument(
254 default=os.cpu_count(),
255 help=
"Number of trees (subdomains) of the hardcoded load balancing. They all live on rank 0, i.e. one tree per thread.",
258 build = parser.add_argument_group(
"build")
261 choices=list(Compilers),
262 default=
"producer-consumer-fusion",
263 help=
"Task graph compiler, i.e. how time step tasks are mapped onto mesh traversals.",
267 choices=list(Variants),
268 default=
"production",
269 help=
"Build variant: compile mode and default size of the setup.",
272 "--verbosity", choices=list(Verbosities), default=
"text"
275 "--output-directory",
277 help=
"Directory the code is generated into and the checkpoints are written to.",
282 help=
"Root of the Peano installation.",
287 help=
"Generate the code but do not compile it.",
292 help=
"Do not run make clean before the build.",
295 arguments = parser.parse_args()
297 for key, value
in Variants[arguments.variant].items():
298 if key !=
"mode" and getattr(arguments, key)
is None:
299 setattr(arguments, key, value)
301 if arguments.patch_size % 2 != 0:
302 parser.error(
"--patch-size has to be even")
303 if arguments.scheme ==
"fv" and (arguments.ko_sigma > 0.0
or arguments.lopsided):
304 parser.error(
"--ko-sigma and --lopsided require --scheme fd4")
305 if arguments.ko_quantities
is not None and arguments.ko_sigma <= 0.0:
306 parser.error(
"--ko-quantities requires --ko-sigma > 0")
307 if arguments.amr_levels < 0:
308 parser.error(
"--amr-levels must not be negative")
309 if arguments.amr_levels > 0
and arguments.scheme ==
"fd4" and arguments.ko_sigma > 0.0:
310 parser.error(
"--amr-levels with --scheme fd4 does not support --ko-sigma yet")
311 if arguments.load_balancing ==
"hardcoded" and arguments.trees < 2:
312 parser.error(
"--trees has to be at least 2 for the hardcoded load balancing")
313 if arguments.checkpoint_interval < 0.0
or arguments.plot_interval < 0.0:
314 parser.error(
"--checkpoint-interval and --plot-interval must not be negative")
400def min_volume_size(arguments):
401 """! Volumes of this size or bigger may still be refined.
403 The regular mesh of --volume-size is the coarsest mesh the benchmark
404 allows (README.dox), so the AMR levels sit on top of its actual volume
405 size. Refining a cell yields volumes strictly smaller than the bound, so
406 the bound is the volume size of the second-finest level, slightly
407 reduced to be robust against rounding. Without AMR levels, the bound
408 would exceed the --volume-size. It is capped there, which is still above the
409 volume size of the regular mesh, i.e. the mesh stays regular.
412 actual_volume_size(arguments) / 3.0 ** (arguments.amr_levels - 1) * 0.99,
413 arguments.volume_size,
427def create_load_balancing(arguments):
428 """! Name and constructor arguments of the load balancing strategy
430 The hardcoded strategy splits the regular mesh into arguments.trees trees
431 of the same number of cells, i.e. the outcome SpreadOutOnceGridStagnates
432 aims for. The splits are computed offline on a synthetic regular tree
433 along the space-filling curve, and all trees live on rank 0. AMR levels
434 do not enter, as the splits fire once the mesh has reached the regular
435 mesh and are bottom-up.
437 if arguments.load_balancing == "spread-out":
439 "toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates",
440 "new ::exahype2::LoadBalancingConfiguration()",
443 tree = RegularGridGenerator.RegularGridGenerator(
444 max_level=regular_mesh_levels(arguments), dimensions=3
446 if arguments.decomposition == "quantised":
447 decomposition = Decomposition.quantised_splitting(
448 peano_tree=tree, number_of_subtrees=arguments.trees, dimension=3
451 decomposition = Decomposition.equidistant_splitting(
452 peano_tree=tree, number_of_subtrees=arguments.trees
454 SplitTrees.split_tree(
455 tree, decomposition=decomposition, periodic_BC=[False, False, False]
457 destination_ranks = Hardcoded.assign_trees_to_ranks_round_Robin(
458 number_of_subtrees=tree.number_of_subtrees, max_ranks=1
460 configuration, _ = Hardcoded.create_constructor_initialisation_string(
461 tree, destination_ranks, modes=SplitModes[arguments.split_mode]
463 return "toolbox::loadbalancing::strategies::Hardcoded", configuration
467 arguments = parse_arguments()
469 project = exahype2.api.Project(
470 namespace=["benchmarks", "exagrype", "singleblackhole"],
471 project_name="single-black-hole",
472 directory=arguments.output_directory,
473 executable="single-black-hole",
476 solver = exagrype.api.FOCCZ4Solver(
478 parameters={"CCZ4b": 1, "CCZ4s": 1},
481 exagrype.api.initialvalues.single_black_hole(mass=arguments.mass)
483 solver.enforce_ccz4_constraint(EnforceModes[arguments.enforce_constraints])
485 exahype2.api.SommerfeldBoundaryConditions(
486 implementation="::exagrype::initialvalues::flat(Q, x, 0.0);"
489 # The criterion never asks for an erase. The mesh is a function of the
490 # position only, i.e. it is static, and it never coarsens below the
491 # regular mesh anyway. Without AMR levels, the volume size bound keeps
494 exahype2.api.RefineErasePointwisely(
496 const double r2 = tarch::la::norm2Squared(x);
497 if (r2 < {arguments.amr_radius ** 2}) *refinementCommand = ::exahype2::RefinementCommand::Refine;
501 create_numerical_scheme(solver, arguments)
502 project.add_solver(solver)
504 project.compiler = Compilers[arguments.compiler]
506 half_size = arguments.domain_size / 2.0
507 project.set_global_simulation_parameters(
509 offset=[-half_size] * 3,
510 size=[arguments.domain_size] * 3,
511 min_end_time=arguments.end_time,
512 max_end_time=arguments.end_time,
513 periodic_BC=[False, False, False],
516 project.set_load_balancing(*create_load_balancing(arguments))
518 project.set_Peano4_installation(
519 arguments.peano_directory, Variants[arguments.variant]["mode"]
521 peano4_project = project.generate_Peano4_project(
522 verbosity=Verbosities[arguments.verbosity]
524 peano4_project.generate()
526 h = actual_volume_size(arguments)
528 f"Volume size {h:.6g} ({round(arguments.domain_size / h)} volumes per axis), "
529 f"scheme {arguments.scheme}, {arguments.amr_levels} AMR levels, "
530 f"variant {arguments.variant}, compiler {arguments.compiler}, "
531 f"end time {arguments.end_time}"
534 if not arguments.no_build:
535 peano4_project.build(make_clean_first=not arguments.no_clean)