17fileName =
"sodShock.hdf5"
23boxSize = x_max - x_min
24numPart_R = int(numPart_L * (rho_R / rho_L))
25numPart = numPart_L + numPart_R
28delta_L = (boxSize / 2) / numPart_L
29delta_R = (boxSize / 2) / numPart_R
34coords = zeros((numPart, 3))
35v = zeros((numPart, 3))
36ids = linspace(1, numPart, numPart)
42for i
in range(numPart_L):
43 coords[i, 0] = x_min + offset_L + i * delta_L
44 u[i] = P_L / (rho_L * (gamma - 1.0))
45 h[i] = 1.2348 * delta_L
46 m[i] = boxSize * rho_L / (2.0 * numPart_L)
50for j
in range(numPart_R):
52 coords[i, 0] = offset_R + j * delta_R
53 u[i] = P_R / (rho_R * (gamma - 1.0))
54 h[i] = 1.2348 * delta_R
55 m[i] = boxSize * rho_R / (2.0 * numPart_R)
63file = h5py.File(fileName,
"w")
66grp = file.create_group(
"/Header")
67grp.attrs[
"BoxSize"] = boxSize
68grp.attrs[
"NumPart_Total"] = [numPart, 0, 0, 0, 0, 0]
69grp.attrs[
"NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
70grp.attrs[
"NumPart_ThisFile"] = [numPart, 0, 0, 0, 0, 0]
71grp.attrs[
"Time"] = 0.0
72grp.attrs[
"NumFilesPerSnapshot"] = 1
73grp.attrs[
"MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
74grp.attrs[
"Flag_Entropy_ICs"] = 0
75grp.attrs[
"Dimension"] = 1
78grp = file.create_group(
"/Units")
79grp.attrs[
"Unit length in cgs (U_L)"] = 1.0
80grp.attrs[
"Unit mass in cgs (U_M)"] = 1.0
81grp.attrs[
"Unit time in cgs (U_t)"] = 1.0
82grp.attrs[
"Unit current in cgs (U_I)"] = 1.0
83grp.attrs[
"Unit temperature in cgs (U_T)"] = 1.0
86grp = file.create_group(
"/PartType0")
87grp.create_dataset(
"Coordinates", data=coords, dtype=
"d")
88grp.create_dataset(
"Velocities", data=v, dtype=
"f")
89grp.create_dataset(
"Masses", data=m, dtype=
"f")
90grp.create_dataset(
"SmoothingLength", data=h, dtype=
"f")
91grp.create_dataset(
"InternalEnergy", data=u, dtype=
"f")
92grp.create_dataset(
"ParticleIDs", data=ids, dtype=
"L")