Skip to content

Commit

Permalink
Documentation, small refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
w1th0utnam3 committed Jul 26, 2023
1 parent 67f9c4e commit 4c0ea27
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 205 deletions.
5 changes: 5 additions & 0 deletions splashsurf/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! The `splashsurf` surface reconstruction CLI.
//!
//! For documentation of the CLI see the [README](https://github.com/InteractiveComputerGraphics/splashsurf) in the project repository.
//! The reconstruction procedure and other internals of the CLI are provided by the [`splashsurf_lib`] crate.

mod convert;
mod io;
mod reconstruction;
Expand Down
4 changes: 2 additions & 2 deletions splashsurf_lib/src/dense_subdomains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ pub(crate) fn compute_global_density_vector<I: Index, R: Real>(
&subdomain_particles,
parameters.compact_support_radius,
neighborhood_lists,
is_inside,
|i| is_inside[i],
);

sequential_compute_particle_densities_filtered::<I, R, _>(
Expand All @@ -576,7 +576,7 @@ pub(crate) fn compute_global_density_vector<I: Index, R: Real>(
parameters.compact_support_radius,
parameters.particle_rest_mass,
particle_densities,
is_inside,
|i| is_inside[i],
);

// Write particle densities into global storage
Expand Down
44 changes: 19 additions & 25 deletions splashsurf_lib/src/density_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn compute_particle_densities<I: Index, R: Real>(
&mut densities,
)
} else {
sequential_compute_particle_densities::<I, R>(
sequential_compute_particle_densities::<I, R, _>(
particle_positions,
particle_neighbor_lists,
compact_support_radius,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn compute_particle_densities_inplace<I: Index, R: Real>(
densities,
)
} else {
sequential_compute_particle_densities::<I, R>(
sequential_compute_particle_densities::<I, R, _>(
particle_positions,
particle_neighbor_lists,
compact_support_radius,
Expand All @@ -120,43 +120,37 @@ fn init_density_storage<R: Real>(densities: &mut Vec<R>, new_len: usize) {

/// Computes the individual densities of particles using a standard SPH sum, sequential implementation
#[inline(never)]
pub fn sequential_compute_particle_densities<I: Index, R: Real>(
pub fn sequential_compute_particle_densities<I: Index, R: Real, Nl: NeighborhoodList + ?Sized>(
particle_positions: &[Vector3<R>],
particle_neighbor_lists: &[Vec<usize>],
particle_neighbor_lists: &Nl,
compact_support_radius: R,
particle_rest_mass: R,
particle_densities: &mut Vec<R>,
) {
profile!("sequential_compute_particle_densities");

init_density_storage(particle_densities, particle_positions.len());

// Pre-compute the kernel which can be queried using squared distances
let kernel = DiscreteSquaredDistanceCubicKernel::new::<f64>(1000, compact_support_radius);

for (i, (particle_i_position, particle_i_neighbors)) in particle_positions
.iter()
.zip(particle_neighbor_lists.iter())
.enumerate()
{
let mut particle_i_density = kernel.evaluate(R::zero());
for particle_j_position in particle_i_neighbors.iter().map(|&j| &particle_positions[j]) {
let r_squared = (particle_j_position - particle_i_position).norm_squared();
particle_i_density += kernel.evaluate(r_squared);
}
particle_i_density *= particle_rest_mass;
particle_densities[i] = particle_i_density;
}
sequential_compute_particle_densities_filtered::<I, R, Nl>(
particle_positions,
particle_neighbor_lists,
compact_support_radius,
particle_rest_mass,
particle_densities,
|_| true,
)
}

#[inline(never)]
pub fn sequential_compute_particle_densities_filtered<I: Index, R: Real, Nl: NeighborhoodList>(
pub fn sequential_compute_particle_densities_filtered<
I: Index,
R: Real,
Nl: NeighborhoodList + ?Sized,
>(
particle_positions: &[Vector3<R>],
particle_neighbor_lists: &Nl,
compact_support_radius: R,
particle_rest_mass: R,
particle_densities: &mut Vec<R>,
filter: &[bool],
filter: impl Fn(usize) -> bool,
) {
profile!("sequential_compute_particle_densities_filtered");

Expand All @@ -168,7 +162,7 @@ pub fn sequential_compute_particle_densities_filtered<I: Index, R: Real, Nl: Nei
for (i, particle_i_position) in particle_positions
.iter()
.enumerate()
.filter(|(i, _)| filter[*i])
.filter(|(i, _)| filter(*i))
{
let mut particle_i_density = kernel.evaluate(R::zero());
for particle_j_position in particle_neighbor_lists
Expand Down
4 changes: 2 additions & 2 deletions splashsurf_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! It is disabled by default because a pure "online" surface reconstruction might not need any file IO.
//! The feature adds several dependencies to support the file formats.
//! - **`profiling`**: Enables profiling of internal functions. The resulting data can be displayed using the functions
//! from the [`profiling`] module. Furthermore, it exposes the [`profile`] macro that can be used e.g.
//! from the [`profiling`] module of this crate. Furthermore, it exposes the [`profile`] macro that can be used e.g.
//! by binary crates calling into this library to add their own profiling scopes to the measurements.
//! If this features is not enabled, the macro will just expend to a no-op and remove the (small)
//! performance overhead of the profiling.
Expand Down Expand Up @@ -64,7 +64,7 @@ pub mod marching_cubes;
pub mod mesh;
pub mod neighborhood_search;
pub mod octree;
pub mod reconstruction;
pub(crate) mod reconstruction;
mod reconstruction_octree;
pub mod sph_interpolation;
pub mod topology;
Expand Down
Loading

0 comments on commit 4c0ea27

Please sign in to comment.