## Overview

This section consists of various projects, with a focus on technology applications, which demonstrate the advanced functionality of Meep and MPB. Refer to their homepages for an introduction to each software package including descriptions of features and Python user interface as well as tutorials demonstrating basic functionality. Each project consists of a Python simulation script, a shell script to run the simulation, and Python post-processing routines for visualizing the output. Additional routines for Matlab/Octave are also provided. A version of this page is available for the Scheme user interface.

## Meep Project #1 — Light-Extraction Efficiency of Organic Light Emitting Diodes (OLEDs)

Organic light-emitting diodes (OLEDs) are being increasingly used in display applications involving mobile devices and televisions due to their higher contrast ratios, color uniformity, and wider viewing angle than liquid-crystal displays. One of the main limitations of OLED energy efficiency is the low light extraction from the device. In this example, we use Meep to compute the light-extraction efficiency of an OLED. This is based on results published in Applied Physics Letters, Vol. 106, No. 041111, 2015 (pdf). US Patent 9761842, related to this work, has been licensed by Universal Display Corporation (NASDAQ: OLED).

A typical device structure for a bottom-emitting OLED is shown below. The device consists of a stack of four planar layers. The organic (ORG) layer is deposited on an indium tin oxide (ITO) coated glass substrate with an aluminum (Al) cathode layer on top. Electrons are injected into the organic layer from the Al cathode and holes from the ITO anode. These charge carriers form bound states called excitons which spontaneously recombine to emit photons. Light is extracted from the device through the transparent glass substrate. Some of the light, however, remains trapped within the device as (1) waveguide modes in the high-index ORG/ITO layers and (2) surface-plasmon polaritons (SPP) at the Al/ORG interface. These losses significantly reduce the external quantum efficiency (EQE) of OLEDs. We compute the fraction of the total power in each of these three device components for broadband emission from a white source spanning 400 to 800 nm. The results can be obtained using a single finite-difference time-domain (FDTD) simulation.

There are three key features involved in developing an accurate model. (1) Material Properties. The complex refractive index over the entire broadband spectrum must be imported for each material. This requires fitting the material data to a sum of Drude-Lorentzian susceptibility terms. In this example, we treat the glass, ITO, and organic as lossless since their absorption coefficient is small. The refractive index of Al can be obtained from Applied Optics, Vol. 37, pp. 5271-83, 1998. (2) Recombining Excitons as Light Source. An ensemble of spontaneously-recombining excitons produces incoherent emission. This can be modeled using a collection of point-dipole sources with random phase positioned within the organic layer. Given the stochastic nature of the sources, the results must be averaged using Monte-Carlo sampling. The number of samples must be large enough to ensure that the variance of the computed quantities is sufficiently small. (3) Flux Monitors. The total power separated into the three device components is computed using flux monitors. The size and position of these monitors must be chosen correctly to fully capture the relevant fields.

The first component of any Meep simulation script is the importing of the Python modules. All examples involve command-line parameters which require the argparase module. This example also involves complex (cmath) and random (random) numbers.
		      
import meep as mp
import cmath
import random
import argparse

def main(args):


We choose the unit length to be 1 μm. The choice of resolution requires a convergence test to determine a value suitable for a desired level of accuracy. This is particularly relevant in this example given the presence of the lossy-metal aluminum with its nanoscale skin depth as well as the flux monitors. Based on tests, the resolution is set to 100 pixels per μm which is equivalent to a pixel size of 10 nm.
		      
resolution = 100            # pixels/um


We specify the frequency bounds of the Gaussian pulse using its minimum and maximum wavelengths in vacuum.
		      
lambda_min = 0.4            # minimum source wavelength
lambda_max = 0.8            # maximum source wavelength
fmin = 1/lambda_max         # minimum source frequency
fmax = 1/lambda_min         # maximum source frequency
fcen = 0.5*(fmin + fmax)    # source frequency center
df = fmax - fmin            # source frequency width


The thickness of each layer is a parameter. This is useful if we want to optimize the design. We use typical values for OLEDs. The length of the absorbing layer should be at least half the largest wavelength in the simulation to ensure negligible reflections. This is because incident waves are absorbed twice through a round-trip reflection from the hard-wall boundaries of the computational cell.
		      
tABS = lambda_max           # absorber/PML thickness
tGLS = 1.0                  # glass thickness
tITO = 0.1                  # indium tin oxide thickness
tORG = 0.1                  # organic thickness
tAl = 0.1                   # aluminum thickness

# length of computational cell along Z
sz = tABS + tGLS + tITO + tORG + tAl


Since this is a 3d simulation, we also need to specify the length of the computational cell in the transverse directions X and Y. This is the length of the high-index organic/ITO waveguide. We choose a value of several wavelengths. The choice of the waveguide length has a direct impact on the results.
  
# length of non-absorbing region of computational cell in X and Y
L = args.L
sxy = L+2*tABS
cell_size = mp.Vector3(sxy,sxy,sz)


Overlapping the lossy-metal aluminum with a perfectly-matched layer (PML) sometimes leads to field instabilities due to backward-wave SPPs. Meep provides an alternative absorber which tends to be more stable. We use an absorber in the X and Y directions and a PML for the outgoing waves in the glass substrate. The metal cathode on top of the device either reflects or absorbs the incident light. No light is transmitted. Thus, we need a PML along just one side in the Z direction.
  
boundary_layers = [ mp.Absorber(tABS, direction=mp.X),
mp.Absorber(tABS, direction=mp.Y),
mp.PML(tABS, direction=mp.Z, side=mp.High) ]


Next, we define the material properties and set up the geometry consisting of the four-layer stack.
  
nORG = 1.75
ORG = mp.Medium(index=nORG)
nITO = 1.8
ITO = mp.Medium(index=nITO)
nGLS = 1.45
GLS = mp.Medium(index=nGLS)

# conversion factor for eV to 1/um
eV_um_scale = 1/1.23984193

# Al, from A.D. Rakic et al., Applied Optics, Vol. 37, No. 22,  pp. 5271-83 (1998)
Al_plasma_frq = 14.98*eV_um_scale
Al_f0 = 0.523
Al_frq0 = 1e-10
Al_gam0 = 0.047*eV_um_scale
Al_sig0 = Al_f0*Al_plasma_frq**2/Al_frq0**2
Al_f1 = 0.050
Al_frq1 = 1.544*eV_um_scale # 803 nm
Al_gam1 = 0.312*eV_um_scale
Al_sig1 = Al_f1*Al_plasma_frq**2/Al_frq1**2
Al_f2 = 0.166
Al_frq2 = 1.808*eV_um_scale # 686 nm
Al_gam2 = 1.351*eV_um_scale
Al_sig2 = Al_f2*Al_plasma_frq**2/Al_frq2**2
Al_f3 = 0.030
Al_frq3 = 3.473*eV_um_scale # 357 nm
Al_gam3 = 3.382*eV_um_scale
Al_sig3 = Al_f3*Al_plasma_frq**2/Al_frq3**2

Al_susc = [ mp.DrudeSusceptibility(frequency=Al_frq0, gamma=Al_gam0, sigma=Al_sig0),
mp.LorentzianSusceptibility(frequency=Al_frq1, gamma=Al_gam1, sigma=Al_sig1),
mp.LorentzianSusceptibility(frequency=Al_frq2, gamma=Al_gam2, sigma=Al_sig2),
mp.LorentzianSusceptibility(frequency=Al_frq3, gamma=Al_gam3, sigma=Al_sig3) ]

Al = mp.Medium(epsilon=1.0, E_susceptibilities=Al_susc)

geometry = [ mp.Block(material=GLS, size=mp.Vector3(mp.inf,mp.inf,tABS+tGLS), center=mp.Vector3(0,0,0.5*sz-0.5*(tABS+tGLS))),
mp.Block(material=ITO, size=mp.Vector3(mp.inf,mp.inf,tITO), center=mp.Vector3(0,0,0.5*sz-tABS-tGLS-0.5*tITO)),
mp.Block(material=ORG, size=mp.Vector3(mp.inf,mp.inf,tORG), center=mp.Vector3(0,0,0.5*sz-tABS-tGLS-tITO-0.5*tORG)),
mp.Block(material=Al, size=mp.Vector3(mp.inf,mp.inf,tAl), center=mp.Vector3(0,0,0.5*sz-tABS-tGLS-tITO-tORG-0.5*tAl)) ]


We use a set of point-dipole sources, each with random phase but fixed polarization, distributed along a line within the middle of the organic layer. The number of point sources is a parameter with a default of 10. The polarization of the source has an important effect on the results which we will investigate. Instead of using a random polarization, which would require multiple runs to obtain a statistical average, the sources can be separated into components which are parallel (directions X and Y) and perpendicular (Z) to the layers. Thus, we will need to do just two sets of simulations. These are averaged to obtain results for random polarization.
		      
# current-source component
if args.perp_dipole:
src_cmpt = mp.Ez
else:
src_cmpt = mp.Ex

num_src = 10                 # number of point sources
sources = [];
for n in range(1, num_src):
sources.append(mp.Source(mp.GaussianSource(fcen, fwidth=df), component=src_cmpt,
center=mp.Vector3(0,0,0.5*sz-tABS-tGLS-tITO-0.4*tORG-0.2*tORG*n/num_src),
amplitude=cmath.exp(2*cmath.pi*random.random()*1j)))


We can also exploit the two mirror symmetry planes of the sources and the structure in order to reduce the size of the computation by a factor four. The phase of the mirror symmetry planes depends on the polarization of the source. Three separate cases are necessary.
		      
if src_cmpt == mp.Ex:
symmetries = [mp.Mirror(mp.X,-1), mp.Mirror(mp.Y,+1)]
elif src_cmpt == mp.Ey:
symmetries = [mp.Mirror(mp.X,+1), mp.Mirror(mp.Y,-1)]
elif src_cmpt == mp.Ez:
symmetries = [mp.Mirror(mp.X,+1), mp.Mirror(mp.Y,+1)]


Three sets of flux monitors are required to capture the power in the sources, glass substrate, and high-index waveguide. We place a set of six flux planes along the sides of a box to enclose the sources. This is used to compute the total power in the device. These monitors must be placed entirely within the organic layer. One flux plane is required to compute the power in the glass substrate. Four flux planes are required to capture the total power of the modes in the high-index waveguide forming the organic/ITO layers. These modes are delocalized and extend slightly beyond these two layers. This requires the height of the flux planes to be larger than the combined thickness of the layers as shown in the figure above. Also, any component of the guided mode which extends into the aluminum will be absorbed due to screening effects of the charges in the metal. The longer the waveguide is made, the more these guided modes will be absorbed. This is why the length of the waveguide (L) should not be made so large that the waveguide component of the total power is zero.
		      
sim = mp.Simulation(resolution=resolution,
cell_size=cell_size,
boundary_layers=boundary_layers,
geometry=geometry,
dimensions=3,
sources=sources,
symmetries=symmetries)

# number of frequency bins for DFT fields
nfreq = 50

# surround source with a six-sided box of flux planes
srcbox_width = 0.05
srcbox_top = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,0,0.5*sz-tABS-tGLS),
size=mp.Vector3(srcbox_width,srcbox_width,0), direction=mp.Z, weight=+1))
srcbox_bot = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,0,0.5*sz-tABS-tGLS-tITO-0.8*tORG),
size=mp.Vector3(srcbox_width,srcbox_width,0), direction=mp.Z, weight=-1))
srcbox_xp = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0.5*srcbox_width,0,0.5*sz-tABS-tGLS-0.5*(tITO+0.8*tORG)),
size=mp.Vector3(0,srcbox_width,tITO+0.8*tORG), direction=mp.X, weight=+1))
srcbox_xm = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(-0.5*srcbox_width,0,0.5*sz-tABS-tGLS-0.5*(tITO+0.8*tORG)),
size=mp.Vector3(0,srcbox_width,tITO+0.8*tORG), direction=mp.X, weight=-1))
srcbox_yp = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,0.5*srcbox_width,0.5*sz-tABS-tGLS-0.5*(tITO+0.8*tORG)),
size=mp.Vector3(srcbox_width,0,tITO+0.8*tORG), direction=mp.Y, weight=+1))
srcbox_ym = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,-0.5*srcbox_width,0.5*sz-tABS-tGLS-0.5*(tITO+0.8*tORG)),
size=mp.Vector3(srcbox_width,0,tITO+0.8*tORG), direction=mp.Y, weight=-1))

# padding for flux box to fully capture waveguide mode
fluxbox_dpad = 0.05

# upward flux into glass substrate
glass_flux = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,0,0.5*sz-tABS-(tGLS-fluxbox_dpad)),
size = mp.Vector3(L,L,0), direction=mp.Z, weight=+1))

# surround ORG/ITO waveguide with four-sided box of flux planes
# NOTE: waveguide mode extends partially into Al cathode and glass substrate
wvgbox_xp = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(size=mp.Vector3(0,L,fluxbox_dpad+tITO+tORG+fluxbox_dpad), direction=mp.X,
center=mp.Vector3(0.5*L,0,0.5*sz-tABS-tGLS-0.5*(tITO+tORG)), weight=+1))
wvgbox_xm = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(size=mp.Vector3(0,L,fluxbox_dpad+tITO+tORG+fluxbox_dpad), direction=mp.X,
center=mp.Vector3(-0.5*L,0,0.5*sz-tABS-tGLS-0.5*(tITO+tORG)), weight=-1))
wvgbox_yp = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(size=mp.Vector3(L,0,fluxbox_dpad+tITO+tORG+fluxbox_dpad), direction=mp.Y,
center=mp.Vector3(0,0.5*L,0.5*sz-tABS-tGLS-0.5*(tITO+tORG)), weight=+1))
wvgbox_ym = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(size=mp.Vector3(L,0,fluxbox_dpad+tITO+tORG+fluxbox_dpad), direction=mp.Y,
center=mp.Vector3(0,-0.5*L,0.5*sz-tABS-tGLS-0.5*(tITO+tORG)), weight=-1))


Finally, with the structure and sources set up, we run the simulation until the fields in the device have sufficiently decayed away. Afterwards, the flux data is written to standard output as a series of columns.
		      
sim.run(until_after_sources=mp.stop_when_fields_decayed(50, src_cmpt, mp.Vector3(0, 0, 0.5*sz-tABS-tGLS-tITO-0.5*tORG), 1e-8))

sim.display_fluxes(srcbox_top, srcbox_bot, srcbox_xp, srcbox_xm, srcbox_yp, srcbox_ym, glass_flux,
wvgbox_xp, wvgbox_xm, wvgbox_yp, wvgbox_ym)


The last component of the script involves specifying the command-line parameters and their default values.
		      
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-L', type=float, default=4.0, help='length of OLED (default: 4.0 um)')
parser.add_argument('--perp_dipole', action='store_false', default=True, help="perpendicular dipole (default: True)")
args = parser.parse_args()
main(args)


We use the following Bash script to launch a parallel Meep simulation using 8 processors.
		      
#!/bin/bash

mpirun -np 8 python oled_ext_eff.py -L $1 > oled-flux.out; grep flux1: oled-flux.out |cut -d , -f2- > oled-flux.dat;   This script is executed from the shell terminal using a waveguide length (L) of 4.   chmod u+x run_oled_python.sh nohup ./run_oled_python.sh 4 &> /dev/null &   This takes about 3 hours to run on an Intel Xeon 2.60 GHz machine. Once the simulation is complete, we plot its output using a Jupyter/IPython notebook. The total power in each device component is the sum of the relevant columns of the output.   from numpy import * from scipy import interpolate import matplotlib.pyplot as plt f = genfromtxt("oled-flux.dat", delimiter=",") total_power = sum(f[:,1:6],axis=1) glass_power = f[:,7] waveguide_power = sum(f[:,8:11],axis=1) glass = glass_power/total_power waveguide = waveguide_power/total_power aluminum = 1-glass-waveguide lambdas_linear = linspace(0.4,0.8,100) lambdas = 1/f[:,0] g_linear = interpolate.interp1d(lambdas,glass,kind='cubic') w_linear = interpolate.interp1d(lambdas,waveguide,kind='cubic') a_linear = interpolate.interp1d(lambdas,aluminum,kind='cubic') glass_linear = g_linear(lambdas_linear) waveguide_linear = w_linear(lambdas_linear) aluminum_linear = a_linear(lambdas_linear) plt.plot(lambdas_linear,glass_linear,'b-',label='glass') plt.plot(lambdas_linear,waveguide_linear,'r-',label='organic + ITO') plt.plot(lambdas_linear,aluminum_linear,'g-',label='aluminum') plt.xlabel("wavelength (um)"); plt.ylabel("fraction of total power") plt.axis([0.4, 0.8, 0, 1]) plt.xticks([t for t in arange(0.4,0.9,0.1)]) plt.legend(loc='upper right') plt.show() print("glass: {} (mean), {} (std. dev.)".format(mean(glass_linear),std(glass_linear))) print("waveguide: {} (mean), {} (std. dev.)".format(mean(waveguide_linear),std(waveguide_linear))) print("aluminum: {} (mean), {} (std. dev.)".format(mean(aluminum_linear),std(aluminum_linear)))   There are significant losses from the SPPs for the perpendicular dipoles as shown in the figure on the right. This is because this dipole orientation couples readily into these modes due to matching boundary conditions of the electric fields. Such losses are smaller for the parallel dipoles. The total power extracted from the device is computing using ⅔P+⅓P≈ 0.20. This value is consistent with experimentally-measured results. As described in the reference paper, we can apply a nanoscale surface texture to the cathode in order to recover the light lost to the SPPs, which dominate the total losses, and also to enhance the rate of spontaneous emission via the Purcell effect. Files: Simulation Script (Python), Simulation Script (Scheme), Shell Launch Script, Sample Output, Post Processing: Python, Jupyter/IPython [html], Matlab/Octave. [gzipped tarball] ## MPB Project #1 — Modes of Silicon on Insulator (SOI) Strip Waveguides A key component of silicon photonic integrated circuits are waveguides. These devices are typically fabricated on silicon on insulator (SOI) wafers. Infrared light at 1.55 μm, the standard wavelength for telecommunications using silica fibers, is routed within the silicon using index guiding. We will use MPB to calculate the dispersion relation, also known as a band diagram, of these waveguide modes as shown in the right figure below. The focus is to design a waveguide which is single mode for the lowest band (i.e., the fundamental mode). The left figure shows the device structure. The silicon waveguide has a rectangular cross section with width w and height h. The buried oxide, typically silicon dioxide, is below the waveguide. A silicon substrate is beneath. No cladding is placed on top of the waveguide which is surrounded by air. The propagation axis is along X. This is the direction in which the waveguide is translationally invariant. We choose the unit length to be 1 μm. The resolution is 64 pixels per μm which is equivalent to a pixel size of approximately 16 nm. This is higher than necessary for accurate results given MPB's subpixel smoothing method.   (set-param! resolution 64) ; pixels/μm   The width and height of the waveguide are design parameters. Most SOI wafers have a 220 nm thick silicon layer which is used as the default value for the height. The default width is 500 nm.   (define-param w 0.50) ; waveguide width (define-param h 0.22) ; waveguide height   This is a 3d calculation based on a 2d computational cell in Y and Z. The size of the computational cell needs to be large enough such that the fields are negligible at the edge of the computational cell. This ensures that MPB's periodic boundaries do not affect the results. Since the guided mode is localized within the silicon, the fields outside are exponentially decaying. There is a tradeoff to increasing the size of the computational cell: the size of the calculation also increases.   (define-param sc-y 2) ; supercell width (define-param sc-z 2) ; supercell height (set! geometry-lattice (make lattice (size no-size sc-y sc-z)))   Next, we specify the material properties of silicon and silicon dioxide. Silicon is lossless at 1.55 μm which is an important feature for these kinds of applications. The large refractive index contrast with silicon dioxide also produces strong mode confinement. Typical values for the refractive indicies are used as default.   (define-param nSi 3.45) (define-param nSiO2 1.45) (define Si (make dielectric (index nSi))) (define SiO2 (make dielectric (index nSiO2)))   Since the oxide layer in which the waveguide modes are exponentially decaying is several microns in thickness, the fields are negligible at the silicon substrate. Thus, the substrate can be omitted from the device geometry. The geometry consists of just two objects: (1) a rectangular silicon waveguide at the center of the computational cell and (2) a planar oxide layer which fills the bottom half.   (set! geometry (list (make block (size infinity w h) (center 0 0 0) (material Si)) (make block (size infinity infinity (* 0.5 (- sc-z h))) (center 0 0 (* 0.25 (+ sc-z h))) (material SiO2))))   The first four bands will be computed even though the single-mode property can be determined from only the first and second bands. The range of propagation wavevectors over which to compute the bands needs to be sufficiently large to contain modes at 1.55 μm. Finding suitable values typically requires a bit of trial and error.   (set-param! num-bands 4) (define-param num-k 20) (define-param k-min 0.1) (define-param k-max 2.0) (set! k-points (interpolate num-k (list (vector3 k-min) (vector3 k-max))))   We can now call the run function to compute the bands. The parity information in the Y direction for each mode is also output. This will help us identify properties of the modes since the fundamental mode has even symmetry.   (run display-yparities)   After the bands have been computed, we identify the mode(s) at 1.55 μm. This involves an inverse calculation where given the mode frequency (in vacuum), we compute its wavevector using MPB's built-in find-k routine. The Poynting vector along X of the fields is also output as an HDF5 file.   (define-param f-mode (/ 1.55)) ; frequency corresponding to 1.55 um (define-param band-min 1) (define-param band-max 1) (define-param kdir (vector3 1 0 0)) (define-param tol 1e-6) (define-param kmag-guess (* f-mode nSi)) (define-param kmag-min (* f-mode 0.1)) (define-param kmag-max (* f-mode 4)) (find-k ODD-Y f-mode band-min band-max kdir tol kmag-guess kmag-min kmag-max output-poynting-x display-group-velocities)   This shell script is used to launch the simulation which takes a few seconds using a single Intel Xeon 2.60 GHz core. Afterwards, h5topng, part of the h5utils package, is used to generate a PNG image from the raw simulation data stored in the HDF5 file.   #!/bin/bash mpb strip-wvg.ctl > strip-wvg-bands.out; grep freqs: strip-wvg-bands.out |cut -d , -f3,7- |sed 1d > strip-wvg-bands.dat; h5topng -o wvg_power.png -x 0 -d x.r -vZc bluered -C strip-wvg-epsilon.h5 strip-wvg-flux.v.k01.b01.x.yodd.h5;   Finally, we plot the results from the output and add the light line for the oxide.   from numpy import * import matplotlib.pyplot as plt f = genfromtxt("strip-wvg-bands.dat", delimiter=",") plt.plot(f[:,0],f[:,1:],'b-',f[:,0],f[:,0]/1.45,'k-') plt.xlabel("wavevector k_x (units of 2\pi\mum^{-1})") plt.ylabel("frequency (units of 2\pix30^{14} Hz)") plt.axis([0,2,0,1]) plt.show()   This plot is shown in the right figure above. There is a single mode at 1.55 μm for the lowest band indicated with the dotted green line. The cutoff frequency of the second band lies above this mode frequency. The inset shows the Poynting vector along X (Sx). The antinode at the center of the waveguide verifies that this is the fundamental mode. This mode has a wavevector at 1.5192 μm-1 as calculated from the find-k routine. Files: Simulation Script, Shell Launch Script, Sample Output, Post Processing: Python, Jupyter/IPython [html], Matlab/Octave. [gzipped tarball] ## Meep Project #2 — Optimizing Far-Field Intensity of SOI Bragg Grating Outcouplers Coupling light into and out of silicon photonic integrated circuits is an important part of the overall device operation. For example, couplers are required when an external laser is used as the input light source or when the circuit signal must be transferred to an optical fiber for long-range transmission. This example involves designing a grating structure to outcouple light from an SOI strip waveguide and direct the beam into a given direction in the vacuum far field while minimizing losses due to reflection and scattering. We will use Meep to compute the far-field intensity of the device and optimize the design by integrating Meep with NLopt, an open-source library for nonlinear optimization. The outcoupler design is based on a concentric Bragg grating with angled sides, shown in the figures below. The input port is an SOI strip waveguide which is connected to the Bragg grating. The figure below shows the device cross section in the XY plane of the computational cell. There are two parameters used to design the Bragg grating outcoupler: periodicity a and length d. In this example, the number of grating periods and the side angle are constants (5 and 20°). The width w and height h of the waveguide are 500 nm and 220 nm, identical to the single-mode waveguide described in the previous section. An eigenmode source is placed at the left edge of the input port to excite the waveguide mode at 1.55 μm. The computational cell is surrounded on all sides by perfectly-matched layer (PML) absorbing boundaries. The first component of the simulation script, as always, is the importing of the various Python modules.   import meep as mp import math import argparse def main(args):   The simulation script consists of the device geometry, source, near-field surface (used to compute the far fields), time-stepping routine, and far-field output. First, the device geometry which includes the Bragg grating, waveguide, and substrate is defined using a combination of various shape objects. The entire structure is parameterized though only two parameters are optimized in this example.   resolution = 20 # pixels/unit length (1 um) h = args.hh w = args.w a = args.a d = args.d N = args.N N = N + 1 nSi = 3.45 Si = mp.Medium(index=nSi) nSiO2 = 1.45 SiO2 = mp.Medium(index=nSiO2) sxy = 16 sz = 4 cell_size = mp.Vector3(sxy,sxy,sz) geometry = [] # rings of Bragg grating for n in range(N,0,-1): geometry.append(mp.Cylinder(material=Si, center=mp.Vector3(0,0,0), radius=n*a, height=h)) geometry.append(mp.Cylinder(material=mp.air, center=mp.Vector3(0,0,0), radius=n*a-d, height=h)) # remove left half of Bragg grating rings to form semi circle geometry.append(mp.Block(material=mp.air, center=mp.Vector3(-0.5*N*a,0,0), size=mp.Vector3(N*a,2*N*a,h))) geometry.append(mp.Cylinder(material=Si, center=mp.Vector3(0,0,0), radius=a-d, height=h)) # angle sides of Bragg grating # rotation angle of sides relative to Y axis (degrees) rot_theta = -math.radians(args.rot_theta) pvec = mp.Vector3(0,0.5*w,0) cvec = mp.Vector3(-0.5*N*a,0.5*N*a+0.5*w,0) rvec = cvec-pvec rrvec = rvec.rotate(mp.Vector3(0,0,1),rot_theta) geometry.append(mp.Block(material=mp.air, center=pvec+rrvec, size=mp.Vector3(N*a,N*a,h), e1=mp.Vector3(1,0,0).rotate(mp.Vector3(0,0,1),rot_theta), e2=mp.Vector3(0,1,0).rotate(mp.Vector3(0,0,1),rot_theta), e3=mp.Vector3(0,0,1))) pvec = mp.Vector3(0,-0.5*w,0) cvec = mp.Vector3(-0.5*N*a,-(0.5*N*a+0.5*w), 0) rvec = cvec-pvec rrvec = rvec.rotate(mp.Vector3(0,0,1),-rot_theta) geometry.append(mp.Block(material=mp.air, center=pvec+rrvec, size=mp.Vector3(N*a,N*a,h), e1=mp.Vector3(1,0,0).rotate(mp.Vector3(0,0,1),-rot_theta), e2=mp.Vector3(0,1,0).rotate(mp.Vector3(0,0,1),-rot_theta), e3=mp.Vector3(0,0,1))) # input waveguide geometry.append(mp.Block(material=mp.air, center=mp.Vector3(-0.25*sxy,0.5*w+0.5*a,0), size=mp.Vector3(0.5*sxy,a,h))) geometry.append(mp.Block(material=mp.air, center=mp.Vector3(-0.25*sxy,-(0.5*w+0.5*a),0), size=mp.Vector3(0.5*sxy,a,h))) geometry.append(mp.Block(material=Si, center=mp.Vector3(-0.25*sxy,0,0), size=mp.Vector3(0.5*sxy,w,h))) # substrate geometry.append(mp.Block(material=SiO2, center=mp.Vector3(0,0,-0.5*sz+0.25*(sz-h)), size=mp.Vector3(mp.inf,mp.inf,0.5*(sz-h)))) dpml = 1.0 boundary_layers = [ mp.PML(dpml) ]   Next, the eigenmode source is defined which is based on calling MPB to compute a definite-frequency mode and using it as the amplitude profile. We use a Gaussian pulsed source, with center wavelength corresponding to 1.55 μm, such that the fields eventually decay away due to absorption by the PMLs and the simulation can be terminated.   # mode frequency fcen = 1/1.55 sources = [ mp.EigenModeSource(src=mp.GaussianSource(fcen, fwidth=0.2*fcen), component=mp.Ey, size=mp.Vector3(0,sxy-2*dpml,sz-2*dpml), center=mp.Vector3(-0.5*sxy+dpml,0,0), eig_match_freq=True, eig_parity=mp.ODD_Y, eig_kpoint=mp.Vector3(1.5,0,0), eig_resolution=32) ]   We can exploit the mirror symmetry in the structure and the sources to reduce the computation size by a factor of 2.   symmetries = [ mp.Mirror(mp.Y,-1) ] sim = mp.Simulation(resolution=resolution, cell_size=cell_size, boundary_layers=boundary_layers, geometry=geometry, sources=sources, dimensions=3, symmetries=symmetries)   We define the near-field surface to span the entire non-PML region above the device, adjacent to the PML in the Z direction.   nearfield = sim.add_near2far(fcen, 0, 1, mp.Near2FarRegion(mp.Vector3(0,0,0.5*sz-dpml), size=mp.Vector3(sxy-2*dpml,sxy-2*dpml,0)))   The fields are time stepped until sufficiently decayed.   sim.run(until_after_sources=mp.stop_when_fields_decayed(50, mp.Ey, mp.Vector3(), 1e-6))   Finally, we compute the far fields at 1.55 μm at a series of points on a semicircle within the XZ plane using Meep's near-to-far-field transformation feature. The radius of the semicircle is 1000 wavelengths which is sufficiently large to obtain the far fields. Each far-field point corresponds to an angle, at equally-spaced intervals, from the X axis. The number of far-field points is a parameter with default of 100. The output consists of the six field components (Ex,Ey,Ez,Hx,Hy,Hz) at each point in space.   r = 1000 * (1 / fcen) # 1000 wavelengths out from the source npts = 100 # number of points in [0,2*pi) range of angles for n in range(npts): ff = sim.get_farfield(nearfield, mp.Vector3(r * math.cos(math.pi * (n / npts)), 0, r * math.sin(math.pi * (n / npts)))) print("farfield: {}, {}, ".format(n, math.pi * n / npts), end='') print(", ".join([str(f).strip('()').replace('j', 'i') for f in ff]))   The last component of the script involves specifying the command-line parameters and their default values.   if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-hh', type=float, default=0.22, help='wavelength height (default: 0.22 um)') parser.add_argument('-w', type=float, default=0.50, help='wavelength width (default: 0.50 um)') parser.add_argument('-a', type=float, default=1.0, help='Bragg grating periodicity/lattice parameter (default: 1.0 um)') parser.add_argument('-d', type=float, default=0.5, help='Bragg grating thickness (default: 0.5 um)') parser.add_argument('-N', type=int, default=5, help='number of grating periods') parser.add_argument('-rot_theta', type=float, default=20, help='rotation angle of sides relative to Y axis (default: 20 degrees)') args = parser.parse_args() main(args)   With this simulation script, we can now create an objective function used in the nonlinear optimization for device design. In this example, the objective function takes two parameters as input, the grating periodicity and length (as a fraction of the periodicity), and returns the fraction of the far-field intensity concentrated within the angular cone spanning 70° to 80°. The script invokes the shell to execute a parallel Meep simulation with 8 processors. The output is written to a file. From the far fields, the power in the XZ plane is computed as a function of angle from the X axis.   from numpy import * from string import * from subprocess import call def compute_fieldintensity(p, grad): a=p[0] dfrac=p[1] d=a*dfrac np=8 rot_theta=20 exec_str = "mpirun -np %d python bragg_outcoupler.py -a %0.2f -d %0.2f -rot_theta %d > ... ...bragg-optimize-a%0.2f-d%0.2f.out" % (np,a,d,rot_theta,a,d) call(exec_str, shell="True") grep_str = "grep farfield: bragg-optimize-a%0.2f-d%0.2f.out |cut -d , -f2- > bragg-optimize-a%0.2f-d%0.2f.dat" % (a,d,a,d) call(grep_str, shell="True") mydata = genfromtxt("bragg-optimize-a%0.2f-d%0.2f.dat" % (a,d), delimiter=",", dtype='str') mydata = char.replace(mydata,'i','j').astype(complex128) Ex=mydata[:,1]; Ey=mydata[:,2]; Ez=mydata[:,3]; Hx=mydata[:,4]; Hy=mydata[:,5]; Hz=mydata[:,6]; Ex=conj(Ex); Ey=conj(Ey); Ez=conj(Ez); Px=real(multiply(Ey,Hz)-multiply(Ez,Hy)) Py=real(multiply(Ez,Hx)-multiply(Ex,Hz)) Pz=real(multiply(Ex,Hy)-multiply(Ey,Hx)) Pr=sqrt(square(Px)+square(Py)) Pnorm = Pr/max(Pr) ang_min = 70 ang_max = 80 ang_min = ang_min*pi/180 ang_max = ang_max*pi/180 idx = where((mydata[:,0] > ang_min) & (mydata[:,0] < ang_max)) val = sum(Pnorm[idx])/sum(Pnorm) print("intensity:, {}, {}, {}".format(a,d,val)) return val;   Finally, we set up the nonlinear optimization using NLopt by defining the parameter constraints, optimization algorithm, and termination criteria. The initial parameters are chosen randomly. We are using a gradient-free approach since the design involves just two parameters. For designs involving a large number of parameters, a gradient-based approach using adjoint methods would be more efficient. This would enable the use of conjugate gradient methods. The optimization is run multiple times to explore various local optima. A benefit of using NLopt is that we can try several different optimization algorithms by changing just one line in the script. Each solve of the objection function takes approximately 15 minutes on a system with 2.8 GHz AMD Opteron processors.   import nlopt import random from compute_fieldintensity import * # lattice parameter (um) a_min = 0.50 a_max = 3.00 # waveguide width (fraction of lattice parameter) dfrac_min = 0.2 dfrac_max = 0.8 opt = nlopt.opt(nlopt.LN_BOBYQA, 2) opt.set_max_objective(compute_fieldintensity) opt.set_lower_bounds([ a_min, dfrac_min ]) opt.set_upper_bounds([ a_max, dfrac_max ]) opt.set_ftol_abs(0.005) opt.set_xtol_abs(0.02) opt.set_initial_step(0.04) opt.max_eval = 50 # random initial parameters a_0 = a_min + (a_max-a_min)*random.random() dfrac_0 = dfrac_min + (dfrac_max-dfrac_min)*random.random() x = opt.optimize([a_0, dfrac_0]) maxf = opt.last_optimum_value() print("optimum at a={} um, d={} um".format(x[0],x[0]*x[1])) print("maximum value = {}".format(maxf)) print("result code = {}".format(opt.last_optimize_result()))   Here are results from the nonlinear optimization for three different local optima found in the search space. Each run took approximately 10 iterations to converge. The polar plot of the far-field intensity is shown for each design. Also shown is the concentration in the angular cone (objective function). The middle inset has just a single lobe in its radiation pattern and thus the highest concentration. Files: Simulation Script (Python), Simulation Script (Scheme), Objective Function: Python, Matlab/Octave, Nonlinear Optimization: Python, Matlab/Octave. [gzipped tarball] ## MPB Project #2 — Band Gap of Photonic-Crystal Nanobeam Waveguide One-dimensional photonic-crystal waveguides consisting of a periodic array of cylindrical holes within a silicon slab of rectangular cross section are found in a wide range of applications involving lasers, optomechanics, and quantum optics. An important feature of these structures is that they can support cavity modes with low losses having quality factors typically exceeding 106 (as demonstrated in the next section) and are simpler to fabricate than their 2d or 3d counterparts. We will use MPB to compute the dispersion relation of a 1d photonic-crystal nanobeam waveguide based on the design in Applied Physics Letters, Vol. 94, No. 121106, 2009 (pdf). This structure can be fabricated using an SOI wafer. A schematic of the waveguide unit cell is shown in the figure below. The lattice periodicity (a) is 0.43 μm and the waveguide width (w) and height (h) are 0.50 and 0.22 μm. The hole radius 0.28a which is 0.12 μm. Given the 1d periodicity, we compute the dispersion relation within the irreducible Brillouin zone which spans axial wavevectors along the X direction from 0 to π/a. This is shown in the figure below. There is a bandgap, a region in which there are no guided modes, in the wavelength range of 1.30-1.70 μm. The light line of air is also shown. The simulation script used to generate this figure is shown below. MPB only supports Bloch-periodic boundary conditions. The waveguide unit cell is periodic along only one direction (X). The other two directions must therefore be made sufficiently large such that the guided modes which are exponentially decaying away from the waveguide produce fields with negligible values at the boundaries. The focus of this example are modes with odd mirror symmetry in Y and even mirror symmetry in Z. All lengths are normalized by the lattice periodicity.   (set-param! resolution 20) ; pixels/a (define-param a 0.43) ; units of um (define-param r 0.12) ; units of um (define-param h 0.22) ; units of um (define-param w 0.50) ; units of um (set! r (/ r a)) ; units of "a" (set! h (/ h a)) ; units of "a" (set! w (/ w a)) ; units of "a" (define-param nSi 3.5) (define Si (make medium (index nSi))) (set! geometry-lattice (make lattice (size 1 4 4))) (set! geometry (list (make block (center 0 0 0) (size infinity w h) (material Si)) (make cylinder (center 0 0 0) (radius r) (height infinity) (material air)))) (set! k-points (list (vector3 0 0 0) (vector3 0.5 0 0))) (define-param num-kpoints 20) (set! k-points (interpolate num-kpoints k-points)) (set-param! num-bands 5) (run-yodd-zeven)   We run the simulation script from the shell terminal, pipe the results to a file, and then grep the relevant contents into a separate file for plotting. This takes a few seconds on a machine with a single 2.8 GHz AMD Opteron processor.   mpb nanobeam-modes.ctl |tee modes.out grep zevenyoddfreqs: modes.out |cut -d , -f3,7- |sed 1d > modes.dat   Finally, we plot the results using matplotlib.   from numpy import * import matplotlib.pyplot as plt f = genfromtxt("modes.dat", delimiter=",") plt.plot(f[:,0],f[:,1:],'b-',f[:,0],f[:,0],'k-') plt.xlabel("wavevector k_x (units of 2\pi/a)") plt.ylabel("frequency (units of 2\pix70^{14} Hz)") plt.axis([0,0.5,0,0.4]) plt.show()   Files: Simulation Script, Sample Output, Post Processing: Python. [gzipped tarball] ## Meep Project #3 — Resonant Modes of a Photonic-Crystal Nanobeam Cavity Using the nanobeam waveguide design of the previous section which has a bandgap between 1.30 and 1.70 μm, we proceed to create a resonant cavity by linearly tapering the lattice periodicity from a starting value of a-start to ending a-end with radii r=0.28a of several holes on either side of a defect as shown in the schematic below. This cavity design is based on the Applied Physics Letters reference from above. We use Meep to design the cavity structure to maximize the quality factor (Q) of the fundamental resonant mode. In this example, there is only one design parameter: the cavity length (s-cav). We can exploit the three-fold mirror symmetry of this design to reduce the size of the computation by a factor of 8. Since this device is designed for telecommunication wavelengths of approximately 1.55 μm where silicon is lossless, we can leverage Meep's subpixel smoothing feature to lower the resolution while still ensuring accuracy. A narrowband, point-dipole source is placed at the center of the cavity to excite the resonant mode. To determine its wavelength and quality factor, we use a field monitor via Meep's harmonic inversion (harminv) which is also placed at the center of the cavity. harminv can be used to resolve high-Q modes using just several periods of the cavity field's time-series data. This can significantly reduce the runtime of these kinds of simulations. The cavity is formed by 5 tapered holes and surrounded by 8 unit cells of the waveguide. The entire computational cell is surrounded by PMLs. The simulation script is shown below.   import meep as mp import argparse def main(args): resolution = 40 # pixels/unit length (1 um) a_start = args.a_start # starting periodicity a_end = args.a_end # ending periodicity s_cav = args.s_cav # cavity length r = args.r # hole radius (units of a) h = args.hh # waveguide height w = args.w # waveguide width dair = 1.00 # air padding dpml = 1.00 # PML thickness Ndef = args.Ndef # number of defect periods a_taper = mp.interpolate(Ndef, [ a_start, a_end ]) dgap = a_end - 2*r*a_end Nwvg = args.Nwvg # number of waveguide periods sx = 2*(Nwvg*a_start+sum(a_taper))-dgap+s_cav sy = dpml+dair+w+dair+dpml sz = dpml+dair+h+dair+dpml cell_size = mp.Vector3(sx,sy,sz) boundary_layers = [ mp.PML(dpml) ] nSi = 3.45 Si = mp.Medium(index=nSi) geometry = [ mp.Block(material=Si, center=mp.Vector3(), size=mp.Vector3(mp.inf,w,h)) ] for mm in range(Nwvg): geometry.append(mp.Cylinder(material=mp.air, radius=r*a_start, height=mp.inf, center=mp.Vector3(-0.5*sx+0.5*a_start+mm*a_start,0,0))) geometry.append(mp.Cylinder(material=mp.air, radius=r*a_start, height=mp.inf, center=mp.Vector3(+0.5*sx-0.5*a_start-mm*a_start,0,0))) for mm in range(Ndef+2): geometry.append(mp.Cylinder(material=mp.air, radius=r*a_taper[mm], height=mp.inf, center=mp.Vector3(-0.5*sx+Nwvg*a_start+(sum(a_taper[:mm]) if mm>0 else 0)+0.5*a_taper[mm],0,0))) geometry.append(mp.Cylinder(material=mp.air, radius=r*a_taper[mm], height=mp.inf, center=mp.Vector3(+0.5*sx-Nwvg*a_start-(sum(a_taper[:mm]) if mm>0 else 0)-0.5*a_taper[mm],0,0))) lambda_min = 1.46 # minimum source wavelength lambda_max = 1.66 # maximum source wavelength fmin = 1/lambda_max fmax = 1/lambda_min fcen = 0.5*(fmin+fmax) df = fmax-fmin sources = [ mp.Source(mp.GaussianSource(fcen, fwidth=df), component=mp.Ey, center=mp.Vector3()) ] symmetries = [ mp.Mirror(mp.X,+1), mp.Mirror(mp.Y,-1), mp.Mirror(mp.Z,+1) ] sim = mp.Simulation(resolution=resolution, cell_size=cell_size, boundary_layers=boundary_layers, geometry=geometry, sources=sources, dimensions=3, symmetries=symmetries) sim.run(mp.in_volume(mp.Volume(center=mp.Vector3(), size=mp.Vector3(sx,sy,0)), mp.at_end(mp.output_epsilon, mp.output_efield_y)), mp.after_sources(mp.Harminv(mp.Ey, mp.Vector3(), fcen, df)), until_after_sources=500) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-a_start', type=float, default=0.43, help='starting periodicity (default: 0.43 um)') parser.add_argument('-a_end', type=float, default=0.33, help='ending periodicity (default: 0.33 um)') parser.add_argument('-s_cav', type=float, default=0.146, help='cavity length (default: 0.146 um)') parser.add_argument('-r', type=float, default=0.28, help='hole radius (default: 0.28 um)') parser.add_argument('-hh', type=float, default=0.22, help='waveguide height (default: 0.22 um)') parser.add_argument('-w', type=float, default=0.50, help='waveguide width (default: 0.50 um)') parser.add_argument('-Ndef', type=int, default=3, help='number of defect periods (default: 3)') parser.add_argument('-Nwvg', type=int, default=8, help='number of waveguide periods (default: 8)') args = parser.parse_args() main(args)   A bash script is used to sweep the cavity length (s-cav) over the range of 0.110-0.180 μm in increments of 0.005 μm. The output is written to a file with the harminv-related information extracted to a different file for plotting. The figures below show a plot of the resonant wavelength and quality factor as a function of the cavity length. The quality factor is maximum for the design with a cavity length of 0.145 μm. These are consistent with the values reported in the reference.   #!/bin/bash for scav in seq 0.110 0.005 0.180; do mpirun -np 2 python nanobeam.py -s_cav${scav} > nanobeam_cavity_length${scav}.out; grep harminv0: nanobeam_cavity_length${scav}.out |cut -d , -f2,4 |grep -v frequency >> nanobeam_cavity_varylength.dat;
done;


The Ey field profile for the optimal design of the fundamental cavity mode is also shown below for two cross sections. The resonant mode is confined by the bandgap in the direction of the holes (X) and index guiding in the Y and Z directions. These images were created using matplotlib as follows:
  
import h5py
import numpy as np
import matplotlib.pyplot as plt

eps_h5file = h5py.File('nanobeam-eps-000040000.h5','r')
eps_data = np.array(eps_h5file['eps'])
ey_h5file = h5py.File('nanobeam-ey-000040000.h5','r')
ey_data = np.array(ey_h5file['ey'])
plt.figure(dpi=100)
plt.imshow(eps_data.transpose(), interpolation='spline36', cmap='binary')
plt.imshow(ey_data.transpose(), interpolation='spline36', cmap='RdBu', alpha=0.9)
plt.axis('off')
plt.show()


Files: Simulation Script (Python), Simulation Script (Scheme), Shell Launch Script, Sample Output. [gzipped tarball]

## Meep Project #4 — Near-Infrared Absorption Spectra of CMOS Image Sensors

Complimentary metal oxide semiconductor (CMOS) image sensors are widely used in camera systems of mobile devices due to their lower power consumption and better electrical-readout capabilities than charge-coupled device (CCD) sensors. CMOS image sensors for visible light have recently been extended to the near infrared (IR) for applications including biomedicine, security, and chemical spectroscopy. The design challenge involves enhancing the light trapping of individual pixels at near-IR wavelengths where the absorption coefficient of silicon is small.

We will investigate the back-illuminated CMOS image-sensor pixel design based on the work of Sony researchers presented in Scientific Reports, Vol. 7, No. 3832, 2017. A glass microlens (silicon dioxide) with a radius of curvature of 0.85 μm is placed on the top of the image sensor. This is necessary for focusing incident light from air into the individual pixels. A metal aperture grid made of a tungsten wire with rectangular cross section (width: 0.1 μm, height: 0.2 μm) surrounds the pixel and is placed on top of the semi-infinite crystalline-silicon substrate (thickness: 3 μm, indirect bandgap: 1.108 μm). A color filter for red, green, and blue light, which in standard designs is placed above the metal grid, is neglected in this structure. A square lattice of inverted cones on the front surface of the substrate is used to scatter the incident light in order to increase the optical path length. Deep-trench isolation is used to mitigate electrical cross talk between adjacent pixels as well as to trap photons via index guiding. This involves surrounding the pixel with a silicon-dioxide trench (width: 0.1 μm, thickness: 2 μm). A schematic of the unit-cell cross section of a single pixel is shown in the left figure below. The right figure shows the square lattice of inverted cones in the unit cell. For a broadband spectrum spanning near-IR wavelengths of 0.7 to 1.0 μm, we will use Meep to compute three device properties: (1) reflection from the top surface, (2) absorption of the tungsten wires, and (3) absorption of the silicon substrate. We will investigate the enhancement of the substrate absorption due to different lattice structures relative to a flat substrate. The design objective is to find the lattice design which maximizes the substrate absorption averaged over the entire spectrum.

The Meep simulation script has three main components: (1) defining the tungsten and silicon material parameters over the broadband wavelength spectrum, (2) setting up the supercell geometry involving a square lattice of inverted cones, and (3) computing the absorption of the metal grid and the substrate via the the total flux within these regions. The silicon material parameters are obtained by fitting the experimental values for crystalline silicon over the near-IR wavelength spectrum to a single Lorentzian-susceptibility term and adding a small imaginary component. This is explained in the supplementary-information section of Applied Physics Letters, Vol. 104, No. 091121, 2014 (pdf). A normally-incident planewave in air above the device is used as the source. The supercell lattice contains 3×3 unit cells with periodic boundary conditions. Four flux planes are used: one for reflection and three for transmission. The absorption is calculated as the difference in the flux entering and exiting each region (normalized by the total flux from just the source). This way, we can calculate the absorption over the entire broadband spectrum for any number of rectilinear regions using a single simulation.

  
import meep as mp
import math
import argparse

def main(args):

resolution = 30

nSiO2 = 1.4
SiO2 = mp.Medium(index=nSiO2)

# conversion factor for eV to 1/um
eV_um_scale = 1/1.23984193

# W, from A.D. Rakic et al., Applied Optics, Vol. 37, No. 22,  pp. 5271-83 (1998)
W_plasma_frq = 13.22*eV_um_scale
W_f0 = 0.206
W_frq0 = 1e-10
W_gam0 = 0.064*eV_um_scale
W_sig0 = W_f0*W_plasma_frq**2/W_frq0**2
W_f1 = 0.054
W_frq1 = 1.004*eV_um_scale # 1.235 um
W_gam1 = 0.530*eV_um_scale
W_sig1 = W_f1*W_plasma_frq**2/W_frq1**2
W_f2 = 0.166
W_frq2 = 1.917*eV_um_scale # 0.647
W_gam2 = 1.281*eV_um_scale
W_sig2 = W_f2*W_plasma_frq**2/W_frq2**2

W_susc = [ mp.DrudeSusceptibility(frequency=W_frq0, gamma=W_gam0, sigma=W_sig0),
mp.LorentzianSusceptibility(frequency=W_frq1, gamma=W_gam1, sigma=W_sig1),
mp.LorentzianSusceptibility(frequency=W_frq2, gamma=W_gam2, sigma=W_sig2) ]

W = mp.Medium(epsilon=1.0, E_susceptibilities=W_susc)

# crystalline Si, from M.A. Green, Solar Energy Materials and Solar Cells, vol. 92, pp. 1305-1310 (2008)
# fitted Lorentzian parameters, only for 600nm-1100nm
Si_eps_inf = 9.14
Si_eps_imag = -0.0334
Si_eps_imag_frq = 1/1.55
Si_frq = 2.2384
Si_gam = 4.3645e-02
Si_sig = 14.797/Si_frq**2

Si = mp.Medium(epsilon=Si_eps_inf,
D_conductivity=2*math.pi*Si_eps_imag_frq*Si_eps_imag/Si_eps_inf,
E_susceptibilities=[ mp.LorentzianSusceptibility(frequency=Si_frq, gamma=Si_gam, sigma=Si_sig) ])

a = args.a                         # lattice periodicity
cone_r = args.cone_r               # cone radius
cone_h = args.cone_h               # cone height
wire_w = args.wire_w               # metal-grid wire width
wire_h = args.wire_h               # metal-grid wire height
trench_w = args.trench_w           # trench width
trench_h = args.trench_h           # trench height
Np = args.Np                       # number of periods in supercell

dair = 1.0                         # air gap thickness
dmcl = 1.7                         # micro lens thickness
dsub = 3.0                         # substrate thickness
dpml = 1.0                         # PML thickness

sxy = Np*a
sz = dpml+dair+dmcl+dsub+dpml
cell_size = mp.Vector3(sxy, sxy, sz)

boundary_layers = [ mp.PML(dpml, direction=mp.Z, side=mp.High),
mp.Absorber(dpml, direction=mp.Z, side=mp.Low) ]

geometry = []

if args.substrate:
geometry = [ mp.Sphere(material=SiO2, radius=dmcl, center=mp.Vector3(0,0,0.5*sz-dpml-dair-dmcl)),
mp.Block(material=Si, size=mp.Vector3(mp.inf,mp.inf,dsub+dpml),
center=mp.Vector3(0,0,-0.5*sz+0.5*(dsub+dpml))),
mp.Block(material=W, size=mp.Vector3(mp.inf, wire_w, wire_h),
center=mp.Vector3(0,-0.5*sxy+0.5*wire_w,-0.5*sz+dpml+dsub+0.5*wire_h)),
mp.Block(material=W, size=mp.Vector3(mp.inf, wire_w, wire_h),
center=mp.Vector3(0,+0.5*sxy-0.5*wire_w,-0.5*sz+dpml+dsub+0.5*wire_h)),
mp.Block(material=W, size=mp.Vector3(wire_w, mp.inf, wire_h),
center=mp.Vector3(-0.5*sxy+0.5*wire_w,0,-0.5*sz+dpml+dsub+0.5*wire_h)),
mp.Block(material=W, size=mp.Vector3(wire_w, mp.inf, wire_h),
center=mp.Vector3(+0.5*sxy-0.5*wire_w,0,-0.5*sz+dpml+dsub+0.5*wire_h)) ]

if args.substrate and args.texture:
for nx in range(Np):
for ny in range(Np):
cx = -0.5*sxy+(nx+0.5)*a
cy = -0.5*sxy+(ny+0.5)*a
geometry.append(mp.Cone(material=SiO2, radius=0, radius2=cone_r, height=cone_h,
center=mp.Vector3(cx,cy,0.5*sz-dpml-dair-dmcl-0.5*cone_h)))

if args.substrate:
geometry.append(mp.Block(material=SiO2, size=mp.Vector3(mp.inf,trench_w,trench_h),
center=mp.Vector3(0,-0.5*sxy+0.5*trench_w,0.5*sz-dpml-dair-dmcl-0.5*trench_h)))
geometry.append(mp.Block(material=SiO2, size=mp.Vector3(mp.inf,trench_w,trench_h),
center=mp.Vector3(0,+0.5*sxy-0.5*trench_w,0.5*sz-dpml-dair-dmcl-0.5*trench_h)))
geometry.append(mp.Block(material=SiO2, size=mp.Vector3(trench_w,mp.inf,trench_h),
center=mp.Vector3(-0.5*sxy+0.5*trench_w,0,0.5*sz-dpml-dair-dmcl-0.5*trench_h)))
geometry.append(mp.Block(material=SiO2, size=mp.Vector3(trench_w,mp.inf,trench_h),
center=mp.Vector3(+0.5*sxy-0.5*trench_w,0,0.5*sz-dpml-dair-dmcl-0.5*trench_h)))

k_point = mp.Vector3(0,0,0)

lambda_min = 0.7        # minimum source wavelength
lambda_max = 1.0        # maximum source wavelength
fmin = 1/lambda_max
fmax = 1/lambda_min
fcen = 0.5*(fmin+fmax)
df = fmax-fmin

sources = [ mp.Source(mp.GaussianSource(fcen, fwidth=df), component=mp.Ex,
center=mp.Vector3(0, 0, 0.5*sz-dpml-0.5*dair), size=mp.Vector3(sxy, sxy, 0)) ]

sim = mp.Simulation(resolution=resolution,
cell_size=cell_size,
boundary_layers=boundary_layers,
geometry=geometry,
dimensions=3,
sources=sources)

nfreq = 50
refl = sim.add_flux(fcen, df, nfreq, mp.FluxRegion(center=mp.Vector3(0,0,0.5*sz-dpml),size=mp.Vector3(sxy,sxy,0)))
trans_grid = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,0,-0.5*sz+dpml+dsub+wire_h),size=mp.Vector3(sxy,sxy,0)))
trans_sub_top = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,0,-0.5*sz+dpml+dsub),size=mp.Vector3(sxy,sxy,0)))
trans_sub_bot = sim.add_flux(fcen, df, nfreq,
mp.FluxRegion(center=mp.Vector3(0,0,-0.5*sz+dpml),size=mp.Vector3(sxy,sxy,0)))

sim.run(mp.at_beginning(mp.output_epsilon),until=0)

if args.substrate:
sim.load_minus_flux('refl-flux', refl)

sim.run(until_after_sources=mp.stop_when_fields_decayed(50, mp.Ex, mp.Vector3(0,0,-0.5*sz+dpml+0.5*dsub), 1e-9))

if not args.substrate:
sim.save_flux('refl-flux', refl)

sim.display_fluxes(refl, trans_grid, trans_sub_top, trans_sub_bot)

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-substrate', action='store_true', default=False, help="add the substrate? (default: False)")
parser.add_argument('-texture', action='store_true', default=False, help="add the texture? (default: False)")
parser.add_argument('-a', type=float, default=0.4, help='lattice periodicity (default: 0.4 um)')
parser.add_argument('-cone_r', type=float, default=0.2, help='cone radius (default: 0.2 um)')
parser.add_argument('-cone_h', type=float, default=0.28247, help='cone height (default: 0.28247 um)')
parser.add_argument('-wire_w', type=float, default=0.1, help='metal-grid wire width (default: 0.1 um)')
parser.add_argument('-wire_h', type=float, default=0.2, help='metal-grid wire height (default: 0.2 um)')
parser.add_argument('-trench_w', type=float, default=0.1, help='trench width (default: 0.1 um)')
parser.add_argument('-trench_h', type=float, default=2.0, help='trench height (default: 2.0 um)')
parser.add_argument('-Np', type=int, default=3, help='number of periods in supercell (default: 3)')
args = parser.parse_args()
main(args)


We will create a Bash shell script to run three simulations for each lattice design: (1) the empty cell with just the source, (2) the flat substrate, and (3) the textured substrate. The lattice periodicity (a) is varied over the range of 0.40 to 0.70 μm. The simulation output is piped to a file for post processing in Python or Octave/Matlab.
  
#!/bin/bash

for a in seq 0.40 0.02 0.70; do
mpirun -np 4 python cmos_sensor.py -a ${a} > cmos_a${a}_empty.out;
grep flux1: cmos_a${a}_empty.out |cut -d , -f2- > cmos_a${a}_empty.dat;

mpirun -np 4 python cmos_sensor.py -a ${a} -substrate > cmos_a${a}_flat.out;
grep flux1: cmos_a${a}_flat.out |cut -d , -f2- > cmos_a${a}_flat.dat;

mpirun -np 4 python cmos_sensor.py -a ${a} -substrate -texture > cmos_a${a}_texture.out;
grep flux1: cmos_a${a}_texture.out |cut -d , -f2- > cmos_a${a}_texture.dat;
done;


The left figure below is a contour plot of the substrate absorption as a function of wavelength and lattice periodicity. This is the fraction of the incident light which is absorbed by just the crystalline-silicon substrate. For all lattice designs, the absorption is largest at the smallest wavelengths which is expected. The right figure shows the enhancement of the substrate absorption due to the lattice relative to a flat substrate (i.e., no lattice). The lattice produces wavelength-dependent scattering effects which can be seen as the dark spots in the contour plot.

The optimal lattice design which has the largest average absorption over the broadband spectrum is a=0.64 μm with 24.5%±12.2%. A plot of the substrate and grid absorption as well as the reflection from the device for this lattice design are shown in the left figure below. For comparison, the average substrate absorption for the no-lattice reference design is 15.4%±8.5%. The optimal lattice yields an average enhancement per wavelength of 1.6±0.6.

Files: Simulation Script (Python), Simulation Script (Scheme), Shell Launch Script, Sample Output, Post Processing: Python, Jupyter/IPython [html], Matlab/Octave. [gzipped tarball]