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