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.
impl MacFluidGrid2D
Simulation, injection, obstacle masking, projection, and visualization API for MacFluidGrid2D.
Sourcepub fn from_config(nx: usize, ny: usize, config: MacFluidConfig) -> Self
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 countnx.usize- Vertical cell countny.MacFluidConfig- Physical and numerical solver configuration.
§Returns
Self- Pre-allocated zero-steady-state-allocation 2D MAC solver.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clears velocities, dye, pressure, and temperature back to rest while keeping solid obstacles intact.
Sourcepub fn set_solid_rect(
&mut self,
min_x: usize,
min_y: usize,
max_x: usize,
max_y: usize,
is_solid: bool,
)
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-trueto mark cells solid,falseto restore fluid.
Sourcepub fn set_solid_circle(
&mut self,
cx: f32,
cy: f32,
radius_cells: f32,
is_solid: bool,
)
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-trueto mark cells solid,falseto restore fluid.
Sourcepub fn inject_source(
&mut self,
center_cell: Vec2,
radius_cells: f32,
velocity_delta: Vec2,
dye_amount: f32,
heat_amount: f32,
)
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.
Sourcepub fn project_incompressible(&mut self)
pub fn project_incompressible(&mut self)
Runs standalone incompressible pressure projection (div(u) -> 0) without advancing advection.
Sourcepub fn step(&mut self, dt_secs: f32)
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.
Sourcepub fn max_divergence(&self) -> f32
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)|ins^-1.
Sourcepub fn sample_velocity(&self, gx: f32, gy: f32) -> Vec2
pub fn sample_velocity(&self, gx: f32, gy: f32) -> Vec2
Sourcepub fn sample_dye(&self, gx: f32, gy: f32) -> f32
pub fn sample_dye(&self, gx: f32, gy: f32) -> f32
Sourcepub fn render_dye_rgba8(&self, out_rgba: &mut [u8])
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§impl MacFluidGrid2D
Implements impl #impl_generics #name #ty_generics #where_clause.
impl MacFluidGrid2D
Implements impl #impl_generics #name #ty_generics #where_clause.
pub fn get_nx(&self) -> usize
pub fn get_mut_nx(&mut self) -> &mut usize
pub fn set_nx(&mut self, val: usize) -> &mut Self
pub fn get_ny(&self) -> usize
pub fn get_mut_ny(&mut self) -> &mut usize
pub fn set_ny(&mut self, val: usize) -> &mut Self
pub fn get_config(&self) -> MacFluidConfig
pub fn get_mut_config(&mut self) -> &mut MacFluidConfig
pub fn set_config(&mut self, val: MacFluidConfig) -> &mut Self
pub fn get_u(&self) -> &Vec<f32>
pub fn get_mut_u(&mut self) -> &mut Vec<f32>
pub fn set_u(&mut self, val: Vec<f32>) -> &mut Self
pub fn get_v(&self) -> &Vec<f32>
pub fn get_mut_v(&mut self) -> &mut Vec<f32>
pub fn set_v(&mut self, val: Vec<f32>) -> &mut Self
pub fn get_pressure(&self) -> &Vec<f32>
pub fn get_mut_pressure(&mut self) -> &mut Vec<f32>
pub fn set_pressure(&mut self, val: Vec<f32>) -> &mut Self
pub fn get_divergence(&self) -> &Vec<f32>
pub fn get_mut_divergence(&mut self) -> &mut Vec<f32>
pub fn set_divergence(&mut self, val: Vec<f32>) -> &mut Self
pub fn get_dye(&self) -> &Vec<f32>
pub fn get_mut_dye(&mut self) -> &mut Vec<f32>
pub fn set_dye(&mut self, val: Vec<f32>) -> &mut Self
pub fn get_temperature(&self) -> &Vec<f32>
pub fn get_mut_temperature(&mut self) -> &mut Vec<f32>
pub fn set_temperature(&mut self, val: Vec<f32>) -> &mut Self
pub fn get_solid(&self) -> &Vec<u8> ⓘ
pub fn get_mut_solid(&mut self) -> &mut Vec<u8> ⓘ
pub fn set_solid(&mut self, val: Vec<u8>) -> &mut Self
pub fn get_scratch(&self) -> &MacScratch2D
pub fn get_mut_scratch(&mut self) -> &mut MacScratch2D
pub fn set_scratch(&mut self, val: MacScratch2D) -> &mut Self
pub fn get_sim_time_secs(&self) -> f32
pub fn get_mut_sim_time_secs(&mut self) -> &mut f32
pub fn set_sim_time_secs(&mut self, val: f32) -> &mut Self
Trait Implementations§
Source§impl Clone for MacFluidGrid2D
impl Clone for MacFluidGrid2D
Source§impl Debug for MacFluidGrid2D
impl Debug for MacFluidGrid2D
Source§impl Default for MacFluidGrid2D
Default 32 × 32 incompressible 2D MAC fluid grid.
impl Default for MacFluidGrid2D
Default 32 × 32 incompressible 2D MAC fluid grid.