Only do pairwise energy conservation if there are two or more particles#6818
Merged
JustinRayAngus merged 2 commits intoBLAST-WarpX:developmentfrom Apr 28, 2026
Conversation
JustinRayAngus
approved these changes
Apr 28, 2026
Contributor
JustinRayAngus
left a comment
There was a problem hiding this comment.
LGTM.
Thanks, Dave.
5711320
into
BLAST-WarpX:development
47 of 48 checks passed
6 tasks
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.
With unequally weight particles in binary collisions, the particle momenta are adjusted to exactly conserve energy and momentum. The adjustment for energy conservation is done pairwise (within each species). This PR adds a check that there are at least two particles in the cell before calling the routine that does the energy correction. Without this check, an infinite loop can arise since due to round off, the relative energy can be negative.
Also, a check is added for the unlikely case where the relative energy is negative for all pairs of particles.