Beispiel #1
0
def _integrateRZOrbit(vxvv, pot, t, method, dt):
    """
    NAME:
       _integrateRZOrbit
    PURPOSE:
       integrate an orbit in a Phi(R,z) potential in the (R,z) plane
    INPUT:
       vxvv - array with the initial conditions stacked like
              [R,vR,vT,z,vz]; vR outward!
       pot - Potential instance
       t - list of times at which to output (0 has to be in this!)
       method - 'odeint' or 'leapfrog'
       dt - if set, force the integrator to use this basic stepsize; must be an integer divisor of output stepsize
    OUTPUT:
       [:,5] array of [R,vR,vT,z,vz] at each t
    HISTORY:
       2010-04-16 - Written - Bovy (NYU)
    """
    #First check that the potential has C
    if '_c' in method:
        if not _check_c(pot):
            if ('leapfrog' in method or 'symplec' in method):
                method = 'leapfrog'
            else:
                method = 'odeint'
            warnings.warn(
                "Cannot use C integration because some of the potentials are not implemented in C (using %s instead)"
                % (method), galpyWarning)
    if method.lower() == 'leapfrog' \
            or method.lower() == 'leapfrog_c' or method.lower() == 'rk4_c' \
            or method.lower() == 'rk6_c' or method.lower() == 'symplec4_c' \
            or method.lower() == 'symplec6_c' or method.lower() == 'dopr54_c':
        #We hack this by upgrading to a FullOrbit
        this_vxvv = nu.zeros(len(vxvv) + 1)
        this_vxvv[0:len(vxvv)] = vxvv
        tmp_out = _integrateFullOrbit(this_vxvv, pot, t, method, dt)
        #tmp_out is (nt,6)
        out = tmp_out[:, 0:5]
    elif method.lower() == 'odeint':
        l = vxvv[0] * vxvv[2]
        l2 = l**2.
        init = [vxvv[0], vxvv[1], vxvv[3], vxvv[4]]
        intOut = integrate.odeint(_RZEOM,
                                  init,
                                  t,
                                  args=(pot, l2),
                                  rtol=10.**-8.)  #,mxstep=100000000)
        out = nu.zeros((len(t), 5))
        out[:, 0] = intOut[:, 0]
        out[:, 1] = intOut[:, 1]
        out[:, 3] = intOut[:, 2]
        out[:, 4] = intOut[:, 3]
        out[:, 2] = l / out[:, 0]
    #post-process to remove negative radii
    neg_radii = (out[:, 0] < 0.)
    out[neg_radii, 0] = -out[neg_radii, 0]
    return out
Beispiel #2
0
def _integrateRZOrbit(vxvv,pot,t,method,dt):
    """
    NAME:
       _integrateRZOrbit
    PURPOSE:
       integrate an orbit in a Phi(R,z) potential in the (R,z) plane
    INPUT:
       vxvv - array with the initial conditions stacked like
              [R,vR,vT,z,vz]; vR outward!
       pot - Potential instance
       t - list of times at which to output (0 has to be in this!)
       method - 'odeint' or 'leapfrog'
       dt - if set, force the integrator to use this basic stepsize; must be an integer divisor of output stepsize
    OUTPUT:
       [:,5] array of [R,vR,vT,z,vz] at each t
    HISTORY:
       2010-04-16 - Written - Bovy (NYU)
    """
    #First check that the potential has C
    if '_c' in method:
        if isinstance(pot,list):
            allHasC= nu.prod([p.hasC for p in pot])
        else:
            allHasC= pot.hasC
        if not allHasC and ('leapfrog' in method or 'symplec' in method):
            method= 'leapfrog'
        elif not allHasC:
            method= 'odeint'
    if method.lower() == 'leapfrog' \
            or method.lower() == 'leapfrog_c' or method.lower() == 'rk4_c' \
            or method.lower() == 'rk6_c' or method.lower() == 'symplec4_c' \
            or method.lower() == 'symplec6_c' or method.lower() == 'dopr54_c':
        #We hack this by upgrading to a FullOrbit
        this_vxvv= nu.zeros(len(vxvv)+1)
        this_vxvv[0:len(vxvv)]= vxvv
        tmp_out= _integrateFullOrbit(this_vxvv,pot,t,method,dt)
        #tmp_out is (nt,6)
        out= tmp_out[:,0:5]
    elif method.lower() == 'odeint':
        l= vxvv[0]*vxvv[2]
        l2= l**2.
        init= [vxvv[0],vxvv[1],vxvv[3],vxvv[4]]
        intOut= integrate.odeint(_RZEOM,init,t,args=(pot,l2),
                                 rtol=10.**-8.)#,mxstep=100000000)
        out= nu.zeros((len(t),5))
        out[:,0]= intOut[:,0]
        out[:,1]= intOut[:,1]
        out[:,3]= intOut[:,2]
        out[:,4]= intOut[:,3]
        out[:,2]= l/out[:,0]
    #post-process to remove negative radii
    neg_radii= (out[:,0] < 0.)
    out[neg_radii,0]= -out[neg_radii,0]
    return out
Beispiel #3
0
def _integrateRZOrbit(vxvv,pot,t,method):
    """
    NAME:
       _integrateRZOrbit
    PURPOSE:
       integrate an orbit in a Phi(R,z) potential in the (R,z) plane
    INPUT:
       vxvv - array with the initial conditions stacked like
              [R,vR,vT,z,vz]; vR outward!
       pot - Potential instance
       t - list of times at which to output (0 has to be in this!)
       method - 'odeint' or 'leapfrog'
    OUTPUT:
       [:,5] array of [R,vR,vT,z,vz] at each t
    HISTORY:
       2010-04-16 - Written - Bovy (NYU)
    """
    if method.lower() == 'leapfrog' \
            or method.lower() == 'leapfrog_c' or method.lower() == 'rk4_c' \
            or method.lower() == 'rk6_c' or method.lower() == 'symplec4_c' \
            or method.lower() == 'symplec6_c' or method.lower() == 'dopr54_c':
        #We hack this by upgrading to a FullOrbit
        this_vxvv= nu.zeros(len(vxvv)+1)
        this_vxvv[0:len(vxvv)]= vxvv
        tmp_out= _integrateFullOrbit(this_vxvv,pot,t,method)
        #tmp_out is (nt,6)
        out= tmp_out[:,0:5]
    elif method.lower() == 'odeint':
        l= vxvv[0]*vxvv[2]
        l2= l**2.
        init= [vxvv[0],vxvv[1],vxvv[3],vxvv[4]]
        intOut= integrate.odeint(_RZEOM,init,t,args=(pot,l2),
                                 rtol=10.**-8.)#,mxstep=100000000)
        out= nu.zeros((len(t),5))
        out[:,0]= intOut[:,0]
        out[:,1]= intOut[:,1]
        out[:,3]= intOut[:,2]
        out[:,4]= intOut[:,3]
        out[:,2]= l/out[:,0]
    #post-process to remove negative radii
    neg_radii= (out[:,0] < 0.)
    out[neg_radii,0]= -out[neg_radii,0]
    return out