Example #1
0
File: csh.py Project: qsnake/gpaw
def intYdYdphi_ey(l1, m1, l2, m2):
    """Calculates::

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

    where u = theta and v = phi in the usual notation. Note that the result
    is only non-zero if `|l1-l2|` is odd and `|m1-m2|` = 1 (stricter rule applies).
    """
    if abs(l1-l2) % 2 != 1 or abs(m1-m2) != 1:
        return 0.0
    scale = C(l1,m1)*C(l2,m2)*np.pi*1j*m2
    if abs(m1) == abs(m2)+1 and l1 > l2: # and (l1-l2)%2 == 1 which is always true
        return scale*2*lmfact(l2,m2)
    elif abs(m1) == abs(m2)-1 and l1 < l2: # and (l2-l1)%2 == 1 which is always true
        return scale*2*lmfact(l1,m1)
    else:
        return 0.0
Example #2
0
def intYdYdphi_ey(l1, m1, l2, m2):
    """Calculates::

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

    where u = theta and v = phi in the usual notation. Note that the result
    is only non-zero if `|l1-l2|` is odd and `|m1-m2|` = 1 (stricter rule applies).
    """
    if abs(l1-l2) % 2 != 1 or abs(m1-m2) != 1:
        return 0.0
    scale = C(l1,m1)*C(l2,m2)*np.pi*1j*m2
    if abs(m1) == abs(m2)+1 and l1 > l2: # and (l1-l2)%2 == 1 which is always true
        return scale*2*lmfact(l2,m2)
    elif abs(m1) == abs(m2)-1 and l1 < l2: # and (l2-l1)%2 == 1 which is always true
        return scale*2*lmfact(l1,m1)
    else:
        return 0.0
Example #3
0
import numpy as np

from gpaw.sphere import lmfact

# Highest l for which associated Legendre polynomials are implemented
lmax = 9

# Integral norm of the associated Legendre polynomials
ilegendre = lambda l, m: 2. / (2. * l + 1.) * lmfact(l, m)


def legendre(l, m, w):
    if m < 0 or l < m:
        return np.zeros_like(w)
    if (l, m) == (0, 0):
        return np.ones_like(w)
    elif (l, m) == (1, 0):
        return w.copy()
    elif (l, m) == (1, 1):
        return (1 - w**2)**0.5
    elif (l, m) == (2, 0):
        return 1.5 * w**2 - 0.5
    elif (l, m) == (2, 1):
        return 3 * (1 - w**2)**0.5 * w
    elif (l, m) == (2, 2):
        return 3 * (1 - w**2)
    elif (l, m) == (3, 0):
        return 2.5 * w**3 - 1.5 * w
    elif (l, m) == (3, 1):
        return (1 - w**2)**0.5 * (7.5 * w**2 - 1.5)
    elif (l, m) == (3, 2):
Example #4
0
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: ((2. * l + 1.) / (4 * np.pi * lmfact(l, m)))**0.5


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


# Define theta-derivative of spherical harmoncics
def dYdtheta(l, m, theta, phi):
    if m == 0:
        return C(l, m) * dlegendre(l, abs(m), np.cos(theta))
    elif m > 0:
        return C(l, m) * dlegendre(l, abs(m), np.cos(theta)) * np.cos(
            m * phi) * 2**0.5
Example #5
0
File: rsh.py Project: 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: ((2.*l+1.)/(4*np.pi*lmfact(l,m)))**0.5

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

# Define theta-derivative of spherical harmoncics
Example #6
0
import numpy as np

from gpaw.sphere import lmfact

# Highest l for which associated Legendre polynomials are implemented
lmax = 9

# Integral norm of the associated Legendre polynomials
ilegendre = lambda l,m: 2./(2.*l+1.)*lmfact(l,m)

def legendre(l, m, w):
    if m < 0 or l < m:
        return np.zeros_like(w)
    if (l,m) == (0,0):
        return np.ones_like(w)
    elif (l,m) == (1,0):
        return w.copy()
    elif (l,m) == (1,1):
        return (1-w**2)**0.5
    elif (l,m) == (2,0):
        return 1.5*w**2-0.5
    elif (l,m) == (2,1):
        return 3*(1-w**2)**0.5*w
    elif (l,m) == (2,2):
        return 3*(1-w**2)
    elif (l,m) == (3,0):
        return 2.5*w**3-1.5*w
    elif (l,m) == (3,1):
        return (1-w**2)**0.5*(7.5*w**2-1.5)
    elif (l,m) == (3,2):
Example #7
0
File: csh.py Project: 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
Example #8
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
Example #9
0
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
                  /  /      *