6project = exahype2.Project(
7 [
"tests",
"exahype2",
"aderdg"],
".", executable=
"ExaHyPE"
10parser = exahype2.ArgumentParser(
"ExaHyPE 2 - ADER-DG Limiting Testing Script")
15args = parser.parse_args()
19use_limiting = use_aderdg
and use_fv
23order = args.degrees_of_freedom - 1
27unknowns = {
"h": 1,
"hu": 1,
"hv": 1,
"z": 1}
30size = [1.58, 1.58, 1.58][0:dimensions]
31offset = [0.0, 0.0, 0.0][0:dimensions]
32max_h = 1.1 * min(size) / (3.0**args.min_depth)
33min_h = max_h / (3.0**args.amr_levels)
37number_of_dmp_observables = 0
38dmp_differences_scaling = 0.01
39dmp_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,
174landslide_case =
"DownTheSlope"
175initial_conditions = landslide_zoo[landslide_case]
177boundary_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));
237adjust_solution = f
"""
238 constexpr double hThreshold = {hThreshold};
239 if (Q[0] < hThreshold) {{
246riemann_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;
287riemann_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;
327isPhysicallyAdmissible =
"return true;"
328if with_limiting == 0:
329 isPhysicallyAdmissible =
"return true; //all ADERDG"
330elif with_limiting == 1:
331 isPhysicallyAdmissible = f
"""
332 // If h is close to zero, it is assumed that limiting is not required.
333 // It allows to reduce the computational intensity, avoiding recalculation
334 // cells with zero heights on the FV layer
335 if (std::abs(Q[0]) < {hThreshold}) {{
339 // Height must be positive!
340 if (Q[0] < {hThreshold}) {{
344 // If non-physical oscillations occur, the wave speed might receive a negative value under the square root.
345 // It results in eigenvalue becoming NaN, which are not marked as TROUBLED, if no isfinte check is performed.
346 for (int i = 0; i < {len(unknowns)}; ++i) {{
347 if (!std::isfinite(Q[i])) {{
352 // Limit close to boundaries
353 if (std::abs(x[0] - DomainOffset[0]) < h[0]
354 || std::abs(x[0] - DomainOffset[0] - DomainSize[0]) < h[0]
355 || std::abs(x[1] - DomainOffset[1]) < h[1]
356 || std::abs(x[1] - DomainOffset[1] - DomainSize[1]) < h[1]
363 isPhysicallyAdmissible =
"return false; //all FV"
366 aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
370 auxiliary_variables=auxiliary,
373 time_step_relaxation=CFL,
375 aderdg_solver.set_implementation(
377 max_eigenvalue=eigenvalues,
378 initial_conditions=initial_conditions,
379 boundary_conditions=boundary_conditions,
381 source_term=source_term,
382 riemann_solver=riemann_solver_aderdg,
384 project.add_solver(aderdg_solver)
387 fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
389 patch_size=2 * order + 1,
391 auxiliary_variables=auxiliary,
394 time_step_relaxation=CFL,
396 fv_solver.set_implementation(
398 max_eigenvalue=eigenvalues,
399 initial_conditions=initial_conditions,
400 boundary_conditions=boundary_conditions,
402 source_term=source_term,
403 riemann_solver=riemann_solver_fv,
404 adjust_solution=adjust_solution,
406 project.add_solver(fv_solver)
409 limiter = exahype2.solvers.limiting.PosterioriLimiting(
410 name=
"LimitingSolver",
411 regular_solver=aderdg_solver,
412 limiting_solver=fv_solver,
413 number_of_dmp_observables=number_of_dmp_observables,
414 dmp_relaxation_parameter=dmp_relaxation_parameter,
415 dmp_differences_scaling=dmp_differences_scaling,
416 physical_admissibility_criterion=isPhysicallyAdmissible,
418 project.add_solver(limiter)
420project.set_output_path(
"solutions")
421project.set_global_simulation_parameters(
422 dimensions=dimensions,
423 offset=offset[0:dimensions],
424 size=size[0:dimensions],
425 min_end_time=end_time,
426 max_end_time=end_time,
427 first_plot_time_stamp=0.0,
428 time_in_between_plots=plot_interval,
429 periodic_BC=[
False,
False,
False][0:dimensions],
432project.set_load_balancer(
"new ::exahype2::LoadBalancingConfiguration")
433project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
434project = project.generate_Peano4_project(verbose=
False)