Peano
Loading...
Searching...
No Matches
makeIC.py
Go to the documentation of this file.
2import h5py
3from numpy import *
4
5# Generates a swift IC file for the Sedov blast test in a periodic cubic box
6
7# Parameters
8numPart = 65
9#numPart = 1001
10gamma = 5.0 / 3.0 # Gas adiabatic index
11rho0 = 1.0 # Background density
12P0 = 1.0e-6 # Background pressure
13E0 = 1.0 # Energy of the explosion
14N_inject = 3 # Number of particles in which to inject energy
15fileName = "sedov.hdf5"
16
17# ---------------------------------------------------
18coords = zeros((numPart, 3))
19h = zeros(numPart)
20vol = 1.0
21
22for i in range(numPart):
23 coords[i, 0] = i * vol / numPart + vol / (2.0 * numPart)
24 h[i] = 1.2348 * vol / numPart
25
26# Generate extra arrays
27v = zeros((numPart, 3))
28ids = linspace(1, numPart, numPart)
29m = zeros(numPart)
30u = zeros(numPart)
31r = zeros(numPart)
32
33r = abs(coords[:, 0] - 0.5)
34m[:] = rho0 * vol / numPart
35u[:] = P0 / (rho0 * (gamma - 1))
36
37# Make the central particle detonate
38index = argsort(r)
39u[index[0:N_inject]] = E0 / (N_inject * m[0])
40
41# --------------------------------------------------
42
43# File
44file = h5py.File(fileName, "w")
45
46# Header
47grp = file.create_group("/Header")
48grp.attrs["BoxSize"] = [1.0, 1.0, 1.0]
49grp.attrs["NumPart_Total"] = [numPart, 0, 0, 0, 0, 0]
50grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
51grp.attrs["NumPart_ThisFile"] = [numPart, 0, 0, 0, 0, 0]
52grp.attrs["Time"] = 0.0
53grp.attrs["NumFilesPerSnapshot"] = 1
54grp.attrs["MassTable"] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
55grp.attrs["Flag_Entropy_ICs"] = 0
56grp.attrs["Dimension"] = 1
57
58# Units
59grp = file.create_group("/Units")
60grp.attrs["Unit length in cgs (U_L)"] = 1.0
61grp.attrs["Unit mass in cgs (U_M)"] = 1.0
62grp.attrs["Unit time in cgs (U_t)"] = 1.0
63grp.attrs["Unit current in cgs (U_I)"] = 1.0
64grp.attrs["Unit temperature in cgs (U_T)"] = 1.0
65
66# Particle group
67grp = file.create_group("/PartType0")
68grp.create_dataset("Coordinates", data=coords, dtype="d")
69grp.create_dataset("Velocities", data=v, dtype="f")
70grp.create_dataset("Masses", data=m, dtype="f")
71grp.create_dataset("SmoothingLength", data=h, dtype="f")
72grp.create_dataset("InternalEnergy", data=u, dtype="f")
73grp.create_dataset("ParticleIDs", data=ids, dtype="L")
74
75file.close()