pub struct MacGrid {
pub nx: usize,
pub ny: usize,
pub dx: f64,
pub cells: Vec<MacCell>,
}Expand description
A 2-D Marker-and-Cell (MAC) grid for incompressible fluid simulation.
The grid is stored in row-major order: cells[j * nx + i] is column i,
row j.
Fields§
§nx: usizeNumber of cells in the x direction.
ny: usizeNumber of cells in the y direction.
dx: f64Cell width / height (uniform, square cells, m).
cells: Vec<MacCell>Flat cell storage (ny * nx entries).
Implementations§
Source§impl MacGrid
impl MacGrid
Sourcepub fn new(nx: usize, ny: usize, dx: f64) -> Self
pub fn new(nx: usize, ny: usize, dx: f64) -> Self
Create a new MAC grid filled with default (fluid) cells.
Sourcepub fn cell(&self, i: usize, j: usize) -> &MacCell
pub fn cell(&self, i: usize, j: usize) -> &MacCell
Return a shared reference to the cell at column i, row j.
Sourcepub fn cell_mut(&mut self, i: usize, j: usize) -> &mut MacCell
pub fn cell_mut(&mut self, i: usize, j: usize) -> &mut MacCell
Return a mutable reference to the cell at column i, row j.
Sourcepub fn divergence(&self, i: usize, j: usize) -> f64
pub fn divergence(&self, i: usize, j: usize) -> f64
Discrete divergence of velocity at cell (i, j).
Uses the MAC staggered layout: east-face minus west-face for u_x,
north-face minus south-face for u_y. Boundary faces are treated as
zero (no-flux).
Sourcepub fn pressure_solve_jacobi(&mut self, n_iter: usize)
pub fn pressure_solve_jacobi(&mut self, n_iter: usize)
Jacobi iteration pressure solve for the Poisson equation ∇²p = ρ/Δt · ∇·u.
n_iter sweeps are performed. Boundary cells keep zero pressure.
Sourcepub fn advect_velocity(&mut self, dt: f64)
pub fn advect_velocity(&mut self, dt: f64)
Semi-Lagrangian advection of velocity components.
Each face velocity is traced back by dt seconds and the value at the
departure point is interpolated bilinearly.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MacGrid
impl RefUnwindSafe for MacGrid
impl Send for MacGrid
impl Sync for MacGrid
impl Unpin for MacGrid
impl UnsafeUnpin for MacGrid
impl UnwindSafe for MacGrid
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