Ejemplo n.º 1
0
def dump(particles, output_filenames, op=None):
    global a, a_dump, drift_fac, i_dump, kick_fac
    # Do nothing if not at dump time
    if a != a_dump:
        return False
    # Synchronize positions and momenta before dumping
    if op == 'drift':
        particles.drift(drift_fac[0])
    elif op == 'kick':
        particles.kick(kick_fac[1])
    # Dump terminal render
    if a in terminal_render_times:
        terminal_render(particles)
    # Dump snapshot
    if a in snapshot_times:
        save(particles, a, output_filenames['snapshot'].format(a))
    # Dump powerspectrum
    if a in powerspec_times:
        powerspec(particles, output_filenames['powerspec'].format(a))
    # Dump render
    if a in render_times:
        render(particles, a, output_filenames['render'].format(a),
               cleanup=(a == render_times[len(render_times) - 1]))
    # Increment dump time
    i_dump += 1
    if i_dump < len(a_dumps):
        a_dump = a_dumps[i_dump]
    # Reset the second kick factor,
    # making the next operation a half kick.
    kick_fac[1] = 0
    return True
Ejemplo n.º 2
0
posx = zeros(N)
posy = zeros(N)
posz = zeros(N)
momx = zeros(N)
momy = zeros(N)
momz = zeros(N)
count = 0
for i in range(round(N**(1/3))):
    for j in range(round(N**(1/3))):
        for k in range(round(N**(1/3))):
            x = (i/N**(1/3)*boxsize + (random()*2 - 1)*mean_sep*0.1) % boxsize
            y = (j/N**(1/3)*boxsize + (random()*2 - 1)*mean_sep*0.1) % boxsize
            z = (k/N**(1/3)*boxsize + (random()*2 - 1)*mean_sep*0.1) % boxsize
            posx[count] = x
            posy[count] = y
            posz[count] = z
            momx[count] = (random()*2 - 1)*max_mom
            momy[count] = (random()*2 - 1)*max_mom
            momz[count] = (random()*2 - 1)*max_mom
            count += 1
particles.populate(posx, 'posx')
particles.populate(posy, 'posy')
particles.populate(posz, 'posz')
particles.populate(momx, 'momx')
particles.populate(momy, 'momy')
particles.populate(momz, 'momz')

# Save snapshot
save(particles, a_begin, IC_file)

Ejemplo n.º 3
0
# This file has to be run in pure Python mode!

# Imports from the CO𝘕CEPT code
from commons import *
from species import Component
from snapshot import save

# Create stationary, homogeneous matter distribution,
# perturbed with global, stationary sine wave along
# the x-direction.
w  = user_params['_w']
ρ0 = user_params['_ρ0']
A  = user_params['_A']
σ  = user_params['_σ']
gridsize = 4*16  # Should be a multiple of 4
N = gridsize**3
component = Component('test fluid', 'matter fluid', gridsize, boltzmann_order=2)
ρ = empty([gridsize]*3)
for i in range(gridsize):
    x = boxsize*i/gridsize
    ρ[i, :, :] = ρ0 + A*sin(x/boxsize*2*π)
component.populate(ρ, 'ϱ')
for multi_index in component.J.multi_indices:
    component.populate(zeros([gridsize]*3), 'J', multi_index)
for multi_index in component.ς.multi_indices:
    component.populate(ones([gridsize]*3)*ρ*(1 + w)*σ, 'ς', multi_index)

# Save snapshot
save(component, initial_conditions)
Ejemplo n.º 4
0
#
# You should have received a copy of the GNU General Public License
# along with CO𝘕CEPT. If not, see http://www.gnu.org/licenses/
#
# The author of CO𝘕CEPT can be contacted at dakin(at)phys.au.dk
# The latest version of CO𝘕CEPT is available at
# https://github.com/jmd-dk/concept/



# This file has to be run in pure Python mode!

# Imports from the CO𝘕CEPT code
from commons import *
from species import Component
from snapshot import save

# Create the particle
N = 1
mass = ρ_mbar*boxsize**3/N
particles = Component('test particles', 'matter particles', N, mass=mass)
particles.populate(np.array([0.75])*boxsize, 'posx')
particles.populate(np.array([0.75])*boxsize, 'posy')
particles.populate(np.array([0.75])*boxsize, 'posz')
particles.populate(ones(N)*boxsize/(10*units.Gyr)*mass, 'momx')
particles.populate(ones(N)*boxsize/(10*units.Gyr)*mass, 'momy')
particles.populate(ones(N)*boxsize/(10*units.Gyr)*mass, 'momz')

# Save snapshot
save(particles, initial_conditions)
Ejemplo n.º 5
0
N = N_lin**3
mass = Ωm*ϱ*boxsize**3/N
particles = construct('dark matter particles', 'dark matter', mass, N)
posx = empty(N)
posy = empty(N)
posz = empty(N)
momx = zeros(N)
momy = zeros(N)
momz = zeros(N)
count = 0
boxsize_over_N_lin = boxsize/N_lin
for i in range(N_lin):
    X = i*boxsize_over_N_lin
    for j in range(N_lin):
        Y = j*boxsize_over_N_lin
        for k in range(N_lin):
            Z = k*boxsize_over_N_lin
            posx[count] = normal(loc=X, scale=R_tophat) % boxsize
            posy[count] = normal(loc=Y, scale=R_tophat) % boxsize
            posz[count] = normal(loc=Z, scale=R_tophat) % boxsize
            count += 1
particles.populate(posx, 'posx')
particles.populate(posy, 'posy')
particles.populate(posz, 'posz')
particles.populate(momx, 'momx')
particles.populate(momy, 'momy')
particles.populate(momz, 'momz')

# Save snapshot
save(particles, a_begin, this_dir + '/snapshot')
Ejemplo n.º 6
0
        Y = j*boxsize_over_N_lin
        for k in range(N_lin):
            Z = k*boxsize_over_N_lin
            posx[count] = mod(random_gaussian(X, R_tophat), boxsize)
            posy[count] = mod(random_gaussian(Y, R_tophat), boxsize)
            posz[count] = mod(random_gaussian(Z, R_tophat), boxsize)
            count += 1
component.populate(posx, 'posx')
component.populate(posy, 'posy')
component.populate(posz, 'posz')
component.populate(momx, 'momx')
component.populate(momy, 'momy')
component.populate(momz, 'momz')

# Save snapshot
save(component, initial_conditions)

# Expand particle locations by a factor of 2
posx = component.posx
posy = component.posy
posz = component.posz
for i in range(N):
    posx[i] *= 2
    posy[i] *= 2
    posz[i] *= 2

# Save another snapshot, this time with an enlarged boxsize,
# matching the expanded particle locations.
save(component,
     '{}_double_boxsize{}'.format(*os.path.splitext(initial_conditions)),
     {'boxsize': 2*boxsize})