Пример #1
0
def amr_inflow_rate(context, dset, center=None, **kwargs):
    from seren3.utils import unit_vec_r, heaviside

    if (center is None):
        # Locate centre of mass
        if hasattr(context, "base"):
            if hasattr(context.base, "region"):
                center = context.base.region.center
        else:
            from seren3.utils import camera_utils
            center = camera_utils.find_center_of_mass(context)

    unit_l = context.array(context.info["unit_length"])
    pos = dset["pos"].in_units(unit_l) - center
    x,y,z = pos.T

    # Cartesian -> spherical polars
    r = np.sqrt(x**2 + y**2 + z**2)
    theta = np.arccos(z / r)
    phi = np.arctan2(y, x)

    rho = dset["rho"]
    vel = dset["vel"]
    rho_u = (rho * vel.T).T

    mass_flux_scalar = np.zeros(len(theta))
    for i in range(len(theta)):
        th, ph = (theta[i], phi[i])
        unit_r = unit_vec_r(th, ph)
        mass_flux_scalar[i] = np.dot(rho_u[i], unit_r)\
                * heaviside(np.dot(-rho_u[i], unit_r))

    return SimArray( mass_flux_scalar, rho_u.units )
Пример #2
0
def outflow_rate(sim):
    import numpy as np
    from pynbody.array import SimArray
    from seren3.utils import unit_vec_r, heaviside

    flux = []
    units = None
    for i in 'xyz':
        #print i
        fi = sim.g["mf%s" % i]
        flux.append(fi)
        units = fi.units
    flux = np.array(flux).T

    x, y, z = sim.g["pos"].T
    r = np.sqrt(x**2 + y**2 + z**2)
    # theta = sim.g["sg_theta"]
    # phi = sim.g["sg_az"]
    theta = np.arccos(z / r)
    phi = np.arctan2(y, x)

    mass_flux_scalar = np.zeros(len(theta))
    for i in range(len(theta)):
        th, ph = (theta[i], phi[i])
        unit_r = unit_vec_r(th, ph)
        mass_flux_scalar[i] = np.dot(flux[i], unit_r)\
                * heaviside(np.dot(flux[i], unit_r))

    return SimArray(mass_flux_scalar, units)
Пример #3
0
def rad_radial(sim, group):
    import numpy as np
    from pynbody.array import SimArray
    from seren3.utils import unit_vec_r, heaviside

    flux = []
    units = None
    for i in 'xyz':
        #print i
        fi = sim.g["rad_%i_flux_%s" % (group, i)]
        flux.append(fi)
        units = fi.units
    flux = np.array(flux).T

    x, y, z = sim.g["pos"].T
    r = np.sqrt(x**2 + y**2 + z**2)
    # theta = sim.g["sg_theta"]
    # phi = sim.g["sg_az"]
    theta = np.arccos(z / r)
    phi = np.arctan2(y, x)

    flux_scalar = np.zeros(len(theta))
    for i in range(len(theta)):
        th, ph = (theta[i], phi[i])
        unit_r = unit_vec_r(th, ph)
        # Compute outward flux (should always be positive)
        flux_scalar[i] = np.dot(flux[i], unit_r)\
                * heaviside(np.dot(flux[i], unit_r))

    return SimArray(flux_scalar, units)
Пример #4
0
def _rad_group_flux_radial(flux_arr, r, theta, phi):
    '''
    Computes outward flux of radiation from the context center
    '''
    from seren3.utils import unit_vec_r, heaviside

    radial_flux = np.zeros(len(theta))
    for i in range(len(theta)):
        th, ph = (theta[i], phi[i])
        unit_r = unit_vec_r(th, ph)
        radial_flux[i] = np.dot(flux_arr[i], unit_r)\
                * heaviside(np.dot(flux_arr[i], unit_r))

    return SimArray( radial_flux, flux_arr.units )
Пример #5
0
def integrate_surface_flux(flux_map,
                           r,
                           smooth=False,
                           ret_map=False,
                           **smooth_kwargs):
    '''
    Integrates a healpix surface flux to compute the total
    net flux out of the sphere.
    r is the radius of the sphere in meters
    '''
    import healpy as hp
    from scipy.integrate import trapz
    from seren3.array import SimArray

    raise Exception("Function deprecated")

    if not ((isinstance(flux_map, SimArray) or isinstance(r, SimArray))):
        raise Exception("Must pass SimArrays")

    # Compute theta/phi
    npix = len(flux_map)
    nside = hp.npix2nside(npix)
    # theta, phi = hp.pix2ang(nside, range(npix))
    theta, phi = hp.pix2ang(nside, range(npix))
    r = r.in_units("m")  # make sure r is in meters

    # Smoothing?
    if smooth:
        flux_map = hp.smoothing(flux_map, **smooth_kwargs)

    # Compute the integral
    integrand = np.zeros(len(theta))

    for i in range(len(theta)):
        th, ph = (theta[i], phi[i])
        unit_r = unit_vec_r(th, ph)
        integrand[i] = r**2 * np.sin(th)\
         * np.dot(flux_map[i], unit_r)\
         * heaviside(np.dot(flux_map[i], unit_r))

    integrand = integrand[:, None] + np.zeros(
        len(phi))  # 2D over theta and phi

    I = trapz(trapz(integrand, phi), theta)

    return SimArray(I, "s**-1")