Peano
Loading...
Searching...
No Matches
gauge-wave-fv.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
3import argparse
4
5import peano4
6import exahype2
7
8size=[1.0, 1.0, 1.0]
9offset=[-0.5, -0.5, -0.5]
10end_time = 1.0
11plot_interval = 0.0
12#periodic_BC = [True, True, True]
13periodic_BC = [False, False, False]
14
15floatparams = {
16 "GLMc0": 1.5,
17 "GLMc": 1.2,
18 "GLMd": 2.0,
19 "GLMepsA": 1.0,
20 "GLMepsP": 1.0,
21 "GLMepsD": 1.0,
22 "itau": 1.0,
23 "k1": 0.1,
24 "k2": 0.0,
25 "k3": 0.5,
26 "eta": 1.0,
27 "f": 0.75,
28 "g": 0.0,
29 "xi": 1.0,
30 "e": 1.0,
31 "c": 1.0,
32 "mu": 0.2,
33 "ds": 1.0,
34 "sk": 0.0,
35 "bs": 0.0,
36 "domain_r": 0.5,
37 "smoothing": 0.0,
38 "KOSigma": 8.0,
39}
40
41intparams = {
42 "BBHType": 2,
43 "LapseType": 0,
44 "tp_grid_setup": 0,
45 "swi": 99,
46 "ReSwi": 1,
47 "SO": 0,
48}
49
50if __name__ == "__main__":
51 parser = argparse.ArgumentParser(
52 description="ExaHyPE 2 - CCZ4 Finite Volume Benchmarking Script"
53 )
54 parser.add_argument(
55 "-md",
56 "--min-depth",
57 type=float,
58 default=3,
59 help="Determines maximum size of a single cell on each axis.",
60 )
61 parser.add_argument(
62 "-amr",
63 "--amr-levels",
64 type=int,
65 default=0,
66 help="Number of AMR grid levels on top of max. size of a cell.",
67 )
68 parser.add_argument(
69 "-ps",
70 "--patch-size",
71 type=int,
72 default=9,
73 help="Number of finite volumes per axis (dimension) per patch.",
74 )
75
76 for k, v in floatparams.items():
77 parser.add_argument(
78 "--{}".format(k),
79 dest="CCZ4{}".format(k),
80 type=float,
81 default=v,
82 help="default: %(default)s",
83 )
84 for k, v in intparams.items():
85 parser.add_argument(
86 "--{}".format(k),
87 dest="CCZ4{}".format(k),
88 type=int,
89 default=v,
90 help="default: %(default)s",
91 )
92
93 args = parser.parse_args()
94
95 class CCZ4Solver(exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep):
97 self, name, patch_size, min_volume_h, max_volume_h, cfl, domain_r, KOSig
98 ):
99 unknowns = {
100 "G": 6, # 0-5
101 "K": 6, # 6-11
102 "theta": 1, # 12
103 "Z": 3, # 13-15
104 "lapse": 1, # 16
105 "shift": 3, # 17-19
106 "b": 3, # 20-22
107 "dLapse": 3, # 23-25
108 "dxShift": 3, # 26-28
109 "dyShift": 3, # 29-31
110 "dzShift": 3, # 32-34
111 "dxG": 6, # 35-40
112 "dyG": 6, # 41-46
113 "dzG": 6, # 47-52
114 "traceK": 1, # 53
115 "phi": 1, # 54
116 "P": 3, # 55-57
117 "K0": 1, # 58
118 }
119
120 number_of_unknowns = sum(unknowns.values())
121
123#include "../../../../applications/exahype2/ccz4/CCZ4Kernels.h"
124"""
125 super(CCZ4Solver, self).__init__(
126 name=name,
127 patch_size=patch_size,
128 unknowns=number_of_unknowns,
129 auxiliary_variables=0,
130 min_volume_h=min_volume_h,
131 max_volume_h=max_volume_h,
132 time_step_relaxation=cfl,
133 )
134
135 self._patch_size = patch_size
136 self._domain_r = domain_r
137
138 self.set_implementation(
139 boundary_conditions=exahype2.solvers.PDETerms.User_Defined_Implementation,
140 refinement_criterion=exahype2.solvers.PDETerms.User_Defined_Implementation,
141 flux=exahype2.solvers.PDETerms.None_Implementation,
142 ncp="""
143 double gradQSerialised[NumberOfUnknowns * 3];
144 for (int i = 0; i < NumberOfUnknowns; i++) {
145 gradQSerialised[i + 0 * NumberOfUnknowns] = 0.0;
146 gradQSerialised[i + 1 * NumberOfUnknowns] = 0.0;
147 gradQSerialised[i + 2 * NumberOfUnknowns] = 0.0;
148 gradQSerialised[i + normal * NumberOfUnknowns] = deltaQ[i];
149 }
150 applications::exahype2::ccz4::ncp(
151 BTimesDeltaQ,
152 Q,
153 gradQSerialised,
154 normal,
155 CCZ4LapseType,
156 CCZ4ds,
157 CCZ4c,
158 CCZ4e,
159 CCZ4f,
160 CCZ4bs,
161 CCZ4sk,
162 CCZ4xi,
163 CCZ4mu,
164 CCZ4SO
165 );
166""",
167 source_term="""
168 std::memset(S, 0, NumberOfUnknowns * sizeof(double));
169 applications::exahype2::ccz4::source(
170 S,
171 Q,
172 CCZ4LapseType,
173 CCZ4ds,
174 CCZ4c,
175 CCZ4e,
176 CCZ4f,
177 CCZ4bs,
178 CCZ4sk,
179 CCZ4xi,
180 CCZ4itau,
181 CCZ4eta,
182 CCZ4k1,
183 CCZ4k2,
184 CCZ4k3,
185 CCZ4SO
186 );
187""",
188 max_eigenvalue="""
189 const double np = 1.0;
190#if defined(CCZ4EINSTEIN)
191 const double qmin = std::min({Q[0], Q[3], Q[5]});
192 const double alpha = std::max({1.0, Q[16]}) * std::max({1.0, pow(Q[54], 1.0 / np)}) / std::sqrt(qmin);
193#else
194 const double alpha = 1.0;
195#endif
196
197 constexpr double sqrtwo = 1.4142135623730951;
198 // NOTE parameters are stored in abstract superclass
199 const double tempA = alpha * std::max({sqrtwo, CCZ4e, CCZ4ds, CCZ4GLMc / alpha, CCZ4GLMd / alpha});
200 const double tempB = Q[17 + normal]; // DOT_PRODUCT(Q(18:20),nv(:))
201 double tem = std::max({1.0, std::abs(-tempA - tempB), std::abs(tempA - tempB)});
202 bool flag = false;
203 return tem;
204 """,
205 )
206
208 int index = 0;
209 for (int i = 0; i < {{NUMBER_OF_VOLUMES_PER_AXIS}} * {{NUMBER_OF_VOLUMES_PER_AXIS}} * {{NUMBER_OF_VOLUMES_PER_AXIS}}; i++) {
210 applications::exahype2::ccz4::enforceCCZ4constraints(QOut + index);
211 index += {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}};
212 }
213"""
214
215 project = exahype2.Project(
216 namespace=["benchmarks", "exahype2", "ccz4"],
217 project_name="GaugeWave",
218 directory=".",
219 executable="GaugeWaveFV",
220 )
221
222 max_h = (1.1 * min(size) / (3.0**args.min_depth))
223 min_h = max_h * 3.0 ** (-args.amr_levels)
224 my_solver = CCZ4Solver(
225 "CCZ4",
226 args.patch_size,
227 min_h,
228 max_h,
229 0.1,
230 args.CCZ4domain_r,
231 args.CCZ4KOSigma,
232 )
233
234 for k, v in intparams.items():
235 intparams.update({k: eval("args.CCZ4{}".format(k))})
236 for k, v in floatparams.items():
237 floatparams.update({k: eval("args.CCZ4{}".format(k))})
238
239 solverconstants = ""
240 for k, v in floatparams.items():
241 solverconstants += "static constexpr double {} = {};\n".format(
242 "CCZ4{}".format(k), v
243 )
244 for k, v in intparams.items():
245 solverconstants += "static constexpr int {} = {};\n".format(
246 "CCZ4{}".format(k), v
247 )
248 my_solver.add_solver_constants(solverconstants)
249 my_solver.add_user_solver_includes(
250 """
251 #include "CCZ4Kernels.h"
252 #include <cstring>
253 """
254 )
255
256 project.add_solver(my_solver)
257 project.set_global_simulation_parameters(
258 dimensions=3,
259 size=size,
260 offset=offset,
261 min_end_time=end_time,
262 max_end_time=end_time,
263 first_plot_time_stamp=0.0,
264 time_in_between_plots=plot_interval,
265 periodic_BC=periodic_BC,
266 plotter_precision=8
267 )
268
269 if plot_interval > 0.0:
270 project.set_output_path("solutions")
271 project.set_Peano4_installation("../../../..", peano4.output.CompileMode.Release)
272 project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
273 peano4_project = project.generate_Peano4_project(verbose=False)
274 peano4_project.output.makefile.add_header_search_path(
275 "../../../../applications/exahype2/ccz4/"
276 )
277
278 peano4_project.output.makefile.add_CXX_flag("-DCCZ4EINSTEIN")
279
280 peano4_project.output.makefile.add_cpp_file("CCZ4.cpp")
281 peano4_project.output.makefile.add_cpp_file(
282 "../../../../applications/exahype2/ccz4/CCZ4Kernels.cpp"
283 )
284
285 peano4_project.generate(throw_away_data_after_generation=True)
286 peano4_project.build(make_clean_first=True)
__init__(self, name, patch_size, min_volume_h, max_volume_h, cfl, domain_r, KOSig)