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 os
4import re
5import sys
6
7import peano4.api
8import exahype2
9
10sys.path.insert(0, os.path.abspath(".."))
11from sweargs import SWEArgumentParser
12
13initial_conditions = """
14 static tarch::reader::NetCDFFieldParser fieldParser(
15 \"tohoku_gebco_ucsb3_2000m_hawaii_bath.nc\",
16 \"tohoku_gebco_ucsb3_2000m_hawaii_displ.nc\",
17 DomainSize(0),
18 DomainSize(1),
19 DomainOffset(0),
20 DomainOffset(1)
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 using s = VariableShortcuts;
28 Q[s::h] = -std::min(bathymetryBeforeEarthquake, 0.0);
29 Q[s::hu] = 0.0;
30 Q[s::hv] = 0.0;
31 Q[s::b] = bathymetryAfterEarthquake;
32"""
33
34boundary_conditions = """
35 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
36 Qoutside[i] = Qinside[i];
37 }
38"""
39
40refinement_criterion = """
41 auto result = ::exahype2::RefinementCommand::Keep;
42 if (x(0) <= 2e6 and x(1) >= 2e6) {
43 result = ::exahype2::RefinementCommand::Refine;
44 }
45 return result;
46"""
47
49parser.set_defaults(
50 end_time=1000.0,
51 width=[4e6, 4e6],
52)
53args = parser.parse_args()
54
55max_h = (1.1 * min(args.width) / (3.0**args.min_depth))
56min_h = max_h * 3.0 ** (-args.amr_levels)
57args.patch_size = args.dg_order * 2 + 1
58
59unknowns={"h": 1, "hu": 1, "hv": 1}
60auxiliary_variables={"b": 1}
61
62riemann_solver = exahype2.solvers.fv.riemann.GlobalAdaptiveTimeStep(
63 name="FWave" + str(args.patch_size),
64 patch_size=args.patch_size,
65 unknowns=unknowns,
66 auxiliary_variables=auxiliary_variables,
67 min_volume_h=min_h,
68 max_volume_h=max_h,
69 time_step_relaxation=args.time_step_relaxation,
70 pde_terms_without_state=args.stateless,
71 initial_conditions=re.sub(r'\bx\b', 'volumeCentre', initial_conditions),
72 boundary_conditions=boundary_conditions,
73 refinement_criterion=re.sub(r'\bx\b', 'volumeCentre', refinement_criterion),
74 riemann_solver="return applications::exahype2::swe::fWave(QR, QL, FR, FL, LR, LL, xR, xL, h, t, dt, normal, APDQ, AMDQ);",
75)
76riemann_solver.plot_description = ", ".join(unknowns.keys()) + ", "
77riemann_solver.plot_description += ", ".join(auxiliary_variables.keys())
78riemann_solver.switch_storage_scheme(exahype2.solvers.Storage[args.storage], exahype2.solvers.Storage[args.storage])
79riemann_solver.add_user_solver_includes(
80 """
81#include "../FWave.h"
82#include "tarch/reader/NetCDFFieldParser.h"
83"""
84)
85
86project = exahype2.Project(
87 namespace=["applications", "exahype2", "swe"],
88 project_name="TohokuTsunami",
89 directory=".",
90 executable=f"TohokuTsunami.{args.build_mode}",
91)
92project.add_solver(riemann_solver)
93
94if args.number_of_snapshots <= 0:
95 time_in_between_plots = 0.0
96else:
97 time_in_between_plots = args.end_time / args.number_of_snapshots
98 project.set_output_path(args.output)
99
100project.set_global_simulation_parameters(
101 dimensions=2,
102 size=args.width,
103 offset=args.offset,
104 min_end_time=args.end_time,
105 max_end_time=args.end_time,
106 first_plot_time_stamp=0.0,
107 time_in_between_plots=time_in_between_plots,
108 periodic_BC=[
109 args.periodic_boundary_conditions_x,
110 args.periodic_boundary_conditions_y,
111 ],
112)
113
114if args.load_balancing_strategy != "None":
115 strategy = f"toolbox::loadbalancing::strategies::{args.load_balancing_strategy}"
116 assume_periodic_boundary_conditions = any([
117 args.periodic_boundary_conditions_x,
118 args.periodic_boundary_conditions_y,
119 ])
120 configuration = (
121 f"new ::exahype2::LoadBalancingConfiguration("
122 f"{args.load_balancing_quality},"
123 f"0,"
124 f"{'true' if assume_periodic_boundary_conditions else 'false'},"
125 f"{args.trees},"
126 f"{args.trees})"
127 )
128 project.set_load_balancing(strategy, configuration)
129
130project.set_number_of_threads(args.threads)
131project.set_timeout(3600)
132project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
133project = project.generate_Peano4_project(verbose=True)
134if args.fpe:
135 project.set_fenv_handler("FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW")
136
137project.output.makefile.add_CXX_flag("-DGRAV=9.81")
138project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
139
140print(args)
141print(project)
142print(riemann_solver)