Commit 4421af3e authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Made the multi-type example generate ICs split into multiple files.

parent 0ae967d8
...@@ -39,143 +39,151 @@ Ldm = int(sys.argv[2]) # Number of particles along one axis ...@@ -39,143 +39,151 @@ Ldm = int(sys.argv[2]) # Number of particles along one axis
massStars = 0.1 massStars = 0.1
Lstars = int(sys.argv[3]) # Number of particles along one axis Lstars = int(sys.argv[3]) # Number of particles along one axis
fileName = "multiTypes.hdf5" fileBaseName = "multiTypes"
num_files = int(sys.argv[4])
#--------------------------------------------------- #---------------------------------------------------
numGas = Lgas**3 numGas_tot = Lgas**3
massGas = boxSize**3 * rhoGas / numGas massGas = boxSize**3 * rhoGas / numGas_tot
internalEnergy = P / ((gamma - 1.)*rhoGas) internalEnergy = P / ((gamma - 1.)*rhoGas)
numDM = Ldm**3 numDM_tot = Ldm**3
massDM = boxSize**3 * rhoDM / numDM massDM = boxSize**3 * rhoDM / numDM_tot
numStars = Lstars**3 numStars_tot = Lstars**3
massStars = massDM * massStars massStars = massDM * massStars
#-------------------------------------------------- #--------------------------------------------------
#File offsetGas = 0
file = h5py.File(fileName, 'w') offsetDM = 0
offsetStars = 0
# Header
grp = file.create_group("/Header") for n in range(num_files):
grp.attrs["BoxSize"] = boxSize
grp.attrs["NumPart_Total"] = [numGas, numDM, 0, 0, numStars, 0] # File name
grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0] if num_files == 1:
grp.attrs["NumPart_ThisFile"] = [numGas, numDM, 0, 0, numStars, 0] fileName = fileBaseName + ".hdf5"
grp.attrs["Time"] = 0.0 else:
grp.attrs["NumFilesPerSnapshot"] = 1 fileName = fileBaseName + ".%d.hdf5"%n
grp.attrs["MassTable"] = [0.0, massDM, 0.0, 0.0, 0.0, 0.0]
grp.attrs["Flag_Entropy_ICs"] = 0 # File
grp.attrs["Dimension"] = 3 file = h5py.File(fileName, 'w')
#Runtime parameters # Number of particles
grp = file.create_group("/RuntimePars") numGas = numGas_tot / num_files
grp.attrs["PeriodicBoundariesOn"] = periodic numDM = numDM_tot / num_files
numStars = numStars_tot / num_files
#Units
grp = file.create_group("/Units") if n == num_files - 1:
grp.attrs["Unit length in cgs (U_L)"] = 1. numGas += numGas_tot % num_files
grp.attrs["Unit mass in cgs (U_M)"] = 1. numDM += numDM_tot % num_files
grp.attrs["Unit time in cgs (U_t)"] = 1. numStars += numStars_tot % num_files
grp.attrs["Unit current in cgs (U_I)"] = 1.
grp.attrs["Unit temperature in cgs (U_T)"] = 1.
# Header
grp = file.create_group("/Header")
# Gas Particle group grp.attrs["BoxSize"] = boxSize
grp = file.create_group("/PartType0") grp.attrs["NumPart_Total"] = [numGas_tot, numDM_tot, 0, 0, numStars_tot, 0]
grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
v = zeros((numGas, 3)) grp.attrs["NumPart_ThisFile"] = [numGas, numDM, 0, 0, numStars, 0]
ds = grp.create_dataset('Velocities', (numGas, 3), 'f') grp.attrs["Time"] = 0.0
ds[()] = v grp.attrs["NumFilesPerSnapshot"] = num_files
v = zeros(1) grp.attrs["MassTable"] = [0.0, massDM, 0.0, 0.0, 0.0, 0.0]
grp.attrs["Flag_Entropy_ICs"] = 0
m = full((numGas, 1), massGas) grp.attrs["Dimension"] = 3
ds = grp.create_dataset('Masses', (numGas,1), 'f')
ds[()] = m #Runtime parameters
m = zeros(1) grp = file.create_group("/RuntimePars")
grp.attrs["PeriodicBoundariesOn"] = periodic
h = full((numGas, 1), eta * boxSize / Lgas)
ds = grp.create_dataset('SmoothingLength', (numGas,1), 'f') #Units
ds[()] = h grp = file.create_group("/Units")
h = zeros(1) grp.attrs["Unit length in cgs (U_L)"] = 1.
grp.attrs["Unit mass in cgs (U_M)"] = 1.
u = full((numGas, 1), internalEnergy) grp.attrs["Unit time in cgs (U_t)"] = 1.
ds = grp.create_dataset('InternalEnergy', (numGas,1), 'f') grp.attrs["Unit current in cgs (U_I)"] = 1.
ds[()] = u grp.attrs["Unit temperature in cgs (U_T)"] = 1.
u = zeros(1)
ids = linspace(0, numGas, numGas, endpoint=False).reshape((numGas,1)) # Gas Particle group
ds = grp.create_dataset('ParticleIDs', (numGas, 1), 'L') grp = file.create_group("/PartType0")
ds[()] = ids + 1
x = ids % Lgas; v = zeros((numGas, 3))
y = ((ids - x) / Lgas) % Lgas; ds = grp.create_dataset('Velocities', (numGas, 3), 'f', data=v)
z = (ids - x - Lgas * y) / Lgas**2;
coords = zeros((numGas, 3)) m = full((numGas, 1), massGas)
coords[:,0] = z[:,0] * boxSize / Lgas + boxSize / (2*Lgas) ds = grp.create_dataset('Masses', (numGas,1), 'f', data=m)
coords[:,1] = y[:,0] * boxSize / Lgas + boxSize / (2*Lgas)
coords[:,2] = x[:,0] * boxSize / Lgas + boxSize / (2*Lgas) h = full((numGas, 1), eta * boxSize / Lgas)
ds = grp.create_dataset('Coordinates', (numGas, 3), 'd') ds = grp.create_dataset('SmoothingLength', (numGas,1), 'f', data=h)
ds[()] = coords
u = full((numGas, 1), internalEnergy)
ds = grp.create_dataset('InternalEnergy', (numGas,1), 'f', data=u)
ids = linspace(offsetGas, offsetGas+numGas, numGas, endpoint=False).reshape((numGas,1))
ds = grp.create_dataset('ParticleIDs', (numGas, 1), 'L', data=ids+1)
# DM Particle group x = ids % Lgas;
grp = file.create_group("/PartType1") y = ((ids - x) / Lgas) % Lgas;
z = (ids - x - Lgas * y) / Lgas**2;
v = zeros((numDM, 3)) coords = zeros((numGas, 3))
ds = grp.create_dataset('Velocities', (numDM, 3), 'f') coords[:,0] = z[:,0] * boxSize / Lgas + boxSize / (2*Lgas)
ds[()] = v coords[:,1] = y[:,0] * boxSize / Lgas + boxSize / (2*Lgas)
v = zeros(1) coords[:,2] = x[:,0] * boxSize / Lgas + boxSize / (2*Lgas)
ds = grp.create_dataset('Coordinates', (numGas, 3), 'd', data=coords)
m = full((numDM, 1), massDM)
ds = grp.create_dataset('Masses', (numDM,1), 'f')
ds[()] = m
m = zeros(1) # DM Particle group
grp = file.create_group("/PartType1")
ids = linspace(0, numDM, numDM, endpoint=False).reshape((numDM,1))
ds = grp.create_dataset('ParticleIDs', (numDM, 1), 'L') v = zeros((numDM, 3))
ds[()] = ids + Lgas**3 + 1 ds = grp.create_dataset('Velocities', (numDM, 3), 'f', data=v)
x = ids % Ldm;
y = ((ids - x) / Ldm) % Ldm; m = full((numDM, 1), massDM)
z = (ids - x - Ldm * y) / Ldm**2; ds = grp.create_dataset('Masses', (numDM,1), 'f', data=m)
coords = zeros((numDM, 3))
coords[:,0] = z[:,0] * boxSize / Ldm + boxSize / (2*Ldm) ids = linspace(offsetDM, offsetDM+numDM, numDM, endpoint=False).reshape((numDM,1))
coords[:,1] = y[:,0] * boxSize / Ldm + boxSize / (2*Ldm) ds = grp.create_dataset('ParticleIDs', (numDM, 1), 'L', data=ids + numGas_tot + 1)
coords[:,2] = x[:,0] * boxSize / Ldm + boxSize / (2*Ldm) ds[()] = ids + Lgas**3 + 1
ds = grp.create_dataset('Coordinates', (numDM, 3), 'd') x = ids % Ldm;
ds[()] = coords y = ((ids - x) / Ldm) % Ldm;
z = (ids - x - Ldm * y) / Ldm**2;
coords = zeros((numDM, 3))
coords[:,0] = z[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
# Star Particle group coords[:,1] = y[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
grp = file.create_group("/PartType4") coords[:,2] = x[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
ds = grp.create_dataset('Coordinates', (numDM, 3), 'd', data=coords)
v = zeros((numStars, 3))
ds = grp.create_dataset('Velocities', (numStars, 3), 'f')
ds[()] = v
v = zeros(1) # Star Particle group
grp = file.create_group("/PartType4")
m = full((numStars, 1), massStars)
ds = grp.create_dataset('Masses', (numStars,1), 'f') v = zeros((numStars, 3))
ds[()] = m ds = grp.create_dataset('Velocities', (numStars, 3), 'f', data=v)
m = zeros(1)
m = full((numStars, 1), massStars)
ids = linspace(0, numStars, numStars, endpoint=False).reshape((numStars,1)) ds = grp.create_dataset('Masses', (numStars,1), 'f', data=m)
ds = grp.create_dataset('ParticleIDs', (numStars, 1), 'L')
ds[()] = ids + Lgas**3 + 1 ids = linspace(0, numStars, numStars, endpoint=False).reshape((numStars,1))
x = ids % Ldm; ds = grp.create_dataset('ParticleIDs', (numStars, 1), 'L', data=ids + numGas_tot + numDM_tot + 1)
y = ((ids - x) / Ldm) % Ldm; x = ids % Ldm;
z = (ids - x - Ldm * y) / Ldm**2; y = ((ids - x) / Ldm) % Ldm;
coords = zeros((numStars, 3)) z = (ids - x - Ldm * y) / Ldm**2;
coords[:,0] = z[:,0] * boxSize / Ldm + boxSize / (2*Ldm) coords = zeros((numStars, 3))
coords[:,1] = y[:,0] * boxSize / Ldm + boxSize / (2*Ldm) coords[:,0] = z[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
coords[:,2] = x[:,0] * boxSize / Ldm + boxSize / (2*Ldm) coords[:,1] = y[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
ds = grp.create_dataset('Coordinates', (numStars, 3), 'd') coords[:,2] = x[:,0] * boxSize / Ldm + boxSize / (2*Ldm)
ds[()] = coords ds = grp.create_dataset('Coordinates', (numStars, 3), 'd', data=coords)
file.close()
# Shift stuff
offsetGas += numGas
offsetDM += numDM
offsetStars += numStars
file.close()
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
if [ ! -e multiTypes.hdf5 ] if [ ! -e multiTypes.hdf5 ]
then then
echo "Generating initial conditions for the multitype box example..." echo "Generating initial conditions for the multitype box example..."
python makeIC.py 9 13 7 python makeIC.py 9 13 7 1
fi fi
../swift -s -g -S -t 1 multiTypes.yml 2>&1 | tee output.log ../swift -s -g -S -t 1 multiTypes.yml 2>&1 | tee output.log
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment