Peano
Loading...
Searching...
No Matches
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
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
14initial_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
38boundary_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
45refinement_criterion = """
46 auto result = ::exahype2::RefinementCommand::Keep;
47 return result;
48"""
49
50limiting_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
79adjust_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
87parser = exahype2.ArgumentParser()
88parser.add_argument(
89 "--friction",
90 type=float,
91 help="Friction parameter.",
92)
93parser.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)
100args = parser.parse_args()
101
102if args.build_mode == "Debug":
103 args.end_time = 1.0
104
105constants = {
106 "g": [9.81, "double"],
107 "phi": [25.0, "double"],
108 "invXi": [1.0 / args.friction, "double"],
109 "hThreshold": [1e-1, "double"],
110}
111constants["mu"] = [
112 math.tan(math.pi / 180.0 * constants["phi"][0]),
113 "double",
114]
115
116size = [1900, 1950]
117max_h = 1.1 * min(size) / (3.0**args.min_depth)
118min_h = max_h * 3.0 ** (-args.amr_levels)
119dg_order = args.degrees_of_freedom - 1
120
121regular_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
122 name="ADERDGSolver",
123 order=dg_order,
124 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
125 auxiliary_variables=0,
126 min_cell_h=min_h,
127 max_cell_h=max_h,
128 time_step_relaxation=0.5,
129)
130
131regular_solver.set_implementation(
132 initial_conditions=initial_conditions,
133 boundary_conditions=boundary_conditions,
134 refinement_criterion=refinement_criterion,
135 flux=flux,
136 ncp=nonconservative_product,
137 max_eigenvalue=eigenvalue
138 + stiff_eigenvalue
139 + """
140 return std::fmax(sFlux, h[normal] * sSource);
141""",
142 diffusive_source_term=stiff_source_term_aderdg,
143 riemann_solver=rusanov_aderdg,
144)
145
146regular_solver.set_plotter(args.plotter)
147regular_solver.add_user_solver_includes(
148 """
149#include "tarch/reader/NetCDFFieldParser.h"
150"""
151)
152regular_solver.add_kernel_optimisations(
153 is_linear=False,
154 polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
155)
156
157limiting_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
158 name="FVSolver",
159 patch_size=dg_order * 2 + 1,
160 unknowns={"h": 1, "hu": 1, "hv": 1},
161 auxiliary_variables={"z": 1},
162 min_volume_h=min_h,
163 max_volume_h=max_h,
164 time_step_relaxation=0.5,
165)
166
167limiting_solver.set_implementation(
168 initial_conditions=initial_conditions,
169 boundary_conditions=boundary_conditions,
170 refinement_criterion=refinement_criterion,
171 flux=flux,
172 max_eigenvalue=eigenvalue
173 + """
174 return sFlux;
175""",
176 ncp=nonconservative_product + stiff_nonconservative_product,
177 riemann_solver=rusanov_fv,
178 diffusive_source_term=stiff_source_term_fv,
179 adjust_solution=adjust_solution,
180)
181
182limiting_solver.set_plotter(args.plotter)
183limiting_solver.add_user_solver_includes(
184 """
185#include "tarch/reader/NetCDFFieldParser.h"
186"""
187)
188
189limiter_solver = exahype2.solvers.limiting.PosterioriLimiting(
190 name="LimiterSolver",
191 regular_solver=regular_solver,
192 limiting_solver=limiting_solver,
193 number_of_dmp_observables=3,
194 dmp_relaxation_parameter=1.0, # MD 3: BOTH FRICTIONS: 1.0, ONLY ONE FRICTION TERM OR ZERO: 0.5,
195 dmp_differences_scaling=0.01, # MD 3: BOTH FRICTIONS: 0.01, ONLY ONE FRICTION TERM OR ZERO: 0.005,
196 physical_admissibility_criterion=limiting_criterion,
197)
198
199project = exahype2.Project(
200 namespace=["applications", "exahype2", "swe"],
201 project_name="TafjordLandslide",
202 directory=".",
203 executable="ExaHyPE-ShallowWater",
204)
205
206project.add_solver(regular_solver)
207project.add_solver(limiting_solver)
208project.add_solver(limiter_solver)
209
210if args.number_of_snapshots <= 0:
211 time_in_between_plots = 0.0
212else:
213 time_in_between_plots = args.end_time / args.number_of_snapshots
214 project.set_output_path(args.output)
215
216project.set_global_simulation_parameters(
217 dimensions=2,
218 size=size,
219 offset=[414895.5, 6904495.5],
220 min_end_time=args.end_time,
221 max_end_time=args.end_time,
222 first_plot_time_stamp=0.0,
223 time_in_between_plots=time_in_between_plots,
224 periodic_BC=[
225 args.periodic_boundary_conditions_x,
226 args.periodic_boundary_conditions_y,
227 ],
228)
229
230project.set_load_balancer(
231 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})"
232)
233project.set_Peano4_installation(
234 "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
235)
236project = project.generate_Peano4_project(verbose=False)
237for const_name, const_info in constants.items():
238 const_val, const_type = const_info
239 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
240project.output.makefile.set_target_device(args.target_device)
241project.set_fenv_handler(args.fpe)
242project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)