Peano
Loading...
Searching...
No Matches
artificial-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.api
4import exahype2
5
6end_time=10.0
7width=[10000, 10000] # [m]
8offset=[-5000, -5000] # [m]
9min_depth=4
10amr_levels=0
11dg_order=5
12number_of_snapshots=0
13build_mode="Release"
14storage="CallStack"
15output="solutions"
16load_balancing_strategy="SpreadOutOnceGridStagnates"
17load_balancing_quality=0.99
18trees=-2
19
20initial_conditions = """
21 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
22 Q[i] = 0.0;
23 }
24
25 constexpr double INITIAL_WATER_HEIGHT = 100.0;
26 constexpr double INITIAL_BATHYMETRY_BEFORE_EARTHQUAKE = -100.0;
27
28 using s = VariableShortcuts;
29 Q[s::h] = INITIAL_WATER_HEIGHT;
30
31 auto displacementX = [](double x) { return std::sin((x / 500.0 + 1.0) * std::numbers::pi); };
32 auto displacementY = [](double y) { return -std::pow(y / 500.0, 2) + 1.0; };
33 auto displacement = [&](double x, double y) { return 5.0 * displacementX(x) * displacementY(y); };
34
35 const double bathymetryAfterEarthquake = INITIAL_BATHYMETRY_BEFORE_EARTHQUAKE + displacement(x(0), x(1));
36
37 if (std::abs(x(0)) <= 500 and std::abs(x(1)) <= 500) { // Center of domain is [0, 0]
38 Q[s::b] = bathymetryAfterEarthquake;
39 } else {
40 Q[s::b] = INITIAL_BATHYMETRY_BEFORE_EARTHQUAKE;
41 }
42"""
43
44boundary_conditions = """
45 using s = VariableShortcuts;
46 Qoutside[s::h] = Qinside[s::h];
47 Qoutside[s::hu] = -Qinside[s::hu];
48 Qoutside[s::hv] = -Qinside[s::hv];
49 Qoutside[s::b] = Qinside[s::b];
50"""
51
52refinement_criterion = """
53 auto result = ::exahype2::RefinementCommand::Keep;
54 if (std::abs(x(0)) <= 500 and std::abs(x(1)) <= 500) { // Center of domain is [0, 0]
55 result = ::exahype2::RefinementCommand::Refine;
56 }
57 return result;
58"""
59
60max_h = (1.1 * min(width) / (3.0**min_depth))
61min_h = max_h * 3.0 ** (-amr_levels)
62
63aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
64 name="ADERDG" + str(dg_order),
65 order=dg_order,
66 unknowns={"h": 1, "hu": 1, "hv": 1, "b": 1},
67 auxiliary_variables=0,
68 min_cell_h=min_h,
69 max_cell_h=max_h,
70 time_step_relaxation=0.5,
71 initial_conditions=initial_conditions,
72 boundary_conditions=boundary_conditions,
73 refinement_criterion=refinement_criterion,
74 flux="applications::exahype2::swe::flux(Q, x, h, t, dt, normal, F);",
75 ncp="applications::exahype2::swe::nonconservativeProduct(Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ);",
76 eigenvalues="return applications::exahype2::swe::maxEigenvalue(Q, x, h, t, dt, normal);",
77)
78aderdg_solver.plot_description = ", ".join({"h": 1, "hu": 1, "hv": 1, "b": 1}.keys())
79aderdg_solver.switch_storage_scheme(exahype2.solvers.Storage[storage], exahype2.solvers.Storage[storage])
80aderdg_solver.add_kernel_optimisations(is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre)
81aderdg_solver.add_user_solver_includes(
82 """
83#include "../../../../applications/exahype2/shallow-water/SWE.h"
84"""
85)
86
87project = exahype2.Project(
88 namespace=["benchmarks", "exahype2", "swe"],
89 project_name="ArtificialTsunami",
90 directory=".",
91 executable=f"ArtificialTsunami.{build_mode}",
92)
93project.add_solver(aderdg_solver)
94
95if number_of_snapshots <= 0:
96 time_in_between_plots = 0.0
97else:
98 time_in_between_plots = end_time / number_of_snapshots
99 project.set_output_path(output)
100
101project.set_global_simulation_parameters(
102 dimensions=2,
103 size=width,
104 offset=offset,
105 min_end_time=end_time,
106 max_end_time=end_time,
107 first_plot_time_stamp=0.0,
108 time_in_between_plots=time_in_between_plots,
109 periodic_BC=[False, False]
110)
111
112if load_balancing_strategy != "None":
113 strategy = f"toolbox::loadbalancing::strategies::{load_balancing_strategy}"
114 configuration = (
115 f"new ::exahype2::LoadBalancingConfiguration("
116 f"{load_balancing_quality},"
117 f"0,"
118 f"{'false'},"
119 f"{trees},"
120 f"{trees})"
121 )
122 project.set_load_balancing(strategy, configuration)
123
124project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(build_mode))
125project = project.generate_Peano4_project(verbose=True)
126project.set_fenv_handler("FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW")
127
128project.output.makefile.add_CXX_flag("-DGRAV=9.81")
129project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
130
131print(project)
132print(aderdg_solver)