6Generates 1D uniform particle distribution with randomized small displacements.
7"Multiscale" variant: Create a region of particles with very high density to
8trigger multilevel interactions with sparse regions
11fileName =
"test_sml_multiscale_1D.hdf5"
14parser = argparse.ArgumentParser(description=
"SPH benchmarking script")
18 dest=
"particle_number",
21 help=
"Particle number (1D)",
37 help=
"Plot historgram of particle positions",
42 dest=
"max_displacement",
46 help=
"Maximal displacement in units of interparticle distance",
50args = parser.parse_args()
51npart = args.particle_number
52seed = args.random_seed
53max_displacement = args.max_displacement
60coords = np.zeros((npart_tot, 3))
61v = np.zeros((npart_tot, 3))
62ids = np.linspace(1, npart_tot, npart_tot)
64h = np.ones(npart_tot) * 4.0 * boxSize / npart_tot
67rng = np.random.RandomState(seed=seed)
72 Generate coordinates for particles between box_min and box_max
75 dx = (box_max - box_min) / npart
77 new_coords = np.zeros((npart, 3))
79 for i
in range(npart):
80 new_coords[i, 0] = box_min + (i + 0.5) * dx
90 displacement = (2.0 * rng.random((npart, 1)) - 1.0) * max_displacement * dx
91 new_coords[:, 0] += displacement[:, 0]
99coords[:npart, 0] = new_coords[:, 0]
100new_coords =
get_coords(1.0 / 3.0, 5.0 / 6 * boxSize, npart)
101coords[npart : 2 * npart, 0] = new_coords[:, 0]
102new_coords =
get_coords(3.0 / 6.0, 5.0 / 6 * boxSize, npart)
103coords[2 * npart : 3 * npart, 0] = new_coords[:, 0]
104new_coords =
get_coords(4.0 / 6.0, 5.0 / 6 * boxSize, npart)
105coords[3 * npart :, 0] = new_coords[:, 0]
109 from matplotlib
import pyplot
as plt
113 plt.plot(coords[:, 0], m, marker=
".")
115 plt.hist(coords[:, 0], bins=200)
120file = h5py.File(fileName,
"w")
123grp = file.create_group(
"/Header")
124grp.attrs[
"BoxSize"] = boxSize
125grp.attrs[
"NumPart_Total"] = [npart_tot, 0, 0, 0, 0, 0]
126grp.attrs[
"NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
127grp.attrs[
"NumPart_ThisFile"] = [npart_tot, 0, 0, 0, 0, 0]
129grp.attrs[
"NumPart_base"] = [npart]
130grp.attrs[
"Time"] = 0.0
131grp.attrs[
"NumFilesPerSnapshot"] = 1
132grp.attrs[
"MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
133grp.attrs[
"Flag_Entropy_ICs"] = 0
134grp.attrs[
"Dimension"] = 1
137grp.attrs[
"RandomSeed"] = seed
138grp.attrs[
"MaxDisplacement"] = max_displacement
139grp.attrs[
"NumpyVersion"] = np.__version__
142grp = file.create_group(
"/Units")
143grp.attrs[
"Unit length in cgs (U_L)"] = 1.0
144grp.attrs[
"Unit mass in cgs (U_M)"] = 1.0
145grp.attrs[
"Unit time in cgs (U_t)"] = 1.0
146grp.attrs[
"Unit current in cgs (U_I)"] = 1.0
147grp.attrs[
"Unit temperature in cgs (U_T)"] = 1.0
150grp = file.create_group(
"/PartType0")
151grp.create_dataset(
"Coordinates", data=coords, dtype=
"d")
152grp.create_dataset(
"Velocities", data=v, dtype=
"f")
153grp.create_dataset(
"Masses", data=m, dtype=
"f")
154grp.create_dataset(
"SmoothingLength", data=h, dtype=
"f")
155grp.create_dataset(
"InternalEnergy", data=u, dtype=
"f")
156grp.create_dataset(
"ParticleIDs", data=ids, dtype=
"L")
get_coords(box_min, box_max, npart)
Generate coordinates for particles between box_min and box_max.