Peano
Loading...
Searching...
No Matches
convergence-study.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 study of the entropy wave benchmark
6
7Generates, builds and runs smooth-convergence-test.py for the three
8standard mesh widths (@ref benchmarks_exahype2_euler_smooth_setup), and
9hands the outcome to compute-errors.py. The script exits with a non-zero
10status if the order of the maximum error between the two finest meshes
11falls below the minimum order of the scheme (e.g. 3.5 for rk4fd4, which yields 4.0).
12By default, the study runs the Finite Difference schemes rk1fd4, rk2fd4, rk3fd4 and
13rk4fd4 one after another (each in a subdirectory of the work directory) and fails
14if any of them misses its minimum order.
15
16This is part of the ExaHyPE 2 integration test (skill exahype2:integration-test).
17
18"""
19import argparse
20import os
21import subprocess
22import sys
23
24HERE = os.path.dirname(os.path.abspath(__file__))
25
26MINIMUM_ORDERS = {
27 "fv": 0.8,
28 "fv-optimistic": 0.8,
29 "rk1fd4": 0.8,
30 "rk2fd4": 1.8,
31 "rk3fd4": 2.8,
32 "rk4fd4": 3.5,
33}
34VOLUME_SIZES = ["0.0075", "0.0025", "0.00083"]
35
36parser = argparse.ArgumentParser(description=__doc__.strip().split("\n")[0])
37parser.add_argument(
38 "--work-directory",
39 required=True,
40 help="Directory the runs are built in (outside of the repository)",
41)
42parser.add_argument(
43 "--schemes",
44 nargs="+",
45 default=["rk1fd4", "rk2fd4", "rk3fd4", "rk4fd4"],
46 choices=list(MINIMUM_ORDERS.keys()),
47 help="Numerical schemes, see smooth-convergence-test.py (default: rk1fd4 rk2fd4 rk3fd4 rk4fd4)",
48)
49parser.add_argument(
50 "--minimum-order",
51 type=float,
52 default=None,
53 help="Minimum order between the two finest meshes, for all schemes (default: slightly below the scheme's formal order, e.g. 3.5 for rk4fd4)",
54)
55parser.add_argument(
56 "-j",
57 "--build-jobs",
58 type=int,
59 default=0,
60 help="Parallel make jobs per build; 0 or less uses all cores (default: all cores)",
61)
62args = parser.parse_args()
63
64work = os.path.abspath(args.work_directory)
65os.makedirs(work, exist_ok=True)
66
67
68def study(scheme):
69 minimum_order = args.minimum_order if args.minimum_order is not None else MINIMUM_ORDERS[scheme]
70 print(f"scheme {scheme}", flush=True)
71 runs = []
72 for volume_size in VOLUME_SIZES:
73 run = os.path.join(work, scheme, f"run-{volume_size}")
74 runs.append(run)
75 executable = os.path.join(run, "smooth-convergence-test")
76 if not os.path.exists(
77 os.path.join(run, "solution-EulerSmooth.peano-patch-file")
78 ):
79 print(f"build and run {scheme} {volume_size}", flush=True)
80 subprocess.run(
81 [
82 sys.executable,
83 os.path.join(HERE, "smooth-convergence-test.py"),
84 "--output-directory",
85 run,
86 "--volume-size",
87 volume_size,
88 "--scheme",
89 scheme,
90 "--build-jobs",
91 str(args.build_jobs),
92 "--verbosity",
93 "text",
94 ],
95 check=True,
96 stdout=subprocess.DEVNULL,
97 )
98 with open(os.path.join(run, "run.log"), "w") as log:
99 subprocess.run([executable], cwd=run, check=True, stdout=log, stderr=log)
100 return subprocess.run(
101 [
102 sys.executable,
103 os.path.join(HERE, "compute-errors.py"),
104 "--minimum-order",
105 str(minimum_order),
106 ]
107 + runs
108 ).returncode
109
110
111failed = [scheme for scheme in args.schemes if study(scheme) != 0]
112if failed:
113 print(f"FAILED: {', '.join(failed)}")
114sys.exit(1 if failed else 0)