Peano
Loading...
Searching...
No Matches
radial-dam-break.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
6define_radial_dam = """
7 constexpr double DamRadius = 1.0;
8
9 const double domainSizeHalfX = DomainSize[0] / 2.0;
10 const double domainSizeHalfY = DomainSize[1] / 2.0;
11
12 const double distanceFromOrigin = std::sqrt(
13 (x[0] - domainSizeHalfX) * (x[0] - domainSizeHalfX) +
14 (x[1] - domainSizeHalfY) * (x[1] - domainSizeHalfY)
15 );
16
17 const bool isInsideDam = distanceFromOrigin <= DamRadius;
18 const bool isOutsideDam = distanceFromOrigin > DamRadius;
19 const bool isDryRing = distanceFromOrigin >= 2 * DamRadius and distanceFromOrigin <= 3 * DamRadius;
20"""
21
22initial_conditions = (
23 define_radial_dam
24 + """
25 constexpr double InitialWaterHeightInsideDam = 1.1;
26 constexpr double InitialWaterHeightOutsideDam = 1.0;
27 constexpr double BathymetryDryRing = 1.2;
28
29 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
30 Q[i] = 0.0;
31 }
32
33 Q[Shortcuts::h] = isInsideDam ? InitialWaterHeightInsideDam : InitialWaterHeightOutsideDam;
34
35 if (isDryRing) {
36 Q[Shortcuts::h] = 0.0; // Dry ring
37 }
38
39 Q[Shortcuts::z] = isDryRing ? BathymetryDryRing : 0.0;
40"""
41)
42
43boundary_conditions = """
44 Qoutside[Shortcuts::h] = Qinside[Shortcuts::h];
45 Qoutside[Shortcuts::hu] = -Qinside[Shortcuts::hu];
46 Qoutside[Shortcuts::hv] = -Qinside[Shortcuts::hv];
47 Qoutside[Shortcuts::z] = Qinside[Shortcuts::z];
48"""
49
50refinement_criterion = (
51 define_radial_dam
52 + """
53 return isInsideDam ? ::exahype2::RefinementCommand::Refine : ::exahype2::RefinementCommand::Keep;
54"""
55)
56
57limiting_criterion = (
58 define_radial_dam
59 + """
60 return distanceFromOrigin < DamRadius * 2; // Everything outside the dam (includes the dry ring) shall be limited
61"""
62)
63
64parser = exahype2.ArgumentParser()
65parser.set_defaults(
66 min_depth=3,
67 end_time=0.1,
68)
69args = parser.parse_args()
70
71constants = {
72 "g": [9.81, "double"],
73 "hThreshold": [1e-5, "double"],
74}
75
76size = [10.0, 10.0]
77max_h = 1.1 * min(size) / (3.0**args.min_depth)
78min_h = max_h * 3.0 ** (-args.amr_levels)
79
80aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
81 name="ADERDGSolver",
82 order=args.degrees_of_freedom,
83 unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
84 auxiliary_variables=0,
85 min_cell_h=min_h,
86 max_cell_h=max_h,
87 time_step_relaxation=0.5,
88)
89
90aderdg_solver.set_implementation(
91 initial_conditions=initial_conditions,
92 boundary_conditions=boundary_conditions,
93 refinement_criterion=refinement_criterion,
94 flux=f"ShallowWater::flux<double, Shortcuts, {aderdg_solver.unknowns}>(Q, x, h, t, dt, normal, F);",
95 max_eigenvalue="return ShallowWater::maxEigenvalue<double, Shortcuts>(Q, x, h, t, dt, normal);",
96 ncp=f"ShallowWater::nonconservativeProduct<double, Shortcuts, {aderdg_solver.unknowns}>(Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ);",
97)
98
99aderdg_solver.add_kernel_optimisations(
100 is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre
101)
102aderdg_solver.add_user_solver_includes(
103 """
104#include "../PDE.h"
105"""
106)
107
108fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
109 name="FVSolver",
110 patch_size=args.degrees_of_freedom * 2 + 1,
111 unknowns={"h": 1, "hu": 1, "hv": 1},
112 auxiliary_variables={"z": 1},
113 min_volume_h=min_h,
114 max_volume_h=max_h,
115 time_step_relaxation=0.5,
116)
117
118fv_solver.set_implementation(
119 initial_conditions=initial_conditions,
120 boundary_conditions=boundary_conditions,
121 refinement_criterion=refinement_criterion,
122 riemann_solver="return hllemRiemannSolver<double, Shortcuts>(QL, QR, x, h, t, dt, normal, FL, FR);",
123)
124
125fv_solver.add_user_solver_includes(
126 """
127#include "../HLLEMRiemannSolver.h"
128"""
129)
130
131limiter_solver = exahype2.solvers.limiting.StaticLimiting(
132 name="LimiterSolver",
133 regular_solver=aderdg_solver,
134 limiting_solver=fv_solver,
135 physical_admissibility_criterion=limiting_criterion,
136)
137
138project = exahype2.Project(
139 namespace=["applications", "exahype2", "ShallowWater"],
140 project_name="RadialDamBreak",
141 directory=".",
142 executable="ExaHyPE",
143)
144
145project.add_solver(aderdg_solver)
146project.add_solver(fv_solver)
147project.add_solver(limiter_solver)
148
149if args.number_of_snapshots <= 0:
150 time_in_between_plots = 0.0
151else:
152 time_in_between_plots = args.end_time / args.number_of_snapshots
153 project.set_output_path(args.output)
154
155project.set_global_simulation_parameters(
156 dimensions=2,
157 size=size,
158 offset=[0.0, 0.0],
159 min_end_time=args.end_time,
160 max_end_time=args.end_time,
161 first_plot_time_stamp=0.0,
162 time_in_between_plots=time_in_between_plots,
163 periodic_BC=[
164 args.periodic_boundary_conditions_x,
165 args.periodic_boundary_conditions_y,
166 ],
167)
168
169project.set_load_balancer(
170 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
171)
172project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
173project = project.generate_Peano4_project(verbose=False)
174for const_name, const_info in constants.items():
175 const_val, const_type = const_info
176 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
177project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)