def calAcc(r, v) : 
    N = r.shape[0]
    a = np.zeros([N,3])
    dt_min = np.ones(N)*1e5*yrs
    dr = r
    dx = r[:,0]
    dy = r[:,1]
    dz = r[:,2]
    dv = v
    dr_gp = np.sqrt(dx*dx + dy*dy)/(r0*kpc) # galpy units
    dz_gp = dz/(r0*kpc)
    drNorm = np.linalg.norm(dr, axis = 1)
    acc = None
    if useNFW : 
        m, rho, sigma = NFWmass( drNorm)
        acc = -G*m/(drNorm*drNorm)[:,np.newaxis]*dr/drNorm[:,np.newaxis]
    elif useHernquist:
        m, rho, sigma = hernquistmass( drNorm)
        acc = -G*m/(drNorm*drNorm)[:,np.newaxis]*dr/drNorm[:,np.newaxis]
    else : 
        acc = np.zeros([dr_gp.size,3])
        conv = 1e-13*1e5
        for i, x_gp, y_gp, r_gp, z_gp in zip(range(dr_gp.size), dx/(r0*kpc), dy/(r0*kpc), dr_gp, dz_gp) : 
            a = gp.evaluateRforces(MWpot,r_gp,z_gp)*bovy_conversion.force_in_10m13kms2(v0,r0)*conv
            acc[i,0] = a*x_gp/r_gp
            acc[i,1] = a*y_gp/r_gp
            acc[i,2] = gp.evaluatezforces(MWpot,r_gp,z_gp)*bovy_conversion.force_in_10m13kms2(v0,r0)*conv
    dt_rmin = np.min(drNorm/np.linalg.norm(dv, axis=1))
    dt_amin = np.min(np.linalg.norm(dv,axis=1)/np.maximum(np.linalg.norm(acc,axis=1), TINY))
    dt_min = min(dt_rmin, dt_amin)
    if(args.use_DF) : 
        acc = acc + accDF( r, v)
    return acc, dt_min
Пример #2
0
def accmaps(npix=200):
    #First setup the potential, the following are the best-fit parameters from the Sec. 5 of our paper
    #params= numpy.array([-1.33663190049,0.998420232634,-3.49031638164,0.31949840593,-1.63965169376])
    params= numpy.array([-1.33663190049,0.998420232634,-3.0736938150237028,0.31949840593,-1.63965169376]) #this has a scale height of 360 pc
    try:
        pot= setup_potential(params)
    except RuntimeError: #if this set of parameters gives a nonsense potential
        raise
    #Setup grid and output
    Rs= numpy.linspace(0.01,20.,npix)/_REFR0
    Zs= numpy.linspace(0.,20.,npix)/_REFR0
    accR_dm= numpy.empty((len(Rs),len(Zs)))
    accZ_dm= numpy.empty((len(Rs),len(Zs)))
    accR_baryon= numpy.empty((len(Rs),len(Zs)))
    accZ_baryon= numpy.empty((len(Rs),len(Zs)))
    #Calculate accelerations
    for ii in range(len(Rs)):
        for jj in range(len(Zs)):
            accR_dm[ii,jj]= potential.evaluateRforces(Rs[ii],Zs[jj],[pot[0]])
            accZ_dm[ii,jj]= potential.evaluatezforces(Rs[ii],Zs[jj],[pot[0]])
            accR_baryon[ii,jj]= potential.evaluateRforces(Rs[ii],Zs[jj],pot[1:])
            accZ_baryon[ii,jj]= potential.evaluatezforces(Rs[ii],Zs[jj],pot[1:])
    accR_dm*= bovy_conversion.force_in_10m13kms2(_REFV0*params[1],_REFR0)
    accZ_dm*= bovy_conversion.force_in_10m13kms2(_REFV0*params[1],_REFR0)
    accR_baryon*= bovy_conversion.force_in_10m13kms2(_REFV0*params[1],_REFR0)
    accZ_baryon*= bovy_conversion.force_in_10m13kms2(_REFV0*params[1],_REFR0)
    return (accR_dm,accZ_dm,accR_baryon,accZ_baryon,Rs,Zs)
Пример #3
0
def test_force_in_10m13kms2():
    #Test the scaling, as a 1st derivative of the potential, should scale as velocity^2/position
    vofid, rofid = 200., 8.
    assert numpy.fabs(
        4. * bovy_conversion.force_in_10m13kms2(vofid, rofid) /
        bovy_conversion.force_in_10m13kms2(2. * vofid, rofid) -
        1.) < 10.**-10., 'force_in_10m13kms2 did not work as expected'
    assert numpy.fabs(
        .5 * bovy_conversion.force_in_10m13kms2(vofid, rofid) /
        bovy_conversion.force_in_10m13kms2(vofid, 2 * rofid) -
        1.) < 10.**-10., 'force_in_10m13kms2 did not work as expected'
    return None
def calAcc(r, v):
    N = r.shape[0]
    a = np.zeros([N, 3])
    dt_min = np.ones(N) * 1e5 * yrs
    dr = r
    dx = r[:, 0]
    dy = r[:, 1]
    dz = r[:, 2]
    dv = v
    dr_gp = np.sqrt(dx * dx + dy * dy) / (r0 * kpc)  # galpy units
    dz_gp = dz / (r0 * kpc)
    drNorm = np.linalg.norm(dr, axis=1)
    acc = None
    if useNFW:
        m, rho, sigma = NFWmass(drNorm)
        acc = -G * m / (drNorm *
                        drNorm)[:, np.newaxis] * dr / drNorm[:, np.newaxis]
    elif useHernquist:
        m, rho, sigma = hernquistmass(drNorm)
        acc = -G * m / (drNorm *
                        drNorm)[:, np.newaxis] * dr / drNorm[:, np.newaxis]
    else:
        acc = np.zeros([dr_gp.size, 3])
        conv = 1e-13 * 1e5
        for i, x_gp, y_gp, r_gp, z_gp in zip(range(dr_gp.size),
                                             dx / (r0 * kpc), dy / (r0 * kpc),
                                             dr_gp, dz_gp):
            a = gp.evaluateRforces(MWpot, r_gp,
                                   z_gp) * bovy_conversion.force_in_10m13kms2(
                                       v0, r0) * conv
            acc[i, 0] = a * x_gp / r_gp
            acc[i, 1] = a * y_gp / r_gp
            acc[i, 2] = gp.evaluatezforces(
                MWpot, r_gp, z_gp) * bovy_conversion.force_in_10m13kms2(
                    v0, r0) * conv
    dt_rmin = np.min(drNorm / np.linalg.norm(dv, axis=1))
    dt_amin = np.min(
        np.linalg.norm(dv, axis=1) /
        np.maximum(np.linalg.norm(acc, axis=1), TINY))
    dt_min = min(dt_rmin, dt_amin)
    if (args.use_DF):
        acc = acc + accDF(r, v)
    return acc, dt_min
Пример #5
0
def calAcc(r, v) : 
    N = r.shape[0]
    dr = r
    dx = r[:,0]
    dy = r[:,1]
    dz = r[:,2]
    dv = v
    dr_gp = np.sqrt(dx*dx + dy*dy)/(r0*kpc) # galpy units
    dz_gp = dz/(r0*kpc)
    drNorm = np.linalg.norm(dr, axis = 1)
    acc = None
    if useNFW : 
        m, rho, sigma = NFWmass( drNorm)
        acc = -G*m/(drNorm*drNorm)[:,np.newaxis]*dr/drNorm[:,np.newaxis]
    elif useHernquist:
        m, rho, sigma = hernquistmass( drNorm)
        acc = (-G*m/(drNorm*drNorm*drNorm))[:,np.newaxis]*dr#[:,np.newaxis]*dr
    else : 
        acc = np.zeros([dr_gp.size,3])
        conv = 1e-13*1e5
        for i, x_gp, y_gp, r_gp, z_gp in zip(range(dr_gp.size), dx/(r0*kpc), dy/(r0*kpc), dr_gp, dz_gp) : 
            a = gp.evaluateRforces(MWpot,r_gp,z_gp)*bovy_conversion.force_in_10m13kms2(v0,r0)*conv
            acc[i,0] = a*x_gp/r_gp
            acc[i,1] = a*y_gp/r_gp
            acc[i,2] = gp.evaluatezforces(MWpot,r_gp,z_gp)*bovy_conversion.force_in_10m13kms2(v0,r0)*conv
    dt_rmin = np.min(drNorm/np.linalg.norm(dv, axis=1))
    dt_amin = np.min(np.linalg.norm(dv,axis=1)/np.maximum(np.linalg.norm(acc,axis=1), TINY))
    dt_min = min(dt_rmin, dt_amin)
    if(useDF) : 
        acc[:Nsat,:] = acc[:Nsat,:] + accDF( r[:Nsat,:], v[:Nsat,:])
    if(useTestParticles and Nsat < N and runSat) :
        # include accelerations from other satellites for test particles
        for i in range(Nsat) : 
            rsat = r[i]
            dr = r[Nsat:,:] - rsat[np.newaxis,:]
            drNorm = np.linalg.norm( dr, axis=1)
            m, rho, sigma = hernquistmass( drNorm, m0=msat[i], vc200=vc200sat[i], r200=r200sat[i], c0=c0sat[i])
            acc[Nsat:,:] =  acc[Nsat:,:] - (G*m/(drNorm*drNorm*drNorm))[:,np.newaxis]*dr
    return acc, dt_min
Пример #6
0
def test_force_in_10m13kms2():
    #Test the scaling, as a 1st derivative of the potential, should scale as velocity^2/position
    vofid, rofid= 200., 8.
    assert numpy.fabs(4.*bovy_conversion.force_in_10m13kms2(vofid,rofid)/bovy_conversion.force_in_10m13kms2(2.*vofid,rofid)-1.) < 10.**-10., 'force_in_10m13kms2 did not work as expected'
    assert numpy.fabs(.5*bovy_conversion.force_in_10m13kms2(vofid,rofid)/bovy_conversion.force_in_10m13kms2(vofid,2*rofid)-1.) < 10.**-10., 'force_in_10m13kms2 did not work as expected'
    return None