Peano
Loading...
Searching...
No Matches
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
3import os
4import sys
5
6import peano4
7import exahype2
8
9sys.path.insert(0, os.path.abspath(".."))
10from PDE import *
11
12initial_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
32boundary_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
39refinement_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
53parser = exahype2.ArgumentParser()
54parser.set_defaults(
55 min_depth=4,
56 end_time=1.0,
57)
58args = parser.parse_args()
59
60constants = {
61 "g": [9.81, "double"],
62 "hThreshold": [1e-5, "double"],
63}
64
65size = [30.0, 30.0]
66max_h = 1.1 * min(size) / (3.0**args.min_depth)
67min_h = max_h * 3.0 ** (-args.amr_levels)
68
69aderdg_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=0.5,
77)
78
79aderdg_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 + """
87 return sFlux;
88""",
89)
90
91aderdg_solver.set_plotter(args.plotter)
92aderdg_solver.add_kernel_optimisations(
93 is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre
94)
95
96project = exahype2.Project(
97 namespace=["applications", "exahype2", "swe"],
98 project_name="CircularIsland",
99 directory=".",
100 executable="ExaHyPE-ShallowWater",
101)
102project.add_solver(aderdg_solver)
103
104if args.number_of_snapshots <= 0:
105 time_in_between_plots = 0.0
106else:
107 time_in_between_plots = args.end_time / args.number_of_snapshots
108 project.set_output_path(args.output)
109
110project.set_global_simulation_parameters(
111 dimensions=2,
112 size=size,
113 offset=[0.0, 0.0],
114 min_end_time=args.end_time,
115 max_end_time=args.end_time,
116 first_plot_time_stamp=0.0,
117 time_in_between_plots=time_in_between_plots,
118 periodic_BC=[
119 args.periodic_boundary_conditions_x,
120 args.periodic_boundary_conditions_y,
121 ],
122)
123
124project.set_load_balancer(
125 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})"
126)
127project.set_Peano4_installation(
128 "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
129)
130project = project.generate_Peano4_project(verbose=False)
131for const_name, const_info in constants.items():
132 const_val, const_type = const_info
133 project.constants.export_constexpr_with_type(const_name, str(const_val), const_type)
134project.set_fenv_handler(args.fpe)
135project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)