Ejemplo n.º 1
0
        def find_roots(wl, epsilon, alpha, beta):
            """Find roots of characteristic equation.

            Given a wavelength, a 3x3 tensor epsilon and the tangential components
            of the wavevector k = (alpha,beta,gamma_i), returns the 4 possible
            gamma_i, i = 1,2,3,4 that satisfy the boundary conditions.
            """

            omega = 2. * S.pi * c / wl
            K = omega**2 * mu0 * epsilon

            k0 = 2. * S.pi / wl
            K /= k0**2
            alpha /= k0
            beta /= k0

            alpha2 = alpha**2
            alpha3 = alpha**3
            alpha4 = alpha**4
            beta2 = beta**2
            beta3 = beta**3
            beta4 = beta**4

            coeff = [
                K[2,
                  2], alpha * (K[0, 2] + K[2, 0]) + beta * (K[1, 2] + K[2, 1]),
                alpha2 * (K[0, 0] + K[2, 2]) + alpha * beta *
                (K[1, 0] + K[0, 1]) + beta2 * (K[1, 1] + K[2, 2]) +
                (K[0, 2] * K[2, 0] + K[1, 2] * K[2, 1] - K[0, 0] * K[2, 2] -
                 K[1, 1] * K[2, 2]), alpha3 * (K[0, 2] + K[2, 0]) + beta3 *
                (K[1, 2] + K[2, 1]) + alpha2 * beta * (K[1, 2] + K[2, 1]) +
                alpha * beta2 * (K[0, 2] + K[2, 0]) + alpha *
                (K[0, 1] * K[1, 2] + K[1, 0] * K[2, 1] - K[0, 2] * K[1, 1] -
                 K[2, 0] * K[1, 1]) + beta *
                (K[0, 1] * K[2, 0] + K[1, 0] * K[0, 2] - K[0, 0] * K[1, 2] -
                 K[0, 0] * K[2, 1]), alpha4 * (K[0, 0]) + beta4 * (K[1, 1]) +
                alpha3 * beta * (K[0, 1] + K[1, 0]) + alpha * beta3 *
                (K[0, 1] + K[1, 0]) + alpha2 * beta2 * (K[0, 0] + K[1, 1]) +
                alpha2 * (K[0, 1] * K[1, 0] + K[0, 2] * K[2, 0] -
                          K[0, 0] * K[2, 2] - K[0, 0] * K[1, 1]) + beta2 *
                (K[0, 1] * K[1, 0] + K[1, 2] * K[2, 1] - K[0, 0] * K[1, 1] -
                 K[1, 1] * K[2, 2]) + alpha * beta *
                (K[0, 2] * K[2, 1] + K[2, 0] * K[1, 2] - K[0, 1] * K[2, 2] -
                 K[1, 0] * K[2, 2]) + K[0, 0] * K[1, 1] * K[2, 2] -
                K[0, 0] * K[1, 2] * K[2, 1] - K[1, 0] * K[0, 1] * K[2, 2] +
                K[1, 0] * K[0, 2] * K[2, 1] + K[2, 0] * K[0, 1] * K[1, 2] -
                K[2, 0] * K[0, 2] * K[1, 1]
            ]

            gamma = S.roots(coeff)
            tmp = S.sort_complex(gamma)
            gamma = tmp[[3, 0, 2, 1]]  # convention

            k = k0 * \
                S.array([alpha *
                         S.ones(gamma.shape), beta *
                         S.ones(gamma.shape), gamma]).T
            v = S.zeros((4, 3), dtype=complex)

            for i, g in enumerate(gamma):

                H = K + [[-beta2 - g**2, alpha * beta, alpha * g],
                         [alpha * beta, -alpha2 - g**2, beta * g],
                         [alpha * g, beta * g, -alpha2 - beta2]]
                v[i, :] = [
                    (K[1, 1] - alpha2 - g**2) *
                    (K[2, 2] - alpha2 - beta2) - (K[1, 2] + beta * g)**2,
                    (K[1, 2] + beta * g) * (K[2, 0] + alpha * g) -
                    (K[0, 1] + alpha * beta) * (K[2, 2] - alpha2 - beta2),
                    (K[0, 1] + alpha * beta) * (K[1, 2] + beta * g) -
                    (K[0, 2] + alpha * g) * (K[1, 1] - alpha2 - g**2)
                ]

            p3 = v[0, :]
            p3 /= norm(p3)
            p4 = v[1, :]
            p4 /= norm(p4)
            p1 = S.cross(p3, k[0, :])
            p1 /= norm(p1)
            p2 = S.cross(p4, k[1, :])
            p2 /= norm(p2)

            p = S.array([p1, p2, p3, p4])
            q = wl / (2. * S.pi * mu0 * c) * S.cross(k, p)

            return k, p, q
Ejemplo n.º 2
0
import scipy
scipy.sort_complex
# OUT: <function sort_complex at 0x972cb1c>
scipy.sort_complex(1,33,12)
# OUT: Traceback (most recent call last):
# OUT:   File "<input>", line 1, in <module>
# OUT: TypeError: sort_complex() takes exactly 1 argument (3 given)
a=[2,33,1,12,3]
scipy.sort_complex(a)
# OUT: array([  1.+0.j,   2.+0.j,   3.+0.j,  12.+0.j,  33.+0.j])
a=[2+12.j,33+1.j,1+13.j,12,3+10.j]
scipy.sort_complex(a)
# OUT: array([  1.+13.j,   2.+12.j,   3.+10.j,  12. +0.j,  33. +1.j])
a=[2+12.j,33+1.j,1+13.j,12,3+10.j,3+3.j]
scipy.sort_complex(a)
# OUT: array([  1.+13.j,   2.+12.j,   3. +3.j,   3.+10.j,  12. +0.j,  33. +1.j])


Ejemplo n.º 3
0
        def find_roots(wl, epsilon, alpha, beta):
            """Find roots of characteristic equation.

            Given a wavelength, a 3x3 tensor epsilon and the tangential components
            of the wavevector k = (alpha,beta,gamma_i), returns the 4 possible
            gamma_i, i = 1,2,3,4 that satisfy the boundary conditions.
            """

            omega = 2.0 * S.pi * c / wl
            K = omega ** 2 * mu0 * epsilon

            k0 = 2.0 * S.pi / wl
            K /= k0 ** 2
            alpha /= k0
            beta /= k0

            alpha2 = alpha ** 2
            alpha3 = alpha ** 3
            alpha4 = alpha ** 4
            beta2 = beta ** 2
            beta3 = beta ** 3
            beta4 = beta ** 4

            coeff = [
                K[2, 2],
                alpha * (K[0, 2] + K[2, 0]) + beta * (K[1, 2] + K[2, 1]),
                alpha2 * (K[0, 0] + K[2, 2])
                + alpha * beta * (K[1, 0] + K[0, 1])
                + beta2 * (K[1, 1] + K[2, 2])
                + (K[0, 2] * K[2, 0] + K[1, 2] * K[2, 1] - K[0, 0] * K[2, 2] - K[1, 1] * K[2, 2]),
                alpha3 * (K[0, 2] + K[2, 0])
                + beta3 * (K[1, 2] + K[2, 1])
                + alpha2 * beta * (K[1, 2] + K[2, 1])
                + alpha * beta2 * (K[0, 2] + K[2, 0])
                + alpha * (K[0, 1] * K[1, 2] + K[1, 0] * K[2, 1] - K[0, 2] * K[1, 1] - K[2, 0] * K[1, 1])
                + beta * (K[0, 1] * K[2, 0] + K[1, 0] * K[0, 2] - K[0, 0] * K[1, 2] - K[0, 0] * K[2, 1]),
                alpha4 * (K[0, 0])
                + beta4 * (K[1, 1])
                + alpha3 * beta * (K[0, 1] + K[1, 0])
                + alpha * beta3 * (K[0, 1] + K[1, 0])
                + alpha2 * beta2 * (K[0, 0] + K[1, 1])
                + alpha2 * (K[0, 1] * K[1, 0] + K[0, 2] * K[2, 0] - K[0, 0] * K[2, 2] - K[0, 0] * K[1, 1])
                + beta2 * (K[0, 1] * K[1, 0] + K[1, 2] * K[2, 1] - K[0, 0] * K[1, 1] - K[1, 1] * K[2, 2])
                + alpha * beta * (K[0, 2] * K[2, 1] + K[2, 0] * K[1, 2] - K[0, 1] * K[2, 2] - K[1, 0] * K[2, 2])
                + K[0, 0] * K[1, 1] * K[2, 2]
                - K[0, 0] * K[1, 2] * K[2, 1]
                - K[1, 0] * K[0, 1] * K[2, 2]
                + K[1, 0] * K[0, 2] * K[2, 1]
                + K[2, 0] * K[0, 1] * K[1, 2]
                - K[2, 0] * K[0, 2] * K[1, 1],
            ]

            gamma = S.roots(coeff)
            tmp = S.sort_complex(gamma)
            gamma = tmp[[3, 0, 2, 1]]  # convention

            k = k0 * S.array([alpha * S.ones(gamma.shape), beta * S.ones(gamma.shape), gamma]).T
            v = S.zeros((4, 3), dtype=complex)

            for i, g in enumerate(gamma):

                H = K + [
                    [-beta2 - g ** 2, alpha * beta, alpha * g],
                    [alpha * beta, -alpha2 - g ** 2, beta * g],
                    [alpha * g, beta * g, -alpha2 - beta2],
                ]
                v[i, :] = [
                    (K[1, 1] - alpha2 - g ** 2) * (K[2, 2] - alpha2 - beta2) - (K[1, 2] + beta * g) ** 2,
                    (K[1, 2] + beta * g) * (K[2, 0] + alpha * g)
                    - (K[0, 1] + alpha * beta) * (K[2, 2] - alpha2 - beta2),
                    (K[0, 1] + alpha * beta) * (K[1, 2] + beta * g)
                    - (K[0, 2] + alpha * g) * (K[1, 1] - alpha2 - g ** 2),
                ]

            p3 = v[0, :]
            p3 /= norm(p3)
            p4 = v[1, :]
            p4 /= norm(p4)
            p1 = S.cross(p3, k[0, :])
            p1 /= norm(p1)
            p2 = S.cross(p4, k[1, :])
            p2 /= norm(p2)

            p = S.array([p1, p2, p3, p4])
            q = wl / (2.0 * S.pi * mu0 * c) * S.cross(k, p)

            return k, p, q