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