-
Notifications
You must be signed in to change notification settings - Fork 634
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
compute adjoint gradient using restriction/interpolation only when anisotropic materials are present #1886
Conversation
…thing is disabled
This isn't quite right.
else if (md->do_averaging && !(md-> medium_1->epsilon_offdiag) && !(md-> medium_2->epsilon_offdiag)) such that the routine is bypassed. (this needs a close look, however).
|
I added a check for off-diagonal ε when deciding to execute the restriction/interpolation portion of Also, I verified that with this PR and turning off subpixel smoothing via |
Attempting to fix forward and pile more changes on top of an incorrect implementation seems very risky. |
But the implementation is changing... normally I would agree with you but in this case, it's apples and oranges. |
It turns out this PR actually prevents the memory violations reported in #1861 even when subpixel smoothing is enabled ( I suspect there is a bug somewhere in this block which determines the starting and ending Lines 2903 to 2910 in efe3b4b
Anyhow, at the very least, this PR fixes a bug in |
#1780 added support for subpixel smoothing of the adjoint gradients in which ε is an anisotropic tensor. However, in the current implementation of
material_grids_addgradient
ofmeepgeom.cpp
, regardless of the value of thedo_averaging
property of theMaterialGrid
object, the adjoint gradient is always computed for the off-diagonal components of ε which is a bug. Also, as reported in #1861, computing these off-diagonal elements involves a memory violation in which the array for the forward fields is read outside of its bounds. The memory violation issue is exacerbated by the fact thatdo_averaging=True
is the default setting inMaterialGrid
:meep/python/geom.py
Lines 538 to 547 in efe3b4b
This PR provides a small fix to
material_grids_addgradient
to ensure that whendo_averaging=False
only the diagonal ε elements are computed (and the memory violation is therefore avoided).