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 math
4
5import peano4
6import exahype2
7
8initial_conditions = """
9 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
10 Q[i] = 0.0;
11 }
12
13 static tarch::reader::NetCDFFieldParser fieldParser(
14 \"Tafjord_5m_EPSG25832.nc\",
15 \"ini_3.0Mm3_5m_EPSG25832.nc\",
16 DomainSize(0),
17 DomainSize(1),
18 DomainOffset(0),
19 DomainOffset(1),
20 "Band1",
21 "x",
22 "y",
23 "Band1",
24 "x",
25 "y"
26 );
27
28 Q[Shortcuts::h] = fieldParser.sampleDisplacement(x(0), x(1));
29 Q[Shortcuts::z] = fieldParser.sampleTopology(x(0), x(1));
30"""
31
32boundary_conditions = """
33 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
34 Qoutside[i] = Qinside[i];
35 }
36"""
37
38refinement_criterion = """
39 auto result = ::exahype2::RefinementCommand::Keep;
40 return result;
41"""
42
43limiting_criterion = """
44 const auto 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.add_argument(
82 "--friction",
83 type=float,
84 help="Friction parameter.",
85)
86parser.set_defaults(
87 min_depth=3,
88 end_time=40.0,
89 degrees_of_freedom=7,
90 friction=200.0,
91)
92args = parser.parse_args()
93
94if args.build_mode == "Debug":
95 args.end_time = 1.0
96
97constants = {
98 "g": [9.81, "double"],
99 "phi": [25.0, "double"],
100 "invXi": [1.0 / args.friction, "double"],
101 "hThreshold": [1e-1, "double"],
102}
103constants["mu"] = [
104 math.tan(math.pi / 180.0 * constants["phi"][0]),
105 "double",
106]
107
108size = [1900, 1900]
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
113aderdg_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.20,
121)
122
123aderdg_solver.set_implementation(
124 initial_conditions=initial_conditions,
125 boundary_conditions=boundary_conditions,
126 refinement_criterion=refinement_criterion,
127 flux=f"ShallowWater::flux<double, Shortcuts, {aderdg_solver.unknowns}>(Q, x, h, t, dt, normal, F);",
128 max_eigenvalue="return FrictionLaws::maxEigenvalue<double, Shortcuts>(Q, x, h, t, dt, normal);",
129 ncp=f"ShallowWater::nonconservativeProduct<double, Shortcuts, {aderdg_solver.unknowns}>(Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ);",
130 diffusive_source_term=f"FrictionLaws::sourceTermADERDG<double, Shortcuts, {aderdg_solver.unknowns}, {aderdg_solver.auxiliary_variables}>(Q, deltaQ, x, h, t, dt, S);",
131 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);",
132)
133
134aderdg_solver.add_kernel_optimisations(
135 is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre
136)
137aderdg_solver.add_user_solver_includes(
138 """
139#include "../PDE.h"
140#include "../FrictionLaws.h"
141#include "../RusanovRiemannSolver.h"
142#include "tarch/reader/NetCDFFieldParser.h"
143"""
144)
145
146fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
147 name="FVSolver",
148 patch_size=dg_order * 2 + 1,
149 unknowns={"h": 1, "hu": 1, "hv": 1},
150 auxiliary_variables={"z": 1},
151 min_volume_h=min_h,
152 max_volume_h=max_h,
153 time_step_relaxation=0.20,
154)
155
156fv_solver.set_implementation(
157 initial_conditions=initial_conditions,
158 boundary_conditions=boundary_conditions,
159 refinement_criterion=refinement_criterion,
160 adjust_solution=adjust_solution,
161 diffusive_source_term=f"FrictionLaws::sourceTermFV<double, Shortcuts, {fv_solver.unknowns}, {fv_solver.auxiliary_variables}>(Q, deltaQ, x, h, t, dt, S);",
162 riemann_solver=f"return rusanovRiemannSolverFV<double, Shortcuts, {fv_solver.unknowns}, {fv_solver.auxiliary_variables}>(QL, QR, x, h, t, dt, normal, FL, FR);",
163)
164
165fv_solver.add_user_solver_includes(
166 """
167#include "../PDE.h"
168#include "../FrictionLaws.h"
169#include "../RusanovRiemannSolver.h"
170#include "tarch/reader/NetCDFFieldParser.h"
171"""
172)
173
174limiter_solver = exahype2.solvers.limiting.PosterioriLimiting(
175 name="LimiterSolver",
176 regular_solver=aderdg_solver,
177 limiting_solver=fv_solver,
178 number_of_dmp_observables=3,
179 dmp_relaxation_parameter=0.001,
180 dmp_differences_scaling=0.0001,
181 physical_admissibility_criterion=limiting_criterion,
182)
183
184project = exahype2.Project(
185 namespace=["applications", "exahype2", "ShallowWater"],
186 project_name="TafjordLandslide",
187 directory=".",
188 executable="ExaHyPE",
189)
190
191fv_solver.set_plotter(peano4.plotter.NetCDFPatchAMRPlotter)
192aderdg_solver.set_plotter(peano4.plotter.NetCDFPatchNodalPlotter)
193
194project.add_solver(aderdg_solver)
195project.add_solver(fv_solver)
196project.add_solver(limiter_solver)
197
198if args.number_of_snapshots <= 0:
199 time_in_between_plots = 0.0
200else:
201 time_in_between_plots = args.end_time / args.number_of_snapshots
202 project.set_output_path(args.output)
203
204project.set_global_simulation_parameters(
205 dimensions=2,
206 size=size,
207 offset=[414895.5, 6904495.5],
208 min_end_time=args.end_time,
209 max_end_time=args.end_time,
210 first_plot_time_stamp=0.0,
211 time_in_between_plots=time_in_between_plots,
212 periodic_BC=[
213 args.periodic_boundary_conditions_x,
214 args.periodic_boundary_conditions_y,
215 ],
216)
217
218project.set_load_balancer(
219 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
220)
221project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
222project = project.generate_Peano4_project(verbose=False)
223for const_name, const_info in constants.items():
224 const_val, const_type = const_info
225 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
226project.output.makefile.set_target_device(args.target_device)
227project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)