Peano
Loading...
Searching...
No Matches
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
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 const double omega = sqrt(0.2 * GRAV);
15
16 using s = VariableShortcuts;
17
18 Q[s::b] = 0.1 * (std::pow(x[0], 2) + std::pow(x[1], 2));
19 Q[s::h] = std::fmax(0.0, 0.05 * (2 * x[0] * std::cos(omega * 0) + 2 * x[1] * std::sin(omega * 0)) + 0.075 - Q[s::b]);
20 Q[s::hu] = 0.5 * omega * std::sin(omega * 0) * Q[s::h];
21 Q[s::hv] = 0.5 * omega * std::cos(omega * 0) * Q[s::h];
22
23 //Q[s::h] = 0.025 * (1.0 - std::sqrt((x(0) * x(0)) + (x(1) * x(1))));
24 //Q[s::b] = -0.2 * (1.0 - std::sqrt((x(0) * x(0)) + (x(1) * x(1)))) - 0.1;
25"""
26
27boundary_conditions = """
28 using s = VariableShortcuts;
29 Qoutside[s::h] = Qinside[s::h];
30 Qoutside[s::hu] = -Qinside[s::hu];
31 Qoutside[s::hv] = -Qinside[s::hv];
32 Qoutside[s::b] = Qinside[s::b];
33"""
34
35refinement_criterion = """
36 return std::sqrt((x(0) * x(0)) + (x(1) * x(1))) <= 1.0
37 ? ::exahype2::RefinementCommand::Refine
38 : ::exahype2::RefinementCommand::Keep;
39"""
40
42parser.set_defaults(
43 end_time=1.0,
44 width=[4.0, 4.0],
45 offset=[-2.0, -2.0],
46)
47args = parser.parse_args()
48
49max_h = (1.1 * min(args.width) / (3.0**args.min_depth))
50min_h = max_h * 3.0 ** (-args.amr_levels)
51args.patch_size = args.dg_order * 2 + 1
52
53unknowns={"h": 1, "hu": 1, "hv": 1}
54auxiliary_variables={"b": 1}
55
56riemann_solver = exahype2.solvers.fv.riemann.GlobalAdaptiveTimeStep(
57 name="HLLEM" + str(args.patch_size),
58 patch_size=args.patch_size,
59 unknowns=unknowns,
60 auxiliary_variables=auxiliary_variables,
61 min_volume_h=min_h,
62 max_volume_h=max_h,
63 time_step_relaxation=args.time_step_relaxation,
64 pde_terms_without_state=args.stateless,
65 initial_conditions=re.sub(r'\bx\b', 'volumeCentre', initial_conditions),
66 boundary_conditions=boundary_conditions,
67 refinement_criterion=re.sub(r'\bx\b', 'volumeCentre', refinement_criterion),
68 riemann_solver="return applications::exahype2::swe::hllem(QR, QL, FR, FL, LR, LL, xR, xL, h, t, dt, normal, APDQ, AMDQ);",
69)
70riemann_solver.plot_description = ", ".join(unknowns.keys()) + ", "
71riemann_solver.plot_description += ", ".join(auxiliary_variables.keys())
72riemann_solver.switch_storage_scheme(exahype2.solvers.Storage[args.storage], exahype2.solvers.Storage[args.storage])
73riemann_solver.add_user_solver_includes(
74 """
75#include "../HLLEM.h"
76"""
77)
78
79project = exahype2.Project(
80 namespace=["applications", "exahype2", "swe"],
81 project_name="OscillatingLake",
82 directory=".",
83 executable=f"OscillatingLake.{args.build_mode}",
84)
85project.add_solver(riemann_solver)
86
87if args.number_of_snapshots <= 0:
88 time_in_between_plots = 0.0
89else:
90 time_in_between_plots = args.end_time / args.number_of_snapshots
91 project.set_output_path(args.output)
92
93project.set_global_simulation_parameters(
94 dimensions=2,
95 size=args.width,
96 offset=args.offset,
97 min_end_time=args.end_time,
98 max_end_time=args.end_time,
99 first_plot_time_stamp=0.0,
100 time_in_between_plots=time_in_between_plots,
101 periodic_BC=[
102 args.periodic_boundary_conditions_x,
103 args.periodic_boundary_conditions_y,
104 ],
105)
106
107if args.load_balancing_strategy != "None":
108 strategy = f"toolbox::loadbalancing::strategies::{args.load_balancing_strategy}"
109 assume_periodic_boundary_conditions = any([
110 args.periodic_boundary_conditions_x,
111 args.periodic_boundary_conditions_y,
112 ])
113 configuration = (
114 f"new ::exahype2::LoadBalancingConfiguration("
115 f"{args.load_balancing_quality},"
116 f"0,"
117 f"{'true' if assume_periodic_boundary_conditions else 'false'},"
118 f"{args.trees},"
119 f"{args.trees})"
120 )
121 project.set_load_balancing(strategy, configuration)
122
123project.set_number_of_threads(args.threads)
124project.set_timeout(3600)
125project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
126project = project.generate_Peano4_project(verbose=True)
127if args.fpe:
128 project.set_fenv_handler("FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW")
129
130project.output.makefile.add_CXX_flag("-DGRAV=9.81")
131project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
132
133print(args)
134print(project)
135print(riemann_solver)