コード例 #1
0
ファイル: rsh.py プロジェクト: robwarm/gpaw-symm
def dYdphi(l,m,theta,phi):
    if m == 0:
        return np.zeros_like(theta)
    elif m > 0:
        return -m*C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(m*phi)*2**0.5
    else:
        return -m*C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(m*phi)*2**0.5
コード例 #2
0
ファイル: rsh.py プロジェクト: robwarm/gpaw-symm
def Y(l,m,theta,phi):
    if m == 0:
        return C(l,m)*legendre(l,abs(m),np.cos(theta))
    elif m > 0:
        return C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(m*phi)*2**0.5
    else:
        return C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(abs(m)*phi)*2**0.5
コード例 #3
0
def dYdphi(l, m, theta, phi):
    if m == 0:
        return np.zeros_like(theta)
    elif m > 0:
        return -m * C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.sin(
            m * phi) * 2**0.5
    else:
        return -m * C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.cos(
            m * phi) * 2**0.5
コード例 #4
0
def Y(l, m, theta, phi):
    if m == 0:
        return C(l, m) * legendre(l, abs(m), np.cos(theta))
    elif m > 0:
        return C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.cos(
            m * phi) * 2**0.5
    else:
        return C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.sin(
            abs(m) * phi) * 2**0.5
コード例 #5
0
ファイル: rsh.py プロジェクト: qsnake/gpaw
def dYdphi(l,m,theta,phi):
    if m == 0:
        #return _dYdphi(l,m,theta,phi)
        return np.zeros_like(theta)
    elif m > 0:
        #return (-1)**m*np.real(_dYdphi(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_dYdphi(l,m,theta,phi)+_dYdphi(l,m,theta,phi).conj())/2**0.5
        #return (-1)**m*(_dYdphi(l,m,theta,phi)+(-1)**m*_dYdphi(l,-m,theta,phi))/2**0.5
        #return -(-1)**m*m*_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(m*phi)*2**0.5
        return -m*C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(m*phi)*2**0.5
    else:
        #return (-1)**m*np.imag(_dYdphi(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_dYdphi(l,abs(m),theta,phi)-_dYdphi(l,abs(m),theta,phi).conj())/(2**0.5*1j)
        #return (-1)**m*(_dYdphi(l,abs(m),theta,phi)-(-1)**abs(m)*_dYdphi(l,-abs(m),theta,phi))/(2**0.5*1j)
        #return (-1)**m*m*_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(abs(m)*phi)*2**0.5
        return -m*C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(m*phi)*2**0.5
コード例 #6
0
ファイル: rsh.py プロジェクト: qsnake/gpaw
def Y(l,m,theta,phi):
    if m == 0:
        #return _Y(l,m,theta,phi)
        return C(l,m)*legendre(l,abs(m),np.cos(theta))
    elif m > 0:
        #return (-1)**m*np.real(_Y(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_Y(l,m,theta,phi)+_Y(l,m,theta,phi).conj())/2**0.5
        #return (-1)**m*(_Y(l,m,theta,phi)+(-1)**m*_Y(l,-m,theta,phi))/2**0.5
        #return (-1)**m*_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(m*phi)*2**0.5
        return C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(m*phi)*2**0.5
    else:
        #return (-1)**m*np.imag(_Y(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_Y(l,abs(m),theta,phi)-_Y(l,abs(m),theta,phi).conj())/(2**0.5*1j)
        #return (-1)**m*(_Y(l,abs(m),theta,phi)-(-1)**abs(m)*_Y(l,-abs(m),theta,phi))/(2**0.5*1j)
        #return -_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(m*phi)*2**0.5
        return -C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(m*phi)*2**0.5
コード例 #7
0
def dYdphi(l, m, theta, phi):
    if m == 0:
        #return _dYdphi(l,m,theta,phi)
        return np.zeros_like(theta)
    elif m > 0:
        #return (-1)**m*np.real(_dYdphi(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_dYdphi(l,m,theta,phi)+_dYdphi(l,m,theta,phi).conj())/2**0.5
        #return (-1)**m*(_dYdphi(l,m,theta,phi)+(-1)**m*_dYdphi(l,-m,theta,phi))/2**0.5
        #return -(-1)**m*m*_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(m*phi)*2**0.5
        return -m * C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.sin(
            m * phi) * 2**0.5
    else:
        #return (-1)**m*np.imag(_dYdphi(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_dYdphi(l,abs(m),theta,phi)-_dYdphi(l,abs(m),theta,phi).conj())/(2**0.5*1j)
        #return (-1)**m*(_dYdphi(l,abs(m),theta,phi)-(-1)**abs(m)*_dYdphi(l,-abs(m),theta,phi))/(2**0.5*1j)
        #return (-1)**m*m*_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(abs(m)*phi)*2**0.5
        return -m * C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.cos(
            m * phi) * 2**0.5
コード例 #8
0
def Y(l, m, theta, phi):
    if m == 0:
        #return _Y(l,m,theta,phi)
        return C(l, m) * legendre(l, abs(m), np.cos(theta))
    elif m > 0:
        #return (-1)**m*np.real(_Y(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_Y(l,m,theta,phi)+_Y(l,m,theta,phi).conj())/2**0.5
        #return (-1)**m*(_Y(l,m,theta,phi)+(-1)**m*_Y(l,-m,theta,phi))/2**0.5
        #return (-1)**m*_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.cos(m*phi)*2**0.5
        return C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.cos(
            m * phi) * 2**0.5
    else:
        #return (-1)**m*np.imag(_Y(l,abs(m),theta,phi))*2**0.5
        #return (-1)**m*(_Y(l,abs(m),theta,phi)-_Y(l,abs(m),theta,phi).conj())/(2**0.5*1j)
        #return (-1)**m*(_Y(l,abs(m),theta,phi)-(-1)**abs(m)*_Y(l,-abs(m),theta,phi))/(2**0.5*1j)
        #return -_C(l,m)*legendre(l,abs(m),np.cos(theta))*np.sin(m*phi)*2**0.5
        return -C(l, m) * legendre(l, abs(m), np.cos(theta)) * np.sin(
            m * phi) * 2**0.5
コード例 #9
0
ファイル: ut_csh.py プロジェクト: robwarm/gpaw-symm
    def test_addition_theorem(self):
        lmax = 9

        # Test that the complex spherical harmonic addition theorem holds
        thetam_L = np.random.uniform(0, np.pi, size=theta_L.shape)
        world.broadcast(thetam_L, 0)
        phim_L = np.random.uniform(0, 2*np.pi, size=phi_L.shape)
        world.broadcast(phim_L, 0)
        cosv_L = np.cos(theta_L)*np.cos(thetam_L) \
            + np.sin(theta_L)*np.sin(thetam_L)*np.cos(phi_L-phim_L)
        P0_lL = np.array([legendre(l, 0, cosv_L) for l in range(lmax+1)])
        P_lL = np.zeros_like(P0_lL)
        for l,m in lmiter(lmax, comm=world):
            P_lL[l] += 4 * np.pi / (2*l + 1.) * Y(l, m, theta_L, phi_L) \
                * Y(l, m, thetam_L, phim_L).conj()
        world.sum(P_lL)
        self.assertAlmostEqual(np.abs(P_lL-P0_lL).max(), 0, 6)
コード例 #10
0
    def test_addition_theorem(self):
        lmax = 9

        # Test that the complex spherical harmonic addition theorem holds
        thetam_L = np.random.uniform(0, np.pi, size=theta_L.shape)
        world.broadcast(thetam_L, 0)
        phim_L = np.random.uniform(0, 2 * np.pi, size=phi_L.shape)
        world.broadcast(phim_L, 0)
        cosv_L = np.cos(theta_L)*np.cos(thetam_L) \
            + np.sin(theta_L)*np.sin(thetam_L)*np.cos(phi_L-phim_L)
        P0_lL = np.array([legendre(l, 0, cosv_L) for l in range(lmax + 1)])
        P_lL = np.zeros_like(P0_lL)
        for l, m in lmiter(lmax, comm=world):
            P_lL[l] += 4 * np.pi / (2*l + 1.) * Y(l, m, theta_L, phi_L) \
                * Y(l, m, thetam_L, phim_L).conj()
        world.sum(P_lL)
        self.assertAlmostEqual(np.abs(P_lL - P0_lL).max(), 0, 6)
コード例 #11
0
ファイル: csh.py プロジェクト: qsnake/gpaw
import numpy as np

from gpaw.utilities import fact
from gpaw.sphere import lmfact
from gpaw.sphere.legendre import ilegendre, legendre, dlegendre

# Define the Heaviside function
heaviside = lambda x: (1.0+np.sign(x))/2.0

# Define spherical harmoncics and normalization coefficient
C = lambda l,m: (-1)**((m+abs(m))//2)*((2.*l+1.)/(4*np.pi*lmfact(l,m)))**0.5
Y = lambda l,m,theta,phi: C(l,m)*legendre(l,abs(m),np.cos(theta))*np.exp(1j*m*phi)

# Define theta-derivative of spherical harmoncics
dYdtheta = lambda l,m,theta,phi: C(l,m)*dlegendre(l,abs(m),np.cos(theta))*np.exp(1j*m*phi)

# Define phi-derivative of spherical harmoncics
dYdphi = lambda l,m,theta,phi: 1j*m*C(l,m)*legendre(l,abs(m),np.cos(theta))*np.exp(1j*m*phi)

# -------------------------------------------------------------------

def intYY(l1, m1, l2, m2):
    """Calculates::

                  pi 2pi
                  /  /      *
           A    = |  |    Y (u,v) Y (u,v) sin(u) dv du
            LL'   /  /     lm      l'm'
                  0  0
コード例 #12
0
from math import factorial as fact
import numpy as np

from gpaw.sphere import lmfact
from gpaw.sphere.legendre import ilegendre, legendre, dlegendre

# Define the Heaviside function
heaviside = lambda x: (1.0+np.sign(x))/2.0

# Define spherical harmoncics and normalization coefficient
C = lambda l,m: (-1)**((m+abs(m))//2)*((2.*l+1.)/(4*np.pi*lmfact(l,m)))**0.5
Y = lambda l,m,theta,phi: C(l,m)*legendre(l,abs(m),np.cos(theta))*np.exp(1j*m*phi)

# Define theta-derivative of spherical harmoncics
dYdtheta = lambda l,m,theta,phi: C(l,m)*dlegendre(l,abs(m),np.cos(theta))*np.exp(1j*m*phi)

# Define phi-derivative of spherical harmoncics
dYdphi = lambda l,m,theta,phi: 1j*m*C(l,m)*legendre(l,abs(m),np.cos(theta))*np.exp(1j*m*phi)

# -------------------------------------------------------------------

def intYY(l1, m1, l2, m2):
    """Calculates::

                  pi 2pi
                  /  /      *
           A    = |  |    Y (u,v) Y (u,v) sin(u) dv du
            LL'   /  /     lm      l'm'
                  0  0

    where u = theta and v = phi in the usual notation. Note that the result