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