pub struct GpuEulerGrid {
pub nx: usize,
pub ny: usize,
pub nz: usize,
pub dx: f64,
pub rho: Vec<f64>,
pub u: Vec<f64>,
pub v: Vec<f64>,
pub w: Vec<f64>,
pub p: Vec<f64>,
}Expand description
A 3-D staggered MAC grid for Eulerian fluid simulation.
Velocity components are face-centred; pressure and density are cell-centred.
Fields§
§nx: usizeNumber of cells in x.
ny: usizeNumber of cells in y.
nz: usizeNumber of cells in z.
dx: f64Grid spacing (m).
rho: Vec<f64>Cell-centred density (kg/m³).
u: Vec<f64>x-face velocity (m/s), size (nx+1)·ny·nz.
v: Vec<f64>y-face velocity (m/s), size nx·(ny+1)·nz.
w: Vec<f64>z-face velocity (m/s), size nx·ny·(nz+1).
p: Vec<f64>Cell-centred pressure (Pa).
Implementations§
Source§impl GpuEulerGrid
impl GpuEulerGrid
Sourcepub fn new(nx: usize, ny: usize, nz: usize, dx: f64) -> Self
pub fn new(nx: usize, ny: usize, nz: usize, dx: f64) -> Self
Create a new GpuEulerGrid with nx × ny × nz cells and spacing dx.
Sourcepub fn cell_count(&self) -> usize
pub fn cell_count(&self) -> usize
Total number of cells.
Sourcepub fn max_velocity(&self) -> f64
pub fn max_velocity(&self) -> f64
Maximum speed over all velocity components.
Sourcepub fn cfl_timestep(&self, cfl: f64) -> f64
pub fn cfl_timestep(&self, cfl: f64) -> f64
CFL-safe time step: cfl · dx / max_velocity (or dx if velocity is zero).
Sourcepub fn gpu_apply_gravity(&mut self, gravity: f64, dt: f64)
pub fn gpu_apply_gravity(&mut self, gravity: f64, dt: f64)
Apply gravitational acceleration to the v (y) velocity field.
Sourcepub fn gpu_compute_divergence(&self) -> Vec<f64>
pub fn gpu_compute_divergence(&self) -> Vec<f64>
Compute the divergence field ∇·u at every cell.
Sourcepub fn divergence_at(&self, i: usize, j: usize, k: usize) -> f64
pub fn divergence_at(&self, i: usize, j: usize, k: usize) -> f64
Local divergence at cell (i, j, k).
Sourcepub fn vorticity_at(&self, i: usize, j: usize, k: usize) -> [f64; 3]
pub fn vorticity_at(&self, i: usize, j: usize, k: usize) -> [f64; 3]
Local vorticity (curl of velocity) at cell (i, j, k).
Returns [ωx, ωy, ωz] using central differences.
Sourcepub fn gpu_enforce_solid_bc(&mut self)
pub fn gpu_enforce_solid_bc(&mut self)
Zero normal velocities at domain boundaries (solid wall BC).
Sourcepub fn gpu_pressure_projection(&mut self, max_iter: usize, tol: f64) -> f64
pub fn gpu_pressure_projection(&mut self, max_iter: usize, tol: f64) -> f64
Jacobi pressure projection to enforce incompressibility.
Iterates up to max_iter times; returns the final L-inf residual.
Sourcepub fn gpu_update_velocity_from_pressure(&mut self, dt: f64)
pub fn gpu_update_velocity_from_pressure(&mut self, dt: f64)
Update velocity from pressure gradient: u -= dt · ∇p.
Sourcepub fn gpu_advect_semi_lagrange(&mut self, dt: f64)
pub fn gpu_advect_semi_lagrange(&mut self, dt: f64)
Semi-Lagrangian advection of velocity (first-order back-trace).
Sourcepub fn gpu_vorticity_confinement(&mut self, epsilon: f64)
pub fn gpu_vorticity_confinement(&mut self, epsilon: f64)
Vorticity confinement: adds a force proportional to epsilon toward
regions of high vorticity to counteract numerical diffusion.
Sourcepub fn compute_stats(&self) -> FluidSimStats
pub fn compute_stats(&self) -> FluidSimStats
Compute simulation diagnostics.
Trait Implementations§
Source§impl Clone for GpuEulerGrid
impl Clone for GpuEulerGrid
Source§fn clone(&self) -> GpuEulerGrid
fn clone(&self) -> GpuEulerGrid
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for GpuEulerGrid
impl RefUnwindSafe for GpuEulerGrid
impl Send for GpuEulerGrid
impl Sync for GpuEulerGrid
impl Unpin for GpuEulerGrid
impl UnsafeUnpin for GpuEulerGrid
impl UnwindSafe for GpuEulerGrid
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