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 os
4import sys
5
6import peano4
7import exahype2
8
9sys.path.insert(0, os.path.abspath("../../../../applications/exahype2/shallow-water"))
10from PDE import *
11
12end_time = 10.0
13size = [10000, 10000] # [m]
14offset = [-5000, -5000] # [m]
15min_depth = 4
16amr_levels = 0
17dg_order = 5
18number_of_snapshots = 0
19build_mode = "Release"
20output = "solutions"
21
22initial_conditions = """
23 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
24 Q[i] = 0.0;
25 }
26
27 constexpr double INITIAL_WATER_HEIGHT = 100.0;
28 constexpr double INITIAL_BATHYMETRY_BEFORE_EARTHQUAKE = -100.0;
29
30 Q[Shortcuts::h] = INITIAL_WATER_HEIGHT;
31
32 auto displacementX = [](double x) { return std::sin((x / 500.0 + 1.0) * tarch::la::PI); };
33 auto displacementY = [](double y) { return -std::pow(y / 500.0, 2) + 1.0; };
34 auto displacement = [&](double x, double y) { return 5.0 * displacementX(x) * displacementY(y); };
35
36 const double bathymetryAfterEarthquake = INITIAL_BATHYMETRY_BEFORE_EARTHQUAKE + displacement(x(0), x(1));
37
38 if (std::abs(x(0)) <= 500 and std::abs(x(1)) <= 500) { // Center of domain is [0, 0]
39 Q[Shortcuts::z] = bathymetryAfterEarthquake;
40 } else {
41 Q[Shortcuts::z] = INITIAL_BATHYMETRY_BEFORE_EARTHQUAKE;
42 }
43"""
44
45boundary_conditions = """
46 Qoutside[Shortcuts::h] = Qinside[Shortcuts::h];
47 Qoutside[Shortcuts::hu] = -Qinside[Shortcuts::hu];
48 Qoutside[Shortcuts::hv] = -Qinside[Shortcuts::hv];
49 Qoutside[Shortcuts::z] = Qinside[Shortcuts::z];
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
60constants = {
61 "g": [9.81, "double"],
62 "hThreshold": [1e-5, "double"],
63}
64
65max_h = 1.1 * min(size) / (3.0**min_depth)
66min_h = max_h * 3.0 ** (-amr_levels)
67
68aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
69 name="ADERDGSolver",
70 order=dg_order,
71 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
72 auxiliary_variables=0,
73 min_cell_h=min_h,
74 max_cell_h=max_h,
75 time_step_relaxation=0.5,
76)
77
78aderdg_solver.set_implementation(
79 initial_conditions=initial_conditions,
80 boundary_conditions=boundary_conditions,
81 refinement_criterion=refinement_criterion,
82 flux=flux,
83 ncp=nonconservative_product,
84 max_eigenvalue=eigenvalue + """
85 return sFlux;
86""",
87)
88
89aderdg_solver.add_kernel_optimisations(is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre)
90
91project = exahype2.Project(
92 namespace=["benchmarks", "exahype2", "swe"],
93 project_name="ArtificialTsunami",
94 directory=".",
95 executable=f"ArtificialTsunami",
96)
97project.add_solver(aderdg_solver)
98
99if number_of_snapshots <= 0:
100 time_in_between_plots = 0.0
101else:
102 time_in_between_plots = end_time / number_of_snapshots
103 project.set_output_path(output)
104
105project.set_global_simulation_parameters(
106 dimensions=2,
107 size=size,
108 offset=offset,
109 min_end_time=end_time,
110 max_end_time=end_time,
111 first_plot_time_stamp=0.0,
112 time_in_between_plots=time_in_between_plots,
113 periodic_BC=[False, False],
114)
115
116project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
117project.set_Peano4_installation("../../../../", mode=peano4.output.string_to_mode(build_mode))
118project = project.generate_Peano4_project(verbose=False)
119for const_name, const_info in constants.items():
120 const_val, const_type = const_info
121 project.constants.export_constexpr_with_type(
122 const_name, str(const_val), const_type
123 )
124project.set_fenv_handler(True)
125project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)