Skip to content

Commit

Permalink
Cleaned up unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kitchenknif committed Jul 4, 2017
1 parent 7e5f225 commit 37110d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 153 deletions.
12 changes: 4 additions & 8 deletions PyATMM/isotropicTransferMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

import numpy
import numpy.linalg
from PyATMM.transferMatrix import *


def build_isotropic_layer_matrix(eps, w, kx, ky, d):
#D_0 = build_isotropic_dynamic_matrix(1, w, kx, ky)
#D = build_isotropic_dynamic_matrix(eps, w, kx, ky)
D = build_isotropic_bounding_layer_matrix(eps, w, kx, ky)
P = build_isotropic_propagation_matrix(eps, w, kx, ky, d)

#LayerMatrix = numpy.dot(numpy.linalg.inv(D_0), numpy.dot(numpy.dot(D, P), numpy.dot(numpy.linalg.inv(D), D_0)))

LayerMatrix = numpy.dot(D, numpy.dot(P, numpy.linalg.inv(D)))
return LayerMatrix


def build_isotropic_bounding_layer_matrix(eps, w, kx, ky):
#
# Build boundary transition matrix
Expand Down Expand Up @@ -106,12 +102,12 @@ def isotropic_polarizations(w, eps, kx, ky, kz):
p = [p_1, p_2, p_3, p_4]
p = [numpy.divide(pi, numpy.sqrt(numpy.dot(pi, pi))) for pi in p]

if not numpy.isclose(numpy.dot(p[0], k[0]), 0+0j) \
or not numpy.isclose(numpy.dot(p[1], k[1]), 0+0j) \
if not numpy.isclose(numpy.dot(p[0], k[0]), 0 + 0j) \
or not numpy.isclose(numpy.dot(p[1], k[1]), 0 + 0j) \
or not numpy.isclose(numpy.dot(p[2], k[2]), 0 + 0j) \
or not numpy.isclose(numpy.dot(p[3], k[3]), 0 + 0j):

print("ALYARMA")
print("polarization not normal to k-vector")

#assert numpy.isclose(numpy.dot(p[0], k[0]), 0+0j)
#assert numpy.isclose(numpy.dot(p[1], k[1]), 0+0j)
Expand Down
145 changes: 3 additions & 142 deletions PyATMM/transferMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,16 @@
import numpy
import numpy.linalg


def build_anisotropic_permittivity(e1, e2, e3):
eps = numpy.zeros([3, 3], dtype=numpy.complex128)
eps[0, 0] = e1
eps[1, 1] = e2
eps[2, 2] = e3
return eps


def build_rotation_matrix(theta, phi, psi):
# Rx = numpy.asarray(
# [1, 0, 0],
# [0, numpy.cos(theta), -numpy.sin(theta)],
# [0, numpy.sin(theta), numpy.cos(theta)]
# )
#
# Ry = numpy.asarray(
# [numpy.cos(phi), 0, numpy.sin(phi)],
# [0, 1, 0],
# [-numpy.sin(phi), numpy.cos(phi)]
# )
#
# Rz = numpy.asarray(
# [numpy.cos(psi), -numpy.sin(psi), 0],
# [numpy.sin(psi), numpy.cos(psi), 0],
# [0, 0, 1]
# )
#
# R = numpy.dot(Rz, numpy.dot(Ry, Rx))
R = numpy.asarray([
[numpy.cos(psi)*numpy.cos(phi) - numpy.cos(theta)*numpy.sin(phi)*numpy.sin(psi),
-numpy.sin(psi)*numpy.cos(phi) - numpy.cos(theta)*numpy.sin(phi)*numpy.cos(psi),
Expand All @@ -42,6 +25,7 @@ def build_rotation_matrix(theta, phi, psi):

return R


def build_general_permittivity_matrix(e1, e2, e3, theta, phi, psi):
E = build_anisotropic_permittivity(e1, e2, e3)
R = build_rotation_matrix(theta, phi, psi)
Expand All @@ -54,131 +38,8 @@ def build_general_permittivity_matrix(e1, e2, e3, theta, phi, psi):

return Eps

def build_polarization_vector(w, Eps, kx, ky, g, mu):

e_zz = Eps[2, 2]
e_yy = Eps[1, 1]
e_xx = Eps[0, 0]
e_xy = Eps[0, 1]
e_yz = Eps[1, 2]
e_xz = Eps[0, 2]

# TODO: Guaranteed bullshit?
p = numpy.asarray(
[(w**2*e_yy - kx**2 - g**2)*(w**2*e_zz - kx**2 - ky**2) - (w**2*e_yz + ky*g)**2,
(w**2*e_yz + ky*g)*(w**2*e_xz + kx*g) - (w**2*e_xy + kx*ky)*(w**2*e_zz - kx**2 - ky**2),
(w**2*e_xy + kx*ky)*(w**2*e_yz + ky*g) - (w**2*e_xz + kx*g)*(w**2*e_yy - kx**2 - g**2)],
dtype=numpy.complex128)
p = numpy.divide(p, numpy.sqrt(numpy.dot(p, p)))
return p

def build_anisotropic_layer_matrix(e1, e2, e3, theta, phi, psi, w, kx, ky, d):
#
# Build epsilon matrix
#
Eps = build_general_permittivity_matrix(e1, e2, e3, theta, phi, psi)

e_zz = Eps[2, 2]
e_yy = Eps[1, 1]
e_xx = Eps[0, 0]
e_xy = Eps[0, 1]
e_yz = Eps[1, 2]
e_xz = Eps[0, 2]
# should be symmetric, so we don't need e_zy, e_zx, e_yx

#
# Solve for eigenmodes
# Solve quartic equation A*kz**4 + B*kz**3 + C*kz**2 + D*kz + E
# Coefficients from Determinant of matrix
# [(w/c)**2 * E + inner(k, k) * I + outer(k, k)]
a = w**2 * e_zz # *kz**4

b = w**2 * (2*e_xz*kx + 2*e_yz*ky) # *kz**3

c = w**2 * ( -e_xx*e_zz*w**2 + e_xx*kx**2 + 2*e_xy*kx*ky + e_xz**2*w**2 - e_yy*e_zz*w**2 + e_yy*ky**2
+ e_yz**2*w**2 + e_zz*kx**2+e_zz*ky**2
) # *kz**2

d = w**2 * ( -2*e_xx*e_yz*w**2*ky + 2*e_xy*e_xz*w**2*ky + 2*e_xy*e_yz**w**2*kx - 2*e_xz*e_yy*w**2*kx + 2*e_xz*kx**3
+ 2*e_xz*kx*ky**2 + 2*e_yz*kx**2*ky + 2*e_yz*ky**3
) # *kz**1

e = w**2 * (e_xx*e_yy*e_zz*w**4 - e_xx*e_yy*w**2*kx**2 - e_xx*e_yy*w**2*ky**2 - e_xx*e_yz**2*w**4
- e_xx*e_zz*w**2*kx**2 + e_xx*kx**4 + e_xx*kx**2*ky**2 - e_xy**2*e_zz*w**4 + e_xy**2*w**2*kx**2
+ e_xy**2*w**2*ky**2 + 2*e_xy*e_xz*e_yz*w**4
- 2*e_xy*e_zz*w**2*kx*ky + 2*e_xy*kx**3*ky + 2*e_xy*kx*ky**3 - e_xz**2*e_yy*w**4
+ e_xz**2*w**2*kx**2 + 2*e_xz*e_yz*w**2*kx*ky - e_yy*e_zz*w**2*ky**2 + e_yy*kx**2*ky**2
+ e_yy*ky**4 + e_yz**2*w**2*ky**2
) # *kz**0
coeffs = [a, b, c, d, e]
gamma = numpy.roots(coeffs)

#TODO: Hack needs fixing
tmp = gamma[2]
gamma[2] = gamma[1]
gamma[1] = tmp

#
# Build polarization vectors
#
mu = 1
c = 1 # m/c

p = [build_polarization_vector(w, Eps, kx, ky, g, mu) for g in gamma]
print("P:", numpy.real(p))
q = [(c/(w*mu))*numpy.cross([kx, ky, gi], pi) for gi, pi in zip(gamma, p)]
print("Q:", numpy.real(q))

#return p, gamma, Eps

#
# Tests
#
#vec = numpy.dot(Eps, p[0])
#print( numpy.dot(vec, [kx, ky, gamma[0]]) )
#
#
#

#
# Build boundary transition matrix
#
D = numpy.asarray(
[
[p[0][0], p[1][0], p[2][0], p[3][0]],
[q[0][1], q[1][1], q[2][1], q[3][1]],
[p[0][1], p[1][1], p[2][1], p[3][1]],
[q[0][0], q[1][0], q[2][0], q[3][0]]
], dtype=numpy.complex128
)
print("D:", numpy.real(D))

#
# Build propagation matrix
#
P = numpy.asarray(
[
[numpy.exp(-1j*gamma[0]*d), 0, 0, 0],
[0, numpy.exp(-1j*gamma[1]*d), 0, 0],
[0, 0, numpy.exp(-1j*gamma[2]*d), 0],
[0, 0, 0, numpy.exp(-1j*gamma[3]*d)]
], dtype=numpy.complex128
)

#
# Multiply matricies
#
LayerMatrix = numpy.dot(D, numpy.dot(P, numpy.linalg.inv(D)))
#return LayerMatrix
return D


def solve_transfer_matrix(M):

denom = M[0, 0]*M[2, 2] - M[0, 2]*M[2, 0]
#print(denom)


#
# Components 3,4 - S
# Components 1,2 - P Was mixed up until 11.08.2016 (switched s and p)
Expand Down
4 changes: 1 addition & 3 deletions PyATMM/uniaxialTransferMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ def build_uniaxial_layer_matrix(e_o, e_e, w, kx, ky, d, opticAxis=([0., 1., 0.])
D = build_uniaxial_bounding_layer_matrix(e_o, e_e, w, kx, ky, opticAxis=opticAxis)
P = build_uniaxial_propagation_matrix(e_o, e_e, w, kx, ky, d, opticAxis=opticAxis)

#LayerMatrix = numpy.dot(numpy.linalg.inv(D_0), numpy.dot(numpy.dot(D, P), numpy.dot(numpy.linalg.inv(D), D_0)))

LayerMatrix = numpy.dot(D, numpy.dot(P, numpy.linalg.inv(D)))
return LayerMatrix

Expand Down Expand Up @@ -65,6 +63,7 @@ def axially_aligned_uniaxial_polarizations(e_o, e_e, w, kx, ky, kz, opticAxis):
# or numpy.allclose(opticAxis, [0, 1, 0]) \
# or numpy.allclose(opticAxis, [1, 0, 0])
# In general, as long as k-vector and optic axis are not colinear, this should work

assert all(not numpy.allclose(opticAxis, [kx, ky, numpy.abs(g)]) for g in kz)
assert numpy.isclose(numpy.dot(opticAxis, opticAxis), 1.)

Expand Down Expand Up @@ -109,7 +108,6 @@ def build_uniaxial_transmitted_wavevectors(e_o, e_e, w, kx, ky, opticAxis=([0.,
dtype=numpy.complex128)
)


k_z1 = mod_kz_ord
k_z2 = -mod_kz_ord
k_z3 = mod_kz_extraord
Expand Down

0 comments on commit 37110d6

Please sign in to comment.