Skip to content

Commit

Permalink
Added support for off-axis incidence and s- p- polarizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
kitchenknif committed Oct 19, 2015
1 parent 81fb422 commit bac7aa8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 11 deletions.
34 changes: 34 additions & 0 deletions examples/antireflection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import numpy as np
import matplotlib.pyplot as plt
from transferMatrix import *
from refractiveIndex import *

n1 = 1.5
n2 = np.sqrt(n1)
d = 700 / (n2 * 4) # quarter-wavelength coating

ran = range(200, 1600, 1)
refl0 = []
refl = []
for i in ran:
# substrate layer (considered infinite, so only bounding layer needed)
a = TransferMatrix.boundingLayer(1, n1)

R, T = solvePropagation(a)
refl0.append(np.abs(R**2))

# antireflective layer layer "left" of substrate
b = TransferMatrix.layer(n2, d, i)
a.appendRight(b)

R, T = solvePropagation(a)
refl.append(np.abs(R**2))


plt.plot(ran, refl0)
plt.plot(ran, refl)
plt.xlabel("Wavelength, nm")
plt.ylabel("Reflectance")
plt.title("Reflectance of ideal single-layer antireflective coating")
plt.legend(['Substrate', 'Coated substrate'], loc='best')
plt.show(block=True)
31 changes: 31 additions & 0 deletions examples/brewster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import numpy as np
import matplotlib.pyplot as plt
from transferMatrix import *
from refractiveIndex import *

n = 2
d = 600 # slab thickness, nm
l = 500 # wavelength, nm
ran = np.linspace(0, np.pi/2, 1000)
TE = []
TM = []
for i in ran:
# TE
a = TransferMatrix.layer(n, d, l, i, Polarization.s)

R, T = solvePropagation(a)
TE.append(np.abs(R**2))

# TM
a = TransferMatrix.layer(n, d, l, i, Polarization.p)
R, T = solvePropagation(a)
TM.append(np.abs(R**2))


plt.plot(ran, TE)
plt.plot(ran, TM)
plt.xlabel("Angle, rad")
plt.ylabel("Reflectance")
plt.title("Angle dependence of reflectivity")
plt.legend(['TE', 'TM'], loc='best')
plt.show(block=True)
44 changes: 33 additions & 11 deletions transferMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@


import numpy
import enum

class Polarization(enum.Enum):
s = 0
p = 1

class TransferMatrix:
"""
Expand All @@ -39,48 +43,66 @@ def structure(*args):
Left to Right = Bottom to Top
:param args:
"""
mat = numpy.identity(2, dtype=numpy.complex64)
mat = numpy.identity(2, dtype=numpy.complex128)
for m in args:
mat = numpy.dot(m.matrix, mat)
return TransferMatrix(mat)

@staticmethod
def layer(n, d, wavelength):
def layer(n, d, wavelength, theta=0, pol=Polarization.s):
"""
Creates a Air-DielectricLayer-Air Transfer Matrix
:param n:
:param d:
:param wavelength:
"""
bottomBoundary = TransferMatrix.boundingLayer(1, n)
topBoundary = TransferMatrix.boundingLayer(n, 1)
propagation = TransferMatrix.propagationLayer(n, d, wavelength)
bottomBoundary = TransferMatrix.boundingLayer(1, n, theta, pol)
topBoundary = TransferMatrix.boundingLayer(n, 1, theta, pol)
propagation = TransferMatrix.propagationLayer(n, d, wavelength, theta, pol)

return TransferMatrix.structure(bottomBoundary,
propagation,
topBoundary)

@staticmethod
def boundingLayer(n1, n2):
def boundingLayer(n1, n2, theta=0, pol=Polarization.s):
"""
Creates a DielectricLayer-DielectricLayer Boundary Transfer Matrix
:param n1:
:param n2:
"""
boundary = numpy.array([[(n1 + n2) / (2 * n2), (n2 - n1) / (2 * n2)],
[(n2 - n1) / (2 * n2), (n1 + n2) / (2 * n2)]], dtype=numpy.complex64)
theta2 = numpy.arcsin((n1/n2)*numpy.sin(theta))

# TE
if pol is Polarization.s:
_n1 = n1*numpy.cos(theta)
_n2 = n2*numpy.cos(theta2)
a21 = 1

# TM
elif pol is Polarization.p:
_n1 = n1/numpy.cos(theta)
_n2 = n2/numpy.cos(theta2)
a21 = numpy.cos(theta2)/numpy.cos(theta)


boundary = 1/(2 * a21 * _n2) *numpy.array([[(_n1 + _n2), (_n2 - _n1)],
[(_n2 - _n1), (_n1 + _n2)]], dtype=numpy.complex128)
return TransferMatrix(boundary)

@staticmethod
def propagationLayer(n, d, wavelength):
def propagationLayer(n, d, wavelength, theta=0, pol=Polarization.s):
"""
Creates a Propagation Transfer Matrix, width d, refractive index n
:param n:
:param d:
:param wavelength:
"""
propagation = numpy.array([[numpy.exp(-1j * n * d * 2 * numpy.pi / wavelength), 0],
[0, numpy.exp(1j * n * d * 2 * numpy.pi / wavelength)]], dtype=numpy.complex64)
theta2 = numpy.arcsin((1/n)*numpy.sin(theta))

propagation = numpy.array([[numpy.exp((-1j * n * d * 2 * numpy.pi / wavelength) * numpy.cos(theta2)), 0],
[0, numpy.exp((1j * n * d * 2 * numpy.pi / wavelength) * numpy.cos(theta2))]],
dtype=numpy.complex128)
return TransferMatrix(propagation)

def __init__(self, matrix):
Expand Down

0 comments on commit bac7aa8

Please sign in to comment.