6 project = exahype2.Project(
7 [
"tests",
"exahype2",
"aderdg"],
".", executable=
"ADERDG-Limiting"
10 parser = exahype2.ArgumentParser(
"ExaHyPE 2 - ADER-DG Limiting Testing Script")
15 args = parser.parse_args()
19 use_limiting = use_aderdg
and use_fv
23 order = args.degrees_of_freedom - 1
27 unknowns = {
"h": 1,
"hu": 1,
"hv": 1,
"z": 1}
30 size = [1.58, 1.58, 1.58][0:dimensions]
31 offset = [0.0, 0.0, 0.0][0:dimensions]
32 max_h = 1.1 *
min(size) / (3.0**args.min_depth)
33 min_h = max_h / (3.0**args.amr_levels)
37 number_of_dmp_observables = 0
38 dmp_differences_scaling = 0.01
39 dmp_relaxation_parameter = 0.02
44 const tarch::la::Vector<DIMENSIONS, double>& granularMaterialCenter = {{ {initCenterX}, {initCenterY} }};
45 const bool nearCentre = tarch::la::norm2(x - granularMaterialCenter) < {initRadius};
46 Q[0] = (nearCentre ? {initHeight} : 0.0); // Granular material height (h)
49 Q[3] = (0.5 + (0.5 * DomainSize[0] - x[0]) * (0.5 * DomainSize[0] - x[0]) / ((0.5 * DomainSize[0] - DomainSize[0]) * (0.5 * DomainSize[0] - DomainSize[0]))) * {amplitude} * std::cos({frequency} * x[0]);
61 "DownTheHyperbolicPar":
"""
62 const tarch::la::Vector<DIMENSIONS, double>& granularMaterialCenter = {{ {initCenterX}, {initCenterY} }};
63 const bool nearCentre = tarch::la::norm2(x - granularMaterialCenter) < {initRadius};
64 Q[0] = (nearCentre ? {initHeight} : 0.0); // Granular material height (h)
67 Q[3] = {initElevationParA} * (x[0] - {initElevationCenterX}) * (x[0] - {initElevationCenterX}) - {initElevationParB} * (x[1] - {initElevationCenterY}) * (x[1] - {initElevationCenterY});
72 "initElevationCenterX": 0.79,
73 "initElevationCenterY": 0.79,
74 "initElevationParA": 1.0,
75 "initElevationParB": 1.0,
81 "DownTheRevolvePar":
"""
82 const tarch::la::Vector<DIMENSIONS, double>& granularMaterialCenter = {{ {initCenterX}, {initCenterY} }};
83 const bool nearCentre = tarch::la::norm2(x - granularMaterialCenter) < {initRadius};
84 Q[0] = (nearCentre ? {initHeight} : 0.0); // Granular material height (h)
87 Q[3] = {initElevationParA} * (x[0] - {initElevationCenterX}) * (x[0] - {initElevationCenterX}) + {initElevationParB} * (x[1] - {initElevationCenterY}) * (x[1] - {initElevationCenterY});
92 "initElevationCenterX": 0.79,
93 "initElevationCenterY": 0.79,
94 "initElevationParA": 1.0,
95 "initElevationParB": 1.0,
101 "DownTheSlopeWithJump":
"""
102 const tarch::la::Vector<DIMENSIONS, double>& granularMaterialCenter = {{ {initCenterX}, {initCenterY} }};
103 const bool nearCentre = tarch::la::norm2(x - granularMaterialCenter) < {initRadius};
104 const double zeta{{ {initZetaDegree} * tarch::la::PI / 180.0}}; // translation from degrees to radians
105 Q[0] = (nearCentre ? {initHeight} : 0.0); // Granular material height (h)
108 Q[3] = (DomainSize[0] - x[0]) * std::tan(zeta);
109 if (tarch::la::greater({jumpX}, x[0])) {{
118 "initZetaDegree": 35,
124 "DownTheSlopeWithPlateau":
"""
125 const tarch::la::Vector<DIMENSIONS, double>& granularMaterialCenter = {{ {initCenterX}, {initCenterY} }};
126 const bool nearCentre = tarch::la::norm2(x - granularMaterialCenter) < {initRadius};
127 const double zeta{{{initZetaDegree} * tarch::la::PI / 180.0}}; // translation from degrees to radians
128 Q[0] = (nearCentre ? {initHeight} : 0.0); // Granular material height (h)
131 if (tarch::la::greater({plateauStartX}, x[0])) {{
132 Q[3] = (DomainSize[0] - x[0]) * std::tan(zeta);
135 if (tarch::la::greater({plateauEndX}, x[0])) {{
136 Q[3] = (DomainSize[0] - {plateauStartX}) * std::tan(zeta);
139 Q[3] = (DomainSize[0] - (x[0] - {plateauEndX} + {plateauStartX})) * std::tan(zeta);
145 "initElevationCenterX": 0.79,
146 "initElevationCenterY": 0.79,
147 "plateauStartX": 0.395,
148 "plateauEndX": 1.185,
149 "initZetaDegree": 35,
156 const tarch::la::Vector<DIMENSIONS, double>& granularMaterialCenter = {{ {initCenterX}, {initCenterY} }};
157 const bool nearCentre = tarch::la::norm2(x - granularMaterialCenter) < {initRadius};
158 const double zeta{{{initZetaDegree} * tarch::la::PI / 180.0}}; // translation from degrees to radians
159 Q[0] = (nearCentre ? {initHeight} : 0.0); // Granular material height (h)
162 Q[3] = (DomainSize[0] - x[0]) * std::tan(zeta);
167 "initZetaDegree": 35,
174 landslide_case =
"DownTheSlope"
175 initial_conditions = landslide_zoo[landslide_case]
177 boundary_conditions = f
"""
178 std::copy_n(Qinside, 4, Qoutside);
179 Qoutside[1] = -Qoutside[1];
180 Qoutside[2] = -Qoutside[2];
184 constexpr double g = {g};
185 constexpr double hThreshold = {hThreshold};
186 if (Q[0] > hThreshold) {{
187 const double un = Q[1 + normal] / Q[0];
188 F[0] = Q[1 + normal];
192 F[1 + normal] += 0.5 * g * Q[0] * Q[0];
203 constexpr double g = {g};
204 constexpr double hThreshold = {hThreshold};
205 if (Q[0] > hThreshold) {{
206 BTimesDeltaQ[0] = 0.0;
207 BTimesDeltaQ[1] = 0.0;
208 BTimesDeltaQ[2] = 0.0;
209 BTimesDeltaQ[3] = 0.0;
210 BTimesDeltaQ[1 + normal] = g * Q[0] * deltaQ[3];
212 BTimesDeltaQ[0] = 0.0;
213 BTimesDeltaQ[1] = 0.0;
214 BTimesDeltaQ[2] = 0.0;
215 BTimesDeltaQ[3] = 0.0;
227 constexpr double g = {g};
228 constexpr double hThreshold = {hThreshold};
229 if(Q[0] > hThreshold) {{
230 const double un = Q[normal+1] / Q[0];
231 const double c = std::sqrt(g * Q[0]);
232 return std::max(std::abs(un - c), std::abs(un + c));
237 adjust_solution = f
"""
238 constexpr double hThreshold = {hThreshold};
239 if (Q[0] < hThreshold) {{
246 riemann_solver_aderdg = f
"""
248 constexpr double g = {g};
249 constexpr double hThreshold = {hThreshold};
250 for(int xy=0; xy<Order+1; xy++){{
251 smax = std::max(smax, maxEigenvalue(&QL[xy*{len(unknowns)}], x, h, t, dt, direction));
252 smax = std::max(smax, maxEigenvalue(&QR[xy*{len(unknowns)}], x, h, t, dt, direction));
255 for(int xy=0; xy<Order+1; xy++){{
256 double fluxLeft[{len(unknowns)}];
257 double fluxRight[{len(unknowns)}];
259 flux(&QL[xy*{len(unknowns)}], x, h, t, dt, direction, fluxLeft);
260 flux(&QR[xy*{len(unknowns)}], x, h, t, dt, direction, fluxRight);
261 for (int varId = 0; varId < {len(unknowns) - 1}; ++varId) {{
262 FL[xy*{len(unknowns)}+varId] = 0.5*(fluxLeft[varId]+fluxRight[varId] + smax*(QL[xy*{len(unknowns)}+varId]-QR[xy*{len(unknowns)}+varId]));
265 for (int varId = 0; varId < {len(unknowns)}; ++varId) {{
266 FR[xy*{len(unknowns)}+varId] = FL[xy*{len(unknowns)}+varId];
269 //Contribution from NCP
270 double AveragedQ[{len(unknowns)}];
271 double DeltaQ[{len(unknowns)}];
272 for (int varId = 0; varId < {len(unknowns)}; ++varId) {{
273 AveragedQ[varId] = 0.5 * (QL[xy*{len(unknowns)} + varId] + QR[xy*{len(unknowns)} + varId]);
274 DeltaQ[varId] = QR[xy*{len(unknowns)} + varId] - QL[xy*{len(unknowns)} + varId];
276 double ncp[{len(unknowns)}];
277 nonconservativeProduct(AveragedQ, DeltaQ, x, h, t, dt, direction, ncp);
278 for (int varId = 0; varId < {len(unknowns)}; ++varId) {{
279 FL[xy*{len(unknowns)}+varId] += 0.5 * ncp[varId];
280 FR[xy*{len(unknowns)}+varId] -= 0.5 * ncp[varId];
282 FL[xy*{len(unknowns)}+{len(unknowns) - 1}] = 0.0;
283 FR[xy*{len(unknowns)}+{len(unknowns) - 1}] = 0.0;
287 riemann_solver_fv = f
"""
289 constexpr double g = {g};
290 constexpr double hThreshold = {hThreshold};
291 smax = std::max(smax, maxEigenvalue(QL, x, h, t, dt, normal));
292 smax = std::max(smax, maxEigenvalue(QR, x, h, t, dt, normal));
294 double fluxLeft[{len(unknowns)}];
295 double fluxRight[{len(unknowns)}];
296 flux(QL, x, h, t, dt, normal, fluxLeft);
297 flux(QR, x, h, t, dt, normal, fluxRight);
298 for (int varId = 0; varId < {len(unknowns) - 1}; ++varId) {{
299 FL[varId] = 0.5*(fluxLeft[varId]+fluxRight[varId] + smax*(QL[varId]-QR[varId]));
302 for (int varId = 0; varId < {len(unknowns)}; ++varId) {{
303 FR[varId] = FL[varId];
306 //Contribution from NCP
307 double AveragedQ[{len(unknowns)}];
308 double DeltaQ[{len(unknowns)}];
309 for (int varId = 0; varId < {len(unknowns)}; ++varId) {{
310 AveragedQ[varId] = 0.5 * (QL[varId] + QR[varId]);
311 DeltaQ[varId] = QR[varId]-QL[varId];
313 double ncp[{len(unknowns)}];
314 nonconservativeProduct(AveragedQ, DeltaQ, x, h, t, dt, normal, ncp);
315 for (int varId = 0; varId < {len(unknowns)}; ++varId) {{
316 FL[varId] += 0.5 * ncp[varId];
317 FR[varId] -= 0.5 * ncp[varId];
320 // the elevation should be constant
321 FL[{len(unknowns) - 1}] = 0.0;
322 FR[{len(unknowns) - 1}] = 0.0;
326 isPhysicallyAdmissible =
"return true;"
327 if with_limiting == 0:
328 isPhysicallyAdmissible =
"return true; //all ADERDG"
329 elif with_limiting == 1:
330 isPhysicallyAdmissible = f
"""
331 // If h is close to zero, it is assumed that limiting is not required.
332 // It allows to reduce the computational intensity, avoiding recalculation
333 // cells with zero heights on the FV layer
334 if (std::abs(Q[0]) < {hThreshold}) {{
338 // Height must be positive!
339 if (Q[0] < {hThreshold}) {{
343 // If non-physical oscillations occur, the wave speed might receive a negative value under the square root.
344 // It results in eigenvalue becoming NaN, which are not marked as TROUBLED, if no isfinte check is performed.
345 for (int i = 0; i < {len(unknowns)}; ++i) {{
346 if (!std::isfinite(Q[i])) {{
351 // Limit close to boundaries
352 if (std::abs(x[0] - DomainOffset[0]) < h[0]
353 || std::abs(x[0] - DomainOffset[0] - DomainSize[0]) < h[0]
354 || std::abs(x[1] - DomainOffset[1]) < h[1]
355 || std::abs(x[1] - DomainOffset[1] - DomainSize[1]) < h[1]
362 isPhysicallyAdmissible =
"return false; //all FV"
365 aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
369 auxiliary_variables=auxiliary,
372 time_step_relaxation=CFL,
374 aderdg_solver.set_implementation(
376 max_eigenvalue=eigenvalues,
377 initial_conditions=initial_conditions,
378 boundary_conditions=boundary_conditions,
380 source_term=source_term,
381 riemann_solver=riemann_solver_aderdg
383 project.add_solver(aderdg_solver)
386 fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
388 patch_size=2 * order + 1,
390 auxiliary_variables=auxiliary,
393 time_step_relaxation=CFL,
395 fv_solver.set_implementation(
397 max_eigenvalue=eigenvalues,
398 initial_conditions=initial_conditions,
399 boundary_conditions=boundary_conditions,
401 source_term=source_term,
402 riemann_solver=riemann_solver_fv,
403 adjust_solution=adjust_solution,
405 project.add_solver(fv_solver)
408 limiter = exahype2.solvers.limiting.PosterioriLimiting(
409 name=
"LimitingSolver",
410 regular_solver=aderdg_solver,
411 limiting_solver=fv_solver,
412 number_of_dmp_observables=number_of_dmp_observables,
413 dmp_relaxation_parameter=dmp_relaxation_parameter,
414 dmp_differences_scaling=dmp_differences_scaling,
415 physical_admissibility_criterion=isPhysicallyAdmissible,
417 project.add_solver(limiter)
419 project.set_output_path(
"solutions")
420 project.set_global_simulation_parameters(
421 dimensions=dimensions,
422 offset=offset[0:dimensions],
423 size=size[0:dimensions],
424 min_end_time=end_time,
425 max_end_time=end_time,
426 first_plot_time_stamp=0.0,
427 time_in_between_plots=plot_interval,
428 periodic_BC=[
False,
False,
False][0:dimensions],
431 project.set_load_balancer(
"new ::exahype2::LoadBalancingConfiguration")
432 project.set_Peano4_installation(
"../../../", mode=peano4.output.string_to_mode(args.build_mode))
433 project = project.generate_Peano4_project(verbose=
False)
434 project.set_fenv_handler(
False)
static double min(double const x, double const y)