9sys.path.insert(0, os.path.abspath(
".."))
10from FWave
import fWave
11from PDE
import nonconservative_product, eigenvalue
13initial_conditions =
"""
14 static tarch::reader::NetCDFFieldParser fieldParser(
15 \"tohoku_gebco_ucsb3_2000m_hawaii_bath.nc\",
16 \"tohoku_gebco_ucsb3_2000m_hawaii_displ.nc\",
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;
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;
33boundary_conditions =
"""
34 Qoutside[0] = Qinside[0];
37 Qoutside[3] = Qinside[3];
40is_physically_admissible =
"""
41 if (tarch::la::smallerEquals(Q[0], 1000.0)) {
47parser = exahype2.ArgumentParser()
53args = parser.parse_args()
56 "g": [9.81,
"double"],
57 "hThreshold": [1e-5,
"double"],
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
65aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
68 unknowns={
"h": 1,
"hu": 1,
"hv": 1,
"z": 1},
69 auxiliary_variables=0,
72 time_step_relaxation=0.9,
75aderdg_solver.set_implementation(
76 initial_conditions=initial_conditions,
77 boundary_conditions=boundary_conditions,
79 double ih = 1.0 / Q[0];
81 F[1] = Q[1 + normal] * Q[1] * ih;
82 F[2] = Q[1 + normal] * Q[2] * ih;
85 ncp=nonconservative_product,
86 max_eigenvalue=eigenvalue+
"""
90 // Compute max eigenvalue over face
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));
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]) );
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];
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]);
116aderdg_solver.set_plotter(args.plotter)
117aderdg_solver.add_user_solver_includes(
119#include "tarch/reader/NetCDFFieldParser.h"
123fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
125 patch_size=dg_order * 2 + 1,
126 unknowns={
"h": 1,
"hu": 1,
"hv": 1},
127 auxiliary_variables={
"z": 1},
130 time_step_relaxation=0.9,
133fv_solver.set_implementation(
134 initial_conditions=initial_conditions,
135 boundary_conditions=boundary_conditions,
139fv_solver.set_plotter(args.plotter)
140fv_solver.add_user_solver_includes(
142#include "tarch/reader/NetCDFFieldParser.h"
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,
153project = exahype2.Project(
154 namespace=[
"applications",
"exahype2",
"swe"],
155 project_name=
"TohokuTsunami",
157 executable=
"ExaHyPE-ShallowWater",
160project.add_solver(aderdg_solver)
161project.add_solver(fv_solver)
162project.add_solver(limiter_solver)
164if args.number_of_snapshots <= 0:
165 time_in_between_plots = 0.0
167 time_in_between_plots = args.end_time / args.number_of_snapshots
168 project.set_output_path(args.output)
170project.set_global_simulation_parameters(
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,
179 args.periodic_boundary_conditions_x,
180 args.periodic_boundary_conditions_y,
184project.set_Peano4_installation(
185 "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
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)