Example #1
0
 def _phiforce(self, R, z, phi=0, t=0):
     """
     NAME:
        _phiforce
     PURPOSE:
        evaluate the azimuth force at (R,z, phi)
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        azimuth force at (R,z, phi)
     HISTORY:
        2016-06-06 - Written - Aladdin 
     """
     if not self.isNonAxi and phi is None:
         phi = 0.
     r, theta, phi = bovy_coords.cyl_to_spher(R, z, phi)
     #x = phi
     dr_dphi = 0
     dtheta_dphi = 0
     dphi_dphi = 1
     return self._computeforceArray(dr_dphi, dtheta_dphi, dphi_dphi, R, z,
                                    phi)
Example #2
0
  def _compute(self, funcTilde, R, z, phi):
      """
      NAME:
         _compute
      PURPOSE:
         evaluate the NxLxM density or potential
      INPUT:
         funcTidle - must be _rhoTilde or _phiTilde
         R - Cylindrical Galactocentric radius
         z - vertical height
         phi - azimuth
      OUTPUT:
         An NxLxM density or potential at (R,z, phi)
      HISTORY:
         2016-05-18 - Written - Aladdin 
      """
      Acos, Asin = self._Acos, self._Asin
      N, L, M = Acos.shape    
      r, theta, phi = bovy_coords.cyl_to_spher(R,z,phi)
      
      
 
      PP = lpmn(M-1,L-1,nu.cos(theta))[0].T ##Get the Legendre polynomials
      func_tilde = funcTilde(r, N, L) ## Tilde of the function of interest 
      
      func = nu.zeros((N,L,M), float) ## The function of interest (density or potential)
      
      m = nu.arange(0, M)[nu.newaxis, nu.newaxis, :]
      mcos = nu.cos(m*phi)
      msin = nu.sin(m*phi)
      func = func_tilde[:,:,None]*(Acos[:,:,:]*mcos + Asin[:,:,:]*msin)*PP[None,:,:]
      return func
Example #3
0
    def _compute(self, funcTilde, R, z, phi):
        """
        NAME:
           _compute
        PURPOSE:
           evaluate the NxLxM density or potential
        INPUT:
           funcTidle - must be _rhoTilde or _phiTilde
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth
        OUTPUT:
           An NxLxM density or potential at (R,z, phi)
        HISTORY:
           2016-05-18 - Written - Aladdin 
        """
        Acos, Asin = self._Acos, self._Asin
        N, L, M = Acos.shape
        r, theta, phi = bovy_coords.cyl_to_spher(R, z, phi)

        PP = lpmn(M - 1, L - 1,
                  nu.cos(theta))[0].T  ##Get the Legendre polynomials
        func_tilde = funcTilde(r, N, L)  ## Tilde of the function of interest

        func = nu.zeros(
            (N, L, M),
            float)  ## The function of interest (density or potential)

        m = nu.arange(0, M)[nu.newaxis, nu.newaxis, :]
        mcos = nu.cos(m * phi)
        msin = nu.sin(m * phi)
        func = func_tilde[:, :, None] * (Acos[:, :, :] * mcos +
                                         Asin[:, :, :] * msin) * PP[None, :, :]
        return func
Example #4
0
    def _computeforce(self, R, z, phi=0, t=0):
        """
        NAME:
           _computeforce
        PURPOSE:
           Evaluate the first derivative of Phi with respect to R, z and phi
        INPUT:
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth
           t - time
        OUTPUT:
           dPhi/dr, dPhi/dtheta, dPhi/dphi
        HISTORY:
           2016-06-07 - Written - Aladdin 
        """
        Acos, Asin = self._Acos, self._Asin
        N, L, M = Acos.shape
        r, theta, phi = bovy_coords.cyl_to_spher(R, z, phi)
        new_hash = hashlib.md5(nu.array([R, z, phi])).hexdigest()

        if new_hash == self._force_hash:
            dPhi_dr = self._cached_dPhi_dr
            dPhi_dtheta = self._cached_dPhi_dtheta
            dPhi_dphi = self._cached_dPhi_dphi

        else:
            PP, dPP = lpmn(M - 1, L - 1,
                           nu.cos(theta))  ##Get the Legendre polynomials
            PP = PP.T[None, :, :]
            dPP = dPP.T[None, :, :]
            phi_tilde = self._phiTilde(r, N, L)[:, :, nu.newaxis]
            dphi_tilde = self._dphiTilde(r, N, L)[:, :, nu.newaxis]

            m = nu.arange(0, M)[nu.newaxis, nu.newaxis, :]
            mcos = nu.cos(m * phi)
            msin = nu.sin(m * phi)
            dPhi_dr = -nu.sum((Acos * mcos + Asin * msin) * PP * dphi_tilde)
            dPhi_dtheta = -nu.sum(
                (Acos * mcos + Asin * msin) * phi_tilde * dPP *
                (-nu.sin(theta)))
            dPhi_dphi = -nu.sum(m *
                                (Asin * mcos - Acos * msin) * phi_tilde * PP)

            self._force_hash = new_hash
            self._cached_dPhi_dr = dPhi_dr
            self._cached_dPhi_dtheta = dPhi_dtheta
            self._cached_dPhi_dphi = dPhi_dphi
        return dPhi_dr, dPhi_dtheta, dPhi_dphi
Example #5
0
 def _computeforce(self,R,z,phi=0,t=0):
     """
     NAME:
        _computeforce
     PURPOSE:
        Evaluate the first derivative of Phi with respect to R, z and phi
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        dPhi/dr, dPhi/dtheta, dPhi/dphi
     HISTORY:
        2016-06-07 - Written - Aladdin 
     """
     Acos, Asin = self._Acos, self._Asin
     N, L, M = Acos.shape    
     r, theta, phi = bovy_coords.cyl_to_spher(R,z,phi)
     new_hash= hashlib.md5(nu.array([R, z,phi])).hexdigest()
     
     if new_hash == self._force_hash:
         dPhi_dr = self._cached_dPhi_dr  
         dPhi_dtheta = self._cached_dPhi_dtheta 
         dPhi_dphi = self._cached_dPhi_dphi
         
     else:        
         PP, dPP = lpmn(M-1,L-1,nu.cos(theta)) ##Get the Legendre polynomials
         PP = PP.T[None,:,:]
         dPP = dPP.T[None,:,:]
         phi_tilde = self._phiTilde(r, N, L)[:,:,nu.newaxis] 
         dphi_tilde = self._dphiTilde(r,N,L)[:,:,nu.newaxis]
         
         m = nu.arange(0, M)[nu.newaxis, nu.newaxis, :]
         mcos = nu.cos(m*phi)
         msin = nu.sin(m*phi)
         dPhi_dr = -nu.sum((Acos*mcos + Asin*msin)*PP*dphi_tilde)
         dPhi_dtheta = -nu.sum((Acos*mcos + Asin*msin)*phi_tilde*dPP*(-nu.sin(theta)))
         dPhi_dphi =-nu.sum(m*(Asin*mcos - Acos*msin)*phi_tilde*PP)
         
         self._force_hash = new_hash
         self._cached_dPhi_dr = dPhi_dr
         self._cached_dPhi_dtheta = dPhi_dtheta
         self._cached_dPhi_dphi = dPhi_dphi
     return dPhi_dr,dPhi_dtheta,dPhi_dphi
Example #6
0
 def _phiforce(self, R,z,phi=0,t=0):
     """
     NAME:
        _phiforce
     PURPOSE:
        evaluate the azimuth force at (R,z, phi)
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        azimuth force at (R,z, phi)
     HISTORY:
        2016-06-06 - Written - Aladdin 
     """
     if not self.isNonAxi and phi is None:
         phi= 0.
     r, theta, phi = bovy_coords.cyl_to_spher(R,z,phi)
     #x = phi
     dr_dphi = 0; dtheta_dphi = 0; dphi_dphi = 1
     return self._computeforceArray(dr_dphi, dtheta_dphi, dphi_dphi, R,z,phi)
Example #7
0
 def _zforce(self, R, z, phi=0., t=0.):
     """
     NAME:
        _zforce
     PURPOSE:
        evaluate the vertical force at (R,z, phi)
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        vertical force at (R,z, phi)
     HISTORY:
        2016-06-06 - Written - Aladdin 
     """
     if not self.isNonAxi and phi is None:
         phi= 0.
     r, theta, phi = bovy_coords.cyl_to_spher(R,z,phi)
     #x = z
     dr_dz = nu.divide(z,r); dtheta_dz = nu.divide(-R,r**2); dphi_dz = 0
     return self._computeforceArray(dr_dz, dtheta_dz, dphi_dz, R,z,phi)
Example #8
0
 def _zforce(self, R, z, phi=0., t=0.):
     """
     NAME:
        _zforce
     PURPOSE:
        evaluate the vertical force at (R,z, phi)
     INPUT:
        R - Cylindrical Galactocentric radius
        z - vertical height
        phi - azimuth
        t - time
     OUTPUT:
        vertical force at (R,z, phi)
     HISTORY:
        2016-06-06 - Written - Aladdin 
     """
     if not self.isNonAxi and phi is None:
         phi= 0.
     r, theta, phi = bovy_coords.cyl_to_spher(R,z,phi)
     #x = z
     dr_dz = nu.divide(z,r); dtheta_dz = nu.divide(-R,r**2); dphi_dz = 0
     return self._computeforceArray(dr_dz, dtheta_dz, dphi_dz, R,z,phi)
Example #9
0
def density1(R, z=0, phi=0.):
    r, theta, phi = bovy_coords.cyl_to_spher(R, z, phi)
    h = potential.HernquistPotential(2)
    return h.dens(R, z, phi) * (1 + numpy.cos(theta) + numpy.cos(theta)**
                                2.) * (1 + numpy.cos(phi) + numpy.sin(phi))
Example #10
0
def axi_density2(R, z=0, phi=0.):
    spherical_coords = bovy_coords.cyl_to_spher(R, z, phi)
    theta = spherical_coords[1]
    return rho_Zeeuw(R, z, phi) * (1 + numpy.cos(theta) + numpy.cos(theta)**2)
Example #11
0
def rho_Zeeuw(R, z, phi, a=1.):
    r, theta, phi = bovy_coords.cyl_to_spher(R, z, phi)
    return 3. / (4 * numpy.pi) * numpy.power((a + r), -4.) * a
Example #12
0
def density1(R, z=0, phi=0.):
    r, theta, phi = bovy_coords.cyl_to_spher(R,z, phi)
    h = potential.HernquistPotential(2)
    return h.dens(R, z, phi)*(1 + numpy.cos(theta) + numpy.cos(theta)**2.)*(1 + numpy.cos(phi) + numpy.sin(phi))
Example #13
0
def axi_density2(R, z=0, phi=0.):
    spherical_coords = bovy_coords.cyl_to_spher(R,z, phi)
    theta = spherical_coords[1]
    return rho_Zeeuw(R,z,phi)*(1 + numpy.cos(theta) + numpy.cos(theta)**2)
Example #14
0
def rho_Zeeuw(R,z,phi,a=1.):
    r, theta, phi = bovy_coords.cyl_to_spher(R,z, phi)
    return 3./(4*numpy.pi) * numpy.power((a + r),-4.) * a