Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow cylindrical adjoint near2far at r=0 #2027

Merged
merged 2 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions python/tests/test_adjoint_cyl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
boundary_layers = [mp.PML(thickness=dpml)]

design_region_resolution = int(2*resolution)
design_r = 4.8
design_r = 5
design_z = 2
Nr, Nz = int(design_r*design_region_resolution), int(design_z*design_region_resolution)

fcen = 1/1.55
width = 0.2
fwidth = width * fcen
source_center = [0.1+design_r/2,0,(sz/2-dpml+design_z/2)/2]
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,
Expand All @@ -51,7 +51,7 @@ def forward_simulation(design_params):
Si,
weights=design_params.reshape(Nr,1,Nz))

geometry = [mp.Block(center=mp.Vector3(0.1+design_r/2,0,0),
geometry = [mp.Block(center=mp.Vector3(design_r/2,0,0),
size=mp.Vector3(design_r,0,design_z),
material=matgrid)]

Expand All @@ -67,7 +67,7 @@ def forward_simulation(design_params):
far_x = [mp.Vector3(5,0,20)]
mode = sim.add_near2far(
frequencies,
mp.Near2FarRegion(center=mp.Vector3(0.1+design_r/2,0,(sz/2-dpml+design_z/2)/2),
mp.Near2FarRegion(center=mp.Vector3(design_r/2,0,(sz/2-dpml+design_z/2)/2),
size=mp.Vector3(design_r,0,0),weight=+1))

sim.run(until_after_sources=1200)
Expand All @@ -81,7 +81,7 @@ def adjoint_solver(design_params):

design_variables = mp.MaterialGrid(mp.Vector3(Nr,0,Nz),SiO2,Si)
design_region = mpa.DesignRegion(design_variables,
volume=mp.Volume(center=mp.Vector3(0.1+design_r/2,0,0),
volume=mp.Volume(center=mp.Vector3(design_r/2,0,0),
size=mp.Vector3(design_r,0,design_z)))
geometry = [mp.Block(center=design_region.center,
size=design_region.size,
Expand All @@ -96,7 +96,7 @@ def adjoint_solver(design_params):
m=m)

far_x = [mp.Vector3(5,0,20)]
NearRegions = [mp.Near2FarRegion(center=mp.Vector3(0.1+design_r/2,0,(sz/2-dpml+design_z/2)/2),
NearRegions = [mp.Near2FarRegion(center=mp.Vector3(design_r/2,0,(sz/2-dpml+design_z/2)/2),
size=mp.Vector3(design_r,0,0),
weight=+1)]
FarFields = mpa.Near2FarFields(sim, NearRegions ,far_x)
Expand Down
2 changes: 1 addition & 1 deletion src/near2far.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ std::vector<struct sourcedata> dft_near2far::near_sourcedata(const vec &x_0, dou
EH0 *= -1;
EH0 /= f->S.multiplicity(ix0);
if (x_0.dim == Dcyl){
EH0 /= xs.r();
if (xs.r() != 0) EH0 /= xs.r();
//Somehow, a factor of (2pi)r for r of the near2far region was double counted.
//2pi is canceled out by the integral over design region, where an extra factor of 2pi*r' (r' of the design region) is needed. See meepgeom.cpp
}
Expand Down