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