Peano
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
3 import os
4 import sys
5 import math
6 
7 import peano4
8 import exahype2
9 
10 sys.path.insert(0, os.path.abspath(".."))
11 from PDE import *
12 from Rusanov import *
13 
14 # https://arxiv.org/pdf/2106.13572
15 # https://brgm.hal.science/hal-03974933/document
16 initial_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 
31 boundary_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 
38 refinement_criterion = """
39  auto result = ::exahype2::RefinementCommand::Keep;
40  return result;
41 """
42 
43 limiting_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 
72 adjust_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 
80 parser = exahype2.ArgumentParser()
81 parser.set_defaults(
82  min_depth=3,
83  end_time=1.0,
84  time_step_relaxation=0.45,
85  degrees_of_freedom=7,
86 )
87 args = parser.parse_args()
88 
89 problem_constants = {
90  "g" : [9.81, "double"],
91  "phi" : [25.0, "double"],
92  "invXi" : [1.0 / 200.0, "double"],
93  "slopeAngleTan" : [math.tan(math.pi / 180.0 * 35.0), "double"],
94  "initCenterX" : [0.15, "double"],
95  "initCenterY" : [0.79, "double"],
96  "squareSide" : [0.1, "double"],
97  "initHeight" : [0.1, "double"],
98 }
99 problem_constants["hThreshold"] = [problem_constants["initHeight"][0] * 1e-3, "double"]
100 problem_constants["mu"] = [math.tan(math.pi / 180.0 * problem_constants["phi"][0]), "double"]
101 
102 size = [1.58, 1.58]
103 max_h = (1.1 * min(size) / (3.0**args.min_depth))
104 min_h = max_h * 3.0 ** (-args.amr_levels)
105 dg_order = args.degrees_of_freedom - 1
106 
107 regular_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
108  name="ADERDGSolver",
109  order=dg_order,
110  unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
111  auxiliary_variables=0,
112  min_cell_h=min_h,
113  max_cell_h=max_h,
114  time_step_relaxation=args.time_step_relaxation,
115 )
116 
117 regular_solver.set_implementation(
118  initial_conditions=initial_conditions,
119  boundary_conditions=boundary_conditions,
120  refinement_criterion=refinement_criterion,
121  flux=flux,
122  ncp=nonconservative_product,
123  max_eigenvalue=eigenvalue + stiff_eigenvalue + """
124  return std::fmax(sFlux, h[normal] * sSource);
125 """,
126  diffusive_source_term=stiff_source_term_aderdg,
127  riemann_solver=rusanov_aderdg,
128 )
129 
130 regular_solver.set_plotter(args.plotter)
131 regular_solver.add_kernel_optimisations(
132  is_linear=False,
133  polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
134 )
135 
136 limiting_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
137  name="FVSolver",
138  patch_size=dg_order * 2 + 1,
139  unknowns={"h": 1, "hu": 1, "hv": 1},
140  auxiliary_variables={"z": 1},
141  min_volume_h=min_h,
142  max_volume_h=max_h,
143  time_step_relaxation=args.time_step_relaxation,
144 )
145 
146 limiting_solver.set_implementation(
147  initial_conditions=initial_conditions,
148  boundary_conditions=boundary_conditions,
149  refinement_criterion=refinement_criterion,
150  flux=flux,
151  max_eigenvalue=eigenvalue + """
152  return sFlux;
153 """,
154  ncp=nonconservative_product + stiff_nonconservative_product,
155  riemann_solver=rusanov_fv,
156  diffusive_source_term=stiff_source_term_fv,
157  adjust_solution=adjust_solution,
158 )
159 
160 limiting_solver.set_plotter(args.plotter)
161 
162 limiter_solver = exahype2.solvers.limiting.PosterioriLimiting(
163  name="LimiterSolver",
164  regular_solver=regular_solver,
165  limiting_solver=limiting_solver,
166  number_of_dmp_observables=3,
167  dmp_relaxation_parameter=0.20, # MD 3: BOTH FRICTIONS: 0.2, ONLY ONE FRICTION TERM OR ZERO: 0.1,
168  dmp_differences_scaling=1e-3, # MD 3: BOTH FRICTIONS: 1e-3, ONLY ONE FRICTION TERM OR ZERO: 5e-4
169  physical_admissibility_criterion=limiting_criterion,
170 )
171 
172 project = exahype2.Project(
173  namespace=["applications", "exahype2", "swe"],
174  project_name="DamBreakLandslide",
175  directory=".",
176  executable="ExaHyPE-ShallowWater",
177 )
178 
179 project.add_solver(regular_solver)
180 project.add_solver(limiting_solver)
181 project.add_solver(limiter_solver)
182 
183 if args.number_of_snapshots <= 0:
184  time_in_between_plots = 0.0
185 else:
186  time_in_between_plots = args.end_time / args.number_of_snapshots
187  project.set_output_path(args.output)
188 
189 project.set_global_simulation_parameters(
190  dimensions=2,
191  size=size,
192  offset=[0.0, 0.0],
193  min_end_time=args.end_time,
194  max_end_time=args.end_time,
195  first_plot_time_stamp=0.0,
196  time_in_between_plots=time_in_between_plots,
197  periodic_BC=[
198  args.periodic_boundary_conditions_x,
199  args.periodic_boundary_conditions_y,
200  ],
201 )
202 
203 project.set_load_balancer(f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})")
204 project.set_Peano4_installation("../../../../", mode=peano4.output.string_to_mode(args.build_mode))
205 project = project.generate_Peano4_project(verbose=False)
206 for const_name, const_info in problem_constants.items():
207  const_val, const_type = const_info
208  project.constants.export_constexpr_with_type(
209  const_name, str(const_val), const_type
210  )
211 project.output.makefile.set_target_device(args.target_device)
212 project.set_fenv_handler(args.fpe)
213 project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
static double min(double const x, double const y)
str
Definition: ccz4.py:55