def test_nemo_PlummerPotential(): pp = potential.PlummerPotential(normalize=1., b=2.) tmax = 3. vo, ro = 213., 8.23 o = Orbit([1., 0.1, 1.1, 0.3, 0.1, 0.4], ro=ro, vo=vo) run_orbitIntegration_comparison(o, pp, tmax, vo, ro, tol=0.03) return None
def test_isotropic_plummer_beta_directint(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) tol= 1e-8 check_beta_directint(dfp,tol,rmin=pot._scale/10.,rmax=pot._scale*10., bins=31) return None
def test_isotropic_plummer_beta(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) numpy.random.seed(10) samp= dfp.sample(n=1000000) tol= 6*1e-2 check_beta(samp,pot,tol,rmin=pot._scale/10.,rmax=pot._scale*10.,bins=31) return None
def test_isotropic_plummer_sigmar_directint(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) tol= 1e-5 check_sigmar_against_jeans_directint(dfp,pot,tol, rmin=pot._scale/10., rmax=pot._scale*10., bins=31) return None
def test_isotropic_plummer_dens_directint(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) tol= 1e-7 check_dens_directint(dfp,pot,tol, lambda r: pot.dens(r,0)/2.3, # need to divide by mass rmin=pot._scale/10., rmax=pot._scale*10.,bins=31) return None
def test_isotropic_plummer_sigmar(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) numpy.random.seed(10) samp= dfp.sample(n=1000000) tol= 0.05 check_sigmar_against_jeans(samp,pot,tol, rmin=pot._scale/10.,rmax=pot._scale*10., bins=31) return None
def test_isotropic_plummer_dens_massprofile(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) numpy.random.seed(10) samp= dfp.sample(n=100000) tol= 5*1e-3 check_spherical_massprofile(samp,lambda r: pot.mass(r)\ /pot.mass(numpy.amax(samp.r())), tol,skip=1000) return None
def test_isotropic_plummer_dens_spherically_symmetric(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) numpy.random.seed(10) samp= dfp.sample(n=100000) # Check spherical symmetry for different harmonics l,m tol= 1e-2 check_spherical_symmetry(samp,0,0,tol) check_spherical_symmetry(samp,1,0,tol) check_spherical_symmetry(samp,1,-1,tol) check_spherical_symmetry(samp,1,1,tol) check_spherical_symmetry(samp,2,0,tol) check_spherical_symmetry(samp,2,-1,tol) check_spherical_symmetry(samp,2,-2,tol) check_spherical_symmetry(samp,2,1,tol) check_spherical_symmetry(samp,2,2,tol) # and some higher order ones check_spherical_symmetry(samp,3,1,tol) check_spherical_symmetry(samp,9,-6,tol) return None
def test_dynamfric_c(): import copy from galpy.orbit import Orbit from galpy.potential.Potential import _check_c from galpy.potential.mwpotentials import McMillan17 #Basic parameters for the test times = numpy.linspace(0., -100., 1001) #~3 Gyr at the Solar circle integrator = 'dop853_c' py_integrator = 'dop853' #Define all of the potentials (by hand, because need reasonable setup) MWPotential3021 = copy.deepcopy(potential.MWPotential2014) MWPotential3021[2] *= 1.5 # Increase mass by 50% pots= [potential.LogarithmicHaloPotential(normalize=1), potential.LogarithmicHaloPotential(normalize=1.3, q=0.9,b=0.7), #nonaxi potential.NFWPotential(normalize=1.,a=1.5), potential.MiyamotoNagaiPotential(normalize=.02,a=10.,b=10.), potential.MiyamotoNagaiPotential(normalize=.6,a=0.,b=3.), # special case potential.PowerSphericalPotential(alpha=2.3,normalize=2.), potential.DehnenSphericalPotential(normalize=4.,alpha=1.2), potential.DehnenCoreSphericalPotential(normalize=4.), potential.HernquistPotential(normalize=1.,a=3.5), potential.JaffePotential(normalize=1.,a=20.5), potential.DoubleExponentialDiskPotential(normalize=0.2, hr=3.,hz=0.6), potential.FlattenedPowerPotential(normalize=3.), potential.FlattenedPowerPotential(normalize=3.,alpha=0), #special case potential.IsochronePotential(normalize=2.), potential.PowerSphericalPotentialwCutoff(normalize=0.3,rc=10.), potential.PlummerPotential(normalize=.6,b=3.), potential.PseudoIsothermalPotential(normalize=.1,a=3.), potential.BurkertPotential(normalize=.2,a=2.5), potential.TriaxialHernquistPotential(normalize=1.,a=3.5, b=0.8,c=0.9), potential.TriaxialNFWPotential(normalize=1.,a=1.5,b=0.8,c=0.9), potential.TriaxialJaffePotential(normalize=1.,a=20.5,b=0.8,c=1.4), potential.PerfectEllipsoidPotential(normalize=.3,a=3.,b=0.7,c=1.5), potential.PerfectEllipsoidPotential(normalize=.3,a=3.,b=0.7,c=1.5, pa=3.,zvec=[0.,1.,0.]), #rotated potential.HomogeneousSpherePotential(normalize=0.02,R=82./8), # make sure to go to dens = 0 part, potential.interpSphericalPotential(\ rforce=potential.HomogeneousSpherePotential(normalize=0.02, R=82./8.), rgrid=numpy.linspace(0.,82./8.,201)), potential.TriaxialGaussianPotential(normalize=.03,sigma=4.,b=0.8,c=1.5,pa=3.,zvec=[1.,0.,0.]), potential.SCFPotential(Acos=numpy.array([[[1.]]]), # same as Hernquist normalize=1.,a=3.5), potential.SCFPotential(Acos=numpy.array([[[1.,0.],[.3,0.]]]), # nonaxi Asin=numpy.array([[[0.,0.],[1e-1,0.]]]), normalize=1.,a=3.5), MWPotential3021, McMillan17 # SCF + DiskSCF ] #tolerances in log10 tol = {} tol['default'] = -7. # Following are a little more difficult tol['DoubleExponentialDiskPotential'] = -4.5 tol['TriaxialHernquistPotential'] = -6. tol['TriaxialNFWPotential'] = -6. tol['TriaxialJaffePotential'] = -6. tol['MWPotential3021'] = -6. tol['HomogeneousSpherePotential'] = -6. tol['interpSphericalPotential'] = -6. # == HomogeneousSpherePotential tol['McMillan17'] = -6. for p in pots: if not _check_c(p, dens=True): continue # dynamfric not in C! pname = type(p).__name__ if pname == 'list': if isinstance(p[0],potential.PowerSphericalPotentialwCutoff) \ and len(p) > 1 \ and isinstance(p[1],potential.MiyamotoNagaiPotential) \ and len(p) > 2 \ and isinstance(p[2],potential.NFWPotential): pname = 'MWPotential3021' # Must be! else: pname = 'McMillan17' #print(pname) if pname in list(tol.keys()): ttol = tol[pname] else: ttol = tol['default'] # Setup orbit, ~ LMC o = Orbit([ 5.13200034, 1.08033051, 0.23323391, -3.48068653, 0.94950884, -1.54626091 ]) # Setup dynamical friction object if pname == 'McMillan17': cdf= potential.ChandrasekharDynamicalFrictionForce(\ GMs=0.5553870441722593,rhm=5./8.,dens=p,maxr=500./8,nr=101) ttimes = numpy.linspace(0., -30., 1001) #~1 Gyr at the Solar circle else: cdf= potential.ChandrasekharDynamicalFrictionForce(\ GMs=0.5553870441722593,rhm=5./8.,dens=p,maxr=500./8,nr=201) ttimes = times # Integrate in C o.integrate(ttimes, p + cdf, method=integrator) # Integrate in Python op = o() op.integrate(ttimes, p + cdf, method=py_integrator) # Compare r (most important) assert numpy.amax(numpy.fabs(o.r(ttimes)-op.r(ttimes))) < 10**ttol, \ 'Dynamical friction in C does not agree with dynamical friction in Python for potential {}'.format(pname) return None
def test_isotropic_plummer_energyoutofbounds(): pot= potential.PlummerPotential(amp=2.3,b=1.3) dfp= isotropicPlummerdf(pot=pot) assert numpy.all(numpy.fabs(dfp((numpy.arange(0.1,10.,0.1),1.1))) < 1e-8), 'Evaluating the isotropic Plummer DF at E > 0 does not give zero' assert numpy.all(numpy.fabs(dfp((pot(0,0)-1e-4,1.1))) < 1e-8), 'Evaluating the isotropic Plummer DF at E < -GM/a does not give zero' return None