euv-core 0.57.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Declarative physical and numerical configuration for `MacFluidGrid2D` and `MacFluidGrid3D`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct MacFluidConfig {
    /// Uniform physical cell spacing `dx` in meters.
    #[get(type(copy))]
    pub(crate) cell_size_m: f32,
    /// Velocity/scalar advection scheme (`SemiLagrangian` or `MacCormack`).
    #[get(type(copy))]
    pub(crate) advection: AdvectionScheme,
    /// Incompressible pressure Poisson solver (`RedBlackGaussSeidel` or `ConjugateGradient`).
    #[get(type(copy))]
    pub(crate) pressure_solver: PressureSolverMode,
    /// Maximum pressure solver iterations executed per projection.
    #[get(type(copy))]
    pub(crate) pressure_iterations: u32,
    /// Thermal buoyancy strength (`+Y` acceleration per unit temperature above `ambient_temperature`).
    #[get(type(copy))]
    pub(crate) thermal_buoyancy: f32,
    /// Ambient reference temperature used by thermal buoyancy.
    #[get(type(copy))]
    pub(crate) ambient_temperature: f32,
    /// Dense dye/smoke downward gravity coefficient along `-Y`.
    #[get(type(copy))]
    pub(crate) dye_gravity: f32,
    /// Vorticity confinement coefficient preserving small-scale eddies.
    #[get(type(copy))]
    pub(crate) vorticity_epsilon: f32,
    /// Exponential dye/density fade rate per second.
    #[get(type(copy))]
    pub(crate) dye_dissipation: f32,
    /// Exponential temperature relaxation rate toward `ambient_temperature` per second.
    #[get(type(copy))]
    pub(crate) temperature_dissipation: f32,
    /// Mild velocity viscosity damping rate per second.
    #[get(type(copy))]
    pub(crate) velocity_damping: f32,
}

/// Pre-allocated scratch buffers enabling zero steady-state heap allocations in `MacFluidGrid2D::step`.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub(crate) struct MacScratch2D {
    /// Primary advection scratch for staggered `u` faces.
    pub(crate) u_scratch: Vec<f32>,
    /// Secondary MacCormack scratch for staggered `u` faces.
    pub(crate) u_aux: Vec<f32>,
    /// Primary advection scratch for staggered `v` faces.
    pub(crate) v_scratch: Vec<f32>,
    /// Secondary MacCormack scratch for staggered `v` faces.
    pub(crate) v_aux: Vec<f32>,
    /// Primary cell-centered scalar scratch for dye/temperature advection.
    pub(crate) scalar_scratch: Vec<f32>,
    /// Secondary cell-centered MacCormack scratch for dye/temperature advection.
    pub(crate) scalar_aux: Vec<f32>,
    /// Cell-centered 2D scalar curl buffer for vorticity confinement.
    pub(crate) curl: Vec<f32>,
    /// Conjugate Gradient residual vector `r`.
    pub(crate) cg_r: Vec<f32>,
    /// Conjugate Gradient search direction vector `p`.
    pub(crate) cg_p: Vec<f32>,
    /// Conjugate Gradient matrix-vector product `A * p`.
    pub(crate) cg_ap: Vec<f32>,
}

/// Incompressible 2D Eulerian staggered Marker-and-Cell (MAC) smoke/water/ink fluid grid solver.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct MacFluidGrid2D {
    /// Horizontal cell count `nx`.
    #[get(type(copy))]
    pub(crate) nx: usize,
    /// Vertical cell count `ny`.
    #[get(type(copy))]
    pub(crate) ny: usize,
    /// Sanitized solver configuration.
    #[get(type(copy))]
    pub(crate) config: MacFluidConfig,
    /// Staggered horizontal velocity component `u` (`(nx + 1) * ny`).
    pub(crate) u: Vec<f32>,
    /// Staggered vertical velocity component `v` (`nx * (ny + 1)`).
    pub(crate) v: Vec<f32>,
    /// Cell-centered pressure solution field (`nx * ny`).
    pub(crate) pressure: Vec<f32>,
    /// Cell-centered discrete divergence diagnostic field (`nx * ny`).
    pub(crate) divergence: Vec<f32>,
    /// Cell-centered dye / smoke / ink density field (`nx * ny`).
    pub(crate) dye: Vec<f32>,
    /// Cell-centered temperature field driving thermal buoyancy (`nx * ny`).
    pub(crate) temperature: Vec<f32>,
    /// Solid obstacle cell mask (`0` = fluid, `1` = solid obstacle, `nx * ny`).
    pub(crate) solid: Vec<u8>,
    /// Pre-allocated advection, vorticity, and Poisson scratch arrays.
    pub(crate) scratch: MacScratch2D,
    /// Accumulated simulation time in seconds.
    #[get(type(copy))]
    pub(crate) sim_time_secs: f32,
}

/// Pre-allocated scratch buffers enabling zero steady-state heap allocations in `MacFluidGrid3D::step`.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub(crate) struct MacScratch3D {
    /// Primary advection scratch for staggered `u` faces.
    pub(crate) u_scratch: Vec<f32>,
    /// Secondary MacCormack scratch for staggered `u` faces.
    pub(crate) u_aux: Vec<f32>,
    /// Primary advection scratch for staggered `v` faces.
    pub(crate) v_scratch: Vec<f32>,
    /// Secondary MacCormack scratch for staggered `v` faces.
    pub(crate) v_aux: Vec<f32>,
    /// Primary advection scratch for staggered `w` faces.
    pub(crate) w_scratch: Vec<f32>,
    /// Secondary MacCormack scratch for staggered `w` faces.
    pub(crate) w_aux: Vec<f32>,
    /// Primary cell-centered scalar scratch.
    pub(crate) scalar_scratch: Vec<f32>,
    /// Secondary cell-centered MacCormack scratch.
    pub(crate) scalar_aux: Vec<f32>,
    /// Cell-centered 3D vorticity vector X component.
    pub(crate) vort_x: Vec<f32>,
    /// Cell-centered 3D vorticity vector Y component.
    pub(crate) vort_y: Vec<f32>,
    /// Cell-centered 3D vorticity vector Z component.
    pub(crate) vort_z: Vec<f32>,
    /// Cell-centered 3D vorticity magnitude `|omega|`.
    pub(crate) vort_mag: Vec<f32>,
    /// Conjugate Gradient residual vector `r`.
    pub(crate) cg_r: Vec<f32>,
    /// Conjugate Gradient search direction vector `p`.
    pub(crate) cg_p: Vec<f32>,
    /// Conjugate Gradient matrix-vector product `A * p`.
    pub(crate) cg_ap: Vec<f32>,
}

/// Incompressible 3D Eulerian staggered Marker-and-Cell (MAC) smoke/water fluid grid solver.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct MacFluidGrid3D {
    /// Cell count along X (`nx`).
    #[get(type(copy))]
    pub(crate) nx: usize,
    /// Cell count along Y (`ny`).
    #[get(type(copy))]
    pub(crate) ny: usize,
    /// Cell count along Z (`nz`).
    #[get(type(copy))]
    pub(crate) nz: usize,
    /// Sanitized solver configuration.
    #[get(type(copy))]
    pub(crate) config: MacFluidConfig,
    /// Staggered X-face velocity `u` (`(nx + 1) * ny * nz`).
    pub(crate) u: Vec<f32>,
    /// Staggered Y-face velocity `v` (`nx * (ny + 1) * nz`).
    pub(crate) v: Vec<f32>,
    /// Staggered Z-face velocity `w` (`nx * ny * (nz + 1)`).
    pub(crate) w: Vec<f32>,
    /// Cell-centered pressure solution field (`nx * ny * nz`).
    pub(crate) pressure: Vec<f32>,
    /// Cell-centered discrete divergence diagnostic field (`nx * ny * nz`).
    pub(crate) divergence: Vec<f32>,
    /// Cell-centered volumetric smoke/dye density field (`nx * ny * nz`).
    pub(crate) dye: Vec<f32>,
    /// Cell-centered volumetric temperature field (`nx * ny * nz`).
    pub(crate) temperature: Vec<f32>,
    /// Solid obstacle cell mask (`0` = fluid, `1` = solid obstacle, `nx * ny * nz`).
    pub(crate) solid: Vec<u8>,
    /// Pre-allocated advection, vorticity, and Poisson scratch arrays.
    pub(crate) scratch: MacScratch3D,
    /// Accumulated simulation time in seconds.
    #[get(type(copy))]
    pub(crate) sim_time_secs: f32,
}

/// Bundled dimensions and cell size for 2D MAC helper calls staying within clippy argument limits.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub(crate) struct MacDims2D {
    /// Horizontal cell count `nx`.
    #[get(type(copy))]
    pub(crate) nx: usize,
    /// Vertical cell count `ny`.
    #[get(type(copy))]
    pub(crate) ny: usize,
    /// Uniform physical cell spacing `dx`.
    #[get(type(copy))]
    pub(crate) dx: f32,
}

/// Bundled dimensions and cell size for 3D MAC helper calls staying within clippy argument limits.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub(crate) struct MacDims3D {
    /// Cell count along X.
    #[get(type(copy))]
    pub(crate) nx: usize,
    /// Cell count along Y.
    #[get(type(copy))]
    pub(crate) ny: usize,
    /// Cell count along Z.
    #[get(type(copy))]
    pub(crate) nz: usize,
    /// Uniform physical cell spacing `dx`.
    #[get(type(copy))]
    pub(crate) dx: f32,
}

/// Disjoint row-range mutable pointer wrapper for parallel bicubic MAC dye rasterization on native targets.
#[cfg(not(target_arch = "wasm32"))]
#[derive(Clone, Copy)]
pub(crate) struct MacRgbaMutView {
    /// Base raw pointer to destination RGBA8 bytes.
    pub(crate) ptr: *mut u8,
}