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