6Generates 2D random particle distribution.
9fileName =
"test_sml_2D.hdf5"
12parser = argparse.ArgumentParser(description=
"SPH benchmarking script")
16 dest=
"particle_number",
19 help=
"Particle number per dimension",
30args = parser.parse_args()
31npart = args.particle_number
32seed = args.random_seed
38coords = np.zeros((npart**2, 3))
39v = np.zeros((npart**2, 3))
40ids = np.linspace(1, npart**2, npart**2)
43h = np.ones(npart**2) * 1.2 * dx
50 for j
in range(npart):
63rng = np.random.RandomState(seed=seed)
65displacement = (2.0 * rng.random(coords.shape) - 1.0) * 0.199 * dx
67coords[:, 0] += displacement[:, 0]
68coords[:, 1] += displacement[:, 1]
83from matplotlib
import pyplot
as plt
86plt.scatter(coords[:, 0], coords[:, 1], s=1, marker=
",")
91file = h5py.File(fileName,
"w")
94grp = file.create_group(
"/Header")
95grp.attrs[
"BoxSize"] = boxSize
96grp.attrs[
"NumPart_Total"] = [npart**2, 0, 0, 0, 0, 0]
97grp.attrs[
"NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
98grp.attrs[
"NumPart_ThisFile"] = [npart**2, 0, 0, 0, 0, 0]
100grp.attrs[
"NumPart_base"] = [npart / scale]
101grp.attrs[
"Time"] = 0.0
102grp.attrs[
"NumFilesPerSnapshot"] = 1
103grp.attrs[
"MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
104grp.attrs[
"Flag_Entropy_ICs"] = 0
105grp.attrs[
"Dimension"] = 2
106grp.attrs[
"RandomSeed"] = seed
109grp = file.create_group(
"/Units")
110grp.attrs[
"Unit length in cgs (U_L)"] = 1.0
111grp.attrs[
"Unit mass in cgs (U_M)"] = 1.0
112grp.attrs[
"Unit time in cgs (U_t)"] = 1.0
113grp.attrs[
"Unit current in cgs (U_I)"] = 1.0
114grp.attrs[
"Unit temperature in cgs (U_T)"] = 1.0
117grp = file.create_group(
"/PartType0")
118grp.create_dataset(
"Coordinates", data=coords, dtype=
"d")
119grp.create_dataset(
"Velocities", data=v, dtype=
"f")
120grp.create_dataset(
"Masses", data=m, dtype=
"f")
121grp.create_dataset(
"SmoothingLength", data=h, dtype=
"f")
122grp.create_dataset(
"InternalEnergy", data=u, dtype=
"f")
123grp.create_dataset(
"ParticleIDs", data=ids, dtype=
"L")