6Generates 1D uniform particle distribution with randomized small displacements.
9fileName =
"test_sml_1D.hdf5"
12parser = argparse.ArgumentParser(description=
"SPH benchmarking script")
16 dest=
"particle_number",
19 help=
"Particle number (1D)",
32 dest=
"max_displacement",
36 help=
"Maximal displacement in units of interparticle distance",
40args = parser.parse_args()
41npart = args.particle_number
42seed = args.random_seed
43max_displacement = args.max_displacement
49coords = np.zeros((npart, 3))
50v = np.zeros((npart, 3))
51ids = np.linspace(1, npart, npart)
54h = np.ones(npart) * 2.0 * dx
59 coords[i, 0] = (i + 0.5) * dx
68rng = np.random.RandomState(seed=seed)
70displacement = (2.0 * rng.random(coords.shape) - 1.0) * max_displacement * dx
71coords[:, 0] += displacement[:, 0]
74file = h5py.File(fileName,
"w")
77grp = file.create_group(
"/Header")
78grp.attrs[
"BoxSize"] = boxSize
79grp.attrs[
"NumPart_Total"] = [npart, 0, 0, 0, 0, 0]
80grp.attrs[
"NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
81grp.attrs[
"NumPart_ThisFile"] = [npart, 0, 0, 0, 0, 0]
83grp.attrs[
"NumPart_base"] = [npart]
84grp.attrs[
"Time"] = 0.0
85grp.attrs[
"NumFilesPerSnapshot"] = 1
86grp.attrs[
"MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
87grp.attrs[
"Flag_Entropy_ICs"] = 0
88grp.attrs[
"Dimension"] = 1
91grp.attrs[
"RandomSeed"] = seed
92grp.attrs[
"MaxDisplacement"] = max_displacement
93grp.attrs[
"NumpyVersion"] = np.__version__
96grp = file.create_group(
"/Units")
97grp.attrs[
"Unit length in cgs (U_L)"] = 1.0
98grp.attrs[
"Unit mass in cgs (U_M)"] = 1.0
99grp.attrs[
"Unit time in cgs (U_t)"] = 1.0
100grp.attrs[
"Unit current in cgs (U_I)"] = 1.0
101grp.attrs[
"Unit temperature in cgs (U_T)"] = 1.0
104grp = file.create_group(
"/PartType0")
105grp.create_dataset(
"Coordinates", data=coords, dtype=
"d")
106grp.create_dataset(
"Velocities", data=v, dtype=
"f")
107grp.create_dataset(
"Masses", data=m, dtype=
"f")
108grp.create_dataset(
"SmoothingLength", data=h, dtype=
"f")
109grp.create_dataset(
"InternalEnergy", data=u, dtype=
"f")
110grp.create_dataset(
"ParticleIDs", data=ids, dtype=
"L")