Commit a9f62315 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Lower memory footprint for the IC generation script.

parent e7f9b9a1
...@@ -27,7 +27,7 @@ from numpy import * ...@@ -27,7 +27,7 @@ from numpy import *
# Parameters # Parameters
periodic= 1 # 1 For periodic box periodic= 1 # 1 For periodic box
boxSize = 1. boxSize = 1.
L = 100 # Number of particles along one axis L = 1200 # Number of particles along one axis
rho = 2. # Density rho = 2. # Density
P = 1. # Pressure P = 1. # Pressure
gamma = 5./3. # Gas adiabatic index gamma = 5./3. # Gas adiabatic index
...@@ -39,21 +39,6 @@ numPart = L**3 ...@@ -39,21 +39,6 @@ numPart = L**3
mass = boxSize**3 * rho / numPart mass = boxSize**3 * rho / numPart
internalEnergy = P / ((gamma - 1.)*rho) internalEnergy = P / ((gamma - 1.)*rho)
#Generate particles
ids = linspace(0, numPart, numPart, endpoint=False, dtype='L').reshape((numPart,1))
v = zeros((numPart, 3))
m = full((numPart, 1), mass)
h = full((numPart, 1), 2.251 * boxSize / L)
u = full((numPart, 1), internalEnergy)
x = ids % L;
y = ((ids - x) / L) % L;
z = (ids - x - L * y) / L**2;
coords = zeros((numPart, 3))
coords[:,0] = z[:,0] * boxSize / L + boxSize / (2*L)
coords[:,1] = y[:,0] * boxSize / L + boxSize / (2*L)
coords[:,2] = x[:,0] * boxSize / L + boxSize / (2*L)
#-------------------------------------------------- #--------------------------------------------------
#File #File
...@@ -77,17 +62,39 @@ grp.attrs["PeriodicBoundariesOn"] = periodic ...@@ -77,17 +62,39 @@ grp.attrs["PeriodicBoundariesOn"] = periodic
#Particle group #Particle group
grp = file.create_group("/PartType0") grp = file.create_group("/PartType0")
ds = grp.create_dataset('Coordinates', (numPart, 3), 'd')
ds[()] = coords v = zeros((numPart, 3))
ds = grp.create_dataset('Velocities', (numPart, 3), 'f') ds = grp.create_dataset('Velocities', (numPart, 3), 'f')
ds[()] = v ds[()] = v
v = zeros(1)
m = full((numPart, 1), mass)
ds = grp.create_dataset('Masses', (numPart,1), 'f') ds = grp.create_dataset('Masses', (numPart,1), 'f')
ds[()] = m ds[()] = m
m = zeros(1)
h = full((numPart, 1), 2.251 * boxSize / L)
ds = grp.create_dataset('SmoothingLength', (numPart,1), 'f') ds = grp.create_dataset('SmoothingLength', (numPart,1), 'f')
ds[()] = h ds[()] = h
h = zeros(1)
u = full((numPart, 1), internalEnergy)
ds = grp.create_dataset('InternalEnergy', (numPart,1), 'f') ds = grp.create_dataset('InternalEnergy', (numPart,1), 'f')
ds[()] = u ds[()] = u
u = zeros(1)
ids = linspace(0, numPart, numPart, endpoint=False, dtype='L').reshape((numPart,1))
ds = grp.create_dataset('ParticleIDs', (numPart, 1), 'L') ds = grp.create_dataset('ParticleIDs', (numPart, 1), 'L')
ds[()] = ids ds[()] = ids
x = ids % L;
y = ((ids - x) / L) % L;
z = (ids - x - L * y) / L**2;
coords = zeros((numPart, 3))
coords[:,0] = z[:,0] * boxSize / L + boxSize / (2*L)
coords[:,1] = y[:,0] * boxSize / L + boxSize / (2*L)
coords[:,2] = x[:,0] * boxSize / L + boxSize / (2*L)
ds = grp.create_dataset('Coordinates', (numPart, 3), 'd')
ds[()] = coords
file.close() file.close()
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