Peano
Loading...
Searching...
No Matches
chile-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 \"chile_gebco_usgs_2000m_bath.nc\",
16 \"chile_gebco_usgs_2000m_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 bool isAdmissible = Q[0] > 100.0;
42
43 tarch::la::Vector<DIMENSIONS, double> bblPos = {3050000., 400000.};
44 isAdmissible &= tarch::la::norm2(x-bblPos) > 5000.;
45
46 tarch::la::Vector<DIMENSIONS, double> blPos = {3050000., 940000.};
47 isAdmissible &= tarch::la::norm2(x-blPos) > 5000.;
48
49 tarch::la::Vector<DIMENSIONS, double> mPos = {5350000., 2320000.};
50 isAdmissible &= tarch::la::norm2(x-mPos) > 25000.;
51
52 tarch::la::Vector<DIMENSIONS, double> tlPos = {3790000., 3360000.};
53 isAdmissible &= tarch::la::norm2(x-tlPos) > 5000.;
54
55 tarch::la::Vector<DIMENSIONS, double> ttlPos = {3665000., 3410000.};
56 isAdmissible &= tarch::la::norm2(x-ttlPos) > 50000.;
57
58 // Juan Fernández Islands
59 tarch::la::Vector<DIMENSIONS, double> jfiPos = {5960000., 1040000.};
60 isAdmissible &= tarch::la::norm2(x-jfiPos) > 10000.;
61
62 return isAdmissible;
63"""
64
65parser = exahype2.ArgumentParser()
66parser.set_defaults(
67 min_depth=4,
68 end_time=5000.0,
69 degrees_of_freedom=7,
70)
71args = parser.parse_args()
72
73constants = {
74 "g": [9.81, "double"],
75 "hThreshold": [1e-5, "double"],
76}
77
78size = [4e6, 4e6]
79offset = [3e6, 0.0]
80max_h = 1.1 * min(size) / (3.0**args.min_depth)
81min_h = max_h * 3.0 ** (-args.amr_levels)
82dg_order = args.degrees_of_freedom - 1
83
84aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
85 name="ADERDGSolver",
86 order=dg_order,
87 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
88 auxiliary_variables=0,
89 min_cell_h=min_h,
90 max_cell_h=max_h,
91 time_step_relaxation=0.9,
92)
93
94aderdg_solver.set_implementation(
95 initial_conditions=initial_conditions,
96 boundary_conditions=boundary_conditions,
97 flux="""
98 double ih = 1.0 / Q[0];
99 F[0] = Q[1 + normal];
100 F[1] = Q[1 + normal] * Q[1] * ih;
101 F[2] = Q[1 + normal] * Q[2] * ih;
102 F[3] = 0.0;
103""",
104 ncp=nonconservative_product,
105 max_eigenvalue=eigenvalue+"""
106 return sFlux;
107""",
108 riemann_solver="""
109 // Compute max eigenvalue over face
110 double smax = 0.0;
111 for(int xy=0; xy<Order+1; xy++){
112 smax = std::max(smax, maxEigenvalue(&QL[xy*4], x, h, t, dt, direction));
113 smax = std::max(smax, maxEigenvalue(&QR[xy*4], x, h, t, dt, direction));
114 }
115
116 for(int xy=0; xy<Order+1; xy++){
117 // h gets added term from bathymetry, u and v are regular Rusanov, b does not change
118 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]) );
119 FL[xy*4+1] = 0.5*(FL[xy*4+1]+FR[xy*4+1] + smax*(QL[xy*4+1]-QR[xy*4+1]) );
120 FL[xy*4+2] = 0.5*(FL[xy*4+2]+FR[xy*4+2] + smax*(QL[xy*4+2]-QR[xy*4+2]) );
121 FL[xy*4+3] = 0.0;
122
123 FR[xy*4+0] = FL[xy*4+0];
124 FR[xy*4+1] = FL[xy*4+1];
125 FR[xy*4+2] = FL[xy*4+2];
126 FR[xy*4+3] = 0.0;
127
128 // Contribution from NCP
129 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]);
130 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]);
131 }
132"""
133)
134
135aderdg_solver.set_plotter(args.plotter)
136aderdg_solver.add_user_solver_includes(
137 """
138#include "tarch/reader/NetCDFFieldParser.h"
139"""
140)
141
142fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
143 name="FVSolver",
144 patch_size=dg_order * 2 + 1,
145 unknowns={"h": 1, "hu": 1, "hv": 1},
146 auxiliary_variables={"z": 1},
147 min_volume_h=min_h,
148 max_volume_h=max_h,
149 time_step_relaxation=0.9,
150)
151
152fv_solver.set_implementation(
153 initial_conditions=initial_conditions,
154 boundary_conditions=boundary_conditions,
155 riemann_solver=fWave,
156)
157
158fv_solver.set_plotter(args.plotter)
159fv_solver.add_user_solver_includes(
160 """
161#include "tarch/reader/NetCDFFieldParser.h"
162"""
163)
164
165limiter_solver = exahype2.solvers.limiting.StaticLimiting(
166 name="LimiterSolver",
167 regular_solver=aderdg_solver,
168 limiting_solver=fv_solver,
169 physical_admissibility_criterion=is_physically_admissible,
170)
171
172project = exahype2.Project(
173 namespace=["applications", "exahype2", "swe"],
174 project_name="ChileTsunami",
175 directory=".",
176 executable="ExaHyPE-ShallowWater",
177)
178
179project.add_solver(aderdg_solver)
180project.add_solver(fv_solver)
181project.add_solver(limiter_solver)
182
183if args.number_of_snapshots <= 0:
184 time_in_between_plots = 0.0
185else:
186 time_in_between_plots = args.end_time / args.number_of_snapshots
187 project.set_output_path(args.output)
188
189project.set_global_simulation_parameters(
190 dimensions=2,
191 size=size,
192 offset=offset,
193 min_end_time=args.end_time,
194 max_end_time=args.end_time,
195 first_plot_time_stamp=0.0,
196 time_in_between_plots=time_in_between_plots,
197 periodic_BC=[
198 args.periodic_boundary_conditions_x,
199 args.periodic_boundary_conditions_y,
200 ],
201)
202
203project.set_load_balancer(
204 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})"
205)
206project.set_Peano4_installation(
207 "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
208)
209project = project.generate_Peano4_project(verbose=False)
210for const_name, const_info in constants.items():
211 const_val, const_type = const_info
212 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
213project.set_fenv_handler(args.fpe)
214project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)