Skip to content

Commit

Permalink
exclude r=0 in source if |m| > 1 for test_adjoint_cyl.py
Browse files Browse the repository at this point in the history
  • Loading branch information
oskooi committed Feb 7, 2023
1 parent 9af8cf5 commit 601609f
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions python/tests/test_adjoint_cyl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 601609f

Please sign in to comment.