Peano
Loading...
Searching...
No Matches
gauge-wave-with-scalar-field.py
Go to the documentation of this file.
1r"""!
2
3@page benchmarks_exagrype_gauge_wave_with_scalar_field Gauge wave with a scalar field
4
5\tableofcontents
6
7The gauge wave is a pure gauge perturbation of flat spacetime, i.e. an analytical solution of the
8Einstein equations that travels along the x-axis with speed one. It is periodic over the unit cube.
9This script evolves it with the first-order CCZ4 solver of exagrype.api (exagrype.api.FOCCZ4Solver).
10Next to CCZ4, it hosts four scalar fields which the spacetime advects
11(exagrype.api.scalarfield.ScalarField)
12
13@f$ \partial_t \phi + \alpha^2 \partial_x \phi = 0, @f$
14
15with the lapse @f$ \alpha @f$ of CCZ4 (the metric component g_xx of the gauge wave is @f$ \alpha^2 @f$).
16The coupling is a fake coupling: the spacetime advects the field, but the field does not feed back.
17The equation has a closed-form solution on the gauge wave, so the benchmark measures the
18error of the scalar field against the exact solution (see convergence-study.py).
19
20## Couplings
21
22The coupling decides how the time integrators of the two solvers interact:
23
24- `--coupling outer-multiplicative`: each solver has its numerical scheme. CCZ4 completes its time
25 step, then the scalar field performs its step with the frozen spacetime of the end of the step
26 (exagrype.api.scalarfield.CCZ4WithScalarField_OuterMultiplicativeCoupling).
27 The scalar field is first order in the time step size, whatever the order of the time integrators is.
28- `--coupling inner-additive` and `--coupling inner-multiplicative`: one numerical scheme for both
29 solvers (a "generator" which one assigns to the coupled solver
30 exagrype.api.scalarfield.CCZ4WithScalarField_InnerCoupling). The solvers exchange data in
31 each stage of the time integrator, i.e. the scalar field sees the spacetime of the time level of its stage. The scalar field has the
32 order of the time integrator (four for `rk4fd4`). Additive: the stages of the solvers run in parallel.
33 Multiplicative: in each stage, the scalar field follows CCZ4.
34
35The numerical scheme (`--scheme`) is the same for both solvers: `fv` (Finite Volumes, explicit Euler)
36or `rk1fd4`, ..., `rk4fd4` (fourth-order Finite Differences with Runge-Kutta of order one to four).
37benchmarks/exagrype/gauge-wave-with-scalar-field/DESIGN.md documents the design.
38
39## Usage
40
41The script requires a Peano build with
42
43 --enable-exahype --enable-blockstructured --enable-loadbalancing --enable-exagrype
44
45and is run from this directory via
46
47 python3 gauge-wave-with-scalar-field.py --mode release --scheme rk4fd4 --coupling inner-additive
48 python3 gauge-wave-with-scalar-field.py --mode debug --scheme fv --coupling outer-multiplicative --mesh-size 0.1
49
50The debug mode visualises the task graphs. The script convergence-study.py runs all couplings
51over several mesh sizes, and estimates the convergence orders.
52
53"""
54
55import argparse
56import os
57
58import peano4.api
59import exahype2.api
60import exagrype.api
61
62
63parser = argparse.ArgumentParser(description="ExaGRyPE gauge wave with a scalar field")
64parser.add_argument(
65 "--mode",
66 choices=["release", "debug"],
67 required=True,
68 help="Build mode of the generated code. Release uses a longer simulation "
69 "and text logging; debug a very short one with visualised logging.",
70)
71parser.add_argument(
72 "--scheme",
73 choices=["fv", "rk1fd4", "rk2fd4", "rk3fd4", "rk4fd4"],
74 required=True,
75 help="Numerical scheme of both solvers: Finite Volumes with explicit Euler (fv), or "
76 "fourth-order Finite Differences with Runge-Kutta of order 1 to 4 (rk1fd4, ..., rk4fd4).",
77)
78parser.add_argument(
79 "--coupling",
80 choices=["outer-multiplicative", "inner-additive", "inner-multiplicative"],
81 required=True,
82 help="How the time integrators of CCZ4 and the scalar field interact.",
83)
84parser.add_argument(
85 "--mesh-size",
86 type=float,
87 default=1.0 / 27.0,
88 help="Edge length h of one volume or grid cell (default: 1/27, i.e. 3x3x3 mesh cells "
89 "with patches of 9x9x9 cells). The mesh is regular and is refined by factors of three "
90 "from the root cell, i.e. h is rounded to patch-size/3^k.",
91)
92parser.add_argument(
93 "--patch-size",
94 type=int,
95 default=9,
96 help="Number of grid cells per patch and axis (default: 9). Peano refines the root "
97 "cell at least once, i.e. h can be at most patch-size/3.",
98)
99parser.add_argument(
100 "--end-time",
101 type=float,
102 default=None,
103 help="Final simulation time (default: 1.0 for release, 0.02 for debug)",
104)
105parser.add_argument(
106 "--directory",
107 default=".",
108 help="Directory for the generated code, its build and the outputs (default: the current directory)",
109)
110parser.add_argument(
111 "--threads",
112 type=int,
113 default=None,
114 help="Number of threads of the generated executable (default: all cores)",
115)
116parser.add_argument(
117 "--plot-along-x-axis",
118 action="store_true",
119 help="Restrict the plots to the patches along the line y=z=0.5 and write them "
120 "with ten digits. Needed to measure the error of the scalar field, see convergence-study.py. "
121 "Four plots per simulation are written.",
122)
123args = parser.parse_args()
124
125
129volume_size = 1.01 * args.mesh_size
130
131if args.mode == "release":
132 build_mode = peano4.api.output.CompileMode.RELEASE
133 end_time = 1.0
134 time_in_between_plots = 0.1
135 verbosity = peano4.api.LoggerVerbosity.TEXT
136else:
137 build_mode = peano4.api.output.CompileMode.DEBUG
138 end_time = 0.02
139 time_in_between_plots = 0.01
140 verbosity = peano4.api.LoggerVerbosity.VISUALISATION
141
142if args.end_time is not None:
143 end_time = args.end_time
144if args.plot_along_x_axis:
145 time_in_between_plots = end_time / 4.0
146
147patch_size = args.patch_size
148finite_volumes = args.scheme == "fv"
149rk_order = None if finite_volumes else int(args.scheme[2])
150flavour = exahype2.api.fv if finite_volumes else exahype2.api.rkfd4
152
154 namespace=["benchmarks", "exagrype", "gaugewavewithscalarfield"],
155 project_name="gauge-wave-with-scalar-field",
156 directory=args.directory,
157 executable="gauge-wave-with-scalar-field",
158)
159
160
161if args.coupling == "outer-multiplicative":
162 coupled = scalarfield.CCZ4WithScalarField_OuterMultiplicativeCoupling()
163 for solver in coupled.solvers:
164
165 if finite_volumes:
167 solver, patch_size
168 )
169 else:
171 Kernel = Scheme.RightHandSideKernel
172 if solver is coupled.ccz4:
173 solver.numerical_scheme = Scheme(
174 solver,
175 patch_size,
176 rk_order=rk_order,
177 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
178 advection_velocity=exagrype.api.FOCCZ4Solver.ADVECTION_VELOCITY,
179 advected_quantities=solver.lopsided_advection_quantities(),
180 )
181 else:
182 solver.numerical_scheme = Scheme(solver, patch_size, rk_order=rk_order)
183else:
184 coupled = scalarfield.CCZ4WithScalarField_InnerCoupling()
185
186 multiplicative = args.coupling == "inner-multiplicative"
187 if finite_volumes:
188 Generator = (
189 scalarfield.FiniteVolumesInnerMultiplicative
190 if multiplicative
191 else scalarfield.FiniteVolumesInnerAdditive
192 )
193 coupled.numerical_scheme = Generator(patch_size)
194 else:
195 Generator = (
196 scalarfield.RungeKuttaFD4InnerMultiplicative
197 if multiplicative
198 else scalarfield.RungeKuttaFD4InnerAdditive
199 )
200 coupled.numerical_scheme = Generator(patch_size, rk_order)
201
202ccz4 = coupled.ccz4
203scalar_field = coupled.scalar_field
204ccz4.add_pde_term(exagrype.api.initialvalues.gauge_wave())
205
206plotter_arguments = {}
207if args.plot_along_x_axis:
208 plotter_arguments["plotter_precision"] = 10
209for solver in coupled.solvers:
210 solver.grid_construction = flavour.SetupSimulationOverRegularGrid(
211 solver, volume_size=volume_size
212 )
213 solver.plotter = flavour.PlotAsVTKFile(
214 solver,
215 first_plot_time_stamp=0.0,
216 time_in_between_plots=time_in_between_plots,
217 **plotter_arguments,
218 )
219 if args.plot_along_x_axis:
220 solver.plotter.add_plot_filter([0.0, 0.49, 0.49], [1.0, 0.02, 0.02])
221
222project.add_solver(coupled)
223
224project.compiler = peano4.api.taskgraph.compiler.FuseSteps.translate
225
226project.set_global_simulation_parameters(
227 dimensions=3,
228 offset=[0.0, 0.0, 0.0],
229 size=[1.0, 1.0, 1.0],
230 min_end_time=end_time,
231 max_end_time=end_time,
232 periodic_BC=[True, True, True],
233)
234
235if args.threads is not None:
236 project.set_number_of_threads(args.threads)
237
238PeanoRoot = os.path.abspath(
239 os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..")
240)
241project.set_Peano4_installation(PeanoRoot, build_mode)
242peano4_project = project.generate_Peano4_project(verbosity=verbosity)
243peano4_project.generate()
244peano4_project.build(make_clean_first=True)
ExaHyPE 2 project.
Definition Project.py:15
Finite Volumes with a Rusanov Riemann solver and explicit Euler time stepping, realised over a block-...
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
exahype2.api.InitPointWisely gauge_wave()
Gauge wave along the x-axis,.
This file is part of the ExaGRyPE project.
Definition __init__.py:1
This file is part of the ExaGRyPE project.
Definition __init__.py:1
Fourth-order Finite Differences with explicit Runge-Kutta time stepping over block-structured meshes.
Definition __init__.py:1