Peano
Loading...
Searching...
No Matches
tohoku-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 os
4import sys
5
6import peano4
7import exahype2
8
9sys.path.insert(0, os.path.abspath(".."))
10from FWave import fWave
11from PDE import nonconservative_product, eigenvalue
12
13initial_conditions = """
14 static tarch::reader::NetCDFFieldParser fieldParser(
15 \"tohoku_gebco_ucsb3_2000m_hawaii_bath.nc\",
16 \"tohoku_gebco_ucsb3_2000m_hawaii_displ.nc\",
17 7000000.0,
18 4000000.0,
19 0.0,
20 0.0
21 );
22
23 const double bathymetryBeforeEarthquake = fieldParser.sampleTopology(x(0), x(1));
24 const double displacement = fieldParser.sampleDisplacement(x(0), x(1));
25 const double bathymetryAfterEarthquake = bathymetryBeforeEarthquake + displacement;
26
27 Q[Shortcuts::h] = -std::min(bathymetryBeforeEarthquake, 0.0);
28 Q[Shortcuts::hu] = 0.0;
29 Q[Shortcuts::hv] = 0.0;
30 Q[Shortcuts::z] = bathymetryAfterEarthquake;
31"""
32
33boundary_conditions = """
34 Qoutside[0] = Qinside[0];
35 Qoutside[1] = 0.0;
36 Qoutside[2] = 0.0;
37 Qoutside[3] = Qinside[3];
38"""
39
40is_physically_admissible = """
41 if (tarch::la::smallerEquals(Q[0], 1000.0)) {
42 return false;
43 }
44 return true;
45"""
46
47parser = exahype2.ArgumentParser()
48parser.set_defaults(
49 min_depth=4,
50 end_time=5000.0,
51 degrees_of_freedom=7,
52)
53args = parser.parse_args()
54
55constants = {
56 "g": [9.81, "double"],
57 "hThreshold": [1e-5, "double"],
58}
59
60size = [4e6, 4e6]
61max_h = 1.1 * min(size) / (3.0**args.min_depth)
62min_h = max_h * 3.0 ** (-args.amr_levels)
63dg_order = args.degrees_of_freedom - 1
64
65aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
66 name="ADERDGSolver",
67 order=dg_order,
68 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
69 auxiliary_variables=0,
70 min_cell_h=min_h,
71 max_cell_h=max_h,
72 time_step_relaxation=0.9,
73)
74
75aderdg_solver.set_implementation(
76 initial_conditions=initial_conditions,
77 boundary_conditions=boundary_conditions,
78 flux="""
79 double ih = 1.0 / Q[0];
80 F[0] = Q[1 + normal];
81 F[1] = Q[1 + normal] * Q[1] * ih;
82 F[2] = Q[1 + normal] * Q[2] * ih;
83 F[3] = 0.0;
84""",
85 ncp=nonconservative_product,
86 max_eigenvalue=eigenvalue+"""
87 return sFlux;
88""",
89 riemann_solver="""
90 // Compute max eigenvalue over face
91 double smax = 0.0;
92 for(int xy=0; xy<Order+1; xy++){
93 smax = std::max(smax, maxEigenvalue(&QL[xy*4], x, h, t, dt, direction));
94 smax = std::max(smax, maxEigenvalue(&QR[xy*4], x, h, t, dt, direction));
95 }
96
97 for(int xy=0; xy<Order+1; xy++){
98 // h gets added term from bathymetry, u and v are regular Rusanov, b does not change
99 FL[xy*4+0] = 0.5*(FL[xy*4+0]+FR[xy*4+0] + smax*(QL[xy*4+0]+QL[xy*4+3]-QR[xy*4+0]-QR[xy*4+3]) );
100 FL[xy*4+1] = 0.5*(FL[xy*4+1]+FR[xy*4+1] + smax*(QL[xy*4+1]-QR[xy*4+1]) );
101 FL[xy*4+2] = 0.5*(FL[xy*4+2]+FR[xy*4+2] + smax*(QL[xy*4+2]-QR[xy*4+2]) );
102 FL[xy*4+3] = 0.0;
103
104 FR[xy*4+0] = FL[xy*4+0];
105 FR[xy*4+1] = FL[xy*4+1];
106 FR[xy*4+2] = FL[xy*4+2];
107 FR[xy*4+3] = 0.0;
108
109 // Contribution from NCP
110 FL[xy*4+direction+1] += 0.5*g*0.5*(QL[xy*4+0]+QR[xy*4+0])*(QR[xy*4+3]+QR[xy*4+0]-QL[xy*4+3]-QL[xy*4+0]);
111 FR[xy*4+direction+1] -= 0.5*g*0.5*(QL[xy*4+0]+QR[xy*4+0])*(QR[xy*4+3]+QR[xy*4+0]-QL[xy*4+3]-QL[xy*4+0]);
112 }
113"""
114)
115
116aderdg_solver.set_plotter(args.plotter)
117aderdg_solver.add_user_solver_includes(
118 """
119#include "tarch/reader/NetCDFFieldParser.h"
120"""
121)
122
123fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
124 name="FVSolver",
125 patch_size=dg_order * 2 + 1,
126 unknowns={"h": 1, "hu": 1, "hv": 1},
127 auxiliary_variables={"z": 1},
128 min_volume_h=min_h,
129 max_volume_h=max_h,
130 time_step_relaxation=0.9,
131)
132
133fv_solver.set_implementation(
134 initial_conditions=initial_conditions,
135 boundary_conditions=boundary_conditions,
136 riemann_solver=fWave
137)
138
139fv_solver.set_plotter(args.plotter)
140fv_solver.add_user_solver_includes(
141 """
142#include "tarch/reader/NetCDFFieldParser.h"
143"""
144)
145
146limiter_solver = exahype2.solvers.limiting.StaticLimiting(
147 name="LimiterSolver",
148 regular_solver=aderdg_solver,
149 limiting_solver=fv_solver,
150 physical_admissibility_criterion=is_physically_admissible,
151)
152
153project = exahype2.Project(
154 namespace=["applications", "exahype2", "swe"],
155 project_name="TohokuTsunami",
156 directory=".",
157 executable="ExaHyPE-ShallowWater",
158)
159
160project.add_solver(aderdg_solver)
161project.add_solver(fv_solver)
162project.add_solver(limiter_solver)
163
164if args.number_of_snapshots <= 0:
165 time_in_between_plots = 0.0
166else:
167 time_in_between_plots = args.end_time / args.number_of_snapshots
168 project.set_output_path(args.output)
169
170project.set_global_simulation_parameters(
171 dimensions=2,
172 size=size,
173 offset=[0.0, 0.0],
174 min_end_time=args.end_time,
175 max_end_time=args.end_time,
176 first_plot_time_stamp=0.0,
177 time_in_between_plots=time_in_between_plots,
178 periodic_BC=[
179 args.periodic_boundary_conditions_x,
180 args.periodic_boundary_conditions_y,
181 ],
182)
183
184project.set_Peano4_installation(
185 "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
186)
187project = project.generate_Peano4_project(verbose=False)
188for const_name, const_info in constants.items():
189 const_val, const_type = const_info
190 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
191project.output.makefile.set_target_device(args.target_device)
192project.set_fenv_handler(args.fpe)
193project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)