8Generates 2D uniform particle distribution with randomized small
9displacements with multiple scales, i.e. recursively nested boxes
10such that the grid will contain multiple scales.
13fileName =
"test_sml_multiscale_2D.hdf5"
16parser = argparse.ArgumentParser(description=
"SPH benchmarking script")
20 dest=
"particle_number",
23 help=
"Particle number per dimension",
39 help=
"Plot historgram of particle positions",
44 dest=
"max_displacement",
48 help=
"Maximal displacement in units of interparticle distance",
52args = parser.parse_args()
53npart = args.particle_number
54seed = args.random_seed
55max_displacement = args.max_displacement
61npart_tot = 4 * (npart**2)
62coords = np.zeros((npart_tot, 3))
63v = np.zeros((npart_tot, 3))
64ids = np.linspace(1, npart_tot, npart_tot)
67h = np.ones(npart_tot) * 2.0 * dx
71rng = np.random.RandomState(seed=seed)
74def get_coords(box_xmin, box_xmax, box_ymin, box_ymax, npart):
76 Generate coordinates for particles between box_min and box_max
77 npart: number of particles in each dimension
80 dx = (box_xmax - box_xmin) / npart
81 dy = (box_ymax - box_ymin) / npart
86 new_coords = np.zeros((npart2, 3))
88 for i
in range(npart):
90 for j
in range(npart):
92 new_coords[ind, 0] = box_xmin + x
93 new_coords[ind, 1] = box_ymin + y
104 displacement_x = (2.0 * rng.random((npart2, 1)) - 1.0) * max_displacement * dx
105 displacement_y = (2.0 * rng.random((npart2, 1)) - 1.0) * max_displacement * dy
106 new_coords[:, 0] += displacement_x[:, 0]
107 new_coords[:, 1] += displacement_y[:, 0]
115new_coords =
get_coords(0.0, boxSize, 0.0, boxSize, npart)
116coords[:npart2, :2] = new_coords[:, :2]
118new_coords =
get_coords(0.0, 2.0 / 3 * boxSize, 0.0, 2.0 / 3 * boxSize, npart)
119coords[npart2 : 2 * npart2, :2] = new_coords[:, :2]
121new_coords =
get_coords(1.0 / 6, 2.0 / 3 * boxSize, 1.0 / 6, 2.0 / 3 * boxSize, npart)
122coords[2 * npart2 : 3 * npart2, :2] = new_coords[:, :2]
124new_coords =
get_coords(2.0 / 6, 2.0 / 3 * boxSize, 2.0 / 6, 2.0 / 3 * boxSize, npart)
125coords[3 * npart2 :, :2] = new_coords[:, :2]
140 from matplotlib
import pyplot
as plt
143 plt.scatter(coords[:, 0], coords[:, 1], s=1, marker=
",")
148file = h5py.File(fileName,
"w")
151grp = file.create_group(
"/Header")
152grp.attrs[
"BoxSize"] = boxSize
153grp.attrs[
"NumPart_Total"] = [npart**2, 0, 0, 0, 0, 0]
154grp.attrs[
"NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
155grp.attrs[
"NumPart_ThisFile"] = [npart**2, 0, 0, 0, 0, 0]
157grp.attrs[
"NumPart_base"] = [npart]
158grp.attrs[
"Time"] = 0.0
159grp.attrs[
"NumFilesPerSnapshot"] = 1
160grp.attrs[
"MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
161grp.attrs[
"Flag_Entropy_ICs"] = 0
162grp.attrs[
"Dimension"] = 2
164grp.attrs[
"RandomSeed"] = seed
165grp.attrs[
"MaxDisplacement"] = max_displacement
166grp.attrs[
"NumpyVersion"] = np.__version__
169grp = file.create_group(
"/Units")
170grp.attrs[
"Unit length in cgs (U_L)"] = 1.0
171grp.attrs[
"Unit mass in cgs (U_M)"] = 1.0
172grp.attrs[
"Unit time in cgs (U_t)"] = 1.0
173grp.attrs[
"Unit current in cgs (U_I)"] = 1.0
174grp.attrs[
"Unit temperature in cgs (U_T)"] = 1.0
177grp = file.create_group(
"/PartType0")
178grp.create_dataset(
"Coordinates", data=coords, dtype=
"d")
179grp.create_dataset(
"Velocities", data=v, dtype=
"f")
180grp.create_dataset(
"Masses", data=m, dtype=
"f")
181grp.create_dataset(
"SmoothingLength", data=h, dtype=
"f")
182grp.create_dataset(
"InternalEnergy", data=u, dtype=
"f")
183grp.create_dataset(
"ParticleIDs", data=ids, dtype=
"L")
get_coords(box_min, box_max, npart)
Generate coordinates for particles between box_min and box_max.