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 re
5import sys
6
7import peano4.api
8import exahype2
9
10sys.path.insert(0, os.path.abspath(".."))
11from sweargs import SWEArgumentParser
12
13initial_conditions = """
14 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
15 Q[i] = 0.0;
16 }
17
18 static constexpr double h0 = 0.32;
19 static constexpr double A = 0.064;
20 static constexpr double xc = 12.5;
21 static constexpr double yc = 15.0;
22 static constexpr double rc = 3.6;
23 const double gamma = std::sqrt((3.0 * A) / (4.0 * h0));
24
25 auto r = [](double x, double y) {
26 return std::sqrt(std::pow(x - xc, 2) + std::pow(y - yc, 2));
27 };
28
29 using s = VariableShortcuts;
30 Q[s::h] = h0 + (A / h0 * std::pow(1.0 / (std::cosh(gamma * (x(0) - 2.5))), 2));
31 Q[s::b] = r(x(0), x(1)) <= rc ? 0.93 * (1.0 - r(x(0), x(1)) / rc) : 0.0;
32"""
33
34boundary_conditions = """
35 using s = VariableShortcuts;
36 Qoutside[s::h] = Qinside[s::h];
37 Qoutside[s::hu] = -Qinside[s::hu];
38 Qoutside[s::hv] = -Qinside[s::hv];
39 Qoutside[s::b] = Qinside[s::b];
40"""
41
42refinement_criterion = """
43 static constexpr double xc = 12.5;
44 static constexpr double yc = 15.0;
45 static constexpr double rc = 3.6;
46
47 auto r = [](double x, double y) {
48 return std::sqrt(std::pow(x - xc, 2) + std::pow(y - yc, 2));
49 };
50
51 return r(x(0), x(1)) <= rc
52 ? ::exahype2::RefinementCommand::Refine
53 : ::exahype2::RefinementCommand::Keep;
54"""
55
57parser.set_defaults(
58 end_time=1.0,
59 width=[30.0, 30.0],
60)
61args = parser.parse_args()
62
63max_h = (1.1 * min(args.width) / (3.0**args.min_depth))
64min_h = max_h * 3.0 ** (-args.amr_levels)
65args.patch_size = args.dg_order * 2 + 1
66
67unknowns={"h": 1, "hu": 1, "hv": 1, "b": 1}
68
69aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
70 name="ADERDG" + str(args.dg_order),
71 order=args.dg_order,
72 unknowns=unknowns,
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 initial_conditions=initial_conditions,
78 boundary_conditions=boundary_conditions,
79 refinement_criterion=refinement_criterion,
80 flux="applications::exahype2::swe::flux(Q, x, h, t, dt, normal, F);",
81 ncp="applications::exahype2::swe::nonconservativeProduct(Q, deltaQ, x, h, t, dt, normal, BTimesDeltaQ);",
82 eigenvalues="return applications::exahype2::swe::maxEigenvalue(Q, x, h, t, dt, normal);",
83)
84aderdg_solver.plot_description = ", ".join(unknowns.keys())
85aderdg_solver.switch_storage_scheme(exahype2.solvers.Storage[args.storage], exahype2.solvers.Storage[args.storage])
86aderdg_solver.add_kernel_optimisations(is_linear=False, polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre)
87aderdg_solver.add_user_solver_includes(
88 """
89#include "../SWE.h"
90"""
91)
92
93project = exahype2.Project(
94 namespace=["applications", "exahype2", "swe"],
95 project_name="CircularIsland",
96 directory=".",
97 executable=f"CircularIsland.{args.build_mode}",
98)
99project.add_solver(aderdg_solver)
100
101if args.number_of_snapshots <= 0:
102 time_in_between_plots = 0.0
103else:
104 time_in_between_plots = args.end_time / args.number_of_snapshots
105 project.set_output_path(args.output)
106
107project.set_global_simulation_parameters(
108 dimensions=2,
109 size=args.width,
110 offset=args.offset,
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
121if args.load_balancing_strategy != "None":
122 strategy = f"toolbox::loadbalancing::strategies::{args.load_balancing_strategy}"
123 assume_periodic_boundary_conditions = any([
124 args.periodic_boundary_conditions_x,
125 args.periodic_boundary_conditions_y,
126 ])
127 configuration = (
128 f"new ::exahype2::LoadBalancingConfiguration("
129 f"{args.load_balancing_quality},"
130 f"0,"
131 f"{'true' if assume_periodic_boundary_conditions else 'false'},"
132 f"{args.trees},"
133 f"{args.trees})"
134 )
135 project.set_load_balancing(strategy, configuration)
136
137project.set_number_of_threads(args.threads)
138project.set_timeout(3600)
139project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
140project = project.generate_Peano4_project(verbose=True)
141if args.fpe:
142 project.set_fenv_handler("FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW")
143
144project.output.makefile.add_CXX_flag("-DGRAV=9.81")
145project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
146
147print(args)
148print(project)
149print(aderdg_solver)