From 6db5908bfd361923e7178ca99d1776c5cd9100ac Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Tue, 24 Jan 2023 20:52:58 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix=20bug=20in=20step-db=20update=20equatio?= =?UTF-8?q?ns=20in=20cylindrical=20coordinates=20for=20m=3D=C2=B11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/tests/test_ldos.py | 40 +++++++++++++++++++++++++-------------- src/step_db.cpp | 2 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/python/tests/test_ldos.py b/python/tests/test_ldos.py index c1d7a547d..0b1b0b162 100644 --- a/python/tests/test_ldos.py +++ b/python/tests/test_ldos.py @@ -1,7 +1,5 @@ import unittest - import numpy as np - import meep as mp @@ -17,17 +15,15 @@ def setUp(cls): 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): + def bulk_ldos_cyl(self, m): """Computes the LDOS of a point dipole in a homogeneous dielectric medium in cylindrical coordinates. + + Args: + m: angular dependence of the fields, exp(imφ). """ sr = self.L + self.dpml sz = self.L + 2 * self.dpml @@ -37,7 +33,7 @@ def bulk_ldos_cyl(self): sources = [ mp.Source( - src=self.src, + src=mp.GaussianSource(self.fcen, fwidth=0.1 * self.fcen), component=mp.Er, center=mp.Vector3(), ) @@ -49,7 +45,7 @@ def bulk_ldos_cyl(self): boundary_layers=pml_layers, sources=sources, dimensions=mp.CYLINDRICAL, - m=-1, + m=m, default_material=mp.Medium(index=self.n), ) @@ -76,7 +72,7 @@ def cavity_ldos_cyl(self, sz): sources = [ mp.Source( - src=self.src, + src=mp.GaussianSource(self.fcen, fwidth=0.1 * self.fcen), component=mp.Er, center=mp.Vector3(), ) @@ -221,7 +217,13 @@ def ext_eff_cyl(self, dmat, h): 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)] + sources = [ + mp.Source( + src=mp.GaussianSource(self.fcen, fwidth=0.1 * self.fcen), + component=src_cmpt, + center=src_pt, + ), + ] geometry = [ mp.Block( @@ -369,13 +371,23 @@ def ext_eff_3D(self, dmat, h): return ext_eff + def test_cyl_plus_minus_one(self): + """Verifies that the radiated flux from a point source is identical + for two different simulations with m=±1. + """ + + ldos_bulk_m_minus_one = self.bulk_ldos_cyl(-1.0) + ldos_bulk_m_plus_one = self.bulk_ldos_cyl(+1.0) + + self.assertEqual(ldos_bulk_m_minus_one, ldos_bulk_m_plus_one) + 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() + ldos_bulk = self.bulk_ldos_cyl(-1.0) # not a Van Hove singularity cavity_thickness = 1.63 @@ -436,7 +448,7 @@ def test_ldos_ext_eff(self): 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) + self.assertAlmostEqual(ext_eff_cyl, ext_eff_3D, delta=0.01) if __name__ == "__main__": diff --git a/src/step_db.cpp b/src/step_db.cpp index eb0338e1b..1e725a288 100644 --- a/src/step_db.cpp +++ b/src/step_db.cpp @@ -329,7 +329,7 @@ bool fields_chunk::step_db(field_type ft) { realnum *fu = siginvu && f_u[cc][cmp] ? f[cc][cmp] : 0; realnum *the_f = fu ? f_u[cc][cmp] : f[cc][cmp]; int sd = ft == D_stuff ? +1 : -1; - realnum f_m_mult = ft == D_stuff ? 2 : (1 - 2 * cmp); + realnum f_m_mult = ft == D_stuff ? 2 : (1 - 2 * cmp) * m; for (int iz = (ft == D_stuff); iz < nz + (ft == D_stuff); ++iz) { realnum df; From 2828d4d92cac52c5666ca18351b6d64f4feefb09 Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Wed, 25 Jan 2023 00:31:09 +0000 Subject: [PATCH 2/2] =?UTF-8?q?verify=20correctness=20of=20m=3D=C2=B11=20s?= =?UTF-8?q?imulation=20using=20flux=20rather=20than=20LDOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/tests/test_ldos.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/python/tests/test_ldos.py b/python/tests/test_ldos.py index 0b1b0b162..3b39e4aac 100644 --- a/python/tests/test_ldos.py +++ b/python/tests/test_ldos.py @@ -18,12 +18,9 @@ def setUp(cls): # termination criteria cls.tol = 1e-8 - def bulk_ldos_cyl(self, m): + def bulk_ldos_cyl(self): """Computes the LDOS of a point dipole in a homogeneous dielectric medium in cylindrical coordinates. - - Args: - m: angular dependence of the fields, exp(imφ). """ sr = self.L + self.dpml sz = self.L + 2 * self.dpml @@ -45,7 +42,7 @@ def bulk_ldos_cyl(self, m): boundary_layers=pml_layers, sources=sources, dimensions=mp.CYLINDRICAL, - m=m, + m=-1, default_material=mp.Medium(index=self.n), ) @@ -197,7 +194,7 @@ def purcell_enh_theory(self, 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): + def ext_eff_cyl(self, dmat, h, m): """Computes the extraction efficiency of a point dipole embedded within a dielectric layer above a lossless ground plane in cylindrical coordinates. @@ -205,6 +202,7 @@ def ext_eff_cyl(self, dmat, h): Args: dmat: thickness of dielectric layer. h: height of dipole above ground plane as fraction of dmat. + m: angular dependence of the fields, exp(imφ). """ sr = self.L + self.dpml sz = dmat + self.dair + self.dpml @@ -237,7 +235,7 @@ def ext_eff_cyl(self, dmat, h): resolution=self.resolution, cell_size=cell_size, dimensions=mp.CYLINDRICAL, - m=-1, + m=m, boundary_layers=boundary_layers, sources=sources, geometry=geometry, @@ -371,23 +369,13 @@ def ext_eff_3D(self, dmat, h): return ext_eff - def test_cyl_plus_minus_one(self): - """Verifies that the radiated flux from a point source is identical - for two different simulations with m=±1. - """ - - ldos_bulk_m_minus_one = self.bulk_ldos_cyl(-1.0) - ldos_bulk_m_plus_one = self.bulk_ldos_cyl(+1.0) - - self.assertEqual(ldos_bulk_m_minus_one, ldos_bulk_m_plus_one) - 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(-1.0) + ldos_bulk = self.bulk_ldos_cyl() # not a Van Hove singularity cavity_thickness = 1.63 @@ -440,16 +428,23 @@ def test_ldos_3D(self): 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. + coordinates (for m=±1, separately) and 3D Cartesian 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_cyl = self.ext_eff_cyl(layer_thickness, dipole_height, -1.0) ext_eff_3D = self.ext_eff_3D(layer_thickness, dipole_height) self.assertAlmostEqual(ext_eff_cyl, ext_eff_3D, delta=0.01) + ext_eff_cyl_m_plus = self.ext_eff_cyl( + layer_thickness, + dipole_height, + +1.0, + ) + self.assertEqual(ext_eff_cyl, ext_eff_cyl_m_plus) + if __name__ == "__main__": unittest.main()