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