Skip to content

Commit 9f0e5c5

Browse files
committed
Small fixes for workspace usage
1 parent 0ac9f52 commit 9f0e5c5

2 files changed

Lines changed: 31 additions & 34 deletions

File tree

splashsurf_lib/src/reconstruction.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -250,60 +250,51 @@ impl<I: Index, R: Real> SurfaceReconstructionOctreeVisitor<I, R> {
250250
parent = parent_scope
251251
);
252252

253-
let particles = if let Some(particle_set) = octree_node.data().particle_set() {
253+
let node_particles = if let Some(particle_set) = octree_node.data().particle_set() {
254254
&particle_set.particles
255255
} else {
256256
// Skip non-leaf nodes
257257
return;
258258
};
259259

260-
let mut tl_workspace = tl_workspaces
261-
.get_local_with_capacity(particles.len())
260+
let mut tl_workspace_ref_mut = tl_workspaces
261+
.get_local_with_capacity(node_particles.len())
262262
.borrow_mut();
263+
let tl_workspace = &mut *tl_workspace_ref_mut;
263264

264-
// Take particle position storage from workspace and fill it with positions of the leaf
265-
let mut node_particle_positions =
266-
std::mem::take(&mut tl_workspace.particle_positions);
267265
Self::collect_node_particle_positions(
268-
particles,
266+
node_particles,
269267
global_particle_positions,
270-
&mut node_particle_positions,
268+
&mut tl_workspace.particle_positions,
271269
);
272270

273-
{
274-
let mut particle_neighbor_lists =
275-
std::mem::take(&mut tl_workspace.particle_neighbor_lists);
276-
let mut particle_densities =
277-
std::mem::take(&mut tl_workspace.particle_densities);
278-
compute_particle_densities_and_neighbors(
279-
grid,
280-
node_particle_positions.as_slice(),
281-
parameters,
282-
&mut particle_neighbor_lists,
283-
&mut particle_densities,
284-
);
285-
286-
tl_workspace.particle_neighbor_lists = particle_neighbor_lists;
287-
tl_workspace.particle_densities = particle_densities;
288-
}
271+
compute_particle_densities_and_neighbors(
272+
grid,
273+
tl_workspace.particle_positions.as_slice(),
274+
parameters,
275+
&mut tl_workspace.particle_neighbor_lists,
276+
&mut tl_workspace.particle_densities,
277+
);
289278

290279
{
291280
profile!("update global density values");
292281

293282
let mut global_densities = global_densities.lock().unwrap();
294-
for (&i, &density) in
295-
particles.iter().zip(tl_workspace.particle_densities.iter())
296-
{
297-
let position = &global_particle_positions[i];
283+
for (&global_idx, (&density, position)) in node_particles.iter().zip(
284+
tl_workspace
285+
.particle_densities
286+
.iter()
287+
.zip(tl_workspace.particle_positions.iter()),
288+
) {
298289
// Check if the particle is actually inside of the cell and not a ghost particle
299290
if octree_node.aabb().contains_point(position) {
300-
global_densities[i] = density;
291+
global_densities[global_idx] = density;
301292
}
302293
}
303294
}
304295
});
305296

306-
// Unpack densities from mutex and move into workspace
297+
// Unpack densities from mutex and move back into workspace
307298
*output_surface.workspace.densities_mut() = global_densities.into_inner().unwrap();
308299
}
309300

@@ -388,9 +379,12 @@ impl<I: Index, R: Real> SurfaceReconstructionOctreeVisitor<I, R> {
388379

389380
trace!("Surface patch successfully processed.");
390381

391-
// Put back the particle position and mesh storage
382+
// Put back everything taken from the workspace
392383
tl_workspace.particle_positions = node_particle_positions;
393384
tl_workspace.mesh = node_mesh;
385+
if let Some(node_particle_densities) = node_particle_densities {
386+
tl_workspace.particle_densities = node_particle_densities;
387+
}
394388
}
395389
});
396390
};
@@ -477,8 +471,11 @@ impl<I: Index, R: Real> SurfaceReconstructionOctreeVisitor<I, R> {
477471
&self.parameters,
478472
);
479473

480-
// Put back the particle position storage
474+
// Put back everything taken from the workspace
481475
tl_workspace.particle_positions = node_particle_positions;
476+
if let Some(node_particle_densities) = node_particle_densities {
477+
tl_workspace.particle_densities = node_particle_densities;
478+
}
482479

483480
surface_patch
484481
};

splashsurf_lib/src/workspace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ pub(crate) struct LocalReconstructionWorkspace<I: Index, R: Real> {
6565
pub particle_neighbor_lists: Vec<Vec<usize>>,
6666
/// Storage for per particle densities
6767
pub particle_densities: Vec<R>,
68-
/// Storage for the mesh
68+
/// Storage for the final surface mesh
6969
pub mesh: TriMesh3d<R>,
70-
/// Storage for the density map
70+
/// Storage for the density level-set
7171
pub density_map: DensityMap<I, R>,
7272
}
7373

0 commit comments

Comments
 (0)