Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oskooi
Last active November 25, 2021 03:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskooi/f745c467ae54e192d5c8340eace9a780 to your computer and use it in GitHub Desktop.
Save oskooi/f745c467ae54e192d5c8340eace9a780 to your computer and use it in GitHub Desktop.
Meep Benchmarking Simulation of Organic Light Emitting Diode (OLED)
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)
# 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(z=0.5*sz-tPML-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(z=0.5*sz-tPML-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-tPML-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-tPML-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-tPML-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-tPML-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
glass_flux = sim.add_flux(fcen, df, nfreq, mp.FluxRegion(center=mp.Vector3(z=0.5*sz-tPML-(tGLS-fluxbox_dpad)), size = mp.Vector3(L,L,0), direction=mp.Z, weight=+1))
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-tPML-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-tPML-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-tPML-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-tPML-tGLS-0.5*(tITO+tORG)), weight=-1))
mp.verbosity(2)
sim.run(until=2.0)
sim.fields.reset_timers()
for _ in range(5):
sim.fields.step()
sim.output_times('oled_timings.csv')
print("field:, {}".format(np.real(sim.get_field_point(mp.Ez, mp.Vector3(0.1235,-0.3165,0.7298)))))
flux_srcbox_top = np.asarray(mp.get_fluxes(srcbox_top))
flux_srcbox_bot = np.asarray(mp.get_fluxes(srcbox_bot))
flux_srcbox_xp = np.asarray(mp.get_fluxes(srcbox_xp))
flux_srcbox_xm = np.asarray(mp.get_fluxes(srcbox_xm))
flux_srcbox_yp = np.asarray(mp.get_fluxes(srcbox_yp))
flux_srcbox_ym = np.asarray(mp.get_fluxes(srcbox_ym))
flux_wvgbox_xp = np.asarray(mp.get_fluxes(wvgbox_xp))
flux_wvgbox_xm = np.asarray(mp.get_fluxes(wvgbox_xm))
flux_wvgbox_yp = np.asarray(mp.get_fluxes(wvgbox_yp))
flux_wvgbox_ym = np.asarray(mp.get_fluxes(wvgbox_ym))
flux_glass = np.asarray(mp.get_fluxes(glass_flux))
flux_total = flux_srcbox_top+flux_srcbox_bot+flux_srcbox_xp+flux_srcbox_xm+flux_srcbox_yp+flux_srcbox_ym
flux_waveguide = flux_wvgbox_xp+flux_wvgbox_xm+flux_wvgbox_yp+flux_wvgbox_ym
print("flux_glass:, {}".format(flux_glass))
print("flux_waveguide:, {}".format(flux_waveguide))
print("flux_total:, {}".format(flux_total))
print("sum(flux_glass):, {}".format(np.sum(flux_glass)))
print("sum(flux_waveguide):, {}".format(np.sum(flux_waveguide)))
print("sum(flux_total):, {}".format(np.sum(flux_total)))
@oskooi
Copy link
Author

oskooi commented Jul 15, 2021

  1. output for single precision:
Meep progress: 0.5636363636363636/2.0 = 28.2% done in 4.1s, 10.3s to go
on time step 62 (time=0.563636), 0.065456 s/step
Meep progress: 1.0999999999999999/2.0 = 55.0% done in 8.1s, 6.6s to go
on time step 121 (time=1.1), 0.0687096 s/step
Meep progress: 1.509090909090909/2.0 = 75.5% done in 12.1s, 3.9s to go
on time step 166 (time=1.50909), 0.0894278 s/step
Meep progress: 1.9636363636363636/2.0 = 98.2% done in 16.2s, 0.3s to go
on time step 216 (time=1.96364), 0.0808322 s/step
run 0 finished at t = 2.0 (220 timesteps)
outputting timing statistics to file "oled_timings.csv"...
field:, -0.0004297305867521808
flux_glass:, [0.00061794 0.00074978 0.00089503 0.00105169 0.00121712 0.00138814
 0.00156106 0.00173184 0.00189619 0.00204977 0.00218828 0.00230771
 0.00240445 0.00247545 0.00251837 0.00253167 0.00251468 0.00246767
 0.0023918  0.00228913 0.00216252 0.00201552 0.00185224 0.00167719
 0.00149511]
flux_waveguide:, [0.06104264 0.07971065 0.10236324 0.12893493 0.15910964 0.19230373
 0.22766815 0.26411161 0.30034509 0.33494572 0.36643675 0.39337797
 0.41446002 0.42859536 0.43499809 0.43324595 0.42331851 0.40560801
 0.38090098 0.35033154 0.31530968 0.27743003 0.2383681  0.19977253
 0.16316161]
flux_total:, [ 1.64351400e-01  1.15919355e-01  4.47967703e-02 -9.80502751e-03
  1.02664718e-03  1.21286733e-01  3.74726858e-01  7.53763754e-01
  1.21653048e+00  1.69364283e+00  2.10327725e+00  2.37054996e+00
  2.44580243e+00  2.31662705e+00  2.01031945e+00  1.58628439e+00
  1.12078644e+00  6.88530293e-01  3.46237066e-01  1.22417859e-01
  1.54794759e-02 -2.83034656e-04  3.65414716e-02  8.70968019e-02
  1.22504183e-01]
sum(flux_glass):, 0.04645034780810235
sum(flux_waveguide):, 7.075850530119095
sum(flux_total):, 19.848410877445428

Elapsed run time = 21.4690 s

time spent on DFT field updates: 0.0122615 s.

  1. output for double precision
Meep progress: 0.00909090909090909/2.0 = 0.5% done in 4.2s, 918.8s to go
on time step 1 (time=0.00909091), 4.19565 s/step
Meep progress: 0.16363636363636364/2.0 = 8.2% done in 8.3s, 92.7s to go
on time step 18 (time=0.163636), 0.238992 s/step
Meep progress: 0.3181818181818182/2.0 = 15.9% done in 12.3s, 65.1s to go
on time step 35 (time=0.318182), 0.238976 s/step
Meep progress: 0.4727272727272727/2.0 = 23.6% done in 16.4s, 52.9s to go
on time step 52 (time=0.472727), 0.238944 s/step
Meep progress: 0.6272727272727272/2.0 = 31.4% done in 20.4s, 44.7s to go
on time step 69 (time=0.627273), 0.238902 s/step
Meep progress: 0.7818181818181817/2.0 = 39.1% done in 24.5s, 38.2s to go
on time step 86 (time=0.781818), 0.238988 s/step
Meep progress: 0.9363636363636363/2.0 = 46.8% done in 28.6s, 32.5s to go
on time step 103 (time=0.936364), 0.239043 s/step
Meep progress: 1.0909090909090908/2.0 = 54.5% done in 32.6s, 27.2s to go
on time step 120 (time=1.09091), 0.238979 s/step
Meep progress: 1.2454545454545454/2.0 = 62.3% done in 36.7s, 22.2s to go
on time step 137 (time=1.24545), 0.239009 s/step
Meep progress: 1.4/2.0 = 70.0% done in 40.8s, 17.5s to go
on time step 154 (time=1.4), 0.239419 s/step
Meep progress: 1.5545454545454545/2.0 = 77.7% done in 44.8s, 12.8s to go
on time step 171 (time=1.55455), 0.238686 s/step
Meep progress: 1.709090909090909/2.0 = 85.5% done in 48.9s, 8.3s to go
on time step 188 (time=1.70909), 0.239289 s/step
Meep progress: 1.8636363636363635/2.0 = 93.2% done in 53.0s, 3.9s to go
on time step 205 (time=1.86364), 0.238977 s/step
run 0 finished at t = 2.0 (220 timesteps)
on time step 222 (time=2.01818), 0.238997 s/step
outputting timing statistics to file "oled_timings.csv"...
field:, -0.0004297287042276192
flux_glass:, [0.00061794 0.00074978 0.00089503 0.00105169 0.00121712 0.00138814
 0.00156106 0.00173184 0.00189619 0.00204977 0.00218828 0.00230771
 0.00240445 0.00247545 0.00251837 0.00253167 0.00251468 0.00246767
 0.0023918  0.00228913 0.00216252 0.00201552 0.00185224 0.00167719
 0.00149511]
flux_waveguide:, [0.06104266 0.07971066 0.10236325 0.12893494 0.15910965 0.19230375
 0.22766817 0.26411163 0.3003451  0.33494573 0.36643677 0.39337799
 0.41446004 0.42859538 0.43499812 0.43324598 0.42331853 0.40560803
 0.380901   0.35033155 0.31530969 0.27743004 0.23836811 0.19977254
 0.16316161]
flux_total:, [ 1.64351336e-01  1.15919382e-01  4.47967381e-02 -9.80505957e-03
  1.02668322e-03  1.21286425e-01  3.74726696e-01  7.53763535e-01
  1.21653043e+00  1.69364312e+00  2.10327682e+00  2.37054976e+00
  2.44580313e+00  2.31662698e+00  2.01031930e+00  1.58628532e+00
  1.12078662e+00  6.88530166e-01  3.46237056e-01  1.22418044e-01
  1.54796577e-02 -2.83059463e-04  3.65414613e-02  8.70967538e-02
  1.22504173e-01]
sum(flux_glass):, 0.046450346802942084
sum(flux_waveguide):, 7.07585093320708
sum(flux_total):, 19.84841146085479

Elapsed run time = 66.2785 s

time spent on DFT field updates: 0.151868 s.

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