Peano
Loading...
Searching...
No Matches
tafjord-landslide.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 tarch::reader::NetCDFFieldParser fieldParser(
19 \"Tafjord_5m_EPSG25832.nc\",
20 \"ini_3.0Mm3_5m_EPSG25832.nc\",
21 DomainSize(0),
22 DomainSize(1),
23 DomainOffset(0),
24 DomainOffset(1),
25 "Band1",
26 "x",
27 "y",
28 "Band1",
29 "x",
30 "y"
31 );
32
33 using s = VariableShortcuts;
34 Q[s::h] = fieldParser.sampleDisplacement(x(0), x(1));
35 Q[s::b] = fieldParser.sampleTopology(x(0), x(1));
36"""
37
38boundary_conditions = """
39 using s = VariableShortcuts;
40 Qoutside[s::h] = Qinside[s::h];
41 Qoutside[s::hu] = -Qinside[s::hu];
42 Qoutside[s::hv] = -Qinside[s::hv];
43 Qoutside[s::b] = Qinside[s::b];
44"""
45
46refinement_criterion = """
47 auto result = ::exahype2::RefinementCommand::Keep;
48 return result;
49"""
50
52parser.set_defaults(
53 end_time=50.0,
54 width=[1900, 1950],
55 offset=[414895.5, 6904495.5],
56)
57args = parser.parse_args()
58
59max_h = (1.1 * min(args.width) / (3.0**args.min_depth))
60min_h = max_h * 3.0 ** (-args.amr_levels)
61args.patch_size = args.dg_order * 2 + 1
62
63unknowns={"h": 1, "hu": 1, "hv": 1}
64auxiliary_variables={
65 "b": 1, # Elevation
66 "hx": 1,
67 "hy": 1,
68 "ux": 1,
69 "uy": 1,
70 "uxx": 1,
71 "uyy": 1,
72 "uxy": 1,
73 "vx": 1,
74 "vy": 1,
75 "vxx": 1,
76 "vyy": 1,
77 "vxy": 1,
78 "bx": 1,
79 "by": 1,
80}
81
82riemann_solver = exahype2.solvers.fv.rusanov.GlobalAdaptiveTimeStep(
83 name="Rusanov" + str(args.patch_size),
84 patch_size=args.patch_size,
85 unknowns=unknowns,
86 auxiliary_variables=auxiliary_variables,
87 min_volume_h=min_h,
88 max_volume_h=max_h,
89 time_step_relaxation=args.time_step_relaxation,
90 pde_terms_without_state=args.stateless,
91 initial_conditions=re.sub(r'\bx\b', 'volumeCentre', initial_conditions),
92 boundary_conditions=boundary_conditions,
93 refinement_criterion=re.sub(r'\bx\b', 'volumeCentre', refinement_criterion),
94 flux="applications::exahype2::swe::frictionlaws::flux(Q, faceCentre, volumeH, t, dt, normal, F);",
95 ncp="""
96 using s = VariableShortcuts;
97 BTimesDeltaQ[s::h] = 0.0;
98 BTimesDeltaQ[s::hu] = 0.0;
99 BTimesDeltaQ[s::hv] = 0.0;
100 BTimesDeltaQ[s::hu + normal] += GRAV * Q[s::h] * deltaQ[s::b];
101""",
102 eigenvalues="return applications::exahype2::swe::frictionlaws::maxEigenvalue(Q, faceCentre, volumeH, t, dt, normal);",
103 source_term="applications::exahype2::swe::frictionlaws::coulombFriction(Q, volumeCentre, volumeH, t, dt, S);",
104)
105riemann_solver.plot_description = ", ".join(unknowns.keys()) + ", "
106riemann_solver.plot_description += ", ".join(auxiliary_variables.keys())
107riemann_solver.switch_storage_scheme(exahype2.solvers.Storage[args.storage], exahype2.solvers.Storage[args.storage])
108riemann_solver.add_user_solver_includes(
109 """
110#include "../SWE.h"
111#include "../FrictionLaws.h"
112#include "../ComputeFirstDerivatives.h"
113#include "tarch/reader/NetCDFFieldParser.h"
114"""
115)
116# riemann_solver._preprocess_reconstructed_patch = """
117# extrapolateHalo<{NumberOfDofs}, {NumberOfUnknowns}, {NumberOfAuxiliaryVariables}>(oldQWithHalo);
118# computeFirstDerivatives<{NumberOfDofs}, {NumberOfUnknowns}, {NumberOfAuxiliaryVariables}>(oldQWithHalo);
119# """.format(
120# NumberOfDofs=args.patch_size,
121# NumberOfUnknowns=sum(unknowns.values()),
122# NumberOfAuxiliaryVariables=sum(auxiliary_variables.values()),
123# )
124
125project = exahype2.Project(
126 namespace=["applications", "exahype2", "swe"],
127 project_name="TafjordLandslide",
128 directory=".",
129 executable=f"TafjordLandslide.{args.build_mode}",
130)
131project.add_solver(riemann_solver)
132
133if args.number_of_snapshots <= 0:
134 time_in_between_plots = 0.0
135else:
136 time_in_between_plots = args.end_time / args.number_of_snapshots
137 project.set_output_path(args.output)
138
139project.set_global_simulation_parameters(
140 dimensions=2,
141 size=args.width,
142 offset=args.offset,
143 min_end_time=args.end_time,
144 max_end_time=args.end_time,
145 first_plot_time_stamp=0.0,
146 time_in_between_plots=time_in_between_plots,
147 periodic_BC=[
148 args.periodic_boundary_conditions_x,
149 args.periodic_boundary_conditions_y,
150 ],
151)
152
153if args.load_balancing_strategy != "None":
154 strategy = f"toolbox::loadbalancing::strategies::{args.load_balancing_strategy}"
155 assume_periodic_boundary_conditions = any([
156 args.periodic_boundary_conditions_x,
157 args.periodic_boundary_conditions_y,
158 ])
159 configuration = (
160 f"new ::exahype2::LoadBalancingConfiguration("
161 f"{args.load_balancing_quality},"
162 f"0,"
163 f"{'true' if assume_periodic_boundary_conditions else 'false'},"
164 f"{args.trees},"
165 f"{args.trees})"
166 )
167 project.set_load_balancing(strategy, configuration)
168
169project.set_number_of_threads(args.threads)
170project.set_timeout(3600)
171project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
172project = project.generate_Peano4_project(verbose=True)
173if args.fpe:
174 project.set_fenv_handler("FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW")
175
176project.output.makefile.add_CXX_flag("-DGRAV=9.81")
177project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
178
179print(args)
180print(project)
181print(riemann_solver)