Skip to content

Commit 809d1f5

Browse files
committed
Fix bug in code for resetting neighborhood lists
1 parent fd14eda commit 809d1f5

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

splashsurf_lib/src/neighborhood_search.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ pub fn search_inplace<I: Index, R: Real>(
7171
/// Allocates enough storage for the given number of particles and clears all existing neighborhood lists
7272
fn init_neighborhood_list(neighborhood_list: &mut Vec<Vec<usize>>, new_len: usize) {
7373
let old_len = neighborhood_list.len();
74-
if old_len != new_len {
75-
// Reset all neighbor lists that won't be truncated
76-
for particle_list in neighborhood_list.iter_mut().take(old_len.min(new_len)) {
77-
particle_list.clear();
78-
}
74+
// Reset all neighbor lists that won't be truncated
75+
for particle_list in neighborhood_list.iter_mut().take(old_len.min(new_len)) {
76+
particle_list.clear();
7977
}
8078

8179
// Ensure that length is correct
@@ -85,15 +83,14 @@ fn init_neighborhood_list(neighborhood_list: &mut Vec<Vec<usize>>, new_len: usiz
8583
/// Allocates enough storage for the given number of particles and clears all existing neighborhood lists in parallel
8684
fn par_init_neighborhood_list(neighborhood_list: &mut Vec<Vec<usize>>, new_len: usize) {
8785
let old_len = neighborhood_list.len();
88-
if old_len != new_len {
89-
// Reset all neighbor lists that won't be truncated
90-
neighborhood_list
91-
.par_iter_mut()
92-
.take(old_len.min(new_len))
93-
.for_each(|particle_list| {
94-
particle_list.clear();
95-
});
96-
}
86+
// Reset all neighbor lists that won't be truncated
87+
neighborhood_list
88+
.par_iter_mut()
89+
.with_min_len(8)
90+
.take(old_len.min(new_len))
91+
.for_each(|particle_list| {
92+
particle_list.clear();
93+
});
9794

9895
// Ensure that length is correct
9996
neighborhood_list.resize_with(new_len, || Vec::with_capacity(15));

0 commit comments

Comments
 (0)