Skip to content

Commit f7c7004

Browse files
committed
Make extents for particle to grid evaluation safer
1 parent d35a49d commit f7c7004

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

splashsurf_lib/src/dense_subdomains.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -851,20 +851,21 @@ pub(crate) fn reconstruction<I: Index, R: Real>(
851851
// Compute lower and upper bounds of the grid points possibly affected by the particle
852852
// We want to loop over the vertices of the enclosing cells plus all points in `cube_radius` distance from the cell
853853

854-
let lower = [
855-
particle_cell[0].saturating_sub(&cube_radius).max(I::zero()),
856-
particle_cell[1].saturating_sub(&cube_radius).max(I::zero()),
857-
particle_cell[2].saturating_sub(&cube_radius).max(I::zero()),
858-
];
854+
let lower = [0, 1, 2].map(|i| {
855+
particle_cell[i]
856+
.saturating_sub(&cube_radius)
857+
.max(I::zero())
858+
.min(extents[i])
859+
});
859860

860-
let upper = [
861+
let upper = [0, 1, 2].map(|i| {
861862
// We add 2 because
862863
// - we want to loop over all grid points of the cell (+1 for upper points) + the radius
863864
// - the upper range limit is exclusive (+1)
864-
(particle_cell[0] + cube_radius + I::two()).min(extents[0]),
865-
(particle_cell[1] + cube_radius + I::two()).min(extents[1]),
866-
(particle_cell[2] + cube_radius + I::two()).min(extents[2]),
867-
];
865+
(particle_cell[i] + cube_radius + I::two())
866+
.min(extents[i])
867+
.max(I::zero())
868+
});
868869

869870
// Loop over all grid points around the enclosing cell
870871
for i in I::range(lower[0], upper[0]).iter() {
@@ -873,8 +874,6 @@ pub(crate) fn reconstruction<I: Index, R: Real>(
873874
let point_ijk = [i, j, k];
874875
let local_point = mc_grid
875876
.get_point(point_ijk)
876-
// TODO: Can this fail if the ghost margin is too large such that upper
877-
// falls outside of the subdomain grid?
878877
.expect("point has to be part of the subdomain grid");
879878
//let point_coordinates = mc_grid.point_coordinates(&point);
880879

@@ -1108,20 +1107,21 @@ pub(crate) fn reconstruction<I: Index, R: Real>(
11081107
// Compute lower and upper bounds of the grid points possibly affected by the particle
11091108
// We want to loop over the vertices of the enclosing cells plus all points in `cube_radius` distance from the cell
11101109

1111-
let lower = [
1112-
particle_cell[0].saturating_sub(&cube_radius).max(I::zero()),
1113-
particle_cell[1].saturating_sub(&cube_radius).max(I::zero()),
1114-
particle_cell[2].saturating_sub(&cube_radius).max(I::zero()),
1115-
];
1110+
let lower = [0, 1, 2].map(|i| {
1111+
particle_cell[i]
1112+
.saturating_sub(&cube_radius)
1113+
.max(I::zero())
1114+
.min(extents[i])
1115+
});
11161116

1117-
let upper = [
1117+
let upper = [0, 1, 2].map(|i| {
11181118
// We add 2 because
11191119
// - we want to loop over all grid points of the cell (+1 for upper points) + the radius
11201120
// - the upper range limit is exclusive (+1)
1121-
(particle_cell[0] + cube_radius + I::two()).min(extents[0]),
1122-
(particle_cell[1] + cube_radius + I::two()).min(extents[1]),
1123-
(particle_cell[2] + cube_radius + I::two()).min(extents[2]),
1124-
];
1121+
(particle_cell[i] + cube_radius + I::two())
1122+
.min(extents[i])
1123+
.max(I::zero())
1124+
});
11251125

11261126
// Loop over all grid points around the enclosing cell
11271127
for i in I::range(lower[0], upper[0]).iter() {
@@ -1318,6 +1318,8 @@ pub(crate) fn reconstruction<I: Index, R: Real>(
13181318
.copied()
13191319
.zip(subdomains.per_subdomain_particles.par_iter())
13201320
.map(|(flat_subdomain_idx, subdomain_particle_indices)| {
1321+
// TODO: Decision should consider size of compact support radius in relation to subdomain
1322+
// If support radius is huge, the dense method might be better even for few particles
13211323
if subdomain_particle_indices.len() <= sparse_limit {
13221324
profile!("subdomain reconstruction (sparse)", parent = parent);
13231325
reconstruct_sparse(flat_subdomain_idx, subdomain_particle_indices)

0 commit comments

Comments
 (0)