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 peano4
4import exahype2
5
6initial_conditions = """
7 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
8 Q[i] = 0.0;
9 }
10
11 constexpr double InitialWaterHeightDam = 0.9;
12
13 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));
14 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));
15 const double m3 = 1.0 - 0.28 * std::sqrt((x(0) - 28.0) * (x(0) - 28.0) + (x(1) - 15.0) * (x(1) - 15.0));
16
17 Q[Shortcuts::h] = x[0] <= 5.0 ? InitialWaterHeightDam : 0.0;
18 Q[Shortcuts::z] = std::max({0.0, m1, m2, m3});
19"""
20
21boundary_conditions = """
22 Qoutside[Shortcuts::h] = Qinside[Shortcuts::h];
23 Qoutside[Shortcuts::hu] = 0.0;
24 Qoutside[Shortcuts::hv] = 0.0;
25 Qoutside[Shortcuts::z] = Qinside[Shortcuts::z];
26"""
27
28refinement_criterion = """
29 auto result = ::exahype2::RefinementCommand::Keep;
30
31 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));
32 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));
33 const double m3 = 1.0 - 0.28 * std::sqrt((x(0) - 28.0) * (x(0) - 28.0) + (x(1) - 15.0) * (x(1) - 15.0));
34
35 if (m1 > 0.0 or m2 > 0.0 or m3 > 0.0) {
36 result = ::exahype2::RefinementCommand::Refine;
37 }
38
39 return result;
40"""
41
42parser = exahype2.ArgumentParser()
43parser.set_defaults(
44 min_depth=5,
45 degrees_of_freedom=16,
46 end_time=20.0,
47)
48args = parser.parse_args()
49
50constants = {
51 "g": [9.81, "double"],
52 "hThreshold": [1e-3, "double"],
53}
54
55size = [30.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="return augmentedStateRiemannSolver<double, Shortcuts>(QL, QR, x, h, t, dt, normal, FL, FR);",
74)
75
76fv_solver.add_user_solver_includes(
77 """
78#include "../AugmentedStateRiemannSolver.h"
79"""
80)
81
82project = exahype2.Project(
83 namespace=["applications", "exahype2", "ShallowWater"],
84 project_name="ThreeMoundsChannel",
85 directory=".",
86 executable="ExaHyPE",
87)
88project.add_solver(fv_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=size,
99 offset=[0.0, 0.0],
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
110project.set_load_balancer(
111 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
112)
113project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
114project = project.generate_Peano4_project(verbose=False)
115for const_name, const_info in constants.items():
116 const_val, const_type = const_info
117 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
118project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)