Skip to content
Snippets Groups Projects
Commit cc2dfa53 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Removed unnecessary lines in script to generate ICs for external point mass example.

parent 60f2b07c
Branches
Tags
No related merge requests found
...@@ -31,7 +31,7 @@ SPH: ...@@ -31,7 +31,7 @@ SPH:
# Parameters related to the initial conditions # Parameters related to the initial conditions
InitialConditions: InitialConditions:
file_name: Sphere.hdf5 # The file to read file_name: PointMass.hdf5 # The file to read
shift_x: 50. # A shift to apply to all particles read from the ICs (in internal units). shift_x: 50. # A shift to apply to all particles read from the ICs (in internal units).
shift_y: 50. shift_y: 50.
shift_z: 50. shift_z: 50.
......
...@@ -24,7 +24,7 @@ import numpy ...@@ -24,7 +24,7 @@ import numpy
import math import math
import random import random
# Generates a random distriution of particles, for motion in an external potnetial centred at (0,0,0) # Generates a random distriution of particles, for motion in an external potential centred at (0,0,0)
# physical constants in cgs # physical constants in cgs
NEWTON_GRAVITY_CGS = 6.67408e-8 NEWTON_GRAVITY_CGS = 6.67408e-8
...@@ -39,34 +39,28 @@ const_unit_velocity_in_cgs = (1e5) ...@@ -39,34 +39,28 @@ const_unit_velocity_in_cgs = (1e5)
print "UnitMass_in_cgs: ", const_unit_mass_in_cgs print "UnitMass_in_cgs: ", const_unit_mass_in_cgs
print "UnitLength_in_cgs: ", const_unit_length_in_cgs print "UnitLength_in_cgs: ", const_unit_length_in_cgs
print "UnitVelocity_in_cgs: ", const_unit_velocity_in_cgs print "UnitVelocity_in_cgs: ", const_unit_velocity_in_cgs
print "UnitTime_in_cgs: ", const_unit_length_in_cgs / const_unit_velocity_in_cgs
# derived units # derived units
const_unit_time_in_cgs = (const_unit_length_in_cgs / const_unit_velocity_in_cgs) const_unit_time_in_cgs = (const_unit_length_in_cgs / const_unit_velocity_in_cgs)
const_G = ((NEWTON_GRAVITY_CGS*const_unit_mass_in_cgs*const_unit_time_in_cgs*const_unit_time_in_cgs/(const_unit_length_in_cgs*const_unit_length_in_cgs*const_unit_length_in_cgs))) const_G = ((NEWTON_GRAVITY_CGS*const_unit_mass_in_cgs*const_unit_time_in_cgs*const_unit_time_in_cgs/(const_unit_length_in_cgs*const_unit_length_in_cgs*const_unit_length_in_cgs)))
print 'G=', const_G print '---------------------'
print 'G in internal units: ', const_G
# Parameters # Parameters
periodic= 1 # 1 For periodic box periodic= 1 # 1 For periodic box
boxSize = 100. # boxSize = 100. #
Radius = boxSize / 4. # maximum radius of particles Radius = boxSize / 4. # maximum radius of particles
G = const_G
Mass = 1e10 Mass = 1e10
print "Mass at the centre: ", Mass
N = int(sys.argv[1]) # Number of particles numPart = int(sys.argv[1]) # Number of particles
L = N**(1./3.) mass = 1.
# these are not used but necessary for I/O fileName = "PointMass.hdf5"
rho = 2. # Density
P = 1. # Pressure
gamma = 5./3. # Gas adiabatic index
fileName = "Sphere.hdf5"
#---------------------------------------------------
numPart = N
mass = 1
internalEnergy = P / ((gamma - 1.)*rho)
#-------------------------------------------------- #--------------------------------------------------
...@@ -98,24 +92,24 @@ grp.attrs["Unit current in cgs (U_I)"] = 1. ...@@ -98,24 +92,24 @@ grp.attrs["Unit current in cgs (U_I)"] = 1.
grp.attrs["Unit temperature in cgs (U_T)"] = 1. grp.attrs["Unit temperature in cgs (U_T)"] = 1.
#Particle group #Particle group
#grp0 = file.create_group("/PartType0")
grp1 = file.create_group("/PartType1") grp1 = file.create_group("/PartType1")
#generate particle positions #generate particle positions
radius = Radius * (numpy.random.rand(N))**(1./3.) radius = Radius * (numpy.random.rand(numPart))**(1./3.)
ctheta = -1. + 2 * numpy.random.rand(N) ctheta = -1. + 2 * numpy.random.rand(numPart)
stheta = numpy.sqrt(1.-ctheta**2) stheta = numpy.sqrt(1.-ctheta**2)
phi = 2 * math.pi * numpy.random.rand(N) phi = 2 * math.pi * numpy.random.rand(numPart)
r = numpy.zeros((numPart, 3)) r = numpy.zeros((numPart, 3))
# r[:,0] = radius * stheta * numpy.cos(phi)
# r[:,1] = radius * stheta * numpy.sin(phi)
# r[:,2] = radius * ctheta
r[:,0] = radius r[:,0] = radius
#
speed = numpy.sqrt(G * Mass / radius) #generate particle velocities
speed = numpy.sqrt(const_G * Mass / radius)
v = numpy.zeros((numPart, 3)) v = numpy.zeros((numPart, 3))
omega = speed / radius omega = speed / radius
period = 2.*math.pi/omega period = 2.*math.pi/omega
print 'period = minimum = ',min(period), ' maximum = ',max(period) print '---------------------'
print 'Period: minimum = ',min(period)
print 'Period: maximum = ',max(period)
v[:,0] = -omega * r[:,1] v[:,0] = -omega * r[:,1]
v[:,1] = omega * r[:,0] v[:,1] = omega * r[:,0]
...@@ -129,17 +123,6 @@ ds = grp1.create_dataset('Masses', (numPart,), 'f') ...@@ -129,17 +123,6 @@ ds = grp1.create_dataset('Masses', (numPart,), 'f')
ds[()] = m ds[()] = m
m = numpy.zeros(1) m = numpy.zeros(1)
h = numpy.full((numPart, ), 1.1255 * boxSize / L)
ds = grp1.create_dataset('SmoothingLength', (numPart,), 'f')
ds[()] = h
h = numpy.zeros(1)
u = numpy.full((numPart, ), internalEnergy)
ds = grp1.create_dataset('InternalEnergy', (numPart,), 'f')
ds[()] = u
u = numpy.zeros(1)
ids = 1 + numpy.linspace(0, numPart, numPart, endpoint=False) ids = 1 + numpy.linspace(0, numPart, numPart, endpoint=False)
ds = grp1.create_dataset('ParticleIDs', (numPart, ), 'L') ds = grp1.create_dataset('ParticleIDs', (numPart, ), 'L')
ds[()] = ids ds[()] = ids
......
#!/bin/bash #!/bin/bash
# Generate the initial conditions if they are not present. # Generate the initial conditions if they are not present.
if [ ! -e Sphere.hdf5 ] if [ ! -e PointMass.hdf5 ]
then then
echo "Generating initial conditions for the point mass potential box example..." echo "Generating initial conditions for the point mass potential box example..."
python makeIC.py 10000 python makeIC.py 10000
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment