Skip to content

Commit 7ea4e53

Browse files
committed
Rename use_custom_grid_decomposition, add auto_disable_subdomain_grid
1 parent a2c36bd commit 7ea4e53

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

pysplashsurf/pysplashsurf/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ def reconstruct_surface(
209209
iso_surface_threshold: float = 0.6,
210210
enable_multi_threading: bool = False,
211211
global_neighborhood_list: bool = False,
212-
subdomain_grid: bool = False,
212+
subdomain_grid: bool = True,
213+
auto_disable_subdomain_grid: bool = True,
213214
subdomain_num_cubes_per_dim: int = 64,
214215
aabb_min = None,
215216
aabb_max = None,
@@ -245,7 +246,10 @@ def reconstruct_surface(
245246
Global neighborhood list flag
246247
247248
subdomain_grid: bool
248-
Enable spatial decomposition using a regular grid-based approach
249+
Enable spatial decomposition using by dividing the domain into subdomains with dense marching cube grids for efficient multi-threading
250+
251+
auto_disable_subdomain_grid: bool
252+
Whether to automatically disable the subdomain grid if the global domain is too small
249253
250254
subdomain_num_cubes_per_dim: int
251255
Each subdomain will be a cube consisting of this number of MC cube cells along each coordinate axis
@@ -267,13 +271,13 @@ def reconstruct_surface(
267271
return reconstruct_surface_f32(particles, particle_radius=particle_radius, rest_density=rest_density,
268272
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
269273
enable_multi_threading=enable_multi_threading, global_neighborhood_list=global_neighborhood_list,
270-
use_custom_grid_decomposition=subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
274+
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
271275
aabb_min=aabb_min, aabb_max=aabb_max)
272276
elif particles.dtype == 'float64':
273277
return reconstruct_surface_f64(particles, particle_radius=particle_radius, rest_density=rest_density,
274278
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
275279
enable_multi_threading=enable_multi_threading, global_neighborhood_list=global_neighborhood_list,
276-
use_custom_grid_decomposition=subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
280+
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
277281
aabb_min=aabb_min, aabb_max=aabb_max)
278282
else:
279283
raise ValueError("Invalid data type (only float32 and float64 are supported, consider explicitly specifying the dtype for particles)")
@@ -530,7 +534,7 @@ def reconstruction_pipeline(
530534
mesh_smoothing_weights_normalization=13.0, mesh_smoothing_iters=None, normals_smoothing_iters=None,
531535
mesh_cleanup=False, mesh_cleanup_snap_dist=None, decimate_barnacles=False, keep_vertices=False,
532536
compute_normals=False, output_raw_normals=False, output_raw_mesh=False, output_mesh_smoothing_weights=False, mesh_aabb_clamp_vertices=False,
533-
subdomain_grid=True, subdomain_num_cubes_per_dim=64, aabb_min=None, aabb_max=None, mesh_aabb_min=None, mesh_aabb_max=None,
537+
subdomain_grid=True, auto_disable_subdomain_grid=True, subdomain_num_cubes_per_dim=64, aabb_min=None, aabb_max=None, mesh_aabb_min=None, mesh_aabb_max=None,
534538
generate_quads=False, quad_max_edge_diag_ratio=1.75, quad_max_normal_angle=10.0, quad_max_interior_angle=135.0
535539
):
536540
"""Surface reconstruction based on particle positions with subsequent post-processing
@@ -622,7 +626,10 @@ def reconstruction_pipeline(
622626
Flag to clamp the vertices of the mesh to the AABB
623627
624628
subdomain_grid: bool
625-
Enables spatial decomposition using a regular grid-based approach
629+
Enable spatial decomposition using by dividing the domain into subdomains with dense marching cube grids for efficient multi-threading
630+
631+
auto_disable_subdomain_grid: bool
632+
Whether to automatically disable the subdomain grid if the global domain is too small
626633
627634
subdomain_num_cubes_per_dim: int
628635
Each subdomain will be a cube consisting of this number of MC cube cells along each coordinate axis
@@ -660,7 +667,7 @@ def reconstruction_pipeline(
660667
tri_mesh, tri_quad_mesh, reconstruction = reconstruction_pipeline_f32(particles, attributes_to_interpolate=attributes_to_interpolate, particle_radius=particle_radius, rest_density=rest_density,
661668
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
662669
aabb_min=aabb_min, aabb_max=aabb_max, enable_multi_threading=enable_multi_threading,
663-
use_custom_grid_decomposition=subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
670+
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
664671
check_mesh_closed=check_mesh_closed, check_mesh_manifold=check_mesh_manifold, check_mesh_orientation=check_mesh_orientation, check_mesh_debug=check_mesh_debug,
665672
mesh_cleanup=mesh_cleanup, max_rel_snap_dist=mesh_cleanup_snap_dist, decimate_barnacles=decimate_barnacles,
666673
keep_vertices=keep_vertices, compute_normals=compute_normals, sph_normals=sph_normals, normals_smoothing_iters=normals_smoothing_iters,
@@ -678,7 +685,7 @@ def reconstruction_pipeline(
678685
tri_mesh, tri_quad_mesh, reconstruction = reconstruction_pipeline_f64(particles, attributes_to_interpolate=attributes_to_interpolate, particle_radius=particle_radius, rest_density=rest_density,
679686
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
680687
aabb_min=aabb_min, aabb_max=aabb_max, enable_multi_threading=enable_multi_threading,
681-
use_custom_grid_decomposition=subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
688+
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
682689
check_mesh_closed=check_mesh_closed, check_mesh_manifold=check_mesh_manifold, check_mesh_orientation=check_mesh_orientation, check_mesh_debug=check_mesh_debug,
683690
mesh_cleanup=mesh_cleanup, max_rel_snap_dist=mesh_cleanup_snap_dist, decimate_barnacles=decimate_barnacles,
684691
keep_vertices=keep_vertices, compute_normals=compute_normals, sph_normals=sph_normals, normals_smoothing_iters=normals_smoothing_iters,

pysplashsurf/src/pipeline.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ fn reconstruction_pipeline_generic<I: Index, R: Real>(
2727
aabb_min: Option<[R; 3]>,
2828
aabb_max: Option<[R; 3]>,
2929
enable_multi_threading: bool,
30-
use_custom_grid_decomposition: bool,
30+
use_subdomain_grid: bool,
31+
auto_disable_subdomain_grid: bool,
3132
subdomain_num_cubes_per_dim: u32,
3233
check_mesh_closed: bool,
3334
check_mesh_manifold: bool,
@@ -64,10 +65,11 @@ fn reconstruction_pipeline_generic<I: Index, R: Real>(
6465
None
6566
};
6667

67-
let spatial_decomposition = if use_custom_grid_decomposition {
68-
let mut grid_params = GridDecompositionParameters::default();
69-
grid_params.subdomain_num_cubes_per_dim = subdomain_num_cubes_per_dim;
70-
SpatialDecomposition::UniformGrid(grid_params)
68+
let spatial_decomposition = if use_subdomain_grid {
69+
SpatialDecomposition::UniformGrid(GridDecompositionParameters {
70+
subdomain_num_cubes_per_dim,
71+
auto_disable: auto_disable_subdomain_grid,
72+
})
7173
} else {
7274
SpatialDecomposition::None
7375
};
@@ -180,7 +182,7 @@ fn attrs_conversion<R: Real + Element>(
180182
#[pyo3(signature = (particles, *, attributes_to_interpolate, particle_radius, rest_density,
181183
smoothing_length, cube_size, iso_surface_threshold,
182184
aabb_min = None, aabb_max = None, enable_multi_threading = false,
183-
use_custom_grid_decomposition = false, subdomain_num_cubes_per_dim = 64,
185+
use_subdomain_grid = true, auto_disable_subdomain_grid = true, subdomain_num_cubes_per_dim = 64,
184186
check_mesh_closed = false, check_mesh_manifold = false, check_mesh_orientation = false, check_mesh_debug = false,
185187
mesh_cleanup, max_rel_snap_dist = None, decimate_barnacles, keep_vertices, compute_normals, sph_normals,
186188
normals_smoothing_iters, mesh_smoothing_iters, mesh_smoothing_weights, mesh_smoothing_weights_normalization,
@@ -199,7 +201,8 @@ pub fn reconstruction_pipeline_py_f32<'py>(
199201
aabb_min: Option<[f32; 3]>,
200202
aabb_max: Option<[f32; 3]>,
201203
enable_multi_threading: bool,
202-
use_custom_grid_decomposition: bool,
204+
use_subdomain_grid: bool,
205+
auto_disable_subdomain_grid: bool,
203206
subdomain_num_cubes_per_dim: u32,
204207
check_mesh_closed: bool,
205208
check_mesh_manifold: bool,
@@ -252,7 +255,8 @@ pub fn reconstruction_pipeline_py_f32<'py>(
252255
aabb_min,
253256
aabb_max,
254257
enable_multi_threading,
255-
use_custom_grid_decomposition,
258+
use_subdomain_grid,
259+
auto_disable_subdomain_grid,
256260
subdomain_num_cubes_per_dim,
257261
check_mesh_closed,
258262
check_mesh_manifold,
@@ -293,7 +297,7 @@ pub fn reconstruction_pipeline_py_f32<'py>(
293297
#[pyo3(signature = (particles, *, attributes_to_interpolate, particle_radius, rest_density,
294298
smoothing_length, cube_size, iso_surface_threshold,
295299
aabb_min = None, aabb_max = None, enable_multi_threading = false,
296-
use_custom_grid_decomposition = false, subdomain_num_cubes_per_dim = 64,
300+
use_subdomain_grid = true, auto_disable_subdomain_grid = true, subdomain_num_cubes_per_dim = 64,
297301
check_mesh_closed = false, check_mesh_manifold = false, check_mesh_orientation = false, check_mesh_debug = false,
298302
mesh_cleanup, max_rel_snap_dist = None, decimate_barnacles, keep_vertices, compute_normals, sph_normals,
299303
normals_smoothing_iters, mesh_smoothing_iters, mesh_smoothing_weights, mesh_smoothing_weights_normalization,
@@ -312,7 +316,8 @@ pub fn reconstruction_pipeline_py_f64<'py>(
312316
aabb_min: Option<[f64; 3]>,
313317
aabb_max: Option<[f64; 3]>,
314318
enable_multi_threading: bool,
315-
use_custom_grid_decomposition: bool,
319+
use_subdomain_grid: bool,
320+
auto_disable_subdomain_grid: bool,
316321
subdomain_num_cubes_per_dim: u32,
317322
check_mesh_closed: bool,
318323
check_mesh_manifold: bool,
@@ -365,7 +370,8 @@ pub fn reconstruction_pipeline_py_f64<'py>(
365370
aabb_min,
366371
aabb_max,
367372
enable_multi_threading,
368-
use_custom_grid_decomposition,
373+
use_subdomain_grid,
374+
auto_disable_subdomain_grid,
369375
subdomain_num_cubes_per_dim,
370376
check_mesh_closed,
371377
check_mesh_manifold,

pysplashsurf/src/reconstruction.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ pub fn reconstruct_surface_py<I: Index, R: Real>(
7979
iso_surface_threshold: R,
8080
enable_multi_threading: bool,
8181
global_neighborhood_list: bool,
82-
use_custom_grid_decomposition: bool,
82+
use_subdomain_grid: bool,
83+
auto_disable_subdomain_grid: bool,
8384
subdomain_num_cubes_per_dim: u32,
8485
aabb_min: Option<[R; 3]>,
8586
aabb_max: Option<[R; 3]>,
@@ -96,10 +97,11 @@ pub fn reconstruct_surface_py<I: Index, R: Real>(
9697
}
9798

9899
let spatial_decomposition;
99-
if use_custom_grid_decomposition {
100-
let mut grid_params = GridDecompositionParameters::default();
101-
grid_params.subdomain_num_cubes_per_dim = subdomain_num_cubes_per_dim;
102-
spatial_decomposition = SpatialDecomposition::UniformGrid(grid_params);
100+
if use_subdomain_grid {
101+
spatial_decomposition = SpatialDecomposition::UniformGrid(GridDecompositionParameters {
102+
subdomain_num_cubes_per_dim,
103+
auto_disable: auto_disable_subdomain_grid,
104+
});
103105
} else {
104106
spatial_decomposition = SpatialDecomposition::None;
105107
}
@@ -126,7 +128,7 @@ pub fn reconstruct_surface_py<I: Index, R: Real>(
126128
#[pyo3(name = "reconstruct_surface_f32")]
127129
#[pyo3(signature = (particles, *, particle_radius, rest_density,
128130
smoothing_length, cube_size, iso_surface_threshold, enable_multi_threading=false,
129-
global_neighborhood_list=false, use_custom_grid_decomposition=false, subdomain_num_cubes_per_dim=64,
131+
global_neighborhood_list=false, use_subdomain_grid=true, auto_disable_subdomain_grid=true, subdomain_num_cubes_per_dim=64,
130132
aabb_min = None, aabb_max = None
131133
))]
132134
pub fn reconstruct_surface_py_f32<'py>(
@@ -138,7 +140,8 @@ pub fn reconstruct_surface_py_f32<'py>(
138140
iso_surface_threshold: f32,
139141
enable_multi_threading: bool,
140142
global_neighborhood_list: bool,
141-
use_custom_grid_decomposition: bool,
143+
use_subdomain_grid: bool,
144+
auto_disable_subdomain_grid: bool,
142145
subdomain_num_cubes_per_dim: u32,
143146
aabb_min: Option<[f32; 3]>,
144147
aabb_max: Option<[f32; 3]>,
@@ -157,7 +160,8 @@ pub fn reconstruct_surface_py_f32<'py>(
157160
iso_surface_threshold,
158161
enable_multi_threading,
159162
global_neighborhood_list,
160-
use_custom_grid_decomposition,
163+
use_subdomain_grid,
164+
auto_disable_subdomain_grid,
161165
subdomain_num_cubes_per_dim,
162166
aabb_min,
163167
aabb_max,
@@ -170,7 +174,7 @@ pub fn reconstruct_surface_py_f32<'py>(
170174
#[pyo3(name = "reconstruct_surface_f64")]
171175
#[pyo3(signature = (particles, *, particle_radius, rest_density,
172176
smoothing_length, cube_size, iso_surface_threshold, enable_multi_threading=false,
173-
global_neighborhood_list=false, use_custom_grid_decomposition=false, subdomain_num_cubes_per_dim=64,
177+
global_neighborhood_list=false, use_subdomain_grid=true, auto_disable_subdomain_grid=true, subdomain_num_cubes_per_dim=64,
174178
aabb_min = None, aabb_max = None
175179
))]
176180
pub fn reconstruct_surface_py_f64<'py>(
@@ -182,7 +186,8 @@ pub fn reconstruct_surface_py_f64<'py>(
182186
iso_surface_threshold: f64,
183187
enable_multi_threading: bool,
184188
global_neighborhood_list: bool,
185-
use_custom_grid_decomposition: bool,
189+
use_subdomain_grid: bool,
190+
auto_disable_subdomain_grid: bool,
186191
subdomain_num_cubes_per_dim: u32,
187192
aabb_min: Option<[f64; 3]>,
188193
aabb_max: Option<[f64; 3]>,
@@ -201,7 +206,8 @@ pub fn reconstruct_surface_py_f64<'py>(
201206
iso_surface_threshold,
202207
enable_multi_threading,
203208
global_neighborhood_list,
204-
use_custom_grid_decomposition,
209+
use_subdomain_grid,
210+
auto_disable_subdomain_grid,
205211
subdomain_num_cubes_per_dim,
206212
aabb_min,
207213
aabb_max,

0 commit comments

Comments
 (0)