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
4import exahype2
5
6initial_conditions_with_input_file = """
7 static tarch::reader::NetCDFFieldParser fieldParser(
8 \"artificial_bath_1000.nc\",
9 \"artificial_displ_1000.nc\",
10 DomainSize(0),
11 DomainSize(1),
12 DomainOffset(0),
13 DomainOffset(1)
14 );
15
16 const double bathymetryBeforeEarthquake = fieldParser.sampleTopology(x(0), x(1));
17 const double displacement = fieldParser.sampleDisplacement(x(0), x(1));
18 const double bathymetryAfterEarthquake = bathymetryBeforeEarthquake + displacement;
19
20 Q[Shortcuts::h] = -std::min(bathymetryBeforeEarthquake, 0.0);
21 Q[Shortcuts::hu] = 0.0;
22 Q[Shortcuts::hv] = 0.0;
23 Q[Shortcuts::z] = bathymetryAfterEarthquake;
24"""
25
26initial_conditions_without_input_file = """
27 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
28 Q[i] = 0.0;
29 }
30
31 constexpr double InitialWaterHeight = 100.0;
32 constexpr double InitialBathymetryBeforeEarthquake = -100.0;
33
34 Q[Shortcuts::h] = InitialWaterHeight;
35
36 auto displacementX = [](double x) { return std::sin((x / 500.0 + 1.0) * tarch::la::PI); };
37 auto displacementY = [](double y) { return -std::pow(y / 500.0, 2) + 1.0; };
38 auto displacement = [&](double x, double y) { return 5.0 * displacementX(x) * displacementY(y); };
39
40 const double bathymetryAfterEarthquake = InitialBathymetryBeforeEarthquake + displacement(x(0), x(1));
41
42 // Assumes offset to be [-5000, -5000]
43 if (std::abs(x(0)) <= 500 and std::abs(x(1)) <= 500) { // Center of domain is [0, 0]
44 Q[Shortcuts::z] = bathymetryAfterEarthquake;
45 } else {
46 Q[Shortcuts::z] = InitialBathymetryBeforeEarthquake;
47 }
48"""
49
50boundary_conditions = """
51 Qoutside[0] = Qinside[0];
52 Qoutside[1] = 0.0;
53 Qoutside[2] = 0.0;
54 Qoutside[3] = Qinside[3];
55"""
56
57refinement_criterion = """
58 auto result = ::exahype2::RefinementCommand::Keep;
59 //if (std::abs(x(0)) <= 500 and std::abs(x(1)) <= 500) { // Center of domain is [0, 0]
60 if (x[0] >= 4500.0 && x[1] >= 4500.0 && x[0] <= 5500.0 && x[1] <= 5500.0) {
61 result = ::exahype2::RefinementCommand::Refine;
62 }
63 return result;
64"""
65
66parser = exahype2.ArgumentParser()
67parser.set_defaults(
68 min_depth=4,
69 end_time=50.0,
70)
71args = parser.parse_args()
72
73constants = {
74 "g": [9.81, "double"],
75 "hThreshold": [1e-5, "double"],
76}
77
78offset = [0.0, 0.0]
79# offset=[-5000, -5000], # [m]
80size = [10000.0, 10000.0] # [m]
81max_h = 1.1 * min(size) / (3.0**args.min_depth)
82min_h = max_h * 3.0 ** (-args.amr_levels)
83
84aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
85 name="ADERDGSolver",
86 order=args.degrees_of_freedom,
87 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
88 auxiliary_variables=0,
89 min_cell_h=min_h,
90 max_cell_h=max_h,
91 time_step_relaxation=0.5,
92)
93
94aderdg_solver.set_implementation(
95 initial_conditions=initial_conditions_with_input_file,
96 boundary_conditions=boundary_conditions,
97 refinement_criterion=refinement_criterion,
98 flux=f"ShallowWater::flux<double, Shortcuts, {aderdg_solver.unknowns}>(Q, x, h, t, dt, normal, F);",
99 max_eigenvalue="return ShallowWater::maxEigenvalue<double, Shortcuts>(Q, x, h, t, dt, normal);",
100 ncp=f"ShallowWater::nonconservativeProduct<double, Shortcuts, {aderdg_solver.unknowns}>(Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ);",
101)
102
103aderdg_solver.add_kernel_optimisations(
104 is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre
105)
106aderdg_solver.add_user_solver_includes(
107 """
108#include "../PDE.h"
109#include "tarch/reader/NetCDFFieldParser.h"
110"""
111)
112
113project = exahype2.Project(
114 namespace=["applications", "exahype2", "ShallowWater"],
115 project_name="ArtificialTsunami",
116 directory=".",
117 executable="ExaHyPE",
118)
119project.add_solver(aderdg_solver)
120
121if args.number_of_snapshots <= 0:
122 time_in_between_plots = 0.0
123else:
124 time_in_between_plots = args.end_time / args.number_of_snapshots
125 project.set_output_path(args.output)
126
127project.set_global_simulation_parameters(
128 dimensions=2,
129 size=size,
130 offset=offset,
131 min_end_time=args.end_time,
132 max_end_time=args.end_time,
133 first_plot_time_stamp=0.0,
134 time_in_between_plots=time_in_between_plots,
135 periodic_BC=[
136 args.periodic_boundary_conditions_x,
137 args.periodic_boundary_conditions_y,
138 ],
139)
140
141project.set_load_balancer(
142 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
143)
144project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
145project = project.generate_Peano4_project(verbose=False)
146for const_name, const_info in constants.items():
147 const_val, const_type = const_info
148 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
149project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)