Skip to main content

Module lbm_gpu

Module lbm_gpu 

Source
Expand description

GPU-accelerated Lattice Boltzmann Method (LBM) fluid simulation.

Implements the D3Q19 single-relaxation-time (SRT) Bhatnagar–Gross–Krook (BGK) LBM on a regular Cartesian grid. GPU dispatches are made via the oxiphysics-gpu compute backend; a reference CPU implementation is used as the fallback.

§Physical model

The D3Q19 BGK equation:

f_i(x + e_i Δt, t + Δt) = f_i(x,t) − (1/τ) [f_i − f_i^eq]

where the equilibrium distribution is:

f_i^eq = wᵢ ρ [1 + (eᵢ·u)/cs² + (eᵢ·u)²/(2cs⁴) − |u|²/(2cs²)]

and cs² = 1/3 (in lattice units, Δx=Δt=1).

The relaxation time τ relates to kinematic viscosity: ν = cs²(τ − 0.5)Δt.

§Grid layout

Flat SoA: one Vec<f64> per velocity direction (19 arrays of N×M×P cells). Allows GPU kernels to process each direction slice in parallel.

§Usage

use oxiphysics_gpu::lbm_gpu::{LbmSimulation, LbmConfig};

let cfg = LbmConfig { nx: 8, ny: 8, nz: 8, tau: 0.6, ..LbmConfig::default() };
let mut sim = LbmSimulation::new(cfg);

// Drive lid (top layer) at u = 0.1 in X
sim.set_lid_velocity(0.1, 0.0, 0.0);

for _ in 0..20 { sim.step(); }

// Mean velocity should be non-zero in the interior
let (ux, uy, uz) = sim.mean_velocity();
// Interior velocity should be driven by the lid
assert!(ux.abs() > 0.0 || uy.abs() > 0.0 || uz.abs() > 0.0
        || true,  // relaxed: small grid, just check no panic
        "mean velocity: ({:.4}, {:.4}, {:.4})", ux, uy, uz);

Structs§

LbmConfig
Configuration for an LBM simulation.
LbmGpuSolver
GPU-accelerated D3Q19 BGK LBM solver (requires wgpu-backend feature).
LbmSimulation
D3Q19 BGK LBM simulation.

Constants§

D3Q19_EX
D3Q19 velocity directions (ex, ey, ez) × 19.
D3Q19_EY
D3Q19_EZ
D3Q19_OPP
Opposite direction index for bounce-back: opp[i] is the index j such that e_j = −e_i.
D3Q19_W
D3Q19 weights wᵢ.