Exemplo n.º 1
0
def iliev_test_5(N=10000,
                 L=15. | units.kpc,
                 source_luminosity=5.e48 | units.s**-1,
                 rhoinit=0.001 | (units.amu / units.cm**3),
                 Tinit=100. | units.K,
                 hydro_parameters=dict(),
                 rad_parameters=dict()):

    gamma = 5. / 3.
    mu = 1. | units.amu

    gas = Particles(N)
    # set particles homogeneously in space
    gas.x = L * numpy.random.uniform(-1., 1., N)
    gas.y = L * numpy.random.uniform(-1., 1., N)
    gas.z = L * numpy.random.uniform(-1., 1., N)
    # set other properties
    gas.h_smooth = 0. | units.parsec
    gas.vx = 0. | (units.km / units.s)
    gas.vy = 0. | (units.km / units.s)
    gas.vz = 0. | (units.km / units.s)
    gas.u = 1 / (gamma - 1) * constants.kB * Tinit / mu
    gas.rho = rhoinit
    gas.mass = rhoinit * (2 * L)**3 / N
    gas.flux = 0. | (units.s**-1)
    gas.xion = 0. | units.none

    # set source in the center of the box
    sources = Particles(1)
    sources.x = 0. * L
    sources.y = 0. * L
    sources.z = 0. * L
    sources.luminosity = source_luminosity

    return gas, sources
Exemplo n.º 2
0
def set_gas_and_src(args, CC):
    """ Given the number of particles and box parameters, sets up gas 
  particles and a source particle. """

    gamma = 5. / 3.
    mu = 1.0 | units.amu

    # set particles homogeneously in space from -Lbox/2 to Lbox/2

    if args.grid == 1:

        x, y, z = regular_grid_unit_cube(args.Ngas).make_xyz()

        Ngas = len(x)
        print 'Ngas being updated to: ', Ngas

        gas = Particles(Ngas)
        gas.x = x * CC.Lbox / 2
        gas.y = y * CC.Lbox / 2
        gas.z = z * CC.Lbox / 2

    elif args.grid == 0:

        Ngas = args.Ngas
        gas = Particles(Ngas)
        gas.x = CC.Lbox / 2 * numpy.random.uniform(-1., 1., Ngas)
        gas.y = CC.Lbox / 2 * numpy.random.uniform(-1., 1., Ngas)
        gas.z = CC.Lbox / 2 * numpy.random.uniform(-1., 1., Ngas)

    else:

        print 'args.grid not recognized'
        print 'args.grid = ', args.grid
        sys.exit(1)

# set other properties

    Vperpar = CC.Lbox**3 / Ngas * args.Nngb
    gas.h_smooth = (3 * Vperpar / (4.0 * numpy.pi))**(1. / 3)

    gas.u = 1 / (gamma - 1) * constants.kB * CC.Tinit / mu

    rho_init = (1.0 | units.amu) * CC.nH

    gas.rho = rho_init

    gas.mass = rho_init * CC.Lbox**3 / Ngas

    gas.xion = 1.2e-3

    # set source in the center of the box

    sources = Particles(1)
    sources.x = 0.0 * CC.Lbox
    sources.y = 0.0 * CC.Lbox
    sources.z = 0.0 * CC.Lbox
    sources.luminosity = CC.Lsrc

    return gas, sources
Exemplo n.º 3
0
def iliev_test_5(N=10000,
                 L=15. | units.kpc,
                 source_luminosity=5.e48 | units.s**-1,
                 rhoinit=0.001 | (units.amu / units.cm**3),
                 Tinit=100. | units.K,
                 hydro_parameters=dict(),
                 rad_parameters=dict()):

    gamma = 5. / 3.
    mu = 1. | units.amu

    x, y, z = body_centered_grid_unit_cube(N).make_xyz()
    N = len(x)
    print N
    gas = Particles(N)

    # set particles homogeneously in space
    #  gas.x=L*numpy.random.uniform(-1.,1.,N)
    #  gas.y=L*numpy.random.uniform(-1.,1.,N)
    #  gas.z=L*numpy.random.uniform(-1.,1.,N)

    gas.x = L * x
    gas.y = L * y
    gas.z = L * z

    gas.x += L * numpy.random.uniform(-1., 1., N) / 1000
    gas.y += L * numpy.random.uniform(-1., 1., N) / 1000
    gas.z += L * numpy.random.uniform(-1., 1., N) / 1000

    # set other properties
    gas.h_smooth = 0. | units.parsec
    gas.vx = 0. | (units.km / units.s)
    gas.vy = 0. | (units.km / units.s)
    gas.vz = 0. | (units.km / units.s)
    gas.u = 1 / (gamma - 1) * constants.kB * Tinit / mu
    gas.rho = rhoinit
    gas.mass = rhoinit * (2 * L)**3 / N
    gas.xion = 0.1
    gas.metallicity = 0.02

    # set source in the center of the box
    sources = Particles(1)
    sources.x = 0. * L
    sources.y = 0. * L
    sources.z = 0. * L
    sources.luminosity = source_luminosity

    return gas, sources
Exemplo n.º 4
0
def splitset_from_input_file(input_file):
    x, y, z, n_H, flux, X_ion, u = read_input_file(input_file)

    particles = Particles(len(x))
    particles.x = x | units.parsec
    particles.y = y | units.parsec
    particles.z = z | units.parsec
    particles.rho = n_H | units.amu / units.cm**3
    particles.xion = X_ion | units.none
    particles.u = u | (units.cm**2 / units.s**2)

    a = numpy.where(numpy.array(flux) > 0.)[0]
    src_particles = Particles(len(a))
    src_particles.x = numpy.array(x)[a] | units.parsec
    src_particles.y = numpy.array(y)[a] | units.parsec
    src_particles.z = numpy.array(z)[a] | units.parsec
    src_particles.luminosity = numpy.array(flux)[a] | 1.e48 * units.s**-1

    return particles, src_particles
Exemplo n.º 5
0
def splitset_from_input_file(input_file):
    x, y, z, n_H, flux, X_ion,u = read_input_file(input_file)
    
    particles = Particles(len(x))
    particles.x = x | units.parsec
    particles.y = y | units.parsec
    particles.z = z | units.parsec
    particles.rho = n_H | units.amu / units.cm**3
    particles.xion = X_ion | units.none
    particles.u = u | (units.cm**2/units.s**2)
   
    a=numpy.where(numpy.array(flux) > 0.)[0]
    src_particles=Particles(len(a))
    src_particles.x = numpy.array(x)[a] | units.parsec
    src_particles.y = numpy.array(y)[a] | units.parsec
    src_particles.z = numpy.array(z)[a] | units.parsec
    src_particles.luminosity = numpy.array(flux)[a] | 1.e48*units.s**-1    
    
    return particles,src_particles
Exemplo n.º 6
0
def iliev_test_7_ic(N=10000, Ns=10, L=6.6 | units.kpc):
    print "Initializing iliev_test_7"

    mp = rhoinit * (2 * L)**3 / N
    Nc = ((rhoclump * 4 * constants.pi / 3 * (0.8 | units.kpc)**3) / mp)
    Nc = int(Nc)

    print Nc

    try:
        f = open("glass%9.9i.pkl" % N, "rb")
        x, y, z = cPickle.load(f)
        f.close()
    except:
        x, y, z = glass_unit_cube(N, target_rms=0.05).make_xyz()
        f = open("glass%9.9i.pkl" % N, "wb")
        cPickle.dump((x, y, z), f)
        f.close()

    sel = numpy.where(((x -
                        (5. / 6.6))**2 + y**2 + z**2)**0.5 > (0.8 / 6.6))[0]

    x = x[sel]
    y = y[sel]
    z = z[sel]

    p = Particles(len(x))
    print len(x)
    # set particles homogeneously in space
    p.x = L * x
    p.y = L * y
    p.z = L * z

    # set other properties
    p.h_smooth = 0. | units.parsec
    p.vx = 0. | (units.km / units.s)
    p.vy = 0. | (units.km / units.s)
    p.vz = 0. | (units.km / units.s)
    p.u = uinit
    p.rho = rhoinit
    p.mass = mp
    p.flux = 0. | (units.s**-1)
    p.xion = 0. | units.none

    sources = Particles(Ns)
    x, y, z = uniform_unit_sphere(Ns).make_xyz()
    if Ns == 1:
        x, y, z = 0., 0., 0.

    sources.x = -(5. | units.kpc) + L * x * (1. / N)**(1. / 3) / 10
    sources.y = L * y * (1. / N)**(1. / 3) / 10
    sources.z = L * z * (1. / N)**(1. / 3) / 10
    sources.luminosity = (1.2e52 / Ns) | (units.s**-1)
    sources.SpcType = 1.

    clump = Particles(Nc)
    x, y, z = uniform_unit_sphere(Nc).make_xyz()

    clump.x = (5. | units.kpc) + (0.8 | units.kpc) * x
    clump.y = (0.8 | units.kpc) * y
    clump.z = (0.8 | units.kpc) * z

    clump.h_smooth = 0. | units.parsec
    clump.vx = 0. | (units.km / units.s)
    clump.vy = 0. | (units.km / units.s)
    clump.vz = 0. | (units.km / units.s)
    clump.u = uclump
    clump.rho = rhoclump
    clump.mass = mp
    clump.flux = 0. | (units.s**-1)
    clump.xion = 0. | units.none

    p.add_particles(clump)

    return p, sources
Exemplo n.º 7
0
def set_gas_and_src(Ngas, Lbox, Lsrc, rho_init, T_init):
    """ Given the number of particles and box parameters, sets up gas 
  particles and a source particle. """

    gamma = 5. / 3.
    mu = 1.0 | units.amu

    # set particles homogeneously in space from -Lbox/2 to Lbox/2
    # NOTE reset Ngas

    if args.grid == 1:

        x, y, z = regular_grid_unit_cube(Ngas).make_xyz()
        #x,y,z = body_centered_grid_unit_cube(Ngas).make_xyz()

        Ngas = len(x)
        gas = Particles(Ngas)

        gas.x = x * Lbox / 2
        gas.y = y * Lbox / 2
        gas.z = z * Lbox / 2

    elif args.grid == 0:

        gas = Particles(Ngas)

        gas.x = Lbox / 2 * numpy.random.uniform(-1., 1., Ngas)
        gas.y = Lbox / 2 * numpy.random.uniform(-1., 1., Ngas)
        gas.z = Lbox / 2 * numpy.random.uniform(-1., 1., Ngas)

    else:

        print 'args.grid not recognized'
        print 'args.grid = ', args.grid
        sys.exit(1)


# set zero velocities

    gas.vx = 0. | (units.km / units.s)
    gas.vy = 0. | (units.km / units.s)
    gas.vz = 0. | (units.km / units.s)

    # set other properties

    gas.h_smooth = 0.0 * Lbox  # will be set in call to hydro code

    gas.u = 1 / (gamma - 1) * constants.kB * T_init / mu

    gas.rho = rho_init

    gas.mass = rho_init * Lbox**3 / Ngas

    gas.xion = 1.2e-3

    #gas.dudt=gas.u/(1.| units.Myr)

    # set source in the center of the box

    sources = Particles(1)
    sources.x = 0.0 * Lbox
    sources.y = 0.0 * Lbox
    sources.z = 0.0 * Lbox
    sources.luminosity = Lsrc

    return gas, sources