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
z = k / Nz * boxsize posx[count] = x posy[count] = y posz[count] = z # Make the momenta diverge from the point of lowest density if isclose(x, 0.75 * boxsize, abs_tol=boxsize / Nx): momx[count] -= 0.01 * mass * boxsize / (100 * units.Gyr) elif abs(x - 0.75 * boxsize) < 0.3 * boxsize: if x <= 0.75 * boxsize: fac = -0.5 * exp(-0.07 * (x - 0.75 * boxsize + 0.1 * boxsize)**2) else: fac = +0.5 * exp(-0.07 * (x - 0.75 * boxsize - 0.1 * boxsize)**2) momx[count] += fac * mass * boxsize / (100 * units.Gyr) count += 1 if i < Nx - 1: x = binary_search(x, mass_unitless) # Instantiate particles particles = Component('control particles', 'matter particles', N, mass=mass) 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, initial_conditions)
# This file has to be run in pure Python mode! # Imports from the CO𝘕CEPT code from commons import * from linear import random_uniform from species import Component from snapshot import save # Create a global sine wave along the x-direction, # traversing the box in the x-direction over 10 Gyr. # The y-velocity is 0 and the z-velocity is random. gridsize = 64 Vcell = (boxsize / gridsize)**3 speed = boxsize / (10 * units.Gyr) component = Component('test fluid', 'matter', gridsize=gridsize) ϱ = empty([gridsize] * 3, dtype=float) for i in range(gridsize): ϱ[i, :, :] = 2 + sin(2 * π * i / gridsize) # Unitless ϱ /= sum(ϱ) # Normalize ϱ *= ρ_mbar * gridsize**3 # Apply units component.populate(ϱ, 'ϱ') component.populate(ϱ * speed, 'J', 0) component.populate(zeros([gridsize] * 3, dtype=float), 'J', 1) component.populate(ϱ * speed * random_uniform(-1, 1), 'J', 2) # Save snapshot save(component, initial_conditions)
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)
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})
# 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)
# # 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)
# 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 homogeneous matter distribution perturbed # with a global sine wave along the x-direction. gridsize = 24 component = Component('matter', 'matter', gridsize=gridsize) x = (0.5 + arange(gridsize)) * boxsize / gridsize f = gridsize // 3 // 2 y = cos(f * π / boxsize * x + π / 4) ϱ = empty([gridsize] * 3, dtype=float) for i in range(gridsize): ϱ[i, :, :] = 2 + y[i] # Unitless ϱ /= sum(ϱ) # Normalize ϱ *= ρ_mbar * gridsize**3 # Apply units component.populate(ϱ, 'ϱ') for index in component.J.multi_indices: component.populate(zeros([gridsize] * 3, dtype=float), 'J', index) # Save snapshot save(component, output_dirs['snapshot'] + '/sine.hdf5')
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')
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})