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

Incorrect FourierFields gradients for D components #2090

Closed
mochen4 opened this issue Jun 2, 2022 · 4 comments · Fixed by #2095
Closed

Incorrect FourierFields gradients for D components #2090

mochen4 opened this issue Jun 2, 2022 · 4 comments · Fixed by #2095

Comments

@mochen4
Copy link
Collaborator

mochen4 commented Jun 2, 2022

The FourierFields gradients for D fields is incorrect by a factor of the permittivity ε (at the location of interest).

Here is an example

Si = mp.Medium(index=3.4)
resolution = 20
Sx = 5
Sy = 3
cell_size = mp.Vector3(Sx,Sy)
pml_layers = [mp.PML(1.0)]
fcen = 1/1.55
width = 0.3
fwidth = width * fcen
frequencies = [fcen]
source_center  = [-1,0,0]
source_size    = mp.Vector3(0,0.5,0)
src = mp.GaussianSource(frequency=fcen,fwidth=fwidth)
source = [mp.Source(src, component=mp.Ez, size = source_size,center=source_center)]
design_region_resolution = 20
Nx = design_region_resolution//2
Ny = design_region_resolution//2

design_variables = mp.MaterialGrid(mp.Vector3(Nx,Ny),mp.air,Si)
design_region = mpa.DesignRegion(design_variables,volume=mp.Volume(center=mp.Vector3(), size=mp.Vector3(0.5, 0.5, 0)))
geometry = [
    mp.Block(center=mp.Vector3(1,0), size = mp.Vector3(0.5, 0.5), material=Si),                 
    mp.Block(center=design_region.center, size=design_region.size, material=design_variables), # design region                          
]
sim = mp.Simulation(cell_size=cell_size,
                    boundary_layers=pml_layers,
                    geometry=geometry,
                    sources=source,
                    resolution=resolution)

Dz = mpa.FourierFields(sim,mp.Volume(center=mp.Vector3(1,0),size=mp.Vector3(0, 0.1)),mp.Dz,yee_grid=True)

ob_list = [Dz]                                                                                          
def J(dz):
    return npa.abs(dz[0,0])**2
opt = mpa.OptimizationProblem(
    simulation=sim,
    objective_functions=J,
    objective_arguments=ob_list,
    design_regions=[design_region],
    frequencies=frequencies)

which has the layout:
image

I found the fd_gradients was approximately ε(=12 in the code above) * adjoint_gradients. If the monitor is placed inside the design region, then the factor is the permittivity corresponding to the design parameter weight at that point.

@stevengj
Copy link
Collaborator

stevengj commented Jun 2, 2022

Probably the adjoint current for a D Fourier-field output should be a D current rather than an E current, and similarly for B?

There is an undocumented feature in which you can specify a current source as D rather than E and it gets multiplied by ε (at least for isotropic media), and similarly a B current is multiplied by µ.

Though I'm a bit confused because it seems like this line already uses the same current type as the Fourier fields?

@stevengj
Copy link
Collaborator

stevengj commented Jun 2, 2022

Oh, I think I may see the problem — this line to multiply the current by ε for a D source is only executed when you add the source term with the usual high-level interface. It's not done by the low-level add_srcdata function that we switched to with @mawc2019's work.

@mawc2019
Copy link
Contributor

mawc2019 commented Jun 7, 2022

this line to multiply the current by ε for a D source is only executed when you add the source term with the usual high-level interface.

PR #2095 is a tentative fix for this issue. It is based on these lines.

It's not done by the low-level add_srcdata function

I tweaked fourier_sourcedata in dft.cpp instead of add_srcdata in sources.cpp to avoid adding extra loops.

@mawc2019
Copy link
Contributor

mawc2019 commented Jun 8, 2022

If the monitor is placed inside the design region, then the factor is the permittivity corresponding to the design parameter weight at that point.

In this example, the monitor is not placed inside the design region. If the monitor is placed inside the design region, PR #2095 does not work even if the design region is uniform. The variation of permittivity with respect to the design parameters needs to be taken into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants