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