Peano
Loading...
Searching...
No Matches
meteotsunami-gulf-of-mexico.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
6physical_offset = [-1514683.37644735, -1108652.87362612]
7physical_size = [3029257.84023389, 2284903.696092]
8square_side = max(physical_size)
9
10offset = [
11 physical_offset[0] - 0.5 * (square_side - physical_size[0]),
12 physical_offset[1] - 0.5 * (square_side - physical_size[1]),
13]
14size = [square_side, square_side]
15
16initial_conditions = """
17 static tarch::reader::NetCDFFieldParser fieldParser(
18 "bathymetry/gebco_projection.nc",
19 PhysicalDomainSizeX,
20 PhysicalDomainSizeY,
21 PhysicalDomainOffsetX,
22 PhysicalDomainOffsetY,
23 "Band1",
24 "x",
25 "y"
26 );
27
28 const double bathymetry = fieldParser.sampleTopology(x(0), x(1));
29
30 if (bathymetry < -15000) {
31 Q[Shortcuts::h] = 999;
32 Q[Shortcuts::hu] = 0.0;
33 Q[Shortcuts::hv] = 0.0;
34 Q[Shortcuts::z] = -999;
35 } else {
36 Q[Shortcuts::h] = -std::min(bathymetry, 0.0);
37 Q[Shortcuts::hu] = 0.0;
38 Q[Shortcuts::hv] = 0.0;
39 Q[Shortcuts::z] = bathymetry;
40 }
41"""
42
43boundary_conditions = """
44 Qoutside[0] = Qinside[0];
45 Qoutside[1] = 0.0;
46 Qoutside[2] = 0.0;
47 Qoutside[3] = Qinside[3];
48"""
49
50is_physically_admissible = """
51 // Low values of h are resolved on FV layer
52 if (tarch::la::smallerEquals(Q[0], 10.0 /*hThreshold*/)) {
53 return false;
54 }
55
56 // Limit close to boundaries
57 if (std::abs(x[0] - DomainOffset[0]) < h[0] or std::abs(x[0] - DomainOffset[0] - DomainSize[0]) < h[0]) {
58 return false;
59 }
60 if (std::abs(x[1] - DomainOffset[1]) < h[1] or std::abs(x[1] - DomainOffset[1] - DomainSize[1]) < h[1]) {
61 return false;
62 }
63
64 // Right
65 if (x(0) - PhysicalDomainOffsetX > 0.6 * PhysicalDomainSizeX) {
66 return false;
67 }
68
69 // Bottom
70 if (x(1) - PhysicalDomainOffsetY < 0.4 * PhysicalDomainSizeY) {
71 return false;
72 }
73
74 // Left
75 if (x(0) - PhysicalDomainOffsetX < 0.3 * PhysicalDomainSizeX) {
76 return false;
77 }
78
79 // Top
80 if (x(1) - PhysicalDomainOffsetY > 0.85 * PhysicalDomainSizeY) {
81 return false;
82 }
83
84 return true;
85"""
86
87parser = exahype2.ArgumentParser()
88parser.set_defaults(
89 min_depth=3,
90 end_time=100.0, # 50000.0,
91 degrees_of_freedom=7,
92)
93args = parser.parse_args()
94
95constants = {
96 "g": [9.81, "double"],
97 "hThreshold": [1e-5, "double"],
98 "PhysicalDomainOffsetX": [physical_offset[0], "double"],
99 "PhysicalDomainOffsetY": [physical_offset[1], "double"],
100 "PhysicalDomainSizeX": [physical_size[0], "double"],
101 "PhysicalDomainSizeY": [physical_size[1], "double"],
102 "aeaEllipsoidA": [
103 6378137.0,
104 "double",
105 ], # Semi-major axis of the WGS84 ellipsoid (in meters)
106 "aeaEllipsoidE": [
107 0.08181919084262157,
108 "double",
109 ], # First numerical eccentricity of the WGS84 ellipsoid
110 "aeaStdParallel1": [18.3333333, "double"], # Standard Parallel 1 (degrees)
111 "aeaStdParallel2": [31.6666667, "double"], # Standard Parallel 2 (degrees)
112 "aeaLon0": [-84.0, "double"], # Central Meridian (degrees)
113 "aeaLat0": [25.0, "double"], # Latitude of Origin (degrees)
114 "aeaEarthRadius": [6371000.0, "double"], # Projection Earth Radius
115 "pointLonA": [-85.107, "double"],
116 "pointLatA": [30.747, "double"],
117 "pointLonB": [-81.562, "double"],
118 "pointLatB": [23.4480, "double"],
119 "water_density": [1000, "double"],
120 "coriolis_omega": [7.2921150e-5, "double"],
121 "manning_param": [0.025, "double"],
122}
123
124args.min_depth = 3
125max_h = 1.1 * min(physical_size) / (3.0**args.min_depth)
126min_h = max_h * 3.0 ** (-args.amr_levels)
127dg_order = args.degrees_of_freedom - 1
128
129aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
130 name="ADERDGSolver",
131 order=dg_order,
132 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
133 auxiliary_variables=0,
134 min_cell_h=min_h,
135 max_cell_h=max_h,
136 time_step_relaxation=0.9,
137)
138
139aderdg_solver.set_implementation(
140 initial_conditions=initial_conditions,
141 boundary_conditions=boundary_conditions,
142 flux=f"ShallowWater::flux<double, Shortcuts, {aderdg_solver.unknowns}>(Q, x, h, t, dt, normal, F);",
143 ncp=f"ShallowWater::nonconservativeProduct<double, Shortcuts, {aderdg_solver.unknowns}>(Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ);",
144 max_eigenvalue="return ShallowWater::maxEigenvalue<double, Shortcuts>(Q,x,h,t,dt,normal);",
145 riemann_solver="""
146 // Compute max eigenvalue over face
147 double smax = 0.0;
148 for(int xy=0; xy<Order+1; xy++){
149 smax = std::max(smax, maxEigenvalue(&QL[xy*4], x, h, t, dt, direction));
150 smax = std::max(smax, maxEigenvalue(&QR[xy*4], x, h, t, dt, direction));
151 }
152
153 for(int xy=0; xy<Order+1; xy++){
154 if (QL[xy*4+0] <= hThreshold or QR[xy*4+0] <= hThreshold) {
155 FR[xy*4+0] = FL[xy*4+0] = 0.0;
156 FR[xy*4+1] = FL[xy*4+1] = 0.0;
157 FR[xy*4+2] = FL[xy*4+2] = 0.0;
158 FR[xy*4+3] = FL[xy*4+3] = 0.0;
159 continue;
160 }
161
162 // h gets added term from bathymetry, u and v are regular Rusanov, b does not change
163 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]) );
164 FL[xy*4+1] = 0.5*(FL[xy*4+1]+FR[xy*4+1] + smax*(QL[xy*4+1]-QR[xy*4+1]) );
165 FL[xy*4+2] = 0.5*(FL[xy*4+2]+FR[xy*4+2] + smax*(QL[xy*4+2]-QR[xy*4+2]) );
166 FL[xy*4+3] = 0.0;
167
168 FR[xy*4+0] = FL[xy*4+0];
169 FR[xy*4+1] = FL[xy*4+1];
170 FR[xy*4+2] = FL[xy*4+2];
171 FR[xy*4+3] = 0.0;
172
173 // Contribution from NCP
174 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]);
175 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]);
176 }
177""",
178 source_term=f"meteotsunami::sourceTerm<double, Shortcuts, {aderdg_solver.unknowns}, {aderdg_solver.auxiliary_variables}>(Q, x, h, t, dt, S);",
179)
180
181aderdg_solver.add_user_solver_includes(
182 """
183#include "../PDE.h"
184#include "SourceTerm.h"
185#include "tarch/reader/NetCDFFieldParser.h"
186"""
187)
188
189fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
190 name="FVSolver",
191 patch_size=dg_order * 2 + 1,
192 unknowns={"h": 1, "hu": 1, "hv": 1},
193 auxiliary_variables={"z": 1},
194 min_volume_h=min_h,
195 max_volume_h=max_h,
196 time_step_relaxation=0.9,
197)
198
199fv_solver.set_implementation(
200 initial_conditions=initial_conditions,
201 boundary_conditions=boundary_conditions,
202 source_term=f"meteotsunami::sourceTerm<double, Shortcuts, {fv_solver.unknowns}, {fv_solver.auxiliary_variables}>(Q, x, h, t, dt, S);",
203 riemann_solver="return fWaveRiemannSolver<double, Shortcuts>(QL, QR, x, h, t, dt, normal, FL, FR);",
204)
205
206fv_solver.add_user_solver_includes(
207 """
208#include "../FWaveRiemannSolver.h"
209#include "SourceTerm.h"
210#include "tarch/reader/NetCDFFieldParser.h"
211"""
212)
213
214limiter_solver = exahype2.solvers.limiting.StaticLimiting(
215 name="LimiterSolver",
216 regular_solver=aderdg_solver,
217 limiting_solver=fv_solver,
218 physical_admissibility_criterion=is_physically_admissible,
219)
220
221project = exahype2.Project(
222 namespace=["applications", "exahype2", "ShallowWater"],
223 project_name="Meteotsunami",
224 directory=".",
225 executable="ExaHyPE",
226)
227
228project.add_solver(aderdg_solver)
229project.add_solver(fv_solver)
230project.add_solver(limiter_solver)
231
232if args.number_of_snapshots <= 0:
233 time_in_between_plots = 0.0
234else:
235 time_in_between_plots = args.end_time / args.number_of_snapshots
236 project.set_output_path(args.output)
237
238project.set_global_simulation_parameters(
239 dimensions=2,
240 size=size,
241 offset=offset,
242 min_end_time=args.end_time,
243 max_end_time=args.end_time,
244 first_plot_time_stamp=0.0,
245 time_in_between_plots=time_in_between_plots,
246 periodic_BC=[
247 args.periodic_boundary_conditions_x,
248 args.periodic_boundary_conditions_y,
249 ],
250)
251
252project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
253project = project.generate_Peano4_project(verbose=False)
254for const_name, const_info in constants.items():
255 const_val, const_type = const_info
256 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
257project.output.makefile.set_target_device(args.target_device)
258project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)