# Inner edge
x3, y3, z3 = random_in_sphere(RSUB * 0.95, RSUB * 1.05, n3)
x3 = np.abs(x3)
y3 = np.abs(y3)
z3 = np.abs(z3)

# Concatenate
x = np.hstack([x0, x1, x2, x3])
y = np.hstack([y0, y1, y2, y3])
z = np.hstack([z0, z1, z2, z3])

# np.savetxt('points.txt', list(zip(x, y, z)))

m.set_voronoi_grid(x, y, z,
                   xmin=-10 * au, xmax=60 * au,
                   ymin=-10 * au, ymax=60 * au,
                   zmin=-10 * au, zmax=60 * au)

density = np.zeros(len(x))

# Ambient medium
in_box = (x > 0.) & (x < 60 * au) & (y > 0.) & (y < 60 * au) & (z > 0.) & (z < 60 * au)
density[in_box] = rho_0

# Set up sphere 1
in_sphere_1 = (x - 10 * au) ** 2 + (y - 15 * au) ** 2 + (z - 20 * au) ** 2 < r_1 ** 2
density[in_sphere_1] = rho_1

# Set up sphere 2
in_sphere_2 = (x - 26.666667 * au) ** 2 + (y - 31.666667 * au) ** 2 + (z - 28.333333 * au) ** 2 < r_2 ** 2
density[in_sphere_2] = rho_2
Exemplo n.º 2
0
def arepo_m_gen(fname, field_add):

    reg, ds, dustdens = arepo_vornoi_grid_generate(fname, field_add)

    xcent = ds.quan(cfg.model.x_cent, 'code_length').to('cm')  #proper cm
    ycent = ds.quan(cfg.model.y_cent, 'code_length').to('cm')
    zcent = ds.quan(cfg.model.z_cent, 'code_length').to('cm')

    boost = np.array([xcent, ycent, zcent])
    print('[arepo_tributary/vornoi_m_gen]:  boost = ', boost)

    #========================================================================
    #Initialize Hyperion Model
    #========================================================================

    m = Model()

    #because we boost the stars to a [0,0,0] coordinate center, we
    #want to make sure our vornoi tesslation is created in the same manner.

    particle_x = reg["gascoordinates"][:, 0].to('cm')
    particle_y = reg["gascoordinates"][:, 1].to('cm')
    particle_z = reg["gascoordinates"][:, 2].to('cm')

    #just for the sake of symmetry, pass on a dx,dy,dz since it can be
    #used optionally downstream in other functions.
    dx = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm')
    dy = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm')
    dz = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm')

    print('[arepo_tributary] boost = ', boost)
    print('[arepo_tributary] xmin (pc)= ', (xcent - dx / 2.).to('pc'))
    print('[arepo_tributary] xmax (pc)= ', (xcent + dx / 2.).to('pc'))
    print('[arepo_tributary] ymin (pc)= ', (ycent - dy / 2.).to('pc'))
    print('[arepo_tributary] ymax (pc)= ', (ycent + dy / 2.).to('pc'))
    print('[arepo_tributary] zmin (pc)= ', (zcent - dz / 2.).to('pc'))
    print('[arepo_tributary] zmax (pc)= ', (zcent + dz / 2.).to('pc'))

    x_pos_boost = (particle_x - xcent).to('cm')
    y_pos_boost = (particle_y - ycent).to('cm')
    z_pos_boost = (particle_z - zcent).to('cm')

    m.set_voronoi_grid(x_pos_boost.value, y_pos_boost.value, z_pos_boost.value)

    #get CMB:

    energy_density_absorbed = energy_density_absorbed_by_CMB()
    specific_energy = np.repeat(energy_density_absorbed.value, dustdens.shape)

    if cfg.par.PAH == True:

        # load PAH fractions for usg, vsg, and big (grain sizes)
        frac = cfg.par.PAH_frac

        # Normalize to 1
        total = np.sum(list(frac.values()))
        frac = {k: v / total for k, v in frac.items()}

        for size in frac.keys():
            d = SphericalDust(cfg.par.dustdir + '%s.hdf5' % size)
            if cfg.par.SUBLIMATION == True:
                d.set_sublimation_temperature(
                    'fast', temperature=cfg.par.SUBLIMATION_TEMPERATURE)
            #m.add_density_grid(dustdens * frac[size], cfg.par.dustdir+'%s.hdf5' % size)
            m.add_density_grid(dustdens * frac[size],
                               d,
                               specific_energy=specific_energy)
        m.set_enforce_energy_range(cfg.par.enforce_energy_range)
    else:
        d = SphericalDust(cfg.par.dustdir + cfg.par.dustfile)
        if cfg.par.SUBLIMATION == True:
            d.set_sublimation_temperature(
                'fast', temperature=cfg.par.SUBLIMATION_TEMPERATURE)
        m.add_density_grid(dustdens, d, specific_energy=specific_energy)
        #m.add_density_grid(dustdens,cfg.par.dustdir+cfg.par.dustfile)
    m.set_specific_energy_type('additional')

    return m, xcent, ycent, zcent, dx.value, dy.value, dz.value, reg, ds, boost
Exemplo n.º 3
0
def arepo_m_gen(fname, field_add):

    reg, ds, dustdens = arepo_vornoi_grid_generate(fname, field_add)

    xcent = ds.quan(cfg.model.x_cent, 'code_length').to('cm')  #proper cm
    ycent = ds.quan(cfg.model.y_cent, 'code_length').to('cm')
    zcent = ds.quan(cfg.model.z_cent, 'code_length').to('cm')

    boost = np.array([xcent, ycent, zcent])
    print('[arepo_tributary/vornoi_m_gen]:  boost = ', boost)

    #========================================================================
    #Initialize Hyperion Model
    #========================================================================

    m = Model()

    #because we boost the stars to a [0,0,0] coordinate center, we
    #want to make sure our vornoi tesslation is created in the same manner.

    particle_x = reg["gas", "coordinates"][:, 0].to('cm')
    particle_y = reg["gas", "coordinates"][:, 1].to('cm')
    particle_z = reg["gas", "coordinates"][:, 2].to('cm')

    #just for the sake of symmetry, pass on a dx,dy,dz since it can be
    #used optionally downstream in other functions.
    dx = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm')
    dy = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm')
    dz = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm')

    print('[arepo_tributary] boost = ', boost)
    print('[arepo_tributary] xmin (pc)= ', (xcent - dx / 2.).to('pc'))
    print('[arepo_tributary] xmax (pc)= ', (xcent + dx / 2.).to('pc'))
    print('[arepo_tributary] ymin (pc)= ', (ycent - dy / 2.).to('pc'))
    print('[arepo_tributary] ymax (pc)= ', (ycent + dy / 2.).to('pc'))
    print('[arepo_tributary] zmin (pc)= ', (zcent - dz / 2.).to('pc'))
    print('[arepo_tributary] zmax (pc)= ', (zcent + dz / 2.).to('pc'))

    x_pos_boost = (particle_x - xcent).to('cm')
    y_pos_boost = (particle_y - ycent).to('cm')
    z_pos_boost = (particle_z - zcent).to('cm')

    m.set_voronoi_grid(x_pos_boost.value, y_pos_boost.value, z_pos_boost.value)

    #get CMB:

    energy_density_absorbed = energy_density_absorbed_by_CMB()
    specific_energy = np.repeat(energy_density_absorbed.value, dustdens.shape)

    if cfg.par.otf_extinction == False:

        if cfg.par.PAH == True:

            # load PAH fractions for usg, vsg, and big (grain sizes)
            frac = cfg.par.PAH_frac

            # Normalize to 1
            total = np.sum(list(frac.values()))
            frac = {k: v / total for k, v in frac.items()}

            for size in frac.keys():
                d = SphericalDust(cfg.par.dustdir + '%s.hdf5' % size)
                if cfg.par.SUBLIMATION == True:
                    d.set_sublimation_temperature(
                        'fast', temperature=cfg.par.SUBLIMATION_TEMPERATURE)
                    #m.add_density_grid(dustdens * frac[size], cfg.par.dustdir+'%s.hdf5' % size)
                m.add_density_grid(dustdens * frac[size],
                                   d,
                                   specific_energy=specific_energy)
            m.set_enforce_energy_range(cfg.par.enforce_energy_range)
        else:
            d = SphericalDust(cfg.par.dustdir + cfg.par.dustfile)
            if cfg.par.SUBLIMATION == True:
                d.set_sublimation_temperature(
                    'fast', temperature=cfg.par.SUBLIMATION_TEMPERATURE)
            m.add_density_grid(dustdens, d, specific_energy=specific_energy)
        #m.add_density_grid(dustdens,cfg.par.dustdir+cfg.par.dustfile)

    else:  #instead of using a constant extinction law across the
        #entire galaxy, we'll compute it on a cell-by-cell bassis by
        #using information about the grain size distribution from
        #the simulation itself.

        ad = ds.all_data()
        nsizes = reg['PartType0', 'NumGrains'].shape[1]
        try:
            assert (np.sum(ad['PartType0', 'NumGrains']) > 0)
        except AssertionError:
            raise AssertionError(
                "[arepo_tributary:] There are no dust grains in this simulation.  This can sometimes happen in an early snapshot of a simulation where the dust has not yet had time to form."
            )
        grid_of_sizes = reg['PartType0', 'NumGrains']
        active_dust_add(ds, m, grid_of_sizes, nsizes, dustdens,
                        specific_energy)

    m.set_specific_energy_type('additional')

    return m, xcent, ycent, zcent, dx.value, dy.value, dz.value, reg, ds, boost