pub struct PySphSimulation { /* private fields */ }Expand description
A 3-D weakly-compressible SPH fluid simulation.
Particles are integrated with forward Euler and use Tait’s equation of state (p = k * (ρ/ρ₀ - 1)) for pressure. Supports an optional flat floor boundary.
Implementations§
Source§impl PySphSimulation
impl PySphSimulation
Sourcepub fn new(config: PySphConfig) -> Self
pub fn new(config: PySphConfig) -> Self
Create an empty SPH simulation with the given configuration.
Sourcepub fn add_particle(&mut self, pos: [f64; 3]) -> usize
pub fn add_particle(&mut self, pos: [f64; 3]) -> usize
Add a particle at pos with zero velocity. Returns the particle index.
Sourcepub fn add_particle_with_velocity(
&mut self,
pos: [f64; 3],
vel: [f64; 3],
) -> usize
pub fn add_particle_with_velocity( &mut self, pos: [f64; 3], vel: [f64; 3], ) -> usize
Add a particle at pos with the given initial velocity.
Sourcepub fn add_particle_block(
&mut self,
origin: [f64; 3],
nx: usize,
ny: usize,
nz: usize,
dx: f64,
)
pub fn add_particle_block( &mut self, origin: [f64; 3], nx: usize, ny: usize, nz: usize, dx: f64, )
Add nx * ny * nz particles in a 3-D lattice starting at origin,
with inter-particle spacing dx.
Sourcepub fn particle_count(&self) -> usize
pub fn particle_count(&self) -> usize
Number of particles.
Sourcepub fn position(&self, i: usize) -> Option<[f64; 3]>
pub fn position(&self, i: usize) -> Option<[f64; 3]>
Position of particle i, or None if out of bounds.
Sourcepub fn velocity(&self, i: usize) -> Option<[f64; 3]>
pub fn velocity(&self, i: usize) -> Option<[f64; 3]>
Velocity of particle i, or None if out of bounds.
Sourcepub fn density(&self, i: usize) -> Option<f64>
pub fn density(&self, i: usize) -> Option<f64>
Density of particle i, or None if out of bounds.
Sourcepub fn step_count(&self) -> u64
pub fn step_count(&self) -> u64
Number of completed steps.
Sourcepub fn all_positions(&self) -> Vec<f64>
pub fn all_positions(&self) -> Vec<f64>
Return all positions as a flat Vecf64` (length = 3 * particle_count).
Sourcepub fn all_velocities(&self) -> Vec<f64>
pub fn all_velocities(&self) -> Vec<f64>
Return all velocities as a flat Vecf64` (length = 3 * particle_count).
Sourcepub fn get_density_field(&self) -> Vec<f64>
pub fn get_density_field(&self) -> Vec<f64>
Return all densities as a Vecf64` (length = particle_count).
Sourcepub fn get_pressure_field(&self) -> Vec<f64>
pub fn get_pressure_field(&self) -> Vec<f64>
Return all pressures as a Vecf64`.
Sourcepub fn mean_density(&self) -> f64
pub fn mean_density(&self) -> f64
Average density over all particles.
Source§impl PySphSimulation
impl PySphSimulation
Sourcepub fn neighbors(&self, i: usize, r: f64) -> Option<Vec<usize>>
pub fn neighbors(&self, i: usize, r: f64) -> Option<Vec<usize>>
Return the indices of all particles within distance r of particle i.
Returns None if i is out of bounds.
Sourcepub fn neighbor_count(&self, i: usize, r: f64) -> Option<usize>
pub fn neighbor_count(&self, i: usize, r: f64) -> Option<usize>
Count of neighbors of particle i within radius r.
Sourcepub fn closest_neighbor(&self, i: usize) -> Option<(usize, f64)>
pub fn closest_neighbor(&self, i: usize) -> Option<(usize, f64)>
Return the index and distance of the closest neighbor to particle i.
Returns None if i is out of bounds or there are no other particles.
Sourcepub fn center_of_mass(&self) -> [f64; 3]
pub fn center_of_mass(&self) -> [f64; 3]
Return the center of mass of all particles.
Sourcepub fn kinetic_energy(&self) -> f64
pub fn kinetic_energy(&self) -> f64
Total kinetic energy of the particle system.
Sourcepub fn max_density(&self) -> f64
pub fn max_density(&self) -> f64
Maximum density among all particles.
Sourcepub fn min_density(&self) -> f64
pub fn min_density(&self) -> f64
Minimum density among all particles.
Sourcepub fn particle_aabb(&self) -> Option<[f64; 6]>
pub fn particle_aabb(&self) -> Option<[f64; 6]>
Return the AABB of all particle positions as [xmin, ymin, zmin, xmax, ymax, zmax].
Returns None if there are no particles.
Sourcepub fn remove_below_y(&mut self, y_min: f64) -> usize
pub fn remove_below_y(&mut self, y_min: f64) -> usize
Remove all particles below a given y-coordinate.
Returns the number of particles removed.
Source§impl PySphSimulation
impl PySphSimulation
Sourcepub fn collect_stats(&self) -> SphStats
pub fn collect_stats(&self) -> SphStats
Collect per-step statistics into a SphStats struct.
Source§impl PySphSimulation
impl PySphSimulation
Sourcepub fn adaptive_h(&self, i: usize, k: usize) -> Option<f64>
pub fn adaptive_h(&self, i: usize, k: usize) -> Option<f64>
Estimate an adaptive smoothing length for particle i based on the
distance to its k-th nearest neighbor (default k=8).
Returns None if i is out of bounds or there are fewer than k other
particles.
Sourcepub fn global_adaptive_h(&self, k: usize) -> Option<f64>
pub fn global_adaptive_h(&self, k: usize) -> Option<f64>
Estimate a global adaptive h as the median of all per-particle adaptive h values.
Source§impl PySphSimulation
impl PySphSimulation
Sourcepub fn detect_surface_particles(&self, r: f64, threshold: usize) -> Vec<bool>
pub fn detect_surface_particles(&self, r: f64, threshold: usize) -> Vec<bool>
Detect surface particles using the color-field divergence method.
A particle i is classified as a surface particle if the number of
neighbors within radius r is below threshold.
Returns a Vecboolof lengthparticle_count()`.
Source§impl PySphSimulation
impl PySphSimulation
Sourcepub fn add_particles(&mut self, positions: &[[f64; 3]]) -> Range<usize>
pub fn add_particles(&mut self, positions: &[[f64; 3]]) -> Range<usize>
Bulk-add a list of positions, returning the range of newly added indices.
Sourcepub fn set_velocity(&mut self, i: usize, vel: [f64; 3])
pub fn set_velocity(&mut self, i: usize, vel: [f64; 3])
Set velocity of particle i. No-op if out of bounds.
Sourcepub fn apply_global_impulse(&mut self, dv: [f64; 3])
pub fn apply_global_impulse(&mut self, dv: [f64; 3])
Apply a uniform velocity impulse \[dvx, dvy, dvz\] to all particles.
Sourcepub fn clamp_velocities(&mut self, max_speed: f64)
pub fn clamp_velocities(&mut self, max_speed: f64)
Clamp all particle velocities to max_speed.
Sourcepub fn total_momentum(&self) -> [f64; 3]
pub fn total_momentum(&self) -> [f64; 3]
Total linear momentum \[px, py, pz\] of all particles.
Sourcepub fn density_variance(&self) -> f64
pub fn density_variance(&self) -> f64
Variance of the density field (measure of compressibility error).
Trait Implementations§
Source§impl Clone for PySphSimulation
impl Clone for PySphSimulation
Source§fn clone(&self) -> PySphSimulation
fn clone(&self) -> PySphSimulation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PySphSimulation
impl RefUnwindSafe for PySphSimulation
impl Send for PySphSimulation
impl Sync for PySphSimulation
impl Unpin for PySphSimulation
impl UnsafeUnpin for PySphSimulation
impl UnwindSafe for PySphSimulation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.