-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix to particle defragmentation #1185
base: develop
Are you sure you want to change the base?
Conversation
"Set empty indices prefix sum", 0, nmax_pool_ - num_active_ - 1, | ||
KOKKOS_LAMBDA(const int nn, int &update, const bool &final) { | ||
const int n = nn + num_active; | ||
"Set empty indices prefix sum", num_active, nmax_pool_ - 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a change to behavior, this is just clearer IMO
if (final) scan_scratch_toread(n) = update; | ||
if (final) { | ||
scan_scratch_toread(n) = update; | ||
empty_indices(n - num_active) = n; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bugfix
@@ -62,6 +62,11 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) { | |||
destroy_particles_frac >= 0. && destroy_particles_frac <= 1., | |||
"Fraction of particles to destroy each timestep must be between 0 and 1"); | |||
|
|||
Real defrag_threshold = pin->GetOrAddReal("Particles", "defrag_threshold", 0.9); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful to be able to control this at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! The defrag in outputs happens even when particles aren't being dumped, which is also likely undesirable.
PR Summary
There was a bug in the defragmentation routine acting on particle lists. The issue was that empty indices weren't being updated after defragmentation. This PR fixes that.
As an aside: this produced the surprising effect that simulation correctness depended on frequency of simulation output, even when no particle fields were being output. This is because particle defragmentation is called during every output cycle. Not saying we can't do this, just mentioning it because it was unexpected. Shouldn't be a correctness issue if defragmentation actually works :)
PR Checklist