pub struct NavierStokesGpu {
pub velocity: FluidGpuBuffer,
pub pressure: FluidGpuBuffer,
pub density: FluidGpuBuffer,
pub dx: f64,
pub viscosity: f64,
}Expand description
GPU (CPU mock) Navier-Stokes solver on a 3-D Cartesian grid.
Implements semi-Lagrangian advection, divergence, pressure projection via Jacobi iteration, and curl (vorticity) computation.
Fields§
§velocity: FluidGpuBufferVelocity field — 3 components (u, v, w) per cell.
pressure: FluidGpuBufferPressure field — 1 component per cell.
density: FluidGpuBufferDensity field — 1 component per cell.
dx: f64Grid cell size (m).
viscosity: f64Dynamic viscosity (Pa·s).
Implementations§
Sourcepub fn new(nx: usize, ny: usize, nz: usize, dx: f64, viscosity: f64) -> Self
pub fn new(nx: usize, ny: usize, nz: usize, dx: f64, viscosity: f64) -> Self
Create a new Navier-Stokes solver for a nx × ny × nz grid.
Sourcepub fn advect(&mut self, dt: f64)
pub fn advect(&mut self, dt: f64)
Semi-Lagrangian advection kernel (CPU mock).
Traces each cell centre backwards along the velocity field by dt
seconds and samples the field using trilinear interpolation.
Sourcepub fn divergence(&self) -> Vec<f64>
pub fn divergence(&self) -> Vec<f64>
Compute the divergence field into a flat Vecf64`.
result[z * ny * nx + y * nx + x] = divergence at cell (x, y, z).
Sourcepub fn pressure_projection(&mut self, iterations: usize)
pub fn pressure_projection(&mut self, iterations: usize)
Pressure projection: Jacobi iterations to enforce incompressibility.
Runs iterations steps of Jacobi Poisson solve, then subtracts the
pressure gradient from the velocity field.
Trait Implementations§
Source§fn clone(&self) -> NavierStokesGpu
fn clone(&self) -> NavierStokesGpu
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more