Peano
Loading...
Searching...
No Matches
limited-landslide-tsunami.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 peano4, exahype2
4import math
5
6initial_conditions = """
7 // init all to 0.0
8 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
9 Q[i] = 0.0;
10 }
11
12 // landslide model params for granular material
13 double initCenterX = 4.0;
14 double initCenterY = 30;
15 double initRadius = 3.5;
16 double initHeight = 8.0;
17
18 const tarch::la::Vector<DIMENSIONS, double>& granularMaterialCenter = {initCenterX, initCenterY};
19 const bool nearCentre = tarch::la::norm2(x - granularMaterialCenter) < initRadius;
20 Q[Shortcuts::lsh] = (nearCentre ? initHeight : 0.0); // Granular material height (h)
21
22 // swe equation initial conditions
23 Q[Shortcuts::hu] = 0.0;
24 Q[Shortcuts::hv] = 0.0;
25
26 if (x[0] >= 19.5) { // made a smoother transition zone - some water movement at the start
27 Q[Shortcuts::h] = 4.0;
28 } else if (x[0] >= 17.5) {
29 Q[Shortcuts::h] = 4.0 * (x[0] - 17.5) / 2.0;
30 } else {
31 Q[Shortcuts::h] = 0.0;
32 }
33
34 Q[Shortcuts::z] = std::max(20.0 - x[0], 1.0);
35"""
36
37boundary_conditions = """
38 Qoutside[Shortcuts::h] = Qinside[Shortcuts::h];
39 Qoutside[Shortcuts::hu] = -Qinside[Shortcuts::hu];
40 Qoutside[Shortcuts::hv] = -Qinside[Shortcuts::hv];
41 Qoutside[Shortcuts::z] = Qinside[Shortcuts::z];
42
43 Qoutside[Shortcuts::lsh] = 0.;
44 Qoutside[Shortcuts::lshu] = 0.;
45 Qoutside[Shortcuts::lshv] = 0.;
46"""
47
48project = exahype2.Project(
49 namespace=["applications", "exahype2", "landslide"],
50 project_name="LimitedLandslideTsunami",
51 directory=".",
52 executable="ExaHyPE",
53)
54
55project.set_output_path("solutions")
56
57parser = exahype2.ArgumentParser()
58parser.set_defaults(
59 min_depth=4,
60 end_time=30.0,
61)
62args = parser.parse_args()
63
64dimensions = 2
65size = [60.0, 60.0]
66dg_order = args.degrees_of_freedom - 1
67max_h = 1.1 * min(size) / (3.0**args.min_depth)
68min_h = max_h * 3.0 ** (-args.amr_levels)
69
70constants = {
71 "g": [9.81, "double"],
72 "phi": [25.0, "double"],
73 "invXi": [1.0 / 200.0, "double"],
74 "hThreshold": [1e-1, "double"],
75}
76constants["mu"] = [
77 math.tan(math.pi / 180.0 * constants["phi"][0]),
78 "double",
79]
80
81
82unknowns = {"h": 1, "hu": 1, "hv": 1, "lsh": 1, "lshu": 1, "lshv": 1}
83auxiliary_variables = {"z": 1}
84
85aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
86 name="ADERDGSolver",
87 order=dg_order,
88 unknowns={"h": 1, "hu": 1, "hv": 1, "lsh": 1, "lshu": 1, "lshv": 1, "z": 1},
89 auxiliary_variables={},
90 min_cell_h=min_h,
91 max_cell_h=max_h,
92 time_step_relaxation=0.9,
93)
94
95aderdg_solver.set_implementation(
96 flux="""
97 ShallowWater::flux<double, Shortcuts, NumberOfUnknowns>(
98 Q,x,h,t,dt,normal,F
99 );
100
101 landslide::flux<double, Shortcuts>(
102 Q,x,h,t,dt,normal,F
103 );""",
104 ncp="""
105 ShallowWater::nonconservativeProduct<double, Shortcuts, NumberOfUnknowns>(
106 Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ
107 );
108 landslide::nonconservativeProduct<double, Shortcuts>(
109 Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ
110 );""",
111 max_eigenvalue="""
112 return std::fmax(
113 landslide::maxEigenvalue<double, Shortcuts>(
114 Q, x, h, t, dt, normal
115 ),
116 ShallowWater::maxEigenvalue<double, Shortcuts>(
117 Q, x, h, t, dt, normal
118 )
119 );""",
120 boundary_conditions=boundary_conditions,
121 initial_conditions=initial_conditions,
122 # riemann_solver="""
123 # landslide::rusanovRiemannSolverFV<double, Shortcuts, NumberOfUnknowns, NumberOfAuxiliaryVariables>(
124 # QL, QR, x, h, t, dt, direction, FL, FR
125 # );"""
126)
127aderdg_solver.add_user_solver_includes(
128 """
129#include "../RusanovRiemannSolver.h"
130"""
131)
132
133project.add_solver(aderdg_solver)
134
135fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
136 name="FVSolver",
137 min_volume_h=min_h,
138 max_volume_h=max_h,
139 patch_size=dg_order * 2 + 1,
140 unknowns=unknowns,
141 auxiliary_variables=auxiliary_variables,
142 time_step_relaxation=0.45,
143)
144
145fv_solver.set_implementation(
146 flux="""
147 ShallowWater::flux<double, Shortcuts, NumberOfUnknowns>(
148 Q,x,h,t,dt,normal,F
149 );
150
151 landslide::flux<double, Shortcuts>(
152 Q,x,h,t,dt,normal,F
153 );""",
154 ncp="""
155 ShallowWater::nonconservativeProduct<double, Shortcuts, NumberOfUnknowns>(
156 Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ
157 );
158 landslide::nonconservativeProduct<double, Shortcuts>(
159 Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ
160 );""",
161 max_eigenvalue="""
162 return std::fmax(
163 landslide::maxEigenvalue<double, Shortcuts>(
164 Q, x, h, t, dt, normal
165 ),
166 ShallowWater::maxEigenvalue<double, Shortcuts>(
167 Q, x, h, t, dt, normal
168 )
169 );""",
170 boundary_conditions=boundary_conditions,
171 initial_conditions=initial_conditions,
172 diffusive_source_term="""
173landslide::diffusiveSourceTerm<double, Shortcuts, NumberOfUnknowns, NumberOfAuxiliaryVariables>(
174 Q, deltaQ, x, h, t, dt, S
175 );""",
176 riemann_solver="""
177return landslide::rusanovRiemannSolverFV<double, Shortcuts, NumberOfUnknowns, NumberOfAuxiliaryVariables>(
178 QL, QR, x, h, t, dt, normal, FL, FR
179 );""",
180)
181fv_solver.add_user_solver_includes(
182 """
183#include "../RusanovRiemannSolver.h"
184"""
185)
186
187project.add_solver(fv_solver)
188
189limiter_solver = exahype2.solvers.limiting.StaticLimiting(
190 name="LimiterSolver",
191 regular_solver=aderdg_solver,
192 limiting_solver=fv_solver,
193 physical_admissibility_criterion="""
194 return Q[VariableShortcutsADERDGSolver::h] >= hThreshold;""",
195)
196
197project.add_solver(limiter_solver)
198
199if args.number_of_snapshots <= 0:
200 time_in_between_plots = 0.0
201else:
202 time_in_between_plots = args.end_time / args.number_of_snapshots
203 project.set_output_path(args.output)
204
205project.set_global_simulation_parameters(
206 dimensions=dimensions,
207 size=size,
208 offset=[0.0, 0.0],
209 min_end_time=args.end_time,
210 max_end_time=args.end_time,
211 first_plot_time_stamp=0.0,
212 time_in_between_plots=time_in_between_plots,
213 periodic_BC=[False, False],
214)
215
216project.set_load_balancer(
217 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
218)
219project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
220project = project.generate_Peano4_project(verbose=False)
221for const_name, const_info in constants.items():
222 const_val, const_type = const_info
223 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
224project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)