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