6Generates 3D uniform particle distribution with randomized small displacements.
9fileName =
"test_sml_3D.hdf5"
12parser = argparse.ArgumentParser(description=
"SPH benchmarking script")
16 dest=
"particle_number",
19 help=
"Particle number per dimension",
35 help=
"Plot historgram of particle positions",
40 dest=
"max_displacement",
44 help=
"Maximal displacement in units of interparticle distance",
48args = parser.parse_args()
49npart = args.particle_number
50seed = args.random_seed
51max_displacement = args.max_displacement
57coords = np.zeros((npart**3, 3))
58v = np.zeros((npart**3, 3))
59ids = np.linspace(1, npart**3, npart**3)
62h = np.ones(npart**3) * 2.0 * dx
69 for j
in range(npart):
71 for k
in range(npart):
86rng = np.random.RandomState(seed=seed)
88displacement = (2.0 * rng.random(coords.shape) - 1.0) * max_displacement * dx
90coords[:, 0] += displacement[:, 0]
91coords[:, 1] += displacement[:, 1]
92coords[:, 2] += displacement[:, 2]
109 from matplotlib
import pyplot
as plt
112 plt.scatter(coords[:, 0], coords[:, 1], s=1, marker=
",")
117file = h5py.File(fileName,
"w")
120grp = file.create_group(
"/Header")
121grp.attrs[
"BoxSize"] = boxSize
122grp.attrs[
"NumPart_Total"] = [npart**3, 0, 0, 0, 0, 0]
123grp.attrs[
"NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
124grp.attrs[
"NumPart_ThisFile"] = [npart**3, 0, 0, 0, 0, 0]
126grp.attrs[
"NumPart_base"] = [npart]
127grp.attrs[
"Time"] = 0.0
128grp.attrs[
"NumFilesPerSnapshot"] = 1
129grp.attrs[
"MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
130grp.attrs[
"Flag_Entropy_ICs"] = 0
131grp.attrs[
"Dimension"] = 3
133grp.attrs[
"RandomSeed"] = seed
134grp.attrs[
"MaxDisplacement"] = max_displacement
135grp.attrs[
"NumpyVersion"] = np.__version__
138grp = file.create_group(
"/Units")
139grp.attrs[
"Unit length in cgs (U_L)"] = 1.0
140grp.attrs[
"Unit mass in cgs (U_M)"] = 1.0
141grp.attrs[
"Unit time in cgs (U_t)"] = 1.0
142grp.attrs[
"Unit current in cgs (U_I)"] = 1.0
143grp.attrs[
"Unit temperature in cgs (U_T)"] = 1.0
146grp = file.create_group(
"/PartType0")
147grp.create_dataset(
"Coordinates", data=coords, dtype=
"d")
148grp.create_dataset(
"Velocities", data=v, dtype=
"f")
149grp.create_dataset(
"Masses", data=m, dtype=
"f")
150grp.create_dataset(
"SmoothingLength", data=h, dtype=
"f")
151grp.create_dataset(
"InternalEnergy", data=u, dtype=
"f")
152grp.create_dataset(
"ParticleIDs", data=ids, dtype=
"L")