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