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