[2/13][Adjoint Module] Fix source deposition across chunk boundaries - #3298
Open
smartalecH wants to merge 1 commit into
Open
[2/13][Adjoint Module] Fix source deposition across chunk boundaries#3298smartalecH wants to merge 1 commit into
smartalecH wants to merge 1 commit into
Conversation
Zero-thickness sources can restrict onto multiple Yee points. When a chunk boundary intersects that stencil, source deposition can become dependent on the chunk layout, especially with a nonzero geometry center.\n\nEnumerate the full component-local stencil with global parity, then use the existing boundary-source relocation path to transfer samples to their timestep-owning chunks. Compact relocated source records and avoid collective setup when no relocation is needed.\n\nAdd deterministic 2D and 3D chunk-boundary regressions, including an evolved-field energy comparison.
stevengj
reviewed
Sep 4, 2026
| data.amp *= gv.a; // correct units for J delta-function amplitude | ||
| } | ||
| sources = src.add_to(sources, &data.src); | ||
| register_src_time(data.src); |
Collaborator
There was a problem hiding this comment.
Suggested change
| register_src_time(data.src); | |
| register_src_time(data.src); // needed by fix_boundary_sources |
stevengj
reviewed
Sep 4, 2026
| ivec _iscoS(S.transform(gvu.little_owned_corner(cS), sn)); | ||
| ivec _iecoS(S.transform(gvu.big_owned_corner(cS), sn)); | ||
| ivec _iscoS(S.transform(use_symmetry ? gvu.little_owned_corner(cS) | ||
| : gvu.little_corner() + gvu.iyee_shift(cS), |
Collaborator
There was a problem hiding this comment.
Note: gvu.little_corner() + gvu.iyee_shift(cS) is the first point in the chunk for that component, whether it is owned or not.
It would be good to add a comment explaining why this is needed for the !use_symmetry case.
stevengj
reviewed
Sep 4, 2026
| if (parity) iscS.set_direction(d, iscS.in_direction(d) + 1); | ||
| if ((iecS.in_direction(d) - (is - shifti).in_direction(d)) % 2) | ||
| iecS.set_direction(d, iecS.in_direction(d) - 1); | ||
| } |
Collaborator
There was a problem hiding this comment.
This is a little bit weird? Won't shifting by 1 shift it to a different Yee grid?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #3290.
Closes #1051
When users specify a geometry center, it shifts the locations of the sources relative to the chunk pattern (as expected). One bug that was fixed long ago, was when sources were accidentally placed on both chunks after a shift. Another issue (which is resolved here) is when a source shifts, but not all of it is properly shifted due to the way meep handles "ownership."
More specifically, when a zero-thickness source lies on a chunk boundary, Meep must interpolate it onto grid points on both sides. Previously, each chunk clipped that interpolation to its locally owned grid points. With a shifted simulation center, this could omit part of the source or store it on the wrong chunk, making results depend on the chunk layout.
The fix computes the complete source interpolation first, then moves each resulting source sample to the chunk that owns the corresponding field update. This makes source deposition independent of domain decomposition.