Skip to content

Comments

Wrap particle positions after converting to physical units and before the KDTree is built#285

Open
bwkeller wants to merge 1 commit intopynbody:masterfrom
bwkeller:master
Open

Wrap particle positions after converting to physical units and before the KDTree is built#285
bwkeller wants to merge 1 commit intopynbody:masterfrom
bwkeller:master

Conversation

@bwkeller
Copy link

@bwkeller bwkeller commented Feb 3, 2026

Converting to physical units before building the KDTree can cause spurious, roundoff-caused problems with periodic boxes. In a snapshot where the boxsize was 1.0, and two or more particles are at -0.5 and 0.5 in code units, these same particles may fail pynbody's boundary check in smCheckFits(), and calculations will end up falling back to assuming no periodicity.

This small change just call's pynbody's wrap() before the treebuild to make sure any particles that have been shifted over the border by roundoff get re-wrapped to fit within the periodic box in physical units.

spurious, roundoff-caused problems with periodic boxes.  In a snapshot
where the boxsize was 1.0, and two or more particles are at -0.5 and 0.5
in code units, these same particles may fail pynbody's boundary check in
smCheckFits, and calculations will end up falling back to assuming no
periodicity.
@apontzen
Copy link
Member

apontzen commented Feb 3, 2026

Thanks Ben! Does it need to be repeated in two places? I’d naively think putting it just in build_tree would be sufficient.

@bwkeller
Copy link
Author

bwkeller commented Feb 3, 2026

Thanks Ben! Does it need to be repeated in two places? I’d naively think putting it just in build_tree would be sufficient.

It might, it looks like my change fails the tests anyway! I'll try and fix this and update my fork.

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.

2 participants