Peano
Loading...
Searching...
No Matches
performance_testbed.py
Go to the documentation of this file.
1import os
2import sys
3import argparse
4
5import peano4
6import exahype2
7import peano4.toolbox.particles
8
9sys.path.insert(0, os.path.abspath("../../../applications/ccz4"))
10
11from Probe_file_gene import tracer_seeds_generate
12from ComputeFirstDerivatives import ComputeFirstDerivativesFD4RK
13
14modes = {
15 "release": peano4.output.CompileMode.Release,
16 "trace": peano4.output.CompileMode.Trace,
17 "assert": peano4.output.CompileMode.Asserts,
18 "debug": peano4.output.CompileMode.Debug,
19}
20
21floatparams = {
22 "GLMc0": 1.5,
23 "GLMc": 1.2,
24 "GLMd": 2.0,
25 "GLMepsA": 1.0,
26 "GLMepsP": 1.0,
27 "GLMepsD": 1.0,
28 "itau": 1.0,
29 "k1": 0.1,
30 "k2": 0.0,
31 "k3": 0.5,
32 "eta": 1.0,
33 "f": 0.75,
34 "g": 0.0,
35 "xi": 1.0,
36 "e": 1.0,
37 "c": 1.0,
38 "mu": 0.2,
39 "ds": 1.0,
40 "sk": 1.0,
41 "bs": 1.0,
42 "domain_r": 1.5,
43 "smoothing": 0.0,
44 "KOSigma": 8.0 # , \
45}
46
47intparams = {
48 "BBHType": 2,
49 "LapseType": 1,
50 "tp_grid_setup": 0,
51 "swi": 99,
52 "ReSwi": 1,
53 "SO": 0,
54}
55# sss
56if __name__ == "__main__":
57 parser = argparse.ArgumentParser(description="ExaHyPE 2 - CCZ4 script")
58 parser.add_argument(
59 "-maxh",
60 "--max-h",
61 dest="max_h",
62 type=float,
63 default=0.05,
64 help="upper limit for refinement. Refers to volume size, i.e. not to patch size",
65 )
66 parser.add_argument(
67 "-minh",
68 "--min-h",
69 dest="min_h",
70 type=float,
71 default=0.02,
72 help="lower limit for refinement (set to 0 to make it equal to max_h - default). Refers to volume size, i.e. not to patch size",
73 )
74 parser.add_argument(
75 "-ps",
76 "--patch-size",
77 dest="patch_size",
78 type=int,
79 default=9,
80 help="Patch size, i.e. number of volumes per patch per direction",
81 )
82 parser.add_argument(
83 "-plt",
84 "--plot-step-size",
85 dest="plot_step_size",
86 type=float,
87 default=0,
88 help="Plot step size (0 to switch it off)",
89 )
90 parser.add_argument(
91 "-m", "--mode", dest="mode", default="release", help="|".join(modes.keys())
92 )
93 parser.add_argument(
94 "-impl",
95 "--implementation",
96 dest="implementation",
97 default="fd4-rk1-adaptive",
98 choices=["fd4-rk1-adaptive", "fd4-rk1-adaptive-enclave"],
99 help="Pick solver type",
100 )
101 parser.add_argument(
102 "-no-pbc",
103 "--no-periodic-boundary-conditions",
104 dest="periodic_bc",
105 action="store_false",
106 default=True,
107 help="switch on or off the periodic BC",
108 )
109 parser.add_argument(
110 "-sommerfeld",
111 "--sommerfeld-boundary-conditions",
112 dest="sommerfeld_bc",
113 action="store_true",
114 default=False,
115 help="switch on or off the Sommerfeld radiative BC",
116 )
117 parser.add_argument(
118 "-et",
119 "--end-time",
120 dest="end_time",
121 type=float,
122 default=0.01,
123 help="End (terminal) time",
124 )
125 parser.add_argument(
126 "-pst",
127 "--plot-start-time",
128 dest="plot_start_time",
129 type=float,
130 default=0.0,
131 help="start time for plot",
132 )
133 parser.add_argument(
134 "-s",
135 "--scenario",
136 dest="scenario",
137 default="single-puncture",
138 choices=[
139 "single-puncture",
140 "two-punctures",
141 ],
142 help="Scenario",
143 )
144 parser.add_argument(
145 "-cfl", "--CFL-ratio", dest="cfl", type=float, default=0.1, help="Set CFL ratio"
146 )
147 parser.add_argument(
148 "-exn",
149 "--exe-name",
150 dest="exe_name",
151 type=str,
152 default="test",
153 help="name of output executable file",
154 )
155 parser.add_argument(
156 "-outdir",
157 "--output-directory",
158 dest="path",
159 type=str,
160 default="./",
161 help="specify the output directory, include the patch file and tracer file",
162 )
163 parser.add_argument(
164 "-interp",
165 "--interpolation",
166 dest="interpolation",
167 choices=[
168 "constant",
169 "linear-constant-extrap",
170 "linear-linear-extrap",
171 "linear-con-extrap-lin-normal-interp",
172 "linear-lin-extrap-lin-normal-interp",
173 "matrix",
174 "second_order",
175 "third_order",
176 ],
177 default="second_order",
178 help="interpolation scheme for AMR",
179 )
180 parser.add_argument(
181 "-restrict",
182 "--restriction",
183 dest="restriction",
184 choices=["average", "inject", "matrix", "second_order"],
185 default="second_order",
186 help="restriction scheme for AMR",
187 )
188 parser.add_argument(
189 "-so",
190 "--second-order",
191 dest="SO_flag",
192 default=True,
193 action="store_true",
194 help="enable double communication per timestep, used in the soccz4 formulation.",
195 )
196
197 for k, v in floatparams.items():
198 parser.add_argument(
199 "--{}".format(k),
200 dest="CCZ4{}".format(k),
201 type=float,
202 default=v,
203 help="default: %(default)s",
204 )
205 for k, v in intparams.items():
206 if k == "ReSwi":
207 parser.add_argument(
208 "--{}".format(k),
209 dest="CCZ4{}".format(k),
210 type=int,
211 default=v,
212 help="default: %(default)s, choose refinement criterion, 0-no refinement, 1-radius based, 2-SBH phi gradient based, 3-BBH phi gradient based. Notice: 2 and 3 only work with -ext Full",
213 )
214 else:
215 parser.add_argument(
216 "--{}".format(k),
217 dest="CCZ4{}".format(k),
218 type=int,
219 default=v,
220 help="default: %(default)s",
221 )
222
223 args = parser.parse_args()
224
225 SuperClass = None
226
227 print(args.implementation)
228 if args.implementation == "fd4-rk1-adaptive":
229 SuperClass = exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStep
230 if args.implementation == "fd4-rk1-adaptive-enclave":
231 SuperClass = exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepWithEnclaveTasking
232 args.SO_flag = False
233
234 class CCZ4Solver(SuperClass):
236 self, name, patch_size, min_volume_h, max_volume_h, cfl, domain_r, KOSig
237 ):
238 unknowns = {
239 "G": 6, # 0-5
240 "K": 6, # 6-11
241 "theta": 1, # 12
242 "Z": 3, # 13-15
243 "lapse": 1, # 16
244 "shift": 3, # 17-19
245 "b": 3, # 20-22
246 "dLapse": 3, # 23-25
247 "dxShift": 3, # 26-28
248 "dyShift": 3, # 29-31
249 "dzShift": 3, # 32-34
250 "dxG": 6, # 35-40
251 "dyG": 6, # 41-46
252 "dzG": 6, # 47-52
253 "traceK": 1, # 53
254 "phi": 1, # 54
255 "P": 3, # 55-57
256 "K0": 1, # 58
257 }
258
259 number_of_unknowns = sum(unknowns.values())
260
262#include "../CCZ4Kernels.h"
263"""
264 if SuperClass == exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStep:
265 SuperClass.__init__(
266 self,
267 name=name,
268 patch_size=patch_size,
269 rk_order=1,
270 unknowns=number_of_unknowns,
271 auxiliary_variables=0,
272 min_meshcell_h=min_volume_h,
273 max_meshcell_h=max_volume_h,
274 time_step_relaxation=cfl,
275 KOSigma=KOSig,
276 reconstruction_with_rk=args.SO_flag,
277 )
278 elif (
279 SuperClass
280 == exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepWithEnclaveTasking
281 ):
282 SuperClass.__init__(
283 self,
284 name=name,
285 patch_size=patch_size,
286 rk_order=1,
287 unknowns=number_of_unknowns,
288 auxiliary_variables=0,
289 min_meshcell_h=min_volume_h,
290 max_meshcell_h=max_volume_h,
291 time_step_relaxation=cfl,
292 KOSigma=KOSig,
293 pde_terms_without_state=True,
294 )
295 elif SuperClass==exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepInExaGRyPE:
296 SuperClass.__init__(
297 self,
298 name=name,
299 patch_size=patch_size,
300 rk_order=1,
301 unknowns=number_of_unknowns,
302 auxiliary_variables=0,
303 min_meshcell_h=min_volume_h,
304 max_meshcell_h=max_volume_h,
305 time_step_relaxation=cfl,
306 KOSigma=KOSig,
307 reconstruction_with_rk=args.SO_flag
308 )
309
310 self._patch_size = patch_size
311 self._domain_r = domain_r
312
313 self.set_implementation(
314 boundary_conditions=exahype2.solvers.PDETerms.User_Defined_Implementation,
315 ncp=exahype2.solvers.PDETerms.User_Defined_Implementation,
316 flux=exahype2.solvers.PDETerms.None_Implementation,
317 source_term=exahype2.solvers.PDETerms.User_Defined_Implementation,
318 refinement_criterion=exahype2.solvers.PDETerms.User_Defined_Implementation,
319 eigenvalues=exahype2.solvers.PDETerms.User_Defined_Implementation,
320 )
321
322 if (
323 SuperClass
324 == exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepWithEnclaveTasking
325 ):
326 self._fused_compute_kernel_call_cpu = exahype2.solvers.rkfd.fd4.kernels.create_compute_kernel_for_FD4_DSL(
330 compute_max_eigenvalue_of_next_time_step=True,
331 solver_variant=exahype2.solvers.rkfd.kernels.SolverVariant.Stateless,
332 kernel_variant=exahype2.solvers.rkfd.kernels.KernelVariant.BatchedAoSHeap,
333 KOSigma=self._KO_Sigma,
334 )
335 self._fused_compute_kernel_call_gpu = exahype2.solvers.rkfd.fd4.kernels.create_compute_kernel_for_FD4_DSL(
339 compute_max_eigenvalue_of_next_time_step=True,
340 solver_variant=exahype2.solvers.rkfd.kernels.SolverVariant.AcceleratorWithExplicitCopy,
341 kernel_variant=exahype2.solvers.rkfd.kernels.KernelVariant.BatchedAoSHeap,
342 KOSigma=self._KO_Sigma,
343 )
345{
346"""
347
348 if (
349 SuperClass == exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStep
350 or SuperClass == exahype2.solvers.rkfd.fd4.GlobalFixedTimeStep
351 or SuperClass
352 == exahype2.solvers.rkfd.fd4.GlobalAdaptiveTimeStepWithEnclaveTasking
353 ):
354 self.postprocess_updated_patch += """
355 #if DIMENSIONS==2
356 constexpr int itmax = {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} * {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
357 #endif
358
359 #if DIMENSIONS==3
360 constexpr int itmax = {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} * {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} * {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
361 #endif
362"""
363 # elif SuperClass == exahype2.solvers.rkdg.rusanov.GlobalAdaptiveTimeStep: fix it after rkdg is back
364 # self.postprocess_updated_patch = """
365 # constexpr int itmax = ({{ORDER}}+1) * ({{ORDER}}+1) * ({{ORDER}}+1); // only support 3d
366 # """
367 else:
368 self.postprocess_updated_patch += """
369 #if DIMENSIONS==2
370 constexpr int itmax = {{NUMBER_OF_VOLUMES_PER_AXIS}} * {{NUMBER_OF_VOLUMES_PER_AXIS}};
371 #endif
372
373 #if DIMENSIONS==3
374 constexpr int itmax = {{NUMBER_OF_VOLUMES_PER_AXIS}} * {{NUMBER_OF_VOLUMES_PER_AXIS}} * {{NUMBER_OF_VOLUMES_PER_AXIS}};
375 #endif
376"""
377
378 self.postprocess_updated_patch += """
379 int index = 0;
380 for (int i=0;i<itmax;i++)
381 {
382 applications::exahype2::ccz4::enforceCCZ4constraints( newQ+index );
383 index += {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}};
384 }
385 }
386"""
387
389 SuperClass.create_action_sets(self)
390 self._action_set_couple_resolution_transitions_and_handle_dynamic_mesh_refinement.additional_includes += """
391#include "../CCZ4Kernels.h"
392 """
393
395 """
396 We take this routine to add a few additional include statements.
397 """
398 return (
399 SuperClass.get_user_action_set_includes(self) + self._my_user_includes
400 )
401
402
405 userinfo = []
406 exe = "peano4"
407
408 if args.exe_name != "":
409 exe += "_"
410 exe += args.exe_name
411 project = exahype2.Project(
412 ["benchmarks", "exahype2", "ccz4"], "ccz4", executable=exe
413 )
414
415
418 solver_name = "CCZ4"
419 min_h = args.min_h
420 if min_h <= 0.0:
421 print("No minimal mesh size chosen. Set it to max mesh size (regular grid)")
422 min_h = args.max_h
423
424 my_solver = CCZ4Solver(
425 solver_name,
426 args.patch_size,
427 min_h,
428 args.max_h,
429 args.cfl,
430 args.CCZ4domain_r,
431 args.CCZ4KOSigma,
432 )
433 userinfo.append(("CFL ratio set as " + str(args.cfl), None))
434
435 userinfo.append(("The solver is " + args.implementation, None))
436
437
440
441
442 if args.interpolation == "constant":
443 my_solver.interpolation = "piecewise_constant"
444 print("Interpolation rule: piecewise_constant")
445 if args.interpolation == "linear-constant-extrap":
446 my_solver.interpolation = "linear_with_constant_extrapolation"
447 print("Interpolation rule: linear constant extrapolation")
448 if args.interpolation == "linear-linear-extrap":
449 my_solver.interpolation = "linear_with_linear_extrapolation"
450 print("Interpolation rule: linear extrapolation")
451 if args.interpolation == "linear-con-extrap-lin-normal-interp":
452 my_solver.interpolation = (
453 "linear_with_constant_extrapolation_and_linear_normal_interpolation"
454 )
455 print(
456 "Interpolation rule: linear+constant extrapolation and linear normal interpolation"
457 )
458
459 tem_interp = ["TP_constant", "TP_linear_with_linear_extrap_normal_interp"]
460 tem_restrict = ["TP_inject_normal_extrap", "TP_average_normal_extrap"]
461 if "fd4-rk" in args.implementation:
462 if args.interpolation == "matrix":
463 exahype2.solvers.rkfd.fd4.switch_to_FD4_matrix_interpolation(my_solver)
464 elif args.interpolation == "second_order":
465 exahype2.solvers.rkfd.fd4.switch_to_FD4_second_order_interpolation(
466 my_solver
467 )
468 elif args.interpolation == "third_order":
469 exahype2.solvers.rkfd.fd4.switch_to_FD4_third_order_interpolation(my_solver)
470 else:
471 exahype2.solvers.rkfd.fd4.switch_to_FD4_tensor_product_interpolation(
472 my_solver, tem_interp[1]
473 )
474 userinfo.append(("FD4 Interpolation: " + tem_interp[1], None))
475
476 if args.restriction == "matrix":
477 exahype2.solvers.rkfd.fd4.switch_to_FD4_matrix_restriction(my_solver)
478 elif args.restriction == "second_order":
479 exahype2.solvers.rkfd.fd4.switch_to_FD4_second_order_restriction(my_solver)
480 else:
481 exahype2.solvers.rkfd.fd4.switch_to_FD4_tensor_product_restriction(
482 my_solver, tem_restrict[1]
483 )
484 userinfo.append(("FD4 Restriction: " + tem_restrict[1], None))
485
486
489 for k, v in intparams.items():
490 intparams.update({k: eval("args.CCZ4{}".format(k))})
491 for k, v in floatparams.items():
492 floatparams.update({k: eval("args.CCZ4{}".format(k))})
493
494 if args.SO_flag == True:
495 intparams.update({"SO": 1})
496
497 if args.scenario == "two-punctures":
498 msg = "Periodic BC deactivated because you pick Puncture scenario\nInitialize binary black holes"
499 print(msg)
500 periodic_boundary_conditions = [False, False, False]
501 intparams.update(
502 {"swi": 2}
503 ) # notice it may change, see according function in CCZ4.cpp
504 print(intparams)
505 userinfo.append((msg, None))
506 elif args.scenario == "single-puncture":
507 msg = "Periodic BC deactivated because you pick Puncture scenario\nInitialize single black hole"
508 print(msg)
509 periodic_boundary_conditions = [False, False, False]
510 intparams.update({"swi": 0})
511 userinfo.append((msg, None))
512 elif args.periodic_bc == True:
513 msg = "Periodic BC set"
514 print(msg)
515 periodic_boundary_conditions = [True, True, True] # Periodic BC
516 userinfo.append((msg, None))
517 else:
518 msg = "WARNING: Periodic BC deactivated by hand"
519 print(msg)
520 periodic_boundary_conditions = [False, False, False]
521 userinfo.append((msg, None))
522
523 solverconstants = ""
524
525 if (args.scenario == "two-punctures") or (args.scenario == "single-puncture"):
526 solverconstants += "static constexpr int Scenario=2; /* Two-puncture */ \n"
527 userinfo.append(("picking black hole scenario", None))
528 else:
529 raise Exception("Scenario " + args.scenario + " is now unknown")
530
531 for k, v in floatparams.items():
532 solverconstants += "static constexpr double {} = {};\n".format(
533 "CCZ4{}".format(k), v
534 )
535 for k, v in intparams.items():
536 solverconstants += "static constexpr int {} = {};\n".format(
537 "CCZ4{}".format(k), v
538 )
539 my_solver.add_solver_constants(solverconstants)
540
541 project.add_solver(my_solver)
542
543 build_mode = modes[args.mode]
544
545 dimensions = 3
546
547
550 floatparams.update({"domain_r": args.CCZ4domain_r})
551 dr = floatparams["domain_r"]
552 offset = [-dr, -dr, -dr]
553 domain_size = [2 * dr, 2 * dr, 2 * dr]
554 msg = "domain set as " + str(offset) + " and " + str(domain_size)
555 print(msg)
556 userinfo.append((msg, None))
557
558 project.set_global_simulation_parameters(
559 dimensions, # dimensions
560 offset,
561 domain_size,
562 args.end_time, # end time
563 args.plot_start_time,
564 args.plot_step_size, # snapshots
565 periodic_boundary_conditions,
566 8, # plotter precision
567 )
568 userinfo.append(
569 (
570 "plot start time: "
571 + str(args.plot_start_time)
572 + ", plot step size: "
573 + str(args.plot_step_size),
574 None,
575 )
576 )
577 userinfo.append(("Terminal time: " + str(args.end_time), None))
578
579 project.set_build_mode(build_mode)
580
581
584 path = "./"
585 if not args.path == "./":
586 path = args.path
587 project.set_output_path(path)
588
589 project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
590
591
594 peano4_project = project.generate_Peano4_project(verbose=True)
595 peano4_project.output.makefile.add_header_search_path(
596 "../../../applications/ccz4/"
597 )
598
599 if args.scenario == "two-punctures" or args.scenario == "single-puncture":
600 peano4_project.output.makefile.add_linker_flag("-lm -lgsl -lgslcblas")
601 peano4_project.output.makefile.add_cpp_file(
602 "../../../applications/ccz4/libtwopunctures/TP_Utilities.cpp"
603 )
604 peano4_project.output.makefile.add_cpp_file(
605 "../../../applications/ccz4/libtwopunctures/TP_Parameters.cpp"
606 )
607 peano4_project.output.makefile.add_cpp_file(
608 "../../../applications/ccz4/libtwopunctures/TP_Logging.cpp"
609 )
610 peano4_project.output.makefile.add_cpp_file(
611 "../../../applications/ccz4/libtwopunctures/TwoPunctures.cpp"
612 )
613 peano4_project.output.makefile.add_cpp_file(
614 "../../../applications/ccz4/libtwopunctures/CoordTransf.cpp"
615 )
616 peano4_project.output.makefile.add_cpp_file(
617 "../../../applications/ccz4/libtwopunctures/Equations.cpp"
618 )
619 peano4_project.output.makefile.add_cpp_file(
620 "../../../applications/ccz4/libtwopunctures/FuncAndJacobian.cpp"
621 )
622 peano4_project.output.makefile.add_cpp_file(
623 "../../../applications/ccz4/libtwopunctures/Newton.cpp"
624 )
625 peano4_project.output.makefile.add_CXX_flag("-DIncludeTwoPunctures")
626 else:
627 raise Exception("Scenario " + args.scenario + " is now unknown")
628
629 peano4_project.output.makefile.add_CXX_flag("-DCCZ4EINSTEIN")
630
631 peano4_project.output.makefile.add_h_file("CCZ4.h")
632 peano4_project.output.makefile.add_cpp_file("CCZ4.cpp")
633 peano4_project.output.makefile.add_cpp_file(
634 "../../../applications/ccz4/InitialValues.cpp"
635 )
636 peano4_project.output.makefile.add_cpp_file(
637 "../../../applications/ccz4/CCZ4Kernels.cpp"
638 )
639
640 peano4_project.generate(throw_away_data_after_generation=False)
641 peano4_project.build(make_clean_first=True)
642
643 # Report the application information
644 userinfo.append(("the executable file name: " + exe, None))
645 userinfo.append(("output directory: " + path, None))
646 print("=========================================================")
647 if len(userinfo) > 0:
648 print("The building information:")
649 for msg, exception in userinfo:
650 if exception is None:
651 print(msg)
652 else:
653 print(msg, "Exception: {}".format(exception))
654 print(intparams)
655 print(floatparams)
656 print("=========================================================")
__init__(self, name, patch_size, min_volume_h, max_volume_h, cfl, domain_r, KOSig)
get_user_action_set_includes(self)
We take this routine to add a few additional include statements.