Peano
Loading...
Searching...
No Matches
fv.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 argparse
4
5import peano4
6import exahype2
7
8parser = argparse.ArgumentParser(
9 description="ExaHyPE 2 - Testing Script for Various Finite Volumes Solvers"
10)
11
12available_solvers = {
15}
16parser.add_argument(
17 "-s",
18 "--solver",
19 default="FVRusanovGlobalAdaptive",
20 choices=available_solvers.keys(),
21 help="|".join(available_solvers.keys()),
22)
23parser.add_argument(
24 "-d",
25 "--dimensions",
26 type=int,
27 default=2,
28 help="Number of space dimensions.",
29)
30parser.add_argument(
31 "-m",
32 "--build-mode",
33 choices=peano4.output.CompileModes,
34 default=peano4.output.CompileModes[0], # Release
35 help="|".join(peano4.output.CompileModes),
36)
37parser.add_argument(
38 "-et",
39 "--end-time",
40 type=float,
41 default=1.0,
42 help="End time of the simulation.",
43)
44parser.add_argument(
45 "-ns",
46 "--number-of-snapshots",
47 type=int,
48 default=20,
49 help="Number of snapshots (plots).",
50)
51parser.add_argument(
52 "-ps",
53 "--patch-size",
54 type=int,
55 default=16,
56 help="Number of finite volumes per axis (dimension) per patch.",
57)
58parser.add_argument(
59 "-md",
60 "--min-depth",
61 type=float,
62 default=6,
63 help="Determines maximum size of a single cell on each axis.",
64)
65parser.add_argument(
66 "-amr",
67 "--amr-levels",
68 type=int,
69 default=0,
70 help="Number of AMR grid levels on top of max. size of a cell.",
71)
72parser.add_argument(
73 "--storage",
74 type=str,
75 choices=[e.name for e in exahype2.solvers.Storage],
76 default="Heap",
77 help="The storage scheme to use."
78)
79available_load_balancing_strategies = [
80 "None",
81 "SpreadOut",
82 "SpreadOutHierarchically",
83 "SpreadOutOnceGridStagnates",
84 "RecursiveBipartition",
85 "SplitOversizedTree",
86 "cascade::SpreadOut_RecursiveBipartition",
87 "cascade::SpreadOut_SplitOversizedTree",
88]
89parser.add_argument(
90 "-lbs",
91 "--load-balancing-strategy",
92 choices=available_load_balancing_strategies,
93 default="SpreadOutOnceGridStagnates",
94 help="|".join(available_load_balancing_strategies),
95)
96parser.add_argument(
97 "-lbq",
98 "--load-balancing-quality",
99 type=float,
100 default=0.99,
101 help="The quality of the load balancing.",
102)
103parser.add_argument(
104 "--trees",
105 type=int,
106 default=-1,
107 help="Number of trees (partitions) per rank after initial decomposition.",
108)
109parser.add_argument(
110 "--threads",
111 type=int,
112 default=0,
113 help="Number of threads per rank.",
114)
115parser.add_argument(
116 "-fuse",
117 "--fuse",
118 action="store_true",
119 default=False,
120 help="Fuse enclave tasks on the CPU (requires an enclave solver).",
121)
122parser.add_argument(
123 "-gpu",
124 "--gpu",
125 action="store_true",
126 default=False,
127 help="Fuse enclave tasks on the GPU (requires an enclave solver).",
128)
129parser.add_argument(
130 "-timeout",
131 "--timeout",
132 type=int,
133 default=3600,
134 help="MPI timeout in seconds.",
135)
136parser.add_argument(
137 "-fpe",
138 "--fpe",
139 action="store_true",
140 help="Enable a floating-point exception handler.",
141)
142parser.add_argument(
143 "-pbc-x",
144 "--periodic-boundary-conditions-x",
145 action="store_true",
146 default=True,
147 help="Use periodic boundary conditions in the x-axis.",
148)
149parser.add_argument(
150 "-pbc-y",
151 "--periodic-boundary-conditions-y",
152 action="store_true",
153 default=False,
154 help="Use periodic boundary conditions in the y-axis.",
155)
156parser.add_argument(
157 "-pbc-z",
158 "--periodic-boundary-conditions-z",
159 action="store_true",
160 default=False,
161 help="Use periodic boundary conditions in the z-axis.",
162)
163parser.add_argument(
164 "-o",
165 "--output",
166 type=str,
167 default="solutions",
168 help="Output path for project solutions output. The project will create a new folder at the given path. Default is 'solutions'.",
169)
170
171args = parser.parse_args()
172
173initial_conditions = """
174 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
175 Q[i] = std::sin(volumeCentre(0) * tarch::la::PI) * std::sin(volumeCentre(1) * tarch::la::PI)
176 #if Dimensions == 3
177 * std::sin(volumeCentre(2) * tarch::la::PI)
178 #endif
179 ;
180 }
181"""
182
183boundary_conditions = """
184 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
185 Qoutside[i] = Qinside[i];
186 }
187"""
188
189refinement_criterion = """
190 auto result = ::exahype2::RefinementCommand::Keep;
191
192 if (volumeCentre(0) > 0.5) {
193 result = ::exahype2::RefinementCommand::Refine;
194 } else {
195 result = ::exahype2::RefinementCommand::Erase;
196 }
197
198 return result;
199"""
200
201max_h = 1.1 / 3.0**args.min_depth
202min_h = max_h * 3.0**(-args.amr_levels)
203
204fv_solver = available_solvers[args.solver](
205 name=args.solver,
206 patch_size=16,
207 unknowns={"v": args.dimensions},
208 auxiliary_variables=0,
209 min_volume_h=min_h,
210 max_volume_h=max_h,
211 time_step_relaxation=0.5,
212 pde_terms_without_state=True,
213 initial_conditions=initial_conditions,
214 boundary_conditions=boundary_conditions,
215 refinement_criterion=refinement_criterion,
216 flux="""
217 for (int i = 0; i < NumberOfUnknowns; i++) {
218 F[i] = 0.0;
219 }
220 F[normal] = Q[normal];
221""",
222 eigenvalues="maxEigenvalue[0] = 1.0;",
223)
224fv_solver.plot_description = ", ".join({"v": args.dimensions}.keys())
225fv_solver.switch_storage_scheme(exahype2.solvers.Storage[args.storage], exahype2.solvers.Storage[args.storage])
226
228 namespace=["tests", "exahype2", "fv"],
229 project_name=args.solver,
230 directory=".",
231 executable=args.solver,
232)
233project.add_solver(fv_solver)
234
235if args.number_of_snapshots <= 0:
236 time_in_between_plots = 0.0
237else:
238 time_in_between_plots = args.end_time / args.number_of_snapshots
239 project.set_output_path(args.output)
240
241project.set_global_simulation_parameters(
242 dimensions=args.dimensions,
243 size=[1.0, 1.0, 1.0][0:args.dimensions],
244 offset=[0.0, 0.0, 0.0][0:args.dimensions],
245 min_end_time=args.end_time,
246 max_end_time=args.end_time,
247 first_plot_time_stamp=0.0,
248 time_in_between_plots=time_in_between_plots,
249 periodic_BC=[
250 args.periodic_boundary_conditions_x,
251 args.periodic_boundary_conditions_y,
252 args.periodic_boundary_conditions_z,
253 ],
254)
255
256if args.load_balancing_strategy != "None":
257 strategy = f"toolbox::loadbalancing::strategies::{args.load_balancing_strategy}"
258 assume_periodic_boundary_conditions = any([
259 args.periodic_boundary_conditions_x,
260 args.periodic_boundary_conditions_y,
261 args.periodic_boundary_conditions_z,
262 ])
263 configuration = (
264 f"new ::exahype2::LoadBalancingConfiguration("
265 f"{args.load_balancing_quality},"
266 f"0,"
267 f"{'true' if assume_periodic_boundary_conditions else 'false'},"
268 f"{args.trees},"
269 f"{args.trees})"
270 )
271 project.set_load_balancing(strategy, configuration)
272
273project.set_number_of_threads(args.threads)
274project.set_timeout(args.timeout)
275project.set_Peano4_installation("../../../", mode=peano4.output.string_to_mode(args.build_mode))
276project = project.generate_Peano4_project(verbose=True)
277if args.fpe:
278 project.set_fenv_handler("FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW")
279
280project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
281
282print(args)
283print(project)
284print(fv_solver)
ExaHyPE 2 project.
Definition Project.py:14