Skip to content

Commit 99cdcc1

Browse files
committed
Formatting and update handling of neighborhood lists in result
1 parent 7cc9feb commit 99cdcc1

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

splashsurf_lib/src/dense_subdomains.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ pub(crate) fn compute_global_densities_and_neighbors<I: Index, R: Real>(
623623
.copied()
624624
.zip(particle_densities.iter().copied()),
625625
)
626-
// Update density values only for particles inside of the subdomain (ghost particles have wrong values)
626+
// Update density values only for particles inside the subdomain (ghost particles have wrong values)
627627
.filter(|(is_inside, _)| *is_inside)
628628
.for_each(|(_, (particle_idx, density))| {
629629
global_particle_densities[particle_idx] = density;
@@ -659,17 +659,6 @@ pub(crate) fn compute_global_densities_and_neighbors<I: Index, R: Real>(
659659
let global_particle_densities = global_particle_densities.into_inner();
660660
let global_neighbors = global_neighbors.into_inner();
661661

662-
/*
663-
{
664-
let points = PointCloud3d::new(global_particles.clone());
665-
let mesh = MeshWithData::new(points).with_cell_data(MeshAttribute::new_real_scalar(
666-
"density".to_string(),
667-
global_particle_densities.clone(),
668-
));
669-
splashsurf_lib::io::vtk_format::write_vtk(&mesh, "out/new_density.vtk", "particles").unwrap();
670-
}
671-
*/
672-
673662
(global_particle_densities, global_neighbors)
674663
}
675664

splashsurf_lib/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub struct SurfaceReconstruction<I: Index, R: Real> {
213213
}
214214

215215
impl<I: Index, R: Real> Default for SurfaceReconstruction<I, R> {
216-
/// Returns an empty [SurfaceReconstruction] to pass into the inplace surface reconstruction
216+
/// Returns an empty [SurfaceReconstruction] to pass into the in-place surface reconstruction
217217
fn default() -> Self {
218218
Self {
219219
grid: UniformGrid::new_zero(),
@@ -227,22 +227,22 @@ impl<I: Index, R: Real> Default for SurfaceReconstruction<I, R> {
227227
}
228228

229229
impl<I: Index, R: Real> SurfaceReconstruction<I, R> {
230-
/// Returns a reference to the actual triangulated surface mesh that is the result of the reconstruction
230+
/// Returns a reference to the surface mesh that is the result of the reconstruction
231231
pub fn mesh(&self) -> &TriMesh3d<R> {
232232
&self.mesh
233233
}
234234

235-
/// Returns a reference to the global particle density vector if it was computed during the reconstruction (always `None` when using independent subdomains with domain decomposition)
235+
/// Returns a reference to the global particle density vector if computed during the reconstruction (currently, all reconstruction approaches return this)
236236
pub fn particle_densities(&self) -> Option<&Vec<R>> {
237237
self.particle_densities.as_ref()
238238
}
239239

240-
/// Returns a reference to the global particle density vector if it was computed during the reconstruction (always `None` when using octree based domain decomposition)
240+
/// Returns a reference to the global list of per-particle neighborhood lists if computed during the reconstruction (`None` if not specified in the parameters)
241241
pub fn particle_neighbors(&self) -> Option<&Vec<Vec<usize>>> {
242242
self.particle_neighbors.as_ref()
243243
}
244244

245-
/// Returns a reference to the virtual background grid that was used as a basis for discretization of the density map for marching cubes, can be used to convert the density map to a hex mesh (using [`density_map::sparse_density_map_to_hex_mesh`])
245+
/// Returns a reference to the virtual background grid that was used for marching cubes
246246
pub fn grid(&self) -> &UniformGrid<I, R> {
247247
&self.grid
248248
}
@@ -308,7 +308,7 @@ pub fn reconstruct_surface<I: Index, R: Real>(
308308
Ok(surface)
309309
}
310310

311-
/// Performs a marching cubes surface construction of the fluid represented by the given particle positions, inplace
311+
/// Performs a marching cubes surface construction of the fluid represented by the given particle positions, in-place
312312
pub fn reconstruct_surface_inplace<I: Index, R: Real>(
313313
particle_positions: &[Vector3<R>],
314314
parameters: &Parameters<R>,

splashsurf_lib/src/reconstruction.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,9 @@ pub(crate) fn reconstruct_surface_subdomain_grid<I: Index, R: Real>(
2727
.global_marching_cubes_grid()
2828
.context("failed to convert global marching cubes grid")?;
2929

30-
// Filter "narrow band"
31-
/*
32-
let narrow_band_particles = extract_narrow_band(&parameters, &particles);
33-
let particles = narrow_band_particles;
34-
*/
35-
3630
let subdomains =
3731
decomposition::<I, R, GhostMarginClassifier<I>>(&internal_parameters, particle_positions)?;
3832

39-
/*
40-
{
41-
use super::dense_subdomains::debug::*;
42-
subdomain_stats(&parameters, &particle_positions, &subdomains);
43-
info!(
44-
"Number of subdomains with only ghost particles: {}",
45-
count_no_owned_particles_subdomains(&parameters, &particle_positions, &subdomains)
46-
);
47-
}
48-
*/
49-
5033
let (particle_densities, particle_neighbors) = compute_global_densities_and_neighbors(
5134
&internal_parameters,
5235
particle_positions,
@@ -70,6 +53,7 @@ pub(crate) fn reconstruct_surface_subdomain_grid<I: Index, R: Real>(
7053
output_surface.mesh = global_mesh;
7154
output_surface.particle_densities = Some(particle_densities);
7255
if parameters.global_neighborhood_list {
56+
// The global neighborhood list is only non-empty if requested from the user (requires merging)
7357
output_surface.particle_neighbors = Some(particle_neighbors);
7458
}
7559
Ok(())
@@ -92,15 +76,21 @@ pub(crate) fn reconstruct_surface_global<I: Index, R: Real>(
9276
.borrow_mut();
9377

9478
// Reuse allocated memory: swap particle densities from output object into the workspace if the former has a larger capacity
95-
if let Some(output_densities) = output_surface.particle_densities.as_ref() {
96-
if output_densities.capacity() > workspace.particle_densities.capacity() {
97-
std::mem::swap(
98-
output_surface.particle_densities.as_mut().unwrap(),
99-
&mut workspace.particle_densities,
100-
);
79+
fn swap_output_vec<T>(output_vec: &mut Option<Vec<T>>, workspace_vec: &mut Vec<T>) {
80+
if output_vec.as_ref().map(Vec::capacity).unwrap_or(0) > workspace_vec.capacity() {
81+
std::mem::swap(output_vec.as_mut().unwrap(), workspace_vec);
10182
}
10283
}
10384

85+
swap_output_vec(
86+
&mut output_surface.particle_densities,
87+
&mut workspace.particle_densities,
88+
);
89+
swap_output_vec(
90+
&mut output_surface.particle_neighbors,
91+
&mut workspace.particle_neighbor_lists,
92+
);
93+
10494
// Clear the current mesh, as reconstruction will be appended to output
10595
output_surface.mesh.clear();
10696
// Perform global reconstruction without domain decomposition
@@ -113,6 +103,8 @@ pub(crate) fn reconstruct_surface_global<I: Index, R: Real>(
113103
)?;
114104

115105
output_surface.particle_densities = Some(std::mem::take(&mut workspace.particle_densities));
106+
output_surface.particle_neighbors =
107+
Some(std::mem::take(&mut workspace.particle_neighbor_lists));
116108

117109
Ok(())
118110
}

0 commit comments

Comments
 (0)