Skip to content

Instantly share code, notes, and snippets.

@oskooi
Last active July 19, 2021 04:44
Show Gist options
  • Save oskooi/2279c48206a3594d35c6351f20e08726 to your computer and use it in GitHub Desktop.
Save oskooi/2279c48206a3594d35c6351f20e08726 to your computer and use it in GitHub Desktop.
DFT field monitors with yee_grid=True
import meep as mp
from meep.materials import Al as ALU
import numpy as np
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
resolution = 55
nfreq = 25
tABS = 0.5
tPML = 0.5
tGLS = 0.5
tITO = 0.5
tORG = 0.5
tALU = 0.2
L = 1.0 # length of OLED
# length of computational cell along Z
sz = tPML+tGLS+tITO+tORG+tALU
# length of non-absorbing region of computational cell in X and Y
sxy = L+2*tABS
cell_size = mp.Vector3(sxy,sxy,sz)
boundary_layers = [mp.Absorber(tABS,direction=mp.X),
mp.Absorber(tABS,direction=mp.Y),
mp.PML(tPML,direction=mp.Z,side=mp.High)]
ORG = mp.Medium(index=1.75)
geometry = [mp.Block(material=mp.Medium(index=1.5),
size=mp.Vector3(mp.inf,mp.inf,tPML+tGLS),
center=mp.Vector3(z=0.5*sz-0.5*(tPML+tGLS))),
mp.Block(material=mp.Medium(index=1.2),
size=mp.Vector3(mp.inf,mp.inf,tITO),
center=mp.Vector3(z=0.5*sz-tPML-tGLS-0.5*tITO)),
mp.Block(material=ORG,
size=mp.Vector3(mp.inf,mp.inf,tORG),
center=mp.Vector3(z=0.5*sz-tPML-tGLS-tITO-0.5*tORG)),
mp.Block(material=ALU,
size=mp.Vector3(mp.inf,mp.inf,tALU),
center=mp.Vector3(z=0.5*sz-tPML-tGLS-tITO-tORG-0.5*tALU))]
sources = [mp.Source(mp.ContinuousSource(fcen),
component=mp.Ez,
center=mp.Vector3(z=0.5*sz-tPML-tGLS-tITO-0.5*tORG))]
sim = mp.Simulation(resolution=resolution,
cell_size=cell_size,
boundary_layers=boundary_layers,
geometry=geometry,
sources=sources,
eps_averaging=False)
cmpts = [mp.Ex, mp.Ey, mp.Ez]
srcbox_width = 0.05
srcbox_top = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(center=mp.Vector3(z=0.5*sz-tPML-tGLS), size=mp.Vector3(srcbox_width,srcbox_width,0)),
yee_grid=True)
srcbox_bot = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(center=mp.Vector3(z=0.5*sz-tPML-tGLS-tITO-0.8*tORG), size=mp.Vector3(srcbox_width,srcbox_width,0)),
yee_grid=True)
srcbox_xp = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(center=mp.Vector3(0.5*srcbox_width,0,0.5*sz-tPML-tGLS-0.5*(tITO+0.8*tORG)), size=mp.Vector3(0,srcbox_width,tITO+0.8*tORG)),
yee_grid=True)
srcbox_xm = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(center=mp.Vector3(-0.5*srcbox_width,0,0.5*sz-tPML-tGLS-0.5*(tITO+0.8*tORG)), size=mp.Vector3(0,srcbox_width,tITO+0.8*tORG)),
yee_grid=True)
srcbox_yp = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(center=mp.Vector3(0,0.5*srcbox_width,0.5*sz-tPML-tGLS-0.5*(tITO+0.8*tORG)), size=mp.Vector3(srcbox_width,0,tITO+0.8*tORG)),
yee_grid=True)
srcbox_ym = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(center=mp.Vector3(0,-0.5*srcbox_width,0.5*sz-tPML-tGLS-0.5*(tITO+0.8*tORG)), size=mp.Vector3(srcbox_width,0,tITO+0.8*tORG)),
yee_grid=True)
# padding for flux box to fully capture waveguide mode
fluxbox_dpad = 0.05
glass_flux = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(center=mp.Vector3(z=0.5*sz-tPML-(tGLS-fluxbox_dpad)), size = mp.Vector3(L,L,0)),
yee_grid=True)
wvgbox_xp = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(size=mp.Vector3(0,L,fluxbox_dpad+tITO+tORG+fluxbox_dpad), center=mp.Vector3(0.5*L,0,0.5*sz-tPML-tGLS-0.5*(tITO+tORG))),
yee_grid=True)
wvgbox_xm = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(size=mp.Vector3(0,L,fluxbox_dpad+tITO+tORG+fluxbox_dpad), center=mp.Vector3(-0.5*L,0,0.5*sz-tPML-tGLS-0.5*(tITO+tORG))),
yee_grid=True)
wvgbox_yp = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(size=mp.Vector3(L,0,fluxbox_dpad+tITO+tORG+fluxbox_dpad), center=mp.Vector3(0,0.5*L,0.5*sz-tPML-tGLS-0.5*(tITO+tORG))),
direction=True)
wvgbox_ym = sim.add_dft_fields(cmpts, fcen, df, nfreq,
where=mp.Volume(size=mp.Vector3(L,0,fluxbox_dpad+tITO+tORG+fluxbox_dpad), center=mp.Vector3(0,-0.5*L,0.5*sz-tPML-tGLS-0.5*(tITO+tORG))),
yee_grid=True)
mp.verbosity(2)
sim.run(until=2.0)
sim.fields.reset_timers()
for _ in range(5):
sim.fields.step()
print("DFT-updates:, {}".format(sim.time_spent_on(6)[0]))
@oskooi
Copy link
Author

oskooi commented Jul 19, 2021

Results comparing the unmodified vs. modified DFT field updates for clang (v11.0.1-2) for the above test run 10 different times using single-thread Intel Xeon 2.0 GHz. The results show no performance improvement.

unmodified mean time: 0.028382 ± 0.003934 s

 0.031188448000001756
 0.03005413300000015
 0.03213875999999516
 0.030388086000009196
 0.0319568419999996
 0.02358402000000126
 0.02353230199998535
 0.0333538020000006
 0.02355334700001066
 0.024070516000001874

modified mean time: 0.027437 ± 0.003901 s

 0.024269177999990177
 0.03324260299999793
 0.023582268999994938
 0.031363367000004416
 0.024627072999990673
 0.030343446999992807
 0.023820857000004025
 0.025138560999991455
 0.03338547200000619
 0.024598607000001493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment