1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
|
import unittest
import numpy as np
import meep as mp
class TestLDOS(unittest.TestCase):
@classmethod
def setUp(cls):
cls.resolution = 25 # pixels/μm
cls.dpml = 0.5 # thickness of PML
cls.dair = 1.0 # thickness of air padding
cls.L = 6.0 # length of non-PML region
cls.n = 2.4 # refractive index of surrounding medium
cls.wvl = 1.0 # wavelength (in vacuum)
cls.fcen = 1 / cls.wvl
# source properties (cylindrical)
cls.df = 0.05 * cls.fcen
cls.cutoff = 10.0
cls.src = mp.GaussianSource(cls.fcen, fwidth=cls.df, cutoff=cls.cutoff)
# termination criteria
cls.tol = 1e-8
def bulk_ldos_cyl(self):
"""Computes the LDOS of a point dipole in a homogeneous dielectric
medium in cylindrical coordinates.
"""
sr = self.L + self.dpml
sz = self.L + 2 * self.dpml
cell_size = mp.Vector3(sr, 0, sz)
pml_layers = [mp.PML(self.dpml)]
sources = [
mp.Source(
src=self.src,
component=mp.Er,
center=mp.Vector3(),
)
]
sim = mp.Simulation(
resolution=self.resolution,
cell_size=cell_size,
boundary_layers=pml_layers,
sources=sources,
dimensions=mp.CYLINDRICAL,
m=-1,
default_material=mp.Medium(index=self.n),
)
sim.run(
mp.dft_ldos(self.fcen, 0, 1),
until_after_sources=mp.stop_when_fields_decayed(
20, mp.Er, mp.Vector3(), self.tol
),
)
return sim.ldos_data[0]
def cavity_ldos_cyl(self, sz):
"""Computes the LDOS of a point dipole in a planar cavity with
lossless metallic walls in cylindrical coordinates.
Args:
sz: thickness of cavity.
"""
sr = self.L + self.dpml
cell_size = mp.Vector3(sr, 0, sz)
pml_layers = [mp.PML(self.dpml, direction=mp.R)]
sources = [
mp.Source(
src=self.src,
component=mp.Er,
center=mp.Vector3(),
)
]
sim = mp.Simulation(
resolution=self.resolution,
cell_size=cell_size,
boundary_layers=pml_layers,
sources=sources,
dimensions=mp.CYLINDRICAL,
m=-1,
default_material=mp.Medium(index=self.n),
)
sim.run(
mp.dft_ldos(self.fcen, 0, 1),
until_after_sources=mp.stop_when_fields_decayed(
20, mp.Er, mp.Vector3(), self.tol
),
)
return sim.ldos_data[0]
def bulk_ldos_3D(self):
"""Computes the LDOS of a point dipole in a homogeneous dielectric
medium in 3D Cartesian coordinates.
"""
s = self.L + 2 * self.dpml
cell_size = mp.Vector3(s, s, s)
pml_layers = [mp.PML(self.dpml)]
sources = [
mp.Source(
src=mp.GaussianSource(self.fcen, fwidth=0.2 * self.fcen),
component=mp.Ex,
center=mp.Vector3(),
)
]
symmetries = [
mp.Mirror(direction=mp.X, phase=-1),
mp.Mirror(direction=mp.Y),
mp.Mirror(direction=mp.Z),
]
sim = mp.Simulation(
resolution=self.resolution,
cell_size=cell_size,
boundary_layers=pml_layers,
sources=sources,
symmetries=symmetries,
default_material=mp.Medium(index=self.n),
)
sim.run(
mp.dft_ldos(self.fcen, 0, 1),
until_after_sources=mp.stop_when_fields_decayed(
20, mp.Ex, mp.Vector3(), self.tol
),
)
return sim.ldos_data[0]
def cavity_ldos_3D(self, sz):
"""Computes the LDOS of a point dipole in a planar cavity with
lossless metallic walls in 3D Cartesian coordinates.
Args:
sz: thickness of cavity.
"""
sxy = self.L + 2 * self.dpml
cell_size = mp.Vector3(sxy, sxy, sz)
boundary_layers = [
mp.PML(self.dpml, direction=mp.X),
mp.PML(self.dpml, direction=mp.Y),
]
sources = [
mp.Source(
src=mp.GaussianSource(self.fcen, fwidth=0.2 * self.fcen),
component=mp.Ex,
center=mp.Vector3(),
)
]
symmetries = [
mp.Mirror(direction=mp.X, phase=-1),
mp.Mirror(direction=mp.Y),
mp.Mirror(direction=mp.Z),
]
sim = mp.Simulation(
resolution=self.resolution,
cell_size=cell_size,
boundary_layers=boundary_layers,
sources=sources,
symmetries=symmetries,
default_material=mp.Medium(index=self.n),
)
sim.run(
mp.dft_ldos(ldos=mp.Ldos(self.fcen, 0, 1)),
until_after_sources=mp.stop_when_fields_decayed(
20, mp.Ex, mp.Vector3(), self.tol
),
)
return sim.ldos_data[0]
def purcell_enh_theory(self, c):
"""Computes the Purcell enhancement factor of a point dipole in a planar
dielectric cavity with lossless metallic walls using equation 7 of:
I. Abram et al., IEEE J. Quantum Electronics, Vol. 34, pp. 71-76 (1998).
Args:
c: cavity thickness in units of wavelength in the cavity medium.
"""
return 3 * np.fix(c + 0.5) / (4 * c) + (
4 * np.power(np.fix(c + 0.5), 3) - np.fix(c + 0.5)
) / (16 * np.power(c, 3))
def ext_eff_cyl(self, dmat, h):
"""Computes the extraction efficiency of a point dipole embedded
within a dielectric layer above a lossless ground plane in
cylindrical coordinates.
Args:
dmat: thickness of dielectric layer.
h: height of dipole above ground plane as fraction of dmat.
"""
sr = self.L + self.dpml
sz = dmat + self.dair + self.dpml
cell_size = mp.Vector3(sr, 0, sz)
boundary_layers = [
mp.PML(self.dpml, direction=mp.R),
mp.PML(self.dpml, direction=mp.Z, side=mp.High),
]
src_cmpt = mp.Er
src_pt = mp.Vector3(0, 0, -0.5 * sz + h * dmat)
sources = [mp.Source(src=self.src, component=src_cmpt, center=src_pt)]
geometry = [
mp.Block(
material=mp.Medium(index=self.n),
center=mp.Vector3(0, 0, -0.5 * sz + 0.5 * dmat),
size=mp.Vector3(mp.inf, mp.inf, dmat),
)
]
sim = mp.Simulation(
resolution=self.resolution,
cell_size=cell_size,
dimensions=mp.CYLINDRICAL,
m=-1,
boundary_layers=boundary_layers,
sources=sources,
geometry=geometry,
)
flux_air = sim.add_flux(
self.fcen,
0,
1,
mp.FluxRegion(
center=mp.Vector3(0.5 * self.L, 0, 0.5 * sz - self.dpml),
size=mp.Vector3(self.L, 0, 0),
),
mp.FluxRegion(
center=mp.Vector3(self.L, 0, 0.5 * sz - self.dpml - 0.5 * self.dair),
size=mp.Vector3(0, 0, self.dair),
),
)
sim.run(
mp.dft_ldos(self.fcen, 0, 1),
until_after_sources=mp.stop_when_fields_decayed(
20, src_cmpt, src_pt, self.tol
),
)
out_flux = mp.get_fluxes(flux_air)[0]
dV = np.pi / (self.resolution**3)
total_flux = -np.real(sim.ldos_Fdata[0] * np.conj(sim.ldos_Jdata[0])) * dV
ext_eff = out_flux / total_flux
print(f"extraction efficiency (cyl):, " f"{dmat:.4f}, {h:.4f}, {ext_eff:.6f}")
return ext_eff
def ext_eff_3D(self, dmat, h):
"""Computes the extraction efficiency of a point dipole embedded
within a dielectric layer above a lossless ground plane in
3D Cartesian coordinates.
Args:
dmat: thickness of dielectric layer.
h: height of dipole above ground plane as fraction of dmat.
"""
sxy = self.L + 2 * self.dpml
sz = dmat + self.dair + self.dpml
cell_size = mp.Vector3(sxy, sxy, sz)
symmetries = [mp.Mirror(direction=mp.X, phase=-1), mp.Mirror(direction=mp.Y)]
boundary_layers = [
mp.PML(self.dpml, direction=mp.X),
mp.PML(self.dpml, direction=mp.Y),
mp.PML(self.dpml, direction=mp.Z, side=mp.High),
]
src_cmpt = mp.Ex
src_pt = mp.Vector3(0, 0, -0.5 * sz + h * dmat)
sources = [
mp.Source(
src=mp.GaussianSource(self.fcen, fwidth=0.1 * self.fcen),
component=src_cmpt,
center=src_pt,
)
]
geometry = [
mp.Block(
material=mp.Medium(index=self.n),
center=mp.Vector3(0, 0, -0.5 * sz + 0.5 * dmat),
size=mp.Vector3(mp.inf, mp.inf, dmat),
)
]
sim = mp.Simulation(
resolution=self.resolution,
cell_size=cell_size,
boundary_layers=boundary_layers,
sources=sources,
geometry=geometry,
symmetries=symmetries,
)
flux_air = sim.add_flux(
self.fcen,
0,
1,
mp.FluxRegion(
center=mp.Vector3(0, 0, 0.5 * sz - self.dpml),
size=mp.Vector3(self.L, self.L, 0),
),
mp.FluxRegion(
center=mp.Vector3(
0.5 * self.L, 0, 0.5 * sz - self.dpml - 0.5 * self.dair
),
size=mp.Vector3(0, self.L, self.dair),
),
mp.FluxRegion(
center=mp.Vector3(
-0.5 * self.L, 0, 0.5 * sz - self.dpml - 0.5 * self.dair
),
size=mp.Vector3(0, self.L, self.dair),
weight=-1.0,
),
mp.FluxRegion(
center=mp.Vector3(
0, 0.5 * self.L, 0.5 * sz - self.dpml - 0.5 * self.dair
),
size=mp.Vector3(self.L, 0, self.dair),
),
mp.FluxRegion(
center=mp.Vector3(
0, -0.5 * self.L, 0.5 * sz - self.dpml - 0.5 * self.dair
),
size=mp.Vector3(self.L, 0, self.dair),
weight=-1.0,
),
)
sim.run(
mp.dft_ldos(self.fcen, 0, 1),
until_after_sources=mp.stop_when_fields_decayed(
20, src_cmpt, src_pt, self.tol
),
)
out_flux = mp.get_fluxes(flux_air)[0]
dV = 1 / (self.resolution**3)
total_flux = -np.real(sim.ldos_Fdata[0] * np.conj(sim.ldos_Jdata[0])) * dV
ext_eff = out_flux / total_flux
print(f"extraction efficiency (3D):, " f"{dmat:.4f}, {h:.4f}, {ext_eff:.6f}")
return ext_eff
def test_ldos_cyl(self):
"""Verifies that the Purcell enhancement factor of a parallel dipole
in a planar dielectric cavity with lossless metallic walls computed in
cylindrical coordinates agrees with the analytic result.
"""
ldos_bulk = self.bulk_ldos_cyl()
# not a Van Hove singularity
cavity_thickness = 1.63
gap = cavity_thickness * self.wvl / self.n
ldos_cavity = self.cavity_ldos_cyl(gap)
# Purcell enhancement factor (relative to bulk medium)
pe_meep = ldos_cavity / ldos_bulk
pe_theory = self.purcell_enh_theory(cavity_thickness)
rel_err = abs(pe_meep - pe_theory) / pe_theory
print(
"ldos-cyl:, {:.6f} (Meep), {:.6f} (theory), "
"{:.6f} (error)".format(pe_meep, pe_theory, rel_err)
)
self.assertAlmostEqual(pe_meep, pe_theory, delta=0.1)
def test_ldos_3D(self):
"""Verifies that the Purcell enhancement factor of a parallel dipole
in a planar dielectric cavity with lossless metallic walls computed in
3D Cartesian coordinates agrees with the analytic result.
"""
ldos_bulk = self.bulk_ldos_3D()
# not a Van Hove singularity
cavity_thickness = 0.75
gap = cavity_thickness * self.wvl / self.n
ldos_cavity = self.cavity_ldos_3D(gap)
# Purcell enhancement factor (relative to bulk medium)
pe_meep = ldos_cavity / ldos_bulk
pe_theory = self.purcell_enh_theory(cavity_thickness)
rel_err = abs(pe_meep - pe_theory) / pe_theory
print(
"ldos-3D:, {:.6f} (Meep), {:.6f} (theory), "
"{:.6f} (error)".format(pe_meep, pe_theory, rel_err)
)
self.assertAlmostEqual(pe_meep, pe_theory, delta=0.1)
def test_ldos_ext_eff(self):
"""Verifies that the extraction efficiency of a point dipole in a
dielectric layer above a lossless ground plane computed in cylindrical
and 3D Cartesian coordinates agree.
"""
layer_thickness = 0.5 * self.wvl / self.n
dipole_height = 0.5
ext_eff_cyl = self.ext_eff_cyl(layer_thickness, dipole_height)
ext_eff_3D = self.ext_eff_3D(layer_thickness, dipole_height)
self.assertAlmostEqual(ext_eff_cyl, ext_eff_3D, places=2)
if __name__ == "__main__":
unittest.main()
|