A high-performance 3D Lattice-Boltzmann solver for incompressible Navier-Stokes equations using GPU acceleration with WGPU and WGSL shaders.
- D3Q27 Lattice Model: 27-velocity 3D lattice for accurate representation of fluid flow
- GPU Acceleration: WGPU-based compute shaders for high performance
- STL Geometry Input: Import complex geometries from CAD software
- ParaView Compatible Output: VTK format for professional visualization
- Configurable Parameters: JSON-based configuration for easy parameter adjustment
- Boundary Conditions: Support for inlet, outlet, and no-slip wall boundaries
# Build the project
cargo build --release
# Run a simulation
./target/release/lattice-boltzmann-rs config.json geometry.stl
The configuration file (JSON format) contains all simulation parameters:
{
"domain": {
"nx": 100, // Grid points in x-direction
"ny": 50, // Grid points in y-direction
"nz": 50, // Grid points in z-direction
"dx": 0.01, // Grid spacing in x (m)
"dy": 0.01, // Grid spacing in y (m)
"dz": 0.01 // Grid spacing in z (m)
},
"physics": {
"reynolds_number": 100.0, // Reynolds number
"inlet_velocity": [0.1, 0.0, 0.0], // Inlet velocity vector (m/s)
"density": 1.0, // Fluid density (kg/m³)
"viscosity": null // Optional: explicit viscosity (m²/s)
},
"simulation": {
"max_iterations": 10000, // Maximum number of time steps
"convergence_tolerance": 1e-6, // Convergence criterion
"tau": null // Optional: explicit relaxation time
},
"output": {
"output_directory": "./output", // Output directory
"output_frequency": 100, // Output every N iterations
"output_format": "vtk" // Output format (vtk)
}
}
The solver accepts STL files containing the solid geometry. The STL file should:
- Be in ASCII or binary format
- Contain triangulated surfaces representing solid boundaries
- Be positioned within the computational domain defined in the config
The solver generates VTK files compatible with ParaView:
geometry.vtk
: Visualization of the computational domain and boundary conditionsoutput_XXXXXX.vtk
: Transient flow solution files
- Velocity: 3D velocity vector field (for streamlines)
- VelocityMagnitude: Scalar velocity magnitude
- Density: Fluid density field
- Pressure: Pressure field (derived from density)
- Vorticity: 3D vorticity vector (for flow structure analysis)
- NodeType: Boundary condition visualization (0=fluid, 1=solid, 2=inlet, 3=outlet)
- Open ParaView
- Load
geometry.vtk
to visualize the domain setup - Load
output_*.vtk
files as a time series - Create visualizations:
- Streamlines: Use the Velocity vector field
- Pressure contours: Use the Pressure scalar field
- Velocity magnitude: Use VelocityMagnitude for speed visualization
- Vortex structures: Use Vorticity magnitude or Q-criterion
The solver uses the 27-velocity 3D lattice model with:
- 1 rest particle (0,0,0)
- 6 face-connected neighbors (±1,0,0), (0,±1,0), (0,0,±1)
- 12 edge-connected neighbors
- 8 corner-connected neighbors
The simulation runs entirely on the GPU using WGSL compute shaders:
- Collision shader: BGK collision operator with equilibrium distributions
- Streaming shader: Particle streaming to neighboring nodes
- Boundary shader: Implementation of boundary conditions
- Inlet: Prescribed velocity using equilibrium distributions
- Outlet: Zero-gradient (Neumann) boundary condition
- Solid walls: Bounce-back boundary condition for no-slip walls
- Fluid: Standard LBM collision and streaming
- Rust 1.70 or later
- GPU with WGPU support (DirectX 12, Vulkan, Metal, or WebGL)
- ParaView for visualization (free download from kitware.com)