Peano
Loading...
Searching...
No Matches
sedov.py
Go to the documentation of this file.
1import os
2import argparse
3import numpy as np
4
5import peano4.api
6import exaparty
7import exaparty.api.sphtools as sphtools
8import dastgen2
9
10import shutil
11
12
13
16
17parser = argparse.ArgumentParser(description="SPH test script")
18parser.add_argument(
19 "-j",
20 "--parallel-builds",
21 dest="j",
22 type=int,
23 default=-1,
24 help="Parallel builds",
25)
26parser.add_argument(
27 "-v",
28 "--verbose",
29 dest="verbose",
30 action="store_true",
31 default=False,
32 help="Verbose",
33)
34parser.add_argument(
35 "-c",
36 "--clean",
37 dest="clean_temporary_directories",
38 action="store_true",
39 help="Remove temporary directories before script starts",
40)
41parser.add_argument(
42 "-np",
43 "--particle-number",
44 dest="particle_number",
45 required=True,
46 type=int,
47 help="Particle number (1D)",
48)
49parser.add_argument(
50 "-et",
51 "--end-time",
52 dest="end_time",
53 type=float,
54 default=0.2,
55 help="End of simulation",
56)
57parser.add_argument(
58 "-plot",
59 "--plot-delta",
60 dest="plot_delta",
61 type=float,
62 default=0.01,
63 help="Plot delta (0 switches off)",
64)
65parser.add_argument(
66 "-dt",
67 "--timestep-size",
68 dest="timestep_size",
69 type=float,
70 default=1e-4,
71 help="Global timestep size (initial value)",
72)
73parser.add_argument(
74 "-cfl",
75 "--cfl-factor",
76 dest="cfl_factor",
77 type=float,
78 default=0.1,
79 help="Value of the CFL constant",
80)
81parser.add_argument(
82 "-csmax",
83 "--cell-size-max",
84 dest="cell_size_max",
85 type=float,
86 default=0.3,
87 help="Cell size (default 0.3)",
88)
89parser.add_argument(
90 "-csmin",
91 "--cell-size-min",
92 dest="cell_size_min",
93 type=float,
94 default=0.3,
95 help="Cell size (default 0.3)",
96)
97parser.add_argument(
98 "-pd",
99 "--peano-dir",
100 dest="peanodir",
101 default="../../../..",
102 help="Peano4 directory",
103)
104parser.add_argument(
105 "-asserts",
106 "--asserts",
107 dest="asserts",
108 action="store_true",
109 default=False,
110 help="Switch on assertions",
111)
112parser.add_argument(
113 "-debug",
114 "--debug",
115 dest="debug",
116 action="store_true",
117 default=False,
118 help="Switch on full debug checks",
119)
120parser.add_argument(
121 "-k",
122 "--kernel",
123 dest="kernel",
124 type=str,
125 default="quartic_spline",
126 choices=sphtools.sph_kernel_list,
127 help="SPH kernel function to use.",
128)
129parser.add_argument(
130 "-t",
131 "--trees",
132 dest="trees",
133 default=0,
134 type=int,
135 help="Number of trees (subdomains) (0 uses all threads)",
136)
137
138args = parser.parse_args()
139
140
141
144
145project_namespace = ["tests", "exaparty", "sedov2D"]
146
147project = exaparty.api.Project(
148 namespace=project_namespace, project_name="Sedov2D", executable="sedov2D"
149)
150
151# Initialise the SPH particle --------------------------------------------------
152# If multiple particle species are present, we can specify the parameters
153# independently for each case.
154
155name = "HydroPart"
156
157dimensions = 2
158hydro_dimensions = 2 # dimensions for the hydro
159
161 name,
162 dimensions_hydro=hydro_dimensions,
163 cfl_factor=args.cfl_factor,
164 initial_time_step_size=args.timestep_size,
165 constant_time_step_size=True,
166 exaparty_project_namespace=project_namespace,
167 min_h=args.cell_size_min,
168 max_h=args.cell_size_max,
169)
170
171
172
178
179offset = [0, 0, 0]
180domain_size = [1, 1, 1]
181periodic_boundary_conditions = [True, True, False]
182
183# HYDRO_DIMENSION can be smaller than the Peano4 dimensions
184HYDRO_DIMENSIONS = hydro_dimensions
185
186# Particle number along 1 dimension
187HYDRO_PART_NUMBER = args.particle_number
188
189# Time integration parameters
190GLOBAL_TIME_STEP_SIZE = args.timestep_size
191CFL_CONSTANT = args.cfl_factor
192
193# EoS parameter ---------------------------------------------------------------
194gamma_hydro_list = [str(5 / 3), str(7 / 5), str(4 / 3), str(2 / 1)]
195gamma_hydro_list_symbols = [
196 "HYDRO_GAMMA_5_3",
197 "HYDRO_GAMMA_7_5",
198 "HYDRO_GAMMA_4_3",
199 "HYDRO_GAMMA_2_1",
200]
201GAMMA = gamma_hydro_list[0]
202GAMMA_HYDRO_SYMBOL = gamma_hydro_list_symbols[0]
203
204# SPH kernel -------------------------------------------------------
205
206kernel = args.kernel
207KERNEL_SYMBOL = sphtools.sph_kernel_macro_name[kernel]
208KERNEL_SUPPORT_RAD = sphtools.sph_kernel_H_over_h[HYDRO_DIMENSIONS - 1][kernel]
209
210
211# Additional Particle Parameters -----------------------------------------------
212depth = 0
213cellsize = domain_size[0]
214while cellsize > args.cell_size_min:
215 cellsize /= 3.0
216 depth += 1
217 if depth == 100:
218 raise ValueError("Suspicious depth")
219
220dx = domain_size[0] / args.particle_number
221hydro_H_max = 0.499 * cellsize
222if hydro_H_max < 3.0 * dx:
223 raise ValueError("Too small hydro_H_max", 3.0 * dx, hydro_H_max)
224hydro_h_max = exaparty.api.sphtools.sph_kernel_get_smoothing_length_from_interaction_radius(
225 hydro_H_max, kernel, hydro_dimensions
226)
227
228particle.h_hydro_max = hydro_h_max
229
230# particle.h_hydro_min = 1e-6
231# particle.h_max_iterations = 10
232# particle.h_tolerance = 1e-4
233# particle.eta_factor = 1.2348
234# particle.beta_av = 3.0
235# particle.alpha_av = 0.8
236
237# Optional: Reduce the mantissa size for particle attributes -------------------
238# Native size is 53 (double precision)
239# particle.mantissa_size = 23
240
241
242# deploy particle properties
243# This needs to be done if you're changing any of the default values.
244particle.set_parameters()
245
246
247# Add particle to the ExaParty project --------------------------------------------
248# Notice that you any change to the particle will not take effect after adding
249# the particle_set to the project
250particle_set = project.add_particle_species(particle)
251
252if args.debug:
253 build_mode = peano4.api.output.CompileMode.DEBUG
254elif args.asserts:
255 build_mode = peano4.api.output.CompileMode.ASSERTS
256else:
257 build_mode = peano4.api.output.CompileMode.RELEASE
258
259# Set Peano4 simulation parameters ---------------------------------------------
260project.set_global_simulation_parameters(
261 dimensions=dimensions,
262 offset=offset,
263 domain_size=domain_size,
264 min_end_time=args.end_time,
265 max_end_time=0.0,
266 first_plot_time_stamp=0.0,
267 time_in_between_plots=args.plot_delta,
268 periodic_BC=periodic_boundary_conditions,
269 plotter_precision=8,
270)
271
272# Choose realisation
273parallelisation = "domain-decomposition"
274# parallelisation = "task-graph"
275# parallelisation = "multisweep-task-graph"
276storage = "scattered"
277# storage = "continuous-per-vertex"
278# storage = "global-continuous"
279sorting = "multiscale-sort"
280# sorting = "bucket-sort"
281kernel_optimisation = "no-optimisation"
282project.set_realisation(
283 parallelisation=parallelisation,
284 storage=storage,
285 sorting=sorting,
286 kernel_optimisation=kernel_optimisation,
287)
288
289project.set_Peano4_installation(args.peanodir, build_mode)
290
291project.set_load_balancing(
292 "toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates",
293 f"new toolbox::loadbalancing::DefaultConfiguration({args.trees})",
294)
295
296
297
300
301# Sedov-Taylor Blast snippet --------------------------------------------------
302# The particle attributes are set via an initalisation snippet that sets
303# the initial conditions specific for this problem, i.e. the velocity field
304# that converges towards the center of the domain and that generates the
305# collapse.
306
308initialisation_snippet = ICs.initialisation_snippet
309
310# Finally, pass this configuration to the initialisation script
311project.algorithm_step_initial_conditions.add_action_set(
313 particle_set=particle_set,
314 initialisation_call=initialisation_snippet,
315 distance_between_particles_along_one_axis=(
316 domain_size[0] / (args.particle_number)
317 ),
318 noise_scale=0.25,
319 additional_includes="""
320#include "exaparty/kernels/legacy/equation_of_state.h"
321#include "exaparty/kernels/legacy/kernel_hydro.h"
322""",
323 )
324)
325
326
350 "particles",
351 particle_set,
352 "globaldata::{}::getSpecies().getMinTimeStamp()".format(particle.name),
353)
354particle_plotter.add_attribute_to_plot(particle.velocity, dimensions)
355particle_plotter.add_attribute_to_plot(particle.acceleration, dimensions)
356particle_plotter.add_attribute_to_plot(particle.mass, 1)
357particle_plotter.add_attribute_to_plot(particle.density, 1)
358particle_plotter.add_attribute_to_plot(particle.pressure, 1)
359particle_plotter.add_attribute_to_plot(particle.u, 1)
360particle_plotter.add_attribute_to_plot(particle.smoothL, 1)
361if args.asserts or args.debug:
362 particle_plotter.add_attribute_to_plot(particle.partid, 1)
363 particle_plotter.add_attribute_to_plot(particle.density_neighbourcount, 1)
364 particle_plotter.add_attribute_to_plot(particle.force_neighbourcount, 1)
365project.algorithm_step_plot.add_action_set(particle_plotter)
366
367
368
379
380peano4_project = project.generate_Peano4_project(verbose=args.verbose)
381
382# Some sanity checks ----------------------------------------------------------
383if GAMMA not in gamma_hydro_list:
384 print(f"Please check the value of GAMMA. You have chosen: {GAMMA}")
385
386print("-----------------------------------------------------------------------")
387print("SPH parameters summary:")
388print(f"Effective dimensions of the Simulation: {HYDRO_DIMENSIONS}")
389print(f"Global time-step size: {GLOBAL_TIME_STEP_SIZE}")
390print(f"Number of particles (1D): {HYDRO_PART_NUMBER}")
391print(f"Adiabatic index: {GAMMA}")
392print(f"Smoothing length free factor: {particle.eta_factor}")
393print("-----------------------------------------------------------------------")
394
395
396# Export Constants.h file ------------------------------------------------------
397peano4_project.constants.export_const_with_type(
398 "HYDRO_DIMENSIONS", str(HYDRO_DIMENSIONS), "double"
399)
400peano4_project.constants.export_const_with_type(
401 "HYDRO_PART_NUMBER", str(HYDRO_PART_NUMBER), "double"
402)
403peano4_project.constants.export_const_with_type(
404 "GLOBAL_TIME_STEP_SIZE", str(GLOBAL_TIME_STEP_SIZE), "double"
405)
406peano4_project.constants.export_const_with_type("GAMMA", GAMMA, "double")
407
408# Export symbols for compilation (e.g. for SPH kernel) -----------------------
409peano4_project.output.makefile.add_CXX_flag(
410 "-D" + "HYDRO_DIMENSION=" + str(HYDRO_DIMENSIONS)
411)
412peano4_project.output.makefile.add_CXX_flag("-D" + GAMMA_HYDRO_SYMBOL)
413peano4_project.output.makefile.add_CXX_flag("-D" + KERNEL_SYMBOL)
414
415
416
419
420# If we want to start a project from scratch, we may want to remove some of the generated code
421if args.clean_temporary_directories:
422 dirs = ["vertexdata/", "repositories/", "globaldata/", "observers/"]
423 for dir in dirs:
424 shutil.rmtree(dir)
425
426# It is safe (and recommended) to overwrite any existing main file, since this
427# is generated automatically by the ExaParty graph compiler.
428peano4_project.generate(
429 overwrite=peano4.api.output.Overwrite.Always, throw_away_data_after_generation=True
430)
431peano4_project.build(make_clean_first=True, number_of_parallel_builds=args.j)
432
433# remove output files from previous runs
434output_files = [
435 f
436 for f in os.listdir(".")
437 if f.endswith(".peano-patch-file") or f.endswith(".vtu") or f.endswith(".pvd")
438]
439for f in output_files:
440 os.remove(f)
ExaParty project.
Definition Project.py:27
Initialisation snippet for the Sedov Blast problem in different spatial dimensions.
Definition SedovBlast.py:1
This file is part of the ExaParty project.
Definition __init__.py:1