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 sys
5
6import peano4
7import exahype2
8
9sys.path.insert(0, os.path.abspath(".."))
10from PDE import *
11from HLLEM import hllem
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 Q[Shortcuts::h] = x[0] <= 5.0 ? INITIAL_WATER_HEIGHT_DAM : 0.0;
25 Q[Shortcuts::z] = std::max({0.0, m1, m2, m3});
26"""
27
28boundary_conditions = """
29 Qoutside[Shortcuts::h] = Qinside[Shortcuts::h];
30 Qoutside[Shortcuts::hu] = -Qinside[Shortcuts::hu];
31 Qoutside[Shortcuts::hv] = -Qinside[Shortcuts::hv];
32 Qoutside[Shortcuts::z] = Qinside[Shortcuts::z];
33"""
34
35refinement_criterion = """
36 auto result = ::exahype2::RefinementCommand::Keep;
37 if (x(0) >= 20.0 && x(0) <= 50.0) {
38 result = ::exahype2::RefinementCommand::Refine;
39 }
40 return result;
41"""
42
43parser = exahype2.ArgumentParser()
44parser.set_defaults(
45 min_depth=4,
46 end_time=1.0,
47)
48args = parser.parse_args()
49
50constants = {
51 "g": [9.81, "double"],
52 "hThreshold": [1e-5, "double"],
53}
54
55size = [75.0, 30.0]
56max_h = 1.1 * min(size) / (3.0**args.min_depth)
57min_h = max_h * 3.0 ** (-args.amr_levels)
58
59fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
60 name="FVSolver",
61 patch_size=args.degrees_of_freedom,
62 unknowns={"h": 1, "hu": 1, "hv": 1},
63 auxiliary_variables={"z": 1},
64 min_volume_h=min_h,
65 max_volume_h=max_h,
66 time_step_relaxation=0.5,
67)
68
69fv_solver.set_implementation(
70 initial_conditions=initial_conditions,
71 boundary_conditions=boundary_conditions,
72 refinement_criterion=refinement_criterion,
73 riemann_solver=hllem,
74)
75
76fv_solver.set_plotter(args.plotter)
77
78project = exahype2.Project(
79 namespace=["applications", "exahype2", "swe"],
80 project_name="ThreeMoundsChannel",
81 directory=".",
82 executable="ExaHyPE-ShallowWater",
83)
84project.add_solver(fv_solver)
85
86if args.number_of_snapshots <= 0:
87 time_in_between_plots = 0.0
88else:
89 time_in_between_plots = args.end_time / args.number_of_snapshots
90 project.set_output_path(args.output)
91
92project.set_global_simulation_parameters(
93 dimensions=2,
94 size=size,
95 offset=[0.0, 0.0],
96 min_end_time=args.end_time,
97 max_end_time=args.end_time,
98 first_plot_time_stamp=0.0,
99 time_in_between_plots=time_in_between_plots,
100 periodic_BC=[
101 args.periodic_boundary_conditions_x,
102 args.periodic_boundary_conditions_y,
103 ],
104)
105
106project.set_load_balancer(
107 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})"
108)
109project.set_Peano4_installation(
110 "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
111)
112project = project.generate_Peano4_project(verbose=False)
113for const_name, const_info in constants.items():
114 const_val, const_type = const_info
115 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
116project.set_fenv_handler(args.fpe)
117project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)