Peano
Loading...
Searching...
No Matches
three-mounds-channel.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 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
15 Q[i] = 0.0;
16 }
17
18 constexpr double INITIAL_WATER_HEIGHT_DAM = 0.9;
19
20 const double m1 = 1.0 - 0.10 * std::sqrt((x(0) - 15.0) * (x(0) - 15.0) + (x(1) - 22.5) * (x(1) - 22.5));
21 const double m2 = 1.0 - 0.10 * std::sqrt((x(0) - 15.0) * (x(0) - 15.0) + (x(1) - 7.50) * (x(1) - 7.50));
22 const double m3 = 1.0 - 0.28 * std::sqrt((x(0) - 30.0) * (x(0) - 30.0) + (x(1) - 15.0) * (x(1) - 15.0));
23
24 using s = VariableShortcuts;
25 Q[s::h] = x[0] <= 5.0 ? INITIAL_WATER_HEIGHT_DAM : 0.0;
26 Q[s::b] = std::max({0.0, m1, m2, m3});
27"""
28
29boundary_conditions = """
30 using s = VariableShortcuts;
31 Qoutside[s::h] = Qinside[s::h];
32 Qoutside[s::hu] = -Qinside[s::hu];
33 Qoutside[s::hv] = -Qinside[s::hv];
34 Qoutside[s::b] = Qinside[s::b];
35"""
36
37refinement_criterion = """
38 auto result = ::exahype2::RefinementCommand::Keep;
39 if (x(0) >= 20.0 && x(0) <= 50.0) {
40 result = ::exahype2::RefinementCommand::Refine;
41 }
42 return result;
43"""
44
46parser.set_defaults(
47 end_time=5.0,
48 width=[30.0, 30.0],
49)
50args = parser.parse_args()
51
52max_h = (1.1 * min(args.width) / (3.0**args.min_depth))
53min_h = max_h * 3.0 ** (-args.amr_levels)
54args.patch_size = args.dg_order * 2 + 1
55
56unknowns={"h": 1, "hu": 1, "hv": 1}
57auxiliary_variables={"b": 1}
58
59riemann_solver = exahype2.solvers.fv.riemann.GlobalAdaptiveTimeStep(
60 name="HLLEM" + str(args.patch_size),
61 patch_size=args.patch_size,
62 unknowns=unknowns,
63 auxiliary_variables=auxiliary_variables,
64 min_volume_h=min_h,
65 max_volume_h=max_h,
66 time_step_relaxation=args.time_step_relaxation,
67 pde_terms_without_state=args.stateless,
68 initial_conditions=re.sub(r'\bx\b', 'volumeCentre', initial_conditions),
69 boundary_conditions=boundary_conditions,
70 refinement_criterion=re.sub(r'\bx\b', 'volumeCentre', refinement_criterion),
71 riemann_solver="return applications::exahype2::swe::hllem(QR, QL, FR, FL, LR, LL, xR, xL, h, t, dt, normal, APDQ, AMDQ);",
72)
73riemann_solver.plot_description = ", ".join(unknowns.keys()) + ", "
74riemann_solver.plot_description += ", ".join(auxiliary_variables.keys())
75riemann_solver.switch_storage_scheme(exahype2.solvers.Storage[args.storage], exahype2.solvers.Storage[args.storage])
76riemann_solver.add_user_solver_includes(
77 """
78#include "../HLLEM.h"
79"""
80)
81
82project = exahype2.Project(
83 namespace=["applications", "exahype2", "swe"],
84 project_name="ThreeMoundsChannel",
85 directory=".",
86 executable=f"ThreeMoundsChannel.{args.build_mode}",
87)
88project.add_solver(riemann_solver)
89
90if args.number_of_snapshots <= 0:
91 time_in_between_plots = 0.0
92else:
93 time_in_between_plots = args.end_time / args.number_of_snapshots
94 project.set_output_path(args.output)
95
96project.set_global_simulation_parameters(
97 dimensions=2,
98 size=args.width,
99 offset=args.offset,
100 min_end_time=args.end_time,
101 max_end_time=args.end_time,
102 first_plot_time_stamp=0.0,
103 time_in_between_plots=time_in_between_plots,
104 periodic_BC=[
105 args.periodic_boundary_conditions_x,
106 args.periodic_boundary_conditions_y,
107 ],
108)
109
110if args.load_balancing_strategy != "None":
111 strategy = f"toolbox::loadbalancing::strategies::{args.load_balancing_strategy}"
112 assume_periodic_boundary_conditions = any([
113 args.periodic_boundary_conditions_x,
114 args.periodic_boundary_conditions_y,
115 ])
116 configuration = (
117 f"new ::exahype2::LoadBalancingConfiguration("
118 f"{args.load_balancing_quality},"
119 f"0,"
120 f"{'true' if assume_periodic_boundary_conditions else 'false'},"
121 f"{args.trees},"
122 f"{args.trees})"
123 )
124 project.set_load_balancing(strategy, configuration)
125
126project.set_number_of_threads(args.threads)
127project.set_timeout(3600)
128project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
129project = project.generate_Peano4_project(verbose=True)
130if args.fpe:
131 project.set_fenv_handler("FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW")
132
133project.output.makefile.add_CXX_flag("-DGRAV=9.81")
134project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
135
136print(args)
137print(project)
138print(riemann_solver)