Пример #1
0
def setup_sph_code(sph_code, N1, N2, L, rho,u):
    #rho -- local group density
    converter = nbody_system.nbody_to_si(1 | units.MSun, 1 | units.kpc)
    sph_code = sph_code(converter, redirection = 'none')#, mode = 'periodic')#, redirection = 'none')#change periodic
    #sph_code.parameters.periodic_box_size = 10.0 | units.kpc
    dm = Particles(N1)
    dm.mass = (rho * L**3) / N1
    np.random.seed(12345)
    dm.x = L * np.random.uniform(0.0, 1.0, N1)
    dm.y = L * np.random.uniform(0.0, 1.0, N1)
    dm.z = L * np.random.uniform(0.0, 1.0, N1)
    dm.vx = np.zeros(N1) | units.km / units.s
    dm.vy = np.zeros(N1) | units.km / units.s
    dm.vz = np.zeros(N1) | units.km / units.s
    gas = Particles(N2)
    gas.mass = (rho * L**3) / N2
    gas.x = L * np.random.uniform(0.0, 1.0, N2)
    gas.y = L * np.random.uniform(0.0, 1.0, N2)
    gas.z = L * np.random.uniform(0.0, 1.0, N2)
    gas.vx = np.zeros(N2) | units.km / units.s
    gas.vy = np.zeros(N2) | units.km / units.s
    gas.vz = np.zeros(N2) | units.km / units.s
    gas.u = u 
    if isinstance(sph_code, Fi):
        sph_code.parameters.self_gravity_flag = True
        sph_code.parameters.timestep = 5 | units.Myr
        gas.h_smooth = L / N2**(1/3.0)
        dm.h_smooth = L / N1**(1/3.0)
        #gas.position -= 0.5 * L
        
    sph_code.gas_particles.add_particles(gas)
    sph_code.dm_particles.add_particles(dm)
    sph_code.commit_particles()
    return sph_code
Пример #2
0
def setup_sph_code(N1, N2, L, rho, u):
    #rho -- local group density
    #converter = nbody_system.nbody_to_si(1 | units.MSun, 1 | units.kpc)
    #sph_code = sph_code(converter)#, mode = 'periodic')#, redirection = 'none')#change periodic
    #sph_code.parameters.periodic_box_size = 10.0 | units.kpc
    dm = Particles(N1)
    dm.mass = 0.8 * (rho * L**3) / N1
    #np.random.seed(12345)
    dm.x = L * np.random.uniform(-0.5, 0.5, N1)
    dm.y = L * np.random.uniform(-0.5, 0.5, N1)
    dm.z = L * np.random.uniform(-0.5, 0.5, N1)
    dm.vx = np.zeros(N1) | units.km / units.s
    dm.vy = np.zeros(N1) | units.km / units.s
    dm.vz = np.zeros(N1) | units.km / units.s
    gas = Particles(N2)
    gas.mass = 0.2 * (rho * L**3) / N2
    gas.x = L * np.random.uniform(-0.5, 0.5, N2)
    gas.y = L * np.random.uniform(-0.5, 0.5, N2)
    gas.z = L * np.random.uniform(-0.5, 0.5, N2)
    gas.vx = np.zeros(N2) | units.km / units.s
    gas.vy = np.zeros(N2) | units.km / units.s
    gas.vz = np.zeros(N2) | units.km / units.s
    gas.u = u
    gas.h_smooth = L / N2**(1 / 3.0)
    dm.h_smooth = L / N1**(1 / 3.0)

    #sph_code.gas_particles.add_particles(gas)
    #sph_code.dm_particles.add_particles(dm)
    #sph_code.commit_particles()

    return gas, dm