Skip to main content

MacFluidGrid2D

Struct MacFluidGrid2D 

Source
pub struct MacFluidGrid2D { /* private fields */ }
Expand description

Incompressible 2D Eulerian staggered Marker-and-Cell (MAC) smoke/water/ink fluid grid solver.

Implementations§

Source§

impl MacFluidGrid2D

Simulation, injection, obstacle masking, projection, and visualization API for MacFluidGrid2D.

Source

pub fn from_config(nx: usize, ny: usize, config: MacFluidConfig) -> Self

Constructs a pre-allocated MacFluidGrid2D with dimensions (nx, ny) and physical config config.

§Arguments
  • usize - Horizontal cell count nx.
  • usize - Vertical cell count ny.
  • MacFluidConfig - Physical and numerical solver configuration.
§Returns
  • Self - Pre-allocated zero-steady-state-allocation 2D MAC solver.
Source

pub fn reset(&mut self)

Clears velocities, dye, pressure, and temperature back to rest while keeping solid obstacles intact.

Source

pub fn set_solid_rect( &mut self, min_x: usize, min_y: usize, max_x: usize, max_y: usize, is_solid: bool, )

Marks or clears a rectangular obstacle region in cell coordinates [min_x..=max_x] × [min_y..=max_y].

§Arguments
  • usize - Minimum column index.
  • usize - Minimum row index.
  • usize - Maximum column index (inclusive).
  • usize - Maximum row index (inclusive).
  • bool - true to mark cells solid, false to restore fluid.
Source

pub fn set_solid_circle( &mut self, cx: f32, cy: f32, radius_cells: f32, is_solid: bool, )

Marks or clears a circular obstacle disk in cell-center coordinates.

§Arguments
  • f32 - Disk center X in grid cells.
  • f32 - Disk center Y in grid cells.
  • f32 - Disk radius in grid cells.
  • bool - true to mark cells solid, false to restore fluid.
Source

pub fn inject_source( &mut self, center_cell: Vec2, radius_cells: f32, velocity_delta: Vec2, dye_amount: f32, heat_amount: f32, )

Injects velocity, dye concentration, and heat into fluid cells within a circular nozzle footprint.

§Arguments
  • Vec2 - Nozzle center (cx, cy) in grid-cell coordinates.
  • f32 - Nozzle radius in grid cells.
  • Vec2 - Velocity impulse (dvx, dvy) added in meters per second.
  • f32 - Dye concentration increment.
  • f32 - Temperature increment above ambient.
Source

pub fn project_incompressible(&mut self)

Runs standalone incompressible pressure projection (div(u) -> 0) without advancing advection.

Source

pub fn step(&mut self, dt_secs: f32)

Advances the 2D Eulerian MAC fluid grid (advection, buoyancy, vorticity confinement, solid walls, and incompressible projection) with zero steady-state allocations.

§Arguments
  • f32 - Frame step duration in seconds.
Source

pub fn max_divergence(&self) -> f32

Computes the maximum absolute discrete velocity divergence max |div(u)| across all fluid cells.

§Returns
  • f32 - Maximum |div(u)| in s^-1.
Source

pub fn sample_velocity(&self, gx: f32, gy: f32) -> Vec2

Samples the bilinearly interpolated velocity (u, v) at continuous cell coordinates (gx, gy).

§Arguments
  • f32 - Continuous X cell coordinate in [0, nx].
  • f32 - Continuous Y cell coordinate in [0, ny].
§Returns
  • Vec2 - Velocity vector in meters per second.
Source

pub fn sample_dye(&self, gx: f32, gy: f32) -> f32

Samples the bilinearly interpolated dye concentration at continuous cell coordinates (gx, gy).

§Arguments
  • f32 - Continuous X cell coordinate.
  • f32 - Continuous Y cell coordinate.
§Returns
  • f32 - Non-negative dye density.
Source

pub fn render_dye_rgba8(&self, out_rgba: &mut [u8])

Renders the 2D dye, heat, and solid obstacle field into an RGBA8 pixel buffer (nx * ny * 4 bytes).

§Arguments
  • &mut [u8] - Destination RGBA8 buffer of length >= nx * ny * 4.
Source

pub fn render_dye_rgba8_scaled( &self, width: u32, height: u32, out_rgba: &mut [u8], )

Renders the 2D dye, heat, vorticity curl, and smooth obstacle field into a crisp high-resolution RGBA8 framebuffer using bicubic Catmull-Rom interpolation.

§Arguments
  • u32 - Destination image width in pixels (>= 1).
  • u32 - Destination image height in pixels (>= 1).
  • &mut [u8] - Destination RGBA8 buffer of length >= width * height * 4.
Source§

impl MacFluidGrid2D

Implements impl #impl_generics #name #ty_generics #where_clause.

Source

pub fn get_nx(&self) -> usize

Source

pub fn get_mut_nx(&mut self) -> &mut usize

Source

pub fn set_nx(&mut self, val: usize) -> &mut Self

Source

pub fn get_ny(&self) -> usize

Source

pub fn get_mut_ny(&mut self) -> &mut usize

Source

pub fn set_ny(&mut self, val: usize) -> &mut Self

Source

pub fn get_config(&self) -> MacFluidConfig

Source

pub fn get_mut_config(&mut self) -> &mut MacFluidConfig

Source

pub fn set_config(&mut self, val: MacFluidConfig) -> &mut Self

Source

pub fn get_u(&self) -> &Vec<f32>

Source

pub fn get_mut_u(&mut self) -> &mut Vec<f32>

Source

pub fn set_u(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_v(&self) -> &Vec<f32>

Source

pub fn get_mut_v(&mut self) -> &mut Vec<f32>

Source

pub fn set_v(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_pressure(&self) -> &Vec<f32>

Source

pub fn get_mut_pressure(&mut self) -> &mut Vec<f32>

Source

pub fn set_pressure(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_divergence(&self) -> &Vec<f32>

Source

pub fn get_mut_divergence(&mut self) -> &mut Vec<f32>

Source

pub fn set_divergence(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_dye(&self) -> &Vec<f32>

Source

pub fn get_mut_dye(&mut self) -> &mut Vec<f32>

Source

pub fn set_dye(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_temperature(&self) -> &Vec<f32>

Source

pub fn get_mut_temperature(&mut self) -> &mut Vec<f32>

Source

pub fn set_temperature(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_solid(&self) -> &Vec<u8> ⓘ

Source

pub fn get_mut_solid(&mut self) -> &mut Vec<u8> ⓘ

Source

pub fn set_solid(&mut self, val: Vec<u8>) -> &mut Self

Source

pub fn get_scratch(&self) -> &MacScratch2D

Source

pub fn get_mut_scratch(&mut self) -> &mut MacScratch2D

Source

pub fn set_scratch(&mut self, val: MacScratch2D) -> &mut Self

Source

pub fn get_sim_time_secs(&self) -> f32

Source

pub fn get_mut_sim_time_secs(&mut self) -> &mut f32

Source

pub fn set_sim_time_secs(&mut self, val: f32) -> &mut Self

Trait Implementations§

Source§

impl Clone for MacFluidGrid2D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MacFluidGrid2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MacFluidGrid2D

Default 32 × 32 incompressible 2D MAC fluid grid.

Source§

fn default() -> Self

Creates a 32 × 32 MacFluidGrid2D with MacFluidConfig::default().

§Returns
  • Self - Ready pre-allocated 2D MAC grid solver.
Source§

impl PartialEq for MacFluidGrid2D

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MacFluidGrid2D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.