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