From f5b4fca0d075039198a3b4b0ead37a2760c4017b Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Thu, 10 Jun 2021 09:14:08 -0700 Subject: [PATCH 1/3] add unit test for backward-propagating mode in oblique waveguide --- python/tests/test_mode_decomposition.py | 46 ++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/python/tests/test_mode_decomposition.py b/python/tests/test_mode_decomposition.py index 861ba9c02..2031f71d3 100644 --- a/python/tests/test_mode_decomposition.py +++ b/python/tests/test_mode_decomposition.py @@ -1,7 +1,7 @@ import unittest +import numpy as np import meep as mp - class TestModeDecomposition(unittest.TestCase): def test_mode_decomposition(self): @@ -83,6 +83,50 @@ def test_mode_decomposition(self): self.assertAlmostEqual(abs(coeffs[0, 0, 1])**2 / abs(incident_coeffs[0, 0, 0])**2, -taper_flux[0] / incident_flux[0], places=4) + def test_oblique_waveguide_backward_mode(self): + sxy = 12.0 + cell_size = mp.Vector3(sxy,sxy,0) + + dpml = 0.6 + pml_layers = [mp.PML(thickness=dpml)] + + fcen = 1/1.55 + rot_angle = np.radians(35.0) + kpoint = mp.Vector3(1,0,0).rotate(mp.Vector3(0,0,1), rot_angle) * -1.0 + sources = [mp.EigenModeSource(src=mp.GaussianSource(fcen,fwidth=0.1), + center=mp.Vector3(0.5*sxy-3.4,0,0), + size=mp.Vector3(0,sxy,0), + direction=mp.NO_DIRECTION, + eig_kpoint=kpoint, + eig_band=1, + eig_parity=mp.ODD_Z, + eig_match_freq=True)] + + geometry = [mp.Block(center=mp.Vector3(), + size=mp.Vector3(mp.inf,1,mp.inf), + e1 = mp.Vector3(1,0,0).rotate(mp.Vector3(0,0,1), rot_angle), + e2 = mp.Vector3(0,1,0).rotate(mp.Vector3(0,0,1), rot_angle), + material=mp.Medium(index=3.5))] + + sim = mp.Simulation(cell_size=cell_size, + resolution=40, + boundary_layers=pml_layers, + sources=sources, + geometry=geometry) + + mode = sim.add_mode_monitor(fcen, 0, 1, + mp.FluxRegion(center=mp.Vector3(-0.5*sxy+dpml,0,0), + size=mp.Vector3(0,sxy,0))) + + sim.run(until_after_sources=30) + + flux = mp.get_fluxes(mode)[0] + coeff = sim.get_eigenmode_coefficients(mode,[1], + direction=mp.NO_DIRECTION, + kpoint_func=lambda f,n: kpoint).alpha[0,0,0] + + print("oblique-waveguide-flux:, {:.6f}, {:.6f}".format(-flux, abs(coeff)**2)) + self.assertAlmostEqual(-flux, abs(coeff)**2, places=1) if __name__ == '__main__': unittest.main() From 532f3eb51a123956e8f5e953ee74b441a3b4dc46 Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Tue, 15 Jun 2021 18:26:31 -0700 Subject: [PATCH 2/3] add comment for magnitude of flux --- python/tests/test_mode_decomposition.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/tests/test_mode_decomposition.py b/python/tests/test_mode_decomposition.py index 2031f71d3..567d05aa6 100644 --- a/python/tests/test_mode_decomposition.py +++ b/python/tests/test_mode_decomposition.py @@ -126,6 +126,7 @@ def test_oblique_waveguide_backward_mode(self): kpoint_func=lambda f,n: kpoint).alpha[0,0,0] print("oblique-waveguide-flux:, {:.6f}, {:.6f}".format(-flux, abs(coeff)**2)) + ## the magnitude of |flux| is 100.008731 and so we check three significant digits of accuracy self.assertAlmostEqual(-flux, abs(coeff)**2, places=1) if __name__ == '__main__': From 96e553ed212d38cc3b40f854055c6a2ec832cede Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Tue, 15 Jun 2021 18:32:06 -0700 Subject: [PATCH 3/3] check relative accuracy and reduce resolution for speedup by a factor of three in runtime --- python/tests/test_mode_decomposition.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/tests/test_mode_decomposition.py b/python/tests/test_mode_decomposition.py index 567d05aa6..5d861fddb 100644 --- a/python/tests/test_mode_decomposition.py +++ b/python/tests/test_mode_decomposition.py @@ -109,7 +109,7 @@ def test_oblique_waveguide_backward_mode(self): material=mp.Medium(index=3.5))] sim = mp.Simulation(cell_size=cell_size, - resolution=40, + resolution=20, boundary_layers=pml_layers, sources=sources, geometry=geometry) @@ -126,8 +126,8 @@ def test_oblique_waveguide_backward_mode(self): kpoint_func=lambda f,n: kpoint).alpha[0,0,0] print("oblique-waveguide-flux:, {:.6f}, {:.6f}".format(-flux, abs(coeff)**2)) - ## the magnitude of |flux| is 100.008731 and so we check three significant digits of accuracy - self.assertAlmostEqual(-flux, abs(coeff)**2, places=1) + ## the magnitude of |flux| is 100.008731 and so we check two significant digits of accuracy + self.assertAlmostEqual(-1,abs(coeff)**2/flux,places=2) if __name__ == '__main__': unittest.main()