<commit_before>###############################################################################
#   Potential.py: top-level class for a full potential
#
#   Evaluate by calling the instance: Pot(R,z,phi)
#
#   API for Potentials:
#      function _evaluate(self,R,z,phi) returns Phi(R,z,phi)
#    for orbit integration you need
#      function _Rforce(self,R,z,phi) return -d Phi d R
#      function _zforce(self,R,z,phi) return - d Phi d Z
#    density
#      function _dens(self,R,z,phi) return BOVY??
#    for epicycle frequency
#      function _R2deriv(self,R,z,phi) return d2 Phi dR2
###############################################################################
import os, os.path
import cPickle as pickle
import math
import numpy as nu
from scipy import optimize
import galpy.util.bovy_plot as plot
from plotRotcurve import plotRotcurve, vcirc
from plotEscapecurve import plotEscapecurve
_INF= 1000000.
class Potential:
    """Top-level class for a potential"""
    def __init__(self,amp=1.):
        """
        NAME:
           __init__
        PURPOSE:
        INPUT:
           amp - amplitude to be applied when evaluating the potential and its forces
        OUTPUT:
        HISTORY:
        """
        self._amp= amp
        self.dim= 3
        self.isRZ= True
        self.isNonAxi= False
        self.hasC= False
        return None

    def __call__(self,R,z,phi=0.,t=0.,dR=0,dphi=0):
        """
        NAME:
           __call__
        PURPOSE:
           evaluate the potential at (R,z,phi,t)
        INPUT:
           R - Cylindrical Galactocentric radius

           z - vertical height

           phi - azimuth (optional)

           t - time (optional)

           dR= dphi=, if set to non-zero integers, return the dR, dphi't derivative instead
           
        OUTPUT:
           Phi(R,z,t)
        HISTORY:
           2010-04-16 - Written - Bovy (NYU)
        """
        try:
            return self._amp*self._evaluate(R,z,phi=phi,t=t,dR=dR,dphi=dphi)
        except AttributeError:
            raise PotentialError("'_evaluate' function not implemented for this potential")

    def Rforce(self,R,z,phi=0.,t=0.):
        """
        NAME:
           Rforce
        PURPOSE:
           evaluate radial force K_R  (R,z)
        INPUT:
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth (optional)
           t - time (optional)
        OUTPUT:
           K_R (R,z,phi,t)
        HISTORY:
           2010-04-16 - Written - Bovy (NYU)
        DOCTEST:
        """
        try:
            return self._amp*self._Rforce(R,z,phi=phi,t=t)
        except AttributeError:
            raise PotentialError("'_Rforce' function not implemented for this potential")
        
    def zforce(self,R,z,phi=0.,t=0.):
        """
        NAME:
           zforce
        PURPOSE:
           evaluate the vertical force K_R  (R,z,t)
        INPUT:
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth (optional)
           t - time (optional)
        OUTPUT:
           K_z (R,z,phi,t)
        HISTORY:
           2010-04-16 - Written - Bovy (NYU)
        """
        try:
            return self._amp*self._zforce(R,z,phi=phi,t=t)
        except AttributeError:
            raise PotentialError("'_zforce' function not implemented for this potential")

    def dens(self,R,z,phi=0.,t=0.):
        """
        NAME:
           dens
        PURPOSE:
           evaluate the density rho(R,z,t)
        INPUT:
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth (optional)
           t - time (optional)
        OUTPUT:
           rho (R,z,phi,t)
        HISTORY:
           2010-08-08 - Written - Bovy (NYU)
        """
        try:
            return self._amp*self._dens(R,z,phi=phi,t=t)
        except AttributeError:
            raise PotentialError("'_dens' function not implemented for this potential")

    def R2deriv(self,R,Z,phi=0.,t=0.):
        """
        NAME:

           R2deriv

        PURPOSE:

           evaluate the second radial derivative

        INPUT:

           R - Galactocentric radius

           Z - vertical height

           phi - Galactocentric azimuth

           t - time
<commit_msg>Use Poisson's equation for the density<commit_after>###############################################################################
#   Potential.py: top-level class for a full potential
#
#   Evaluate by calling the instance: Pot(R,z,phi)
#
#   API for Potentials:
#      function _evaluate(self,R,z,phi) returns Phi(R,z,phi)
#    for orbit integration you need
#      function _Rforce(self,R,z,phi) return -d Phi d R
#      function _zforce(self,R,z,phi) return - d Phi d Z
#    density
#      function _dens(self,R,z,phi) return BOVY??
#    for epicycle frequency
#      function _R2deriv(self,R,z,phi) return d2 Phi dR2
###############################################################################
import os, os.path
import cPickle as pickle
import math
import numpy as nu
from scipy import optimize
import galpy.util.bovy_plot as plot
from plotRotcurve import plotRotcurve, vcirc
from plotEscapecurve import plotEscapecurve
_INF= 1000000.
class Potential:
    """Top-level class for a potential"""
    def __init__(self,amp=1.):
        """
        NAME:
           __init__
        PURPOSE:
        INPUT:
           amp - amplitude to be applied when evaluating the potential and its forces
        OUTPUT:
        HISTORY:
        """
        self._amp= amp
        self.dim= 3
        self.isRZ= True
        self.isNonAxi= False
        self.hasC= False
        return None

    def __call__(self,R,z,phi=0.,t=0.,dR=0,dphi=0):
        """
        NAME:
           __call__
        PURPOSE:
           evaluate the potential at (R,z,phi,t)
        INPUT:
           R - Cylindrical Galactocentric radius

           z - vertical height

           phi - azimuth (optional)

           t - time (optional)

           dR= dphi=, if set to non-zero integers, return the dR, dphi't derivative instead
           
        OUTPUT:
           Phi(R,z,t)
        HISTORY:
           2010-04-16 - Written - Bovy (NYU)
        """
        try:
            return self._amp*self._evaluate(R,z,phi=phi,t=t,dR=dR,dphi=dphi)
        except AttributeError:
            raise PotentialError("'_evaluate' function not implemented for this potential")

    def Rforce(self,R,z,phi=0.,t=0.):
        """
        NAME:
           Rforce
        PURPOSE:
           evaluate radial force K_R  (R,z)
        INPUT:
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth (optional)
           t - time (optional)
        OUTPUT:
           K_R (R,z,phi,t)
        HISTORY:
           2010-04-16 - Written - Bovy (NYU)
        DOCTEST:
        """
        try:
            return self._amp*self._Rforce(R,z,phi=phi,t=t)
        except AttributeError:
            raise PotentialError("'_Rforce' function not implemented for this potential")
        
    def zforce(self,R,z,phi=0.,t=0.):
        """
        NAME:
           zforce
        PURPOSE:
           evaluate the vertical force K_R  (R,z,t)
        INPUT:
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth (optional)
           t - time (optional)
        OUTPUT:
           K_z (R,z,phi,t)
        HISTORY:
           2010-04-16 - Written - Bovy (NYU)
        """
        try:
            return self._amp*self._zforce(R,z,phi=phi,t=t)
        except AttributeError:
            raise PotentialError("'_zforce' function not implemented for this potential")

    def dens(self,R,z,phi=0.,t=0.,_forcepoisson=False):
        """
        NAME:
           dens
        PURPOSE:
           evaluate the density rho(R,z,t)
        INPUT:
           R - Cylindrical Galactocentric radius
           z - vertical height
           phi - azimuth (optional)
           t - time (optional)
        OUTPUT:
           rho (R,z,phi,t)
        HISTORY:
           2010-08-08 - Written - Bovy (NYU)
        """
        try:
            if _forcepoisson: raise AttributeError #Hack!
            return self._amp*self._dens(R,z,phi=phi,t=t)
        except AttributeError:
            #Use the Poisson equation to get the density
            return (-self.Rforce(R,z,phi=phi,t=t)/R
                     +self.R2deriv(R,z,phi=phi,t=t)
                     +self.phi2deriv(R,z,phi=phi,t=t)/R**2.
                     +self.z2deriv(R,z,phi=phi,t=t))/4./nu.pi

    def R2deriv(self,R,Z,phi=0.,t=0.):
        """
        NAME:

           R2deriv

        PURPOSE:

           evaluate the second radial derivative

        INPUT:

           R - Galactocentric radius

           Z - vertical height

           phi - Galactocentric azimuth

           t - time

{'fraction_non_alphanumeric': 0.12848784878487848, 'fraction_numerical': 0.013613861386138614, 'mean_word_length': 1.761416589002796, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3929808', 'n_tokens_mistral': 2879, 'n_tokens_neox': 2658, 'n_words': 695}