-
Notifications
You must be signed in to change notification settings - Fork 626
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 gradients when materials contain conductivities #1811
Comments
Note that conductivity is handled in a very different place in the code from other dispersive materials — in the |
It seems that when damping is on, dA_du isn't calculated from finite difference but from the trivial case here: Lines 2553 to 2555 in 7019c11
Besides check additionally md->damping == 0 in the if statement above, shouldn't we also use 2*meep::pi*freq instead of freq here?Line 2519 in 7019c11
Making these two changes seems to fix the issue. |
Yes that's a bug.
What do the results look like when you make those two changes? |
With your test script above, the outputs are: I also ran the script a few times without fixing the random seed, and the rel_error is consistently around 1e-3. |
As described in #1788, the adjoint solver does not produce accurate gradients when materials contain conductivities (including artificial damping terms). This is why the following lines are commented out on
master
:meep/src/meepgeom.cpp
Lines 603 to 606 in 7019c11
(Note that even if these lines were active, the actual conductivities themselves still need to be interpolated, as described in our paper -- but that's not why the gradients were failing, as the artificial damping terms introduced in #1788 also fail.)
When calculating Aᵤ (the derivative of the system matrix w.r.t. the design parameters), do a finite difference, performed here:
meep/src/meepgeom.cpp
Lines 2566 to 2592 in 7019c11
The code that evaluates ε(ω,u) is found here:
meep/src/meepgeom.cpp
Lines 2506 to 2533 in 7019c11
What's interesting is gradients for dispersive materials without any global conductivities (e.g. LN in the material database) work just fine -- meaning at least part of the above code is working well...
Here is a test script that can be used during debugging.
(Here is another script that uses LN for the material grid and produces accurate gradients)
(cc @mochen4)
The text was updated successfully, but these errors were encountered: