Peano
Loading...
Searching...
No Matches
smooth-convergence-test-fd4.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3"""!
4
5Convergence test of the fourth-order Finite Differences with Runge-Kutta
6
7Generates and builds one executable of the entropy wave benchmark
8(@ref benchmarks_exahype2_euler_smooth_fd4) for one mesh width. Run the
9script once per mesh width, each time with a different output directory, and
10compare the outcomes with compute-errors.py.
11
12"""
13import argparse
14import os
15
16import peano4.api
17import exahype2.api
18
19
20parser = argparse.ArgumentParser(
21 description="Euler entropy wave with exahype2.api.rkfd4 (fourth-order Finite Differences)"
22)
23parser.add_argument(
24 "--output-directory",
25 default=".",
26 help="Directory the code is generated and built in (default: .)",
27)
28parser.add_argument(
29 "--volume-size",
30 type=float,
31 default=0.0075,
32 help="Maximum grid cell size. 0.0075, 0.0025 and 0.00083 yield 27, 81 and 243 grid cells per axis (default: 0.0075)",
33)
34parser.add_argument(
35 "--rk-order",
36 type=int,
37 default=4,
38 help="Order of the Runge-Kutta scheme, 1 to 4 (default: 4)",
39)
40parser.add_argument(
41 "--end-time", type=float, default=0.05, help="Simulated time (default: 0.05)"
42)
43parser.add_argument(
44 "--time-step-size",
45 type=float,
46 default=None,
47 help="Fixed time step size. Without this argument, the time step size is adaptive",
48)
49parser.add_argument(
50 "--cfl-constant",
51 type=float,
52 default=0.5,
53 help="CFL constant for adaptive time step sizes (default: 0.5)",
54)
55parser.add_argument(
56 "--periodic",
57 action="store_true",
58 help="Use periodic boundary conditions instead of Dirichlet conditions with the exact solution",
59)
60parser.add_argument(
61 "--dimensions", type=int, default=2, choices=[2, 3], help="Dimension (default: 2)"
62)
63parser.add_argument(
64 "--build-mode",
65 default="release",
66 choices=["release", "debug"],
67 help="Peano build flavour to link against (default: release)",
68)
69parser.add_argument(
70 "--peano-root",
71 default=os.path.join(
72 os.path.dirname(os.path.abspath(__file__)), "..", "..", "..", ".."
73 ),
74 help="Configured and built Peano directory (default: the repository this script resides in)",
75)
76parser.add_argument(
77 "--verbosity",
78 default="visualisation",
79 choices=["visualisation", "text"],
80 help="Show the task graphs in a window or print them as text (default: visualisation)",
81)
82args = parser.parse_args()
83
84
86 namespace=["benchmarks", "exahype2", "euler", "smooth_convergence_test_fd4"],
87 project_name="smooth-convergence-test-fd4",
88 directory=args.output_directory,
89 executable="smooth-convergence-test-fd4",
90)
91
93 "EulerFD4Smooth", {"rho": 1, "j": args.dimensions, "E": 1}
94)
95solver.add_user_solver_includes(
96 """
97#include <algorithm>
98#include <cmath>
99"""
100)
101
102# Pressure from the conserved quantities. The momentum has Dimensions
103# components, the energy is the last unknown.
104PRESSURE = """
105 constexpr double gamma = 1.4;
106 const double irho = 1.0 / Q[0];
107 double kineticEnergy = 0.0;
108 for (int d=0; d<Dimensions; d++) {
109 kineticEnergy += 0.5 * irho * Q[1+d] * Q[1+d];
110 }
111 const double p = (gamma - 1.0) * (Q[Dimensions+1] - kineticEnergy);
112"""
113
114solver.add_pde_term(
116 implementation=PRESSURE
117 + """
118 const double velocity = Q[1+normal] * irho;
119 F[0] = Q[1+normal];
120 for (int d=0; d<Dimensions; d++) {
121 F[1+d] = velocity * Q[1+d];
122 }
123 F[1+normal] += p;
124 F[Dimensions+1] = velocity * (Q[Dimensions+1] + p);
125"""
126 )
127)
128solver.add_pde_term(
130 implementation=PRESSURE
131 + """
132 const double c = std::sqrt(gamma * p * irho);
133 const double u = Q[1+normal] * irho;
134 lambdaMax[0] = std::max(std::abs(u + c), std::abs(u - c));
135"""
136 )
137)
138
139# Entropy wave: one period of a sine density profile over the domain
140# [-0.1,0.1]^d, constant velocity u=1 along x and constant pressure p=1. The
141# exact solution is rho(x-ut), i.e. the wave is back where it started after
142# t = 0.2. The same setup as exahype2/euler/smooth-convergence-test.
143EXACT_SOLUTION = """
144 constexpr double gamma = 1.4;
145 constexpr double p = 1.0;
146 constexpr double u = 1.0;
147 constexpr double domainLeft = -0.1;
148 constexpr double domainWidth = 0.2;
149 const double rho = 1.0 + 0.2 * std::sin(2.0 * M_PI * (x(0) - u * t - domainLeft) / domainWidth);
150 Q[0] = rho;
151 Q[1] = rho * u;
152 for (int d=1; d<Dimensions; d++) {
153 Q[1+d] = 0.0;
154 }
155 Q[Dimensions+1] = p / (gamma - 1.0) + 0.5 * rho * u * u;
156"""
157solver.add_pde_term(
159 implementation=" constexpr double t = 0.0;\n" + EXACT_SOLUTION
160 )
161)
162if not args.periodic:
163 solver.add_pde_term(
164 exahype2.api.DirichletBoundaryConditions(implementation=EXACT_SOLUTION)
165 )
166
168 solver,
169 patch_size=9,
170 rk_order=args.rk_order,
171 time_step_size=args.time_step_size,
172 cfl_constant=args.cfl_constant,
173)
175 solver, volume_size=args.volume_size
176)
177# The plot files carry 14 significant digits, as the errors of the finer
178# meshes are far below the default precision
180 solver,
181 first_plot_time_stamp=0.0,
182 time_in_between_plots=args.end_time,
183 plotter_precision=14,
184)
185project.add_solver(solver)
186
187project.set_global_simulation_parameters(
188 dimensions=args.dimensions,
189 offset=[-0.1] * args.dimensions,
190 size=[0.2] * args.dimensions,
191 min_end_time=args.end_time,
192 max_end_time=args.end_time,
193 periodic_BC=[args.periodic] * 3,
194)
195project.set_load_balancing(
196 "toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates",
197 "new ::exahype2::LoadBalancingConfiguration()",
198)
199project.compiler = (
200 peano4.api.taskgraph.compiler.CellTaskProducerConsumer.translate_with_fusion
201)
202
203project.set_Peano4_installation(
204 args.peano_root,
205 peano4.api.output.CompileMode.RELEASE
206 if args.build_mode == "release"
207 else peano4.api.output.CompileMode.DEBUG,
208)
209peano4_project = project.generate_Peano4_project(
210 verbosity=peano4.api.LoggerVerbosity.TEXT
211 if args.verbosity == "text"
212 else peano4.api.LoggerVerbosity.VISUALISATION
213)
214peano4_project.generate()
215peano4_project.build(make_clean_first=True)
The conservative flux F(Q) of a hyperbolic PDE.
Definition Flux.py:8
Point-wise initial condition: given the physical position of a single degree of freedom,...
The maximum absolute eigenvalue of the flux Jacobian in a given direction, i.e.
ExaHyPE 2 project.
Definition Project.py:15
Abstract base class for all ExaHyPE 2 solvers.
Definition Solver.py:17
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....