Peano
Loading...
Searching...
No Matches
dam-break-landslide.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 math
4
5import peano4
6import exahype2
7
8# https://arxiv.org/pdf/2106.13572
9# https://brgm.hal.science/hal-03974933/document
10initial_conditions = """
11 // Determine the position of the material region
12 bool insideTheSquare{true};
13 insideTheSquare &= (x[0] >= (initCenterX - squareSide * 0.5));
14 insideTheSquare &= (x[0] <= (initCenterX + squareSide * 0.5));
15 insideTheSquare &= (x[1] >= (initCenterY - squareSide * 0.5));
16 insideTheSquare &= (x[1] <= (initCenterY + squareSide * 0.5));
17
18 // Assign initial conditions based on the position of the material region
19 Q[Shortcuts::h] = (insideTheSquare ? initHeight : 0.0);
20 Q[Shortcuts::hu] = 0.0;
21 Q[Shortcuts::hv] = 0.0;
22 Q[Shortcuts::z] = (DomainSize[0] - x[0]) * slopeAngleTan;
23"""
24
25boundary_conditions = """
26 Qoutside[Shortcuts::h] = Qinside[Shortcuts::h];
27 Qoutside[Shortcuts::hu] = -Qinside[Shortcuts::hu];
28 Qoutside[Shortcuts::hv] = -Qinside[Shortcuts::hv];
29 Qoutside[Shortcuts::z] = Qinside[Shortcuts::z];
30"""
31
32refinement_criterion = """
33 auto result = ::exahype2::RefinementCommand::Keep;
34 return result;
35"""
36
37limiting_criterion = """
38 const double Qh{Q[0]};
39 if (!std::isfinite(Qh)) {
40 return false;
41 }
42
43 // Try not to limit untouched cells initialised with 0.0
44 if ((Qh < hThreshold) and (Qh > -hThreshold)) {
45 return true;
46 }
47
48 // Low values of h are resolved on FV layer
49 if (Qh <= -hThreshold) {
50 return false;
51 }
52
53 // Limit close to boundaries
54 // x - 0
55 if (std::abs(x[0] - DomainOffset[0]) < h[0] or std::abs(x[0] - DomainOffset[0] - DomainSize[0]) < h[0]) {
56 return false;
57 }
58 // y - 1
59 if (std::abs(x[1] - DomainOffset[1]) < h[1] or std::abs(x[1] - DomainOffset[1] - DomainSize[1]) < h[1]) {
60 return false;
61 }
62
63 return true;
64"""
65
66adjust_solution = r"""
67 if (Q[Shortcuts::h] < hThreshold) {
68 Q[Shortcuts::h] = std::fmax(0.0, Q[Shortcuts::h]);
69 Q[Shortcuts::hu] = 0.0;
70 Q[Shortcuts::hv] = 0.0;
71 }
72"""
73
74parser = exahype2.ArgumentParser()
75parser.set_defaults(
76 min_depth=3,
77 end_time=1.0,
78 degrees_of_freedom=7,
79)
80args = parser.parse_args()
81
82if args.build_mode == "Debug":
83 args.end_time = 0.1
84
85problem_constants = {
86 "g": [9.81, "double"],
87 "phi": [25.0, "double"],
88 "invXi": [1.0 / 200.0, "double"],
89 "slopeAngleTan": [math.tan(math.pi / 180.0 * 35.0), "double"],
90 "initCenterX": [0.15, "double"],
91 "initCenterY": [0.79, "double"],
92 "squareSide": [0.1, "double"],
93 "initHeight": [0.1, "double"],
94}
95problem_constants["hThreshold"] = [problem_constants["initHeight"][0] * 1e-3, "double"]
96problem_constants["mu"] = [
97 math.tan(math.pi / 180.0 * problem_constants["phi"][0]),
98 "double",
99]
100
101size = [1.58, 1.58]
102max_h = 1.1 * min(size) / (3.0**args.min_depth)
103min_h = max_h * 3.0 ** (-args.amr_levels)
104dg_order = args.degrees_of_freedom - 1
105
106aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
107 name="ADERDGSolver",
108 order=dg_order,
109 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
110 auxiliary_variables=0,
111 min_cell_h=min_h,
112 max_cell_h=max_h,
113 time_step_relaxation=0.45,
114)
115
116aderdg_solver.set_implementation(
117 initial_conditions=initial_conditions,
118 boundary_conditions=boundary_conditions,
119 refinement_criterion=refinement_criterion,
120 flux=f"ShallowWater::flux<double, Shortcuts, {aderdg_solver.unknowns}>(Q, x, h, t, dt, normal, F);",
121 max_eigenvalue="return FrictionLaws::maxEigenvalue<double, Shortcuts>(Q, x, h, t, dt, normal);",
122 ncp=f"ShallowWater::nonconservativeProduct<double, Shortcuts, {aderdg_solver.unknowns}>(Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ);",
123 diffusive_source_term=f"FrictionLaws::sourceTermADERDG<double, Shortcuts, {aderdg_solver.unknowns}, {aderdg_solver.auxiliary_variables}>(Q, deltaQ, x, h, t, dt, S);",
124 riemann_solver=f"rusanovRiemannSolverADERDG<double, Shortcuts, kernels::{aderdg_solver.name}::Quadrature<double>, {aderdg_solver.unknowns}, {aderdg_solver.auxiliary_variables}, {aderdg_solver.order}>(QL, QR, x, h, t, dt, direction, FL, FR);",
125)
126
127aderdg_solver.add_kernel_optimisations(
128 is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre
129)
130aderdg_solver.add_user_solver_includes(
131 """
132#include "../PDE.h"
133#include "../FrictionLaws.h"
134#include "../RusanovRiemannSolver.h"
135"""
136)
137
138fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
139 name="FVSolver",
140 patch_size=dg_order * 2 + 1,
141 unknowns={"h": 1, "hu": 1, "hv": 1},
142 auxiliary_variables={"z": 1},
143 min_volume_h=min_h,
144 max_volume_h=max_h,
145 time_step_relaxation=0.45,
146)
147
148fv_solver.set_implementation(
149 initial_conditions=initial_conditions,
150 boundary_conditions=boundary_conditions,
151 refinement_criterion=refinement_criterion,
152 adjust_solution=adjust_solution,
153 diffusive_source_term=f"FrictionLaws::sourceTermFV<double, Shortcuts, {fv_solver.unknowns}, {fv_solver.auxiliary_variables}>(Q, deltaQ, x, h, t, dt, S);",
154 riemann_solver=f"return rusanovRiemannSolverFV<double, Shortcuts, {fv_solver.unknowns}, {fv_solver.auxiliary_variables}>(QL, QR, x, h, t, dt, normal, FL, FR);",
155)
156
157fv_solver.add_user_solver_includes(
158 """
159#include "../PDE.h"
160#include "../FrictionLaws.h"
161#include "../RusanovRiemannSolver.h"
162"""
163)
164
165limiter_solver = exahype2.solvers.limiting.PosterioriLimiting(
166 name="LimiterSolver",
167 regular_solver=aderdg_solver,
168 limiting_solver=fv_solver,
169 number_of_dmp_observables=3,
170 dmp_relaxation_parameter=0.2, # MD 3: BOTH FRICTIONS: 0.2, ONLY ONE FRICTION TERM OR ZERO: 0.1,
171 dmp_differences_scaling=1e-3, # MD 3: BOTH FRICTIONS: 1e-3, ONLY ONE FRICTION TERM OR ZERO: 5e-4
172 physical_admissibility_criterion=limiting_criterion,
173)
174
175project = exahype2.Project(
176 namespace=["applications", "exahype2", "ShallowWater"],
177 project_name="DamBreakLandslide",
178 directory=".",
179 executable="ExaHyPE",
180)
181
182project.add_solver(aderdg_solver)
183project.add_solver(fv_solver)
184project.add_solver(limiter_solver)
185
186if args.number_of_snapshots <= 0:
187 time_in_between_plots = 0.0
188else:
189 time_in_between_plots = args.end_time / args.number_of_snapshots
190 project.set_output_path(args.output)
191
192project.set_global_simulation_parameters(
193 dimensions=2,
194 size=size,
195 offset=[0.0, 0.0],
196 min_end_time=args.end_time,
197 max_end_time=args.end_time,
198 first_plot_time_stamp=0.0,
199 time_in_between_plots=time_in_between_plots,
200 periodic_BC=[
201 args.periodic_boundary_conditions_x,
202 args.periodic_boundary_conditions_y,
203 ],
204)
205
206project.set_load_balancer(
207 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
208)
209project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
210project = project.generate_Peano4_project(verbose=False)
211for const_name, const_info in problem_constants.items():
212 const_val, const_type = const_info
213 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
214project.output.makefile.set_target_device(args.target_device)
215project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)