From 601609f142e5dfb79be48ac4f69355d373e8b5df Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Tue, 7 Feb 2023 23:44:07 +0000 Subject: [PATCH] exclude r=0 in source if |m| > 1 for test_adjoint_cyl.py --- python/tests/test_adjoint_cyl.py | 33 ++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/python/tests/test_adjoint_cyl.py b/python/tests/test_adjoint_cyl.py index 2ff6c0884..0ef340b41 100644 --- a/python/tests/test_adjoint_cyl.py +++ b/python/tests/test_adjoint_cyl.py @@ -36,10 +36,6 @@ fcen = 1 / 1.55 width = 0.2 fwidth = width * fcen -source_center = [design_r / 2, 0, -(sz / 2 - dpml + design_z / 2) / 2] -source_size = mp.Vector3(design_r, 0, 0) -src = mp.GaussianSource(frequency=fcen, fwidth=fwidth) -source = [mp.Source(src, component=mp.Er, center=source_center, size=source_size)] ## random design region p = 0.5 * rng.rand(Nr * Nz) @@ -48,6 +44,31 @@ dp = deps * rng.rand(Nr * Nz) +def get_source(m): + source_center = mp.Vector3( + design_r / 2, + 0, + -(sz / 2 - dpml + design_z / 2) / 2, + ) + # exclude r=0 whenever |m| > 1 + source_size = mp.Vector3( + design_r if abs(m) <= 1 else 0.5 * design_r, + 0, + 0, + ) + src = mp.GaussianSource(frequency=fcen, fwidth=fwidth) + source = [ + mp.Source( + src, + component=mp.Er, + center=source_center, + size=source_size, + ) + ] + + return source + + def forward_simulation(design_params, m, far_x): matgrid = mp.MaterialGrid( mp.Vector3(Nr, 0, Nz), SiO2, Si, weights=design_params.reshape(Nr, 1, Nz) @@ -65,7 +86,7 @@ def forward_simulation(design_params, m, far_x): resolution=resolution, cell_size=cell_size, boundary_layers=boundary_layers, - sources=source, + sources=get_source(m), geometry=geometry, dimensions=dimensions, m=m, @@ -111,7 +132,7 @@ def adjoint_solver(design_params, m, far_x): cell_size=cell_size, boundary_layers=boundary_layers, geometry=geometry, - sources=source, + sources=get_source(m), resolution=resolution, dimensions=dimensions, m=m,