Example #1
0
 def fun(Ecomplex):
     E = Ecomplex[0] + 1j*Ecomplex[1]
     q = sqrt(2*(E+V0))
     g = sqrt(-2*E)
     y = q*spherical_jn(l, q*a, True)*spherical_kn(l,g*a) \
       - g*spherical_kn(l, g*a, True)*spherical_jn(l,q*a)
     return array([real(y), imag(y)])
 def test_spherical_kn_recurrence_complex(self):
     # http://dlmf.nist.gov/10.51.E4
     n = np.array([1, 2, 3, 7, 12])
     x = 1.1 + 1.5j
     assert_allclose(
         (-1) ** (n - 1) * spherical_kn(n - 1, x) - (-1) ** (n + 1) * spherical_kn(n + 1, x),
         (-1) ** n * (2 * n + 1) / x * spherical_kn(n, x),
     )
    def test_sph_in_kn_order0(self):
        x = 1.0
        sph_i0 = np.empty((2,))
        sph_i0[0] = spherical_in(0, x)
        sph_i0[1] = spherical_in(0, x, derivative=True)
        sph_i0_expected = np.array([np.sinh(x) / x, np.cosh(x) / x - np.sinh(x) / x ** 2])
        assert_array_almost_equal(r_[sph_i0], sph_i0_expected)

        sph_k0 = np.empty((2,))
        sph_k0[0] = spherical_kn(0, x)
        sph_k0[1] = spherical_kn(0, x, derivative=True)
        sph_k0_expected = np.array([0.5 * pi * exp(-x) / x, -0.5 * pi * exp(-x) * (1 / x + 1 / x ** 2)])
        assert_array_almost_equal(r_[sph_k0], sph_k0_expected)
    def test_sph_in_kn_order0(self):
        x = 1.
        sph_i0 = np.empty((2, ))
        sph_i0[0] = spherical_in(0, x)
        sph_i0[1] = spherical_in(0, x, derivative=True)
        sph_i0_expected = np.array(
            [np.sinh(x) / x,
             np.cosh(x) / x - np.sinh(x) / x**2])
        assert_array_almost_equal(r_[sph_i0], sph_i0_expected)

        sph_k0 = np.empty((2, ))
        sph_k0[0] = spherical_kn(0, x)
        sph_k0[1] = spherical_kn(0, x, derivative=True)
        sph_k0_expected = np.array(
            [0.5 * pi * exp(-x) / x, -0.5 * pi * exp(-x) * (1 / x + 1 / x**2)])
        assert_array_almost_equal(r_[sph_k0], sph_k0_expected)
Example #5
0
 def test_spherical_kn_inf_complex(self):
     # https://dlmf.nist.gov/10.52.E6
     # The behavior at complex infinity depends on the sign of the real
     # part: if Re(z) >= 0, then the limit is 0; if Re(z) < 0, then it's
     # z*inf.  This distinction cannot be captured, so we return nan.
     n = 7
     x = np.array([-inf + 0j, inf + 0j, inf * (1 + 1j)])
     assert_allclose(spherical_kn(n, x), np.array([-inf, 0, nan]))
 def test_spherical_kn_inf_complex(self):
     # http://dlmf.nist.gov/10.52.E6
     # The behavior at complex infinity depends on the sign of the real
     # part: if Re(z) >= 0, then the limit is 0; if Re(z) < 0, then it's
     # z*inf.  This distinction cannot be captured, so we return nan.
     n = 7
     x = np.array([-inf + 0j, inf + 0j, inf * (1 + 1j)])
     assert_allclose(spherical_kn(n, x), np.array([-inf, 0, nan]))
Example #7
0
    def asym_WF_b(self, r, E):                                                                         
        """
        The asymptotic wave function and its derivative (d/drho!) 
        for both neutral and charged particle bound states. 
        """
        gammaB=np.sqrt(-2*self.mu*E)/self.hbar  # binding momentum
        rho=gammaB *r 
        eta=self.eta_func(gammaB) # corresponding to binding momentum gammaB
        if np.sum(np.shape(rho))==0 :
            if np.absolute(rho)<1.e-16: rho=1.e-16
        else:
            rho[np.isclose(rho,0, atol=1.e-16)]=1.e-16

        if self.test_not_coulomb:
            f=ss.spherical_kn(self.angL, rho)*2./np.pi*rho # note 2/pi factor and the rho factor
            df=f/rho+ss.spherical_kn(self.angL, rho, derivative=True)*2./np.pi*rho
        else:
            hvalue=None
            dirvalue=None
            f=np.array(coulombw_ufunc(self.angL, -eta,  rho)).astype(float)
            df=np.array(drho_coulombw_ufunc(self.angL, -eta,  rho, hvalue, dirvalue)).astype(float)
        return f, df
    def test_sph_kn(self):
        kn = np.empty((2, 3))
        x = 0.2

        kn[0][0] = spherical_kn(0, x)
        kn[0][1] = spherical_kn(1, x)
        kn[0][2] = spherical_kn(2, x)
        kn[1][0] = spherical_kn(0, x, derivative=True)
        kn[1][1] = spherical_kn(1, x, derivative=True)
        kn[1][2] = spherical_kn(2, x, derivative=True)

        kn0 = -kn[0][1]
        kn1 = -kn[0][0] - 2.0 / 0.2 * kn[0][1]
        kn2 = -kn[0][1] - 3.0 / 0.2 * kn[0][2]
        assert_array_almost_equal(kn[0], [6.4302962978445670140, 38.581777787067402086, 585.15696310385559829], 12)
        assert_array_almost_equal(kn[1], [kn0, kn1, kn2], 9)
Example #9
0
    def test_sph_kn(self):
        kn = np.empty((2, 3))
        x = 0.2

        kn[0][0] = spherical_kn(0, x)
        kn[0][1] = spherical_kn(1, x)
        kn[0][2] = spherical_kn(2, x)
        kn[1][0] = spherical_kn(0, x, derivative=True)
        kn[1][1] = spherical_kn(1, x, derivative=True)
        kn[1][2] = spherical_kn(2, x, derivative=True)

        kn0 = -kn[0][1]
        kn1 = -kn[0][0] - 2.0 / 0.2 * kn[0][1]
        kn2 = -kn[0][1] - 3.0 / 0.2 * kn[0][2]
        assert_array_almost_equal(kn[0], [
            6.4302962978445670140, 38.581777787067402086, 585.15696310385559829
        ], 12)
        assert_array_almost_equal(kn[1], [kn0, kn1, kn2], 9)
 def df(self, n, z):
     return spherical_kn(n, z, derivative=True)
 def f(self, n, z):
     return spherical_kn(n, z)
 def test_spherical_kn_at_zero_complex(self):
     # http://dlmf.nist.gov/10.52.E2
     n = np.array([0, 1, 2, 5, 10, 100])
     x = 0 + 0j
     assert_allclose(spherical_kn(n, x), nan * np.ones(shape=n.shape))
Example #13
0
 def test_spherical_kn_at_zero(self):
     # https://dlmf.nist.gov/10.52.E2
     n = np.array([0, 1, 2, 5, 10, 100])
     x = 0
     assert_allclose(spherical_kn(n, x), inf*np.ones(shape=n.shape))
 def test_spherical_kn_inf_real(self):
     # http://dlmf.nist.gov/10.52.E6
     n = 5
     x = np.array([-inf, inf])
     assert_allclose(spherical_kn(n, x), np.array([-inf, 0]))
Example #15
0
 def test_spherical_kn_at_zero(self):
     # http://dlmf.nist.gov/10.52.E2
     n = np.array([0, 1, 2, 5, 10, 100])
     x = 0
     assert_allclose(spherical_kn(n, x), inf * np.ones(shape=n.shape))
Example #16
0
 def test_spherical_kn_exact(self):
     # https://dlmf.nist.gov/10.49.E13
     x = np.array([0.12, 1.23, 12.34, 123.45])
     assert_allclose(spherical_kn(2, x),
                     pi / 2 * exp(-x) * (1 / x + 3 / x * x + 3 / x * x * x))
Example #17
0
 def f(self, n, z):
     return spherical_kn(n, z)
Example #18
0
 def df(self, n, z):
     return spherical_kn(n, z, derivative=True)
Example #19
0
 def test_spherical_kn_recurrence_real(self):
     # https://dlmf.nist.gov/10.51.E4
     n = np.array([1, 2, 3, 7, 12])
     x = 0.12
     assert_allclose((-1)**(n - 1)*spherical_kn(n - 1, x) - (-1)**(n + 1)*spherical_kn(n + 1,x),
                     (-1)**n*(2*n + 1)/x*spherical_kn(n, x))
Example #20
0
def transl_yuk_z_SR_recurs(LMax, dr, k):
    """
    Translate coaxially from regular to singular, Gumerov and Duraiswami.

    Inputs
    ------
    l : int
        Order of multipole expansion to output rotation matrix coefficient H

    Reference
    ---------
    "Recursions for the computation of multipole translation and rotation
    coefficients for the 3-d helmholtz equation."

    https://arxiv.org/pdf/1403.7698v1.pdf
    """
    # Create (E|F)_{l,m}^{m}
    eflm = np.zeros([2 * LMax + 1, LMax + 1])
    # Start (E|F)_{l, 0}^{0}
    ls = np.arange(2 * LMax + 1)
    eflm[:, 0] = (-1)**ls * np.sqrt(2 * ls + 1) * sp.spherical_kn(ls, k * dr)
    # now recursion 4.86 for (E|F)_{l, m}^{m}
    for m in range(LMax):
        for l in range(2 * LMax - m):
            # (n=m)
            blmm = get_bnm(l, -m - 1)
            blmp = get_bnm(l + 1, m)
            bmm = get_bnm(m + 1, -m - 1)
            eflm[l,
                 m + 1] = (eflm[l - 1, m] * blmm - eflm[l + 1, m] * blmp) / bmm

    efms = []
    # Now create (E|F)^m matrices (p-|m|)x(p-|m|)
    # Start with (2*p-|m|)x(p-|m|) and truncate
    for m in range(LMax + 1):
        efm = np.zeros([2 * LMax + 1 - 2 * m, LMax - m + 1])
        efm[:, 0] = eflm[m:2 * LMax + 1 - m, m]
        for n in range(LMax - m):
            for l in range(n + 1, 2 * (LMax - m) - n):
                anm = get_anm(n + m, m)
                alm = get_anm(l + m, m)
                almm = get_anm(l - 1 + m, m)
                anmm = get_anm(n - 1 + m, m)
                print(l, n + 1, l + m, anm, anmm, alm, almm)
                if anmm != 0:
                    print(l, n, m)
                    efm[l,
                        n + 1] = (almm * efm[l - 1, n] - alm * efm[l + 1, n] +
                                  anmm * efm[l, n - 1]) / anm
                else:
                    efm[l, n +
                        1] = (alm * efm[l + 1, n] - almm * efm[l - 1, n]) / anm
        efms.append(efm)

    for m in range(LMax + 1):
        efms[m] = efms[m][:LMax - m + 1, :LMax - m + 1]
        lm = len(efms[m])
        # Start from m since (E|F)^m matrix starts at (m,m) corner
        nls = (np.arange(m, m + lm))
        enl = np.transpose(efms[m]) * np.outer((-1)**(nls), (-1)**(nls))
        efms[m] += enl
        efms[m] -= np.diag(np.diag(enl))

    return eflm, efms
Example #21
0
 def test_spherical_kn_inf_real(self):
     # https://dlmf.nist.gov/10.52.E6
     n = 5
     x = np.array([-inf, inf])
     assert_allclose(spherical_kn(n, x), np.array([-inf, 0]))
Example #22
0
 def test_spherical_kn_recurrence_complex(self):
     # https://dlmf.nist.gov/10.51.E4
     n = np.array([1, 2, 3, 7, 12])
     x = 1.1 + 1.5j
     assert_allclose((-1)**(n - 1)*spherical_kn(n - 1, x) - (-1)**(n + 1)*spherical_kn(n + 1,x),
                     (-1)**n*(2*n + 1)/x*spherical_kn(n, x))
 def test_spherical_kn_exact(self):
     # http://dlmf.nist.gov/10.49.E13
     x = np.array([0.12, 1.23, 12.34, 123.45])
     assert_allclose(spherical_kn(2, x), pi / 2 * exp(-x) * (1 / x + 3 / x ** 2 + 3 / x ** 3))
Example #24
0
 def test_spherical_kn_at_zero_complex(self):
     # https://dlmf.nist.gov/10.52.E2
     n = np.array([0, 1, 2, 5, 10, 100])
     x = 0 + 0j
     assert_allclose(spherical_kn(n, x), nan * np.ones(shape=n.shape))
Example #25
0
 def test_spherical_kn_at_zero(self):
     # https://dlmf.nist.gov/10.52.E2
     n = np.array([0, 1, 2, 5, 10, 100])
     x = 0
     assert_allclose(spherical_kn(n, x), np.full(n.shape, inf))