Peano
circular-island.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 
12 initial_conditions = """
13  for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
14  Q[i] = 0.0;
15  }
16 
17  static constexpr double h0 = 0.32;
18  static constexpr double A = 0.064;
19  static constexpr double xc = 12.5;
20  static constexpr double yc = 15.0;
21  static constexpr double rc = 3.6;
22  const double gamma = std::sqrt((3.0 * A) / (4.0 * h0));
23 
24  auto r = [](double x, double y) {
25  return std::sqrt(std::pow(x - xc, 2) + std::pow(y - yc, 2));
26  };
27 
28  Q[Shortcuts::h] = h0 + (A / h0 * std::pow(1.0 / (std::cosh(gamma * (x(0) - 2.5))), 2));
29  Q[Shortcuts::z] = r(x(0), x(1)) <= rc ? 0.93 * (1.0 - r(x(0), x(1)) / rc) : 0.0;
30 """
31 
32 boundary_conditions = """
33  Qoutside[Shortcuts::h] = Qinside[Shortcuts::h];
34  Qoutside[Shortcuts::hu] = -Qinside[Shortcuts::hu];
35  Qoutside[Shortcuts::hv] = -Qinside[Shortcuts::hv];
36  Qoutside[Shortcuts::z] = Qinside[Shortcuts::z];
37 """
38 
39 refinement_criterion = """
40  static constexpr double xc = 12.5;
41  static constexpr double yc = 15.0;
42  static constexpr double rc = 3.6;
43 
44  auto r = [](double x, double y) {
45  return std::sqrt(std::pow(x - xc, 2) + std::pow(y - yc, 2));
46  };
47 
48  return r(x(0), x(1)) <= rc
49  ? ::exahype2::RefinementCommand::Refine
50  : ::exahype2::RefinementCommand::Keep;
51 """
52 
53 parser = exahype2.ArgumentParser()
54 parser.set_defaults(
55  min_depth=4,
56  end_time=1.0,
57 )
58 args = parser.parse_args()
59 
60 constants = {
61  "g": [9.81, "double"],
62  "hThreshold": [1e-5, "double"],
63 }
64 
65 size = [30.0, 30.0]
66 max_h = (1.1 * min(size) / (3.0**args.min_depth))
67 min_h = max_h * 3.0 ** (-args.amr_levels)
68 
69 aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
70  name="ADERDGSolver",
71  order=args.degrees_of_freedom,
72  unknowns={"h": 1, "hu": 1, "hv": 1, "z": 1},
73  auxiliary_variables=0,
74  min_cell_h=min_h,
75  max_cell_h=max_h,
76  time_step_relaxation=args.time_step_relaxation,
77 )
78 
79 aderdg_solver.set_implementation(
80  initial_conditions=initial_conditions,
81  boundary_conditions=boundary_conditions,
82  refinement_criterion=refinement_criterion,
83  flux=flux,
84  ncp=nonconservative_product,
85  max_eigenvalue=eigenvalue + """
86  return sFlux;
87 """,
88 )
89 
90 aderdg_solver.set_plotter(args.plotter)
91 aderdg_solver.add_kernel_optimisations(is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre)
92 
93 project = exahype2.Project(
94  namespace=["applications", "exahype2", "swe"],
95  project_name="CircularIsland",
96  directory=".",
97  executable="ExaHyPE-ShallowWater",
98 )
99 project.add_solver(aderdg_solver)
100 
101 if args.number_of_snapshots <= 0:
102  time_in_between_plots = 0.0
103 else:
104  time_in_between_plots = args.end_time / args.number_of_snapshots
105  project.set_output_path(args.output)
106 
107 project.set_global_simulation_parameters(
108  dimensions=2,
109  size=size,
110  offset=[0.0, 0.0],
111  min_end_time=args.end_time,
112  max_end_time=args.end_time,
113  first_plot_time_stamp=0.0,
114  time_in_between_plots=time_in_between_plots,
115  periodic_BC=[
116  args.periodic_boundary_conditions_x,
117  args.periodic_boundary_conditions_y,
118  ],
119 )
120 
121 project.set_load_balancer(f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})")
122 project.set_Peano4_installation("../../../../", mode=peano4.output.string_to_mode(args.build_mode))
123 project = project.generate_Peano4_project(verbose=False)
124 for const_name, const_info in constants.items():
125  const_val, const_type = const_info
126  project.constants.export_constexpr_with_type(
127  const_name, str(const_val), const_type
128  )
129 project.set_fenv_handler(args.fpe)
130 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