Peano
Loading...
Searching...
No Matches
fv-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="FVLandslideTsunami",
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
85my_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
86 name="FVSolver",
87 min_volume_h=min_h,
88 max_volume_h=max_h,
89 patch_size=dg_order * 2 + 1,
90 unknowns=unknowns,
91 auxiliary_variables=auxiliary_variables,
92 time_step_relaxation=0.45,
93)
94
95my_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 diffusive_source_term="""
123landslide::diffusiveSourceTerm<double, Shortcuts, NumberOfUnknowns, NumberOfAuxiliaryVariables>(
124 Q, deltaQ, x, h, t, dt, S
125 );""",
126 riemann_solver="""
127return landslide::rusanovRiemannSolverFV<double, Shortcuts, NumberOfUnknowns, NumberOfAuxiliaryVariables>(
128 QL, QR, x, h, t, dt, normal, FL, FR
129 );""",
130)
131my_solver.add_user_solver_includes(
132 """
133#include "../RusanovRiemannSolver.h"
134"""
135)
136
137project.add_solver(my_solver)
138
139if args.number_of_snapshots <= 0:
140 time_in_between_plots = 0.0
141else:
142 time_in_between_plots = args.end_time / args.number_of_snapshots
143 project.set_output_path(args.output)
144
145project.set_global_simulation_parameters(
146 dimensions=dimensions,
147 size=size,
148 offset=[0.0, 0.0],
149 min_end_time=args.end_time,
150 max_end_time=args.end_time,
151 first_plot_time_stamp=0.0,
152 time_in_between_plots=time_in_between_plots,
153 periodic_BC=[False, False],
154)
155
156project.set_load_balancer(
157 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
158)
159project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
160project = project.generate_Peano4_project(verbose=False)
161for const_name, const_info in constants.items():
162 const_val, const_type = const_info
163 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
164project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)