def test_density1_Order(): Acos, Asin = potential.scf_compute_coeffs(density1, 5,5) Acos2, Asin2 = potential.scf_compute_coeffs(density1, 5,5, radial_order=19, costheta_order=19, phi_order=19) assert numpy.all(numpy.fabs(Acos - Acos2) < 1e-3), \ "Increasing the radial, costheta, and phi order fails for Acos from scf_compute_coeffs" assert numpy.all(numpy.fabs(Asin - Asin) < EPS), \ "Increasing the radial, costheta, and phi order fails for Asin from scf_compute_coeffs"
def test_scf_ZeeuwCoeffs_ReducesToSpherical(): Aspherical = potential.scf_compute_coeffs_spherical(rho_Zeeuw, 5) Aaxi = potential.scf_compute_coeffs(rho_Zeeuw, 5, 5, radial_order=20, costheta_order=20) reducesto_spherical(Aspherical, Aaxi, "Zeeuw Potential")
def test_scf_compute_nbody_twopowertriaxial(): N = int(1e5) Mh = 11. ah = 50. / 8. m = Mh / N yfactor = 1.5 zfactor = 2.5 nsamp = 10 Norder = 10 Lorder = 10 hern = potential.HernquistPotential(amp=2 * Mh, a=ah) hern.turn_physical_off() hdf = df.isotropicHernquistdf(hern) numpy.random.seed(2) samp = [hdf.sample(n=N) for i in range(nsamp)] positions = numpy.array( [[samp[i].x(), samp[i].y() * yfactor, samp[i].z() * zfactor] for i in range(nsamp)]) # This is an triaxial Hernquist profile with the same mass as the above tptp = potential.TwoPowerTriaxialPotential(amp=2. * Mh / yfactor / zfactor, a=ah, alpha=1., beta=4., b=yfactor, c=zfactor) tptp.turn_physical_off() cc, ss = potential.scf_compute_coeffs(tptp.dens, Norder, Lorder, a=ah) c, s = numpy.zeros((2, nsamp, Norder, Lorder, Lorder)) for i, p in enumerate(positions): c[i], s[i] = potential.scf_compute_coeffs_nbody(p, Norder, Lorder, mass=m * numpy.ones(N), a=ah) # Check that the difference between the coefficients is within two standard deviations assert (cc - (numpy.mean(c, axis=0)) <= (2. * numpy.std(c, axis=0))).all() # Repeat test for single mass c, s = numpy.zeros((2, nsamp, Norder, Lorder, Lorder)) for i, p in enumerate(positions): c[i], s[i] = potential.scf_compute_coeffs_nbody(p, Norder, Lorder, mass=m, a=ah) assert (cc - (numpy.mean(c, axis=0)) <= (2. * numpy.std(c, axis=0))).all() return None
def compute_Acos_Asin(n=9, l=19, a=1. / ro, radial_order=40, costheta_order=40, phi_order=40): Acos, Asin = potential.scf_compute_coeffs( lambda R, z, p: rho_bar_cyl(R * 8., z * 8., p) / (10**9. * bovy_conversion.dens_in_msolpc3(220., 8.)), N=n + 1, L=l + 1, a=a, radial_order=radial_order, costheta_order=costheta_order, phi_order=phi_order) return (Acos, Asin)
def compare_dens_nbody(): N = int(1e5) Mh = 11. ah = 50. / 8. m = Mh / N factor = 1. nsamp = 10 Norder = 10 Lorder = 10 hern = potential.HernquistPotential(amp=2 * Mh, a=ah) hern.turn_physical_off() hdf = df.isotropicHernquistdf(hern) samp = [hdf.sample(n=N) for i in range(nsamp)] positions = numpy.array([[samp[i].x(), samp[i].y(), samp[i].z() * factor] for i in range(nsamp)]) tptp = potential.TwoPowerTriaxialPotential(amp=2. * Mh, a=ah, alpha=1., beta=4., b=1., c=factor) tptp.turn_physical_off() cc, ss = potential.scf_compute_coeffs(tptp.dens, Norder, Lorder, a=ah) c, s = numpy.zeros((2, nsamp, Norder, Lorder, Lorder)) for i, p in enumerate(positions): c[i], s[i] = potential.scf_compute_coeffs_nbody(p, m * numpy.ones(N) * factor, Norder, Lorder, a=ah) # Check that the difference between the coefficients is within two standard deviations assert (cc - (numpy.mean(c, axis=0)) <= (2. * numpy.std(c, axis=0))).all()
def test_scf_HernquistCoeffs_ReducesToSpherical(): Aspherical = potential.scf_compute_coeffs_spherical( sphericalHernquistDensity, 5) Aaxi = potential.scf_compute_coeffs(sphericalHernquistDensity, 5, 5) reducesto_spherical(Aspherical, Aaxi, "Hernquist Potential")
def test_scf_ZeeuwCoeffs_ReducesToSpherical(): Aspherical = potential.scf_compute_coeffs_spherical(rho_Zeeuw, 5) Aaxi = potential.scf_compute_coeffs(rho_Zeeuw, 5,5,radial_order=20, costheta_order=20) reducesto_spherical(Aspherical,Aaxi, "Zeeuw Potential")
def test_scf_HernquistCoeffs_ReducesToSpherical(): Aspherical = potential.scf_compute_coeffs_spherical(sphericalHernquistDensity, 5) Aaxi = potential.scf_compute_coeffs(sphericalHernquistDensity, 5,5) reducesto_spherical(Aspherical,Aaxi, "Hernquist Potential")