Repository navigation
[2/13][Adjoint Module] Round the grid origin to a whole pixel - #3298
smartalecH wants to merge 1 commit into
Conversation
| 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), |
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.
There was a problem hiding this comment.
Just added -- let me know if this comment works.
| 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); | ||
| } |
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?
235af28 to
08f14c5
Compare
|
@stevengj your question about the parity shift in
I've opened #3333 as a draft alternative. It rounds the origin to a whole pixel, as The trade-off is that a non-pixel I'm also not sure this is in line with the "illusion of continuity," but I may be overthinking things here... Thanks! |
That seems fine. Either way it is the same order of accuracy. |
08f14c5 to
500815f
Compare
geometry_center was rounded to the nearest half pixel, so a non-integer number of pixels gave the grid an odd origin. The Yee lattice assumes an even origin (see grid_volume::icenter), so sources and monitors were placed half a pixel from the fields and materials, and source deposition depended on the chunk layout. Fixes #1051. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
500815f to
650d0b9
Compare
Supersedes #3290.
Fixes #1051.
Root cause.
grid_volume::set_origin(const vec&)rounds to the nearest half pixel, so anygeometry_centerthat is not a whole number of pixels gives the grid an odd originio(e.g.0.1at resolution 15 is 1.5 px). The Yee lattice assumesiois even —icenter()documents this andcenter_origin()enforces it — andloop_in_chunks(vec2diel_floor) andgrid_volume::interpolateplace each component on absolute ivec parities. With an oddiothose disagree with where fields and materials are actually stored, so:get_field_point, DFT monitors and otherloop_in_chunksreadouts are likewise half a pixel off,Fix. Round the origin to a whole pixel, as
center_origin()already does, and roundSimulation.geometry_centerthe same way in Python so the two agree. The rounding is documented.An earlier version of this PR instead patched
loop_in_chunksto realign each chunk with the absolute lattice (the parity shift discussed in review). That made the odd-iocase chunk-independent but left sources and monitors half a pixel off, so it has been replaced by this root-cause fix (prototyped in #3333).Evidence (2D/3D, all six components; point, line, plane and boundary-straddling sources on/off chunk splits; random non-pixel
geometry_center):geometry_centerpre-rounded-np 3/-np 4vs-np 1, 40 configsThe middle column shows that master's source-deposition code is already chunk-independent once
iois even.Behavior change. A non-pixel
geometry_centernow snaps to the nearest pixel instead of the nearest half pixel — the same order of accuracy, but now consistent.Tests. Chunk-boundary tests in
test_source.py(zero-thickness and point sources on a chunk boundary with a half-pixelgeometry_center, compared against a single chunk), plustest_geometry_center_rounded_to_pixelintest_simulation.py.