Peano
Loading...
Searching...
No Matches
gauge-wave.py
Go to the documentation of this file.
1r"""!
2
3@page benchmarks_exagrype_gauge_wave Gauge wave
4
5\tableofcontents
6
7@image html benchmarks/exagrype/gauge-wave/example-output/convergence.png
8
9The gauge wave is a pure gauge perturbation of flat spacetime: an analytical
10solution of the Einstein equations which travels along the x-axis with speed one.
11It is periodic over the unit cube and hence a standard first test of any numerical
12relativity code. The solution is known exactly, so we can always tell what the
13numerical error is. If the wave shape or its amplitude changes over time,
14this is due to numerical effects, and the setup is convenient to assess and compare
15numerical schemes. The picture above shows the error of the lapse over the mesh size
16for five schemes. It is the outcome of the convergence study that doubles as the
17integration test of the numerical schemes (see below).
18
19The script uses exagrype.api, i.e. the first-order CCZ4 solver
20exagrype.api.FOCCZ4Solver, and discretises it with
21
22
23- Finite Volumes with explicit Euler time stepping (`--scheme fv`),
24- the same with optimistic time stepping (`--scheme fv-optimistic`), or
25- fourth-order Finite Differences with a Runge-Kutta scheme of order one to four (`--scheme
26 rk1fd4`, ..., `rk4fd4`).
27
28
29## Prepare Peano
30
31Peano has to be built with ExaHyPE and ExaGRyPE, i.e. with
32
33~~~~~~~~~~~~~~~~~~~~~~~
34--enable-exahype --enable-blockstructured --enable-loadbalancing --enable-exagrype
35~~~~~~~~~~~~~~~~~~~~~~~
36
37The generated code is compiled with the compiler of your choice (we use the
38Intel compiler with its path in `PATH`), and the Python packages have to be
39on the Python path (`export PYTHONPATH=$PYTHONPATH:../../../src`).
40
41
42## Run a simulation
43
44The script has to be told what to do. It requires a build mode and a scheme:
45
46~~~~~~~~~~~~~~~~~~~~~~~
47python3 gauge-wave.py --mode release --scheme rk4fd4
48python3 gauge-wave.py --mode debug --scheme fv --mesh-size 0.1
49~~~~~~~~~~~~~~~~~~~~~~~
50
51Use `--help` to see all options. `--mode release` builds an optimised executable
52and runs until time 1.0; `--mode debug` builds with assertions and visualises the
53task graphs. `--mesh-size` is the edge length h of one grid cell. The default is 1/27, i.e. 3x3x3
54mesh cells with patches of 9x9x9 grid cells. The mesh is regular and refined by factors of
55three, i.e. h is rounded to patch size over 3^k (the patch size can be set via
56`--patch-size`, but the root cell is refined at least once). `--compiler` switches
57between the task graph compilers (sequential, fusion which is the default, and the
58producer-consumer variants of both), `--end-time`, `--threads` and `--directory` do what
59they say.
60
61The script generates the C++ code, the Makefile, and compiles the executable. Run the
62executable `gauge-wave` afterwards. To get rid of all the generated files, remove the
63directories `celldata facedata globaldata observers tasks vertexdata repositories`, the
64`Abstract*` files, the `Makefile` and all `*.o` files. You can recreate them any time by
65rerunning the Python script.
66
67
68## Convergence study (integration test)
69
70The script `convergence-study.py` builds and runs the benchmark for all schemes `fv`,
71`rk1fd4`, ..., `rk4fd4` and for the volume sizes h=1/9, 1/27 and 1/81 (patch size 9; the
72coarsest mesh needs patches of size 3, as Peano refines the root cell at least once) until time
73t=0.1. It records the maximum error of the lapse along the line y=z=0.5 in the last
74snapshot against the exact solution
75
76@f[ \alpha (x,t) = \sqrt{1 - A \sin (2 \pi (x-t))}, \quad A=0.1, @f]
77
78estimates the convergence order p ~ log(e(3h)/e(h))/log(3), and exits with a non-zero
79status if the order between the two finest meshes of a scheme falls below a threshold. It
80is run via the skill `exahype2:integration-test` (see
81documentation/exahype2/integration-test/SKILL.md). Whenever you change a numerical scheme, the
82task graph, the kernels or the code generation, this is the test to rerun.
83
84| scheme | h = 1/9 | h = 1/27 | order | h = 1/81 | order |
85|---|---|---|---|---|---|
86| fv | 1.58e-2 | 6.59e-3 | 0.79 | 2.34e-3 | 0.94 |
87| rk1fd4 | 1.09e-3 | 3.37e-4 | 1.06 | 1.10e-4 | 1.02 |
88| rk2fd4 | 1.46e-4 | 3.01e-6 | 3.53 | 2.39e-7 | 2.31 |
89| rk3fd4 | 1.39e-4 | 2.70e-6 | 3.59 | 3.34e-8 | 4.00 |
90| rk4fd4 | 1.39e-4 | 2.71e-6 | 3.58 | 3.39e-8 | 3.99 |
91
92What we see:
93
94- The Finite Volume scheme is first order, as expected. Its error is orders of magnitude
95 above the one of the Finite Difference schemes, which discretise in space with fourth order.
96- The order of the Finite Difference schemes is the smaller one of the spatial order (four)
97 and the order of the time integration. With one Runge-Kutta stage (explicit Euler),
98 the time integration error dominates from the coarsest mesh on, and the scheme is
99 first order. As the time step size shrinks with the mesh size (CFL condition), the time
100 error is tiny for higher orders on coarse meshes: rk2fd4, rk3fd4 and rk4fd4 yield the same
101 error on the two coarsest meshes, and rk2fd4 leaves the fourth-order regime as soon as its
102 second-order time error becomes visible (order 2.3 between 1/27 and 1/81). Rk3fd4 and
103 rk4fd4 show the full fourth order.
104- The estimated orders on the coarsest meshes are not asymptotic: The wave is barely
105 resolved with 9 volumes per wave length.
106- The error is measured at the last snapshot, whose time stamp overshoots the end time by less
107 than one time step and differs between meshes. This biases the orders by about 0.01.
108- The study ran on an eight-core workstation. The finest meshes are the limit of what
109 fits into 16 GB of memory: A Finite Difference run with 81 volumes per axis needs 2 to 3 GB,
110 and the memory grows with the number of volumes, i.e. h=1/243 needs 27 times more and does not fit
111 (the study tried and the runs were killed). The finest mesh, h=1/81, took between
112 3 and 11 minutes with two threads. These numbers are recorded in the table of the
113 script, but they are not an acceptance criterion; the (to-be-written) skill
114 `exahype2:performance-test` is supposed to cover that.
115
116
117## Postprocess/visualise the results
118
119The convergence study uses `--plot-along-x-axis`, which restricts the output to the patches along
120the line y=z=0.5 and writes them with ten digits. Without this option, the code writes
121the whole solution as Peano patch files every 0.1 time units. You can convert them into vtk and
122visualise them via Paraview:
123
124~~~~~~~~~~~~~~~~~~~~~~~
125pvpython ../../../python/peano4/visualisation/render.py --filter-fine-grid solution-CCZ4.peano-patch-file
126~~~~~~~~~~~~~~~~~~~~~~~
127
128"""
129
130import argparse
131import os
132
133import peano4.api
134import exahype2.api
135import exagrype.api
136
137
138parser = argparse.ArgumentParser(description="ExaGRyPE gauge wave benchmark")
139parser.add_argument(
140 "--mode",
141 choices=["release", "debug"],
142 required=True,
143 help="Build mode of the generated code. Release uses a longer simulation "
144 "and text logging; debug a very short one with visualised logging.",
145)
146parser.add_argument(
147 "--mesh-size",
148 type=float,
149 default=1.0 / 27.0,
150 help="Edge length h of one Finite Volume cell or Finite Difference grid cell "
151 "(default: 1/27, i.e. 3x3x3 mesh cells with patches of 9x9x9 cells). The mesh is "
152 "regular and is refined by factors of three from the root cell, i.e. h is "
153 "rounded to patch-size/3^k.",
154)
155parser.add_argument(
156 "--patch-size",
157 type=int,
158 default=9,
159 help="Number of grid cells per patch and axis (default: 9). Peano refines the root "
160 "cell at least once, i.e. h can be at most patch-size/3.",
161)
162parser.add_argument(
163 "--end-time",
164 type=float,
165 default=None,
166 help="Final simulation time (default: 1.0 for release, 0.02 for debug)",
167)
168parser.add_argument(
169 "--directory",
170 default=".",
171 help="Directory for the generated code, its build and the outputs (default: the current directory)",
172)
173parser.add_argument(
174 "--threads",
175 type=int,
176 default=None,
177 help="Number of threads of the generated executable (default: all cores)",
178)
179parser.add_argument(
180 "--plot-along-x-axis",
181 action="store_true",
182 help="Restrict the plots to the patches along the line y=z=0.5 and write them "
183 "with ten digits. Needed to measure the error of the lapse, see convergence-study.py. "
184 "Four plots per simulation are written.",
185)
186parser.add_argument(
187 "--scheme",
188 choices=["fv", "fv-optimistic", "rk1fd4", "rk2fd4", "rk3fd4", "rk4fd4"],
189 required=True,
190 help="Numerical scheme: Finite Volumes with explicit Euler (fv), the same "
191 "with optimistic time stepping (fv-optimistic), or fourth-order Finite "
192 "Differences with Runge-Kutta of order 1 to 4 (rk1fd4, ..., rk4fd4).",
193)
194parser.add_argument(
195 "--compiler",
196 choices=["sequential", "fusion", "producer-consumer", "producer-consumer-fusion"],
197 default="fusion",
198 help="Task graph compiler: one traversal per task (sequential), tasks fused "
199 "into as few traversals as possible (fusion, default), or the same two "
200 "variants with cell tasks spawned as producer-consumer tasks.",
201)
202args = parser.parse_args()
203
205task_graph_compiler = {
206 "sequential": compilers.Sequential.translate,
207 "fusion": compilers.FuseSteps.translate,
208 "producer-consumer": compilers.CellTaskProducerConsumer.translate_with_sequential,
209 "producer-consumer-fusion": compilers.CellTaskProducerConsumer.translate_with_fusion,
210}[args.compiler]
211
212
216volume_size = 1.01 * args.mesh_size
217
218if args.mode == "release":
219 build_mode = peano4.api.output.CompileMode.RELEASE
220 end_time = 1.0
221 time_in_between_plots = 0.1
222 verbosity = peano4.api.LoggerVerbosity.TEXT
223else:
224 build_mode = peano4.api.output.CompileMode.DEBUG
225 end_time = 0.02
226 time_in_between_plots = 0.01
227 verbosity = peano4.api.LoggerVerbosity.VISUALISATION
228
229if args.end_time is not None:
230 end_time = args.end_time
231if args.plot_along_x_axis:
232 time_in_between_plots = end_time / 4.0
233
234patch_size = args.patch_size
235plotter_arguments = {}
236if args.plot_along_x_axis:
237 plotter_arguments["plotter_precision"] = 10
238
239
241 namespace=["benchmarks", "exagrype", "gaugewave"],
242 project_name="gauge-wave",
243 directory=args.directory,
244 executable="gauge-wave",
245)
246
248solver.add_pde_term(exagrype.api.initialvalues.gauge_wave())
249
250if args.scheme in ["fv", "fv-optimistic"]:
251 if args.scheme == "fv":
253 else:
255 solver.numerical_scheme = scheme_class(solver, patch_size)
257 solver, volume_size=volume_size
258 )
260 solver,
261 first_plot_time_stamp=0.0,
262 time_in_between_plots=time_in_between_plots,
263 **plotter_arguments,
264 )
265 if args.plot_along_x_axis:
266 solver.plotter.add_plot_filter([0.0, 0.49, 0.49], [1.0, 0.02, 0.02])
267else:
268 Kernel = exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel
270 solver,
271 patch_size,
272 rk_order=int(args.scheme[2]),
273 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
274 advection_velocity=exagrype.api.FOCCZ4Solver.ADVECTION_VELOCITY,
275 advected_quantities=solver.advected_quantities(),
276 )
277 solver.grid_construction = exahype2.api.rkfd4.SetupSimulationOverRegularGrid(
278 solver, volume_size=volume_size
279 )
280 solver.plotter = exahype2.api.rkfd4.PlotAsVTKFile(
281 solver,
282 first_plot_time_stamp=0.0,
283 time_in_between_plots=time_in_between_plots,
284 **plotter_arguments,
285 )
286 if args.plot_along_x_axis:
287 solver.plotter.add_plot_filter([0.0, 0.49, 0.49], [1.0, 0.02, 0.02])
288
289project.add_solver(solver)
290project.compiler = task_graph_compiler
291
292project.set_global_simulation_parameters(
293 dimensions=3,
294 offset=[0.0, 0.0, 0.0],
295 size=[1.0, 1.0, 1.0],
296 min_end_time=end_time,
297 max_end_time=end_time,
298 periodic_BC=[True, True, True],
299)
300
301if args.threads is not None:
302 project.set_number_of_threads(args.threads)
303
304PeanoRoot = os.path.abspath(
305 os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..")
306)
307project.set_Peano4_installation(PeanoRoot, build_mode)
308peano4_project = project.generate_Peano4_project(verbosity=verbosity)
309peano4_project.generate()
310peano4_project.build(make_clean_first=True)
Solver for the Einstein equations in the first-order CCZ4 formulation.
ExaHyPE 2 project.
Definition Project.py:15
Plotting counterpart to RusanovWithExplicitEuler: maps the patch data of a Finite Volume scheme with ...
Finite Volumes with a Rusanov Riemann solver and explicit Euler time stepping, realised over a block-...
Finite Volumes with a Rusanov Riemann solver and optimistic explicit Euler time stepping,...
Setup phase counterpart to RusanovWithExplicitEuler: sets the initial condition for a Finite Volume s...
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Plotting counterpart of the fourth-order Finite Differences with Runge-Kutta time stepping (exahype2....
Setup phase of the fourth-order Finite Differences with Runge-Kutta time stepping (exahype2....
exahype2.api.InitPointWisely gauge_wave()
Gauge wave along the x-axis,.
This file is part of the ExaGRyPE project.
Definition __init__.py:1
Compilers are simple functions.
Definition __init__.py:1