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

Faster way of generating ICs in python.

parent bf19a904
...@@ -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 = 50 # Number of particles along one axis L = 100 # 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
...@@ -40,32 +40,19 @@ mass = boxSize**3 * rho / numPart ...@@ -40,32 +40,19 @@ mass = boxSize**3 * rho / numPart
internalEnergy = P / ((gamma - 1.)*rho) internalEnergy = P / ((gamma - 1.)*rho)
#Generate particles #Generate particles
coords = zeros((numPart, 3)) ids = linspace(0, numPart, numPart, endpoint=False, dtype='L').reshape((numPart,1))
v = zeros((numPart, 3)) v = zeros((numPart, 3))
m = zeros((numPart, 1)) m = full((numPart, 1), mass)
h = zeros((numPart, 1)) h = full((numPart, 1), 2.251 * boxSize / L)
u = zeros((numPart, 1)) u = full((numPart, 1), internalEnergy)
ids = zeros((numPart, 1), dtype='L')
for i in range(L): x = ids % L;
for j in range(L): y = ((ids - x) / L) % L;
for k in range(L): z = (ids - x - L * y) / L**2;
index = i*L*L + j*L + k coords = zeros((numPart, 3))
x = i * boxSize / L + boxSize / (2*L) coords[:,0] = z[:,0] * boxSize / L + boxSize / (2*L)
y = j * boxSize / L + boxSize / (2*L) coords[:,1] = y[:,0] * boxSize / L + boxSize / (2*L)
z = k * boxSize / L + boxSize / (2*L) coords[:,2] = x[:,0] * boxSize / L + boxSize / (2*L)
coords[index,0] = x
coords[index,1] = y
coords[index,2] = z
v[index,0] = 0.
v[index,1] = 0.
v[index,2] = 0.
m[index] = mass
h[index] = 2.251 * boxSize / L
u[index] = internalEnergy
ids[index] = index
#-------------------------------------------------- #--------------------------------------------------
......
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