Skip to content

[2/13][Adjoint Module] Fix source deposition across chunk boundaries - #3298

Open
smartalecH wants to merge 1 commit into
fix/adjoint-adjacent-material-gridsfrom
fix/source-boundary-deposition
Open

[2/13][Adjoint Module] Fix source deposition across chunk boundaries#3298
smartalecH wants to merge 1 commit into
fix/adjoint-adjacent-material-gridsfrom
fix/source-boundary-deposition

Conversation

@smartalecH

Copy link
Copy Markdown
Collaborator

Recreated so the whole series can form a single GitHub stack. Native stacked pull requests cannot include PRs opened from a fork, and this branch was previously hosted on one. The content and description are unchanged; earlier review discussion is on the superseded PR linked below, which remains readable.

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.

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.
@smartalecH smartalecH changed the title [2/n][Adjoint Module] Fix source deposition across chunk boundaries [2/13][Adjoint Module] Fix source deposition across chunk boundaries Sep 2, 2026
Comment thread src/sources.cpp
data.amp *= gv.a; // correct units for J delta-function amplitude
}
sources = src.add_to(sources, &data.src);
register_src_time(data.src);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
register_src_time(data.src);
register_src_time(data.src); // needed by fix_boundary_sources

Comment thread src/loop_in_chunks.cpp
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),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/loop_in_chunks.cpp
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);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little bit weird? Won't shifting by 1 shift it to a different Yee grid?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulation result depends on # of processes, using geometry_center

2 participants