Boltzmann Particle Hydrodynamics (BPH) on GPU, written in Rust on top of massively and CubeCL.
This repository is a reimplementation of
bphcuda, which was originally
developed as my master's work. The goal is to keep the BPH algorithmic model
while rebuilding the GPU parallel primitives around massively.
BPH stands for Boltzmann Particle Hydrodynamics. It is a Monte Carlo particle method for hydrodynamics:
- Divide space into Cartesian cells.
- Move particles freely during each time step.
- Sort/group particles by cell.
- Relax each cell stochastically toward a local thermodynamic equilibrium while conserving mass, momentum, and energy.
Because particles are Lagrangian and may cross many cells in one step, BPH is an explicit scheme that is not restricted by the usual CFL condition. It also preserves positive density and pressure, supports arbitrary ratios of specific heats through internal degrees of freedom, and parallelizes naturally over many particles and cells.
The trade-off is statistical fluctuation: useful simulations need many particles, so GPU memory and parallel throughput matter.
For more background, see:
bph.pdfin this repository.- Boltzmann Particle Hydrodynamics (Dr. Matsuda)
- An Engineering Application of BPH Method (Dr. Isaka)
bph-gpu/- the reusable BPH GPU library crate.experiments/shocktube/- Sod shock tube benchmark.experiments/wallshock/- wall shock benchmark.experiments/sjogreen/- Sjogreen rarefaction benchmark.experiments/noh/- 2D Noh implosion benchmark.workspace/draw/- plotting scripts for generated data.workspace/plot/- checked-in result plots.
The core simulation loop follows the same high-level structure across the experiments:
- Allocate particle state arrays on a CubeCL executor.
- Initialize positions, velocities, mass, and internal energy.
- Compute cell indices from particle positions.
- Sort particles by cell using
massively::vector::sort_by_key. - Apply the BPH relaxation step with
bph_gpu::bph. - Stream particles with a first-order Runge-Kutta update.
- Apply benchmark-specific boundary conditions and output derived quantities.
The library keeps reusable GPU operations under bph-gpu/src/tool/ and
algorithmic primitives such as reduction and bucket counting under
bph-gpu/src/algorithm/.
- Rust with edition 2024 support.
- A CubeCL-supported backend. The examples currently create a WGPU executor
with
cubecl::wgpu::WgpuDevice::DefaultDevice. - Ruby and Rake only if you want to regenerate the checked-in plots through
workspace/Rakefile.
The massively dependency is pinned to v0.80 in Cargo.toml; the direct
cubecl dependency follows the matching upstream branch selected by that
release.
Build the workspace:
cargo buildRun tests:
cargo testRun a small shock tube example:
cargo run -p shocktube -- 500 100 2 0.15Write benchmark data to a file:
cargo run -p shocktube -- 500 1000 2 0.15 --out workspace/dat/shocktube.datThe common experiment arguments are:
n- particles per cell, or the per-cell particle scale used by the benchmark.m- number of cells, or the spatial resolution scale.s- internal degrees of freedom parameter used by BPH relaxation.fin- final simulation time.--out- optional output path for post-processing.
sjogreen also takes an additional u0 velocity argument.
From the workspace/ directory, use the Rake tasks:
cd workspace
rake shocktube
rake wallshock
rake sjogreen
rake nohOr run every benchmark and redraw every plot:
cd workspace
rake allThe generated images are written under workspace/plot/.
This implementation has been checked against standard shock-hydrodynamics benchmarks: Sod shock tube, wall shock, Sjogreen rarefaction, and Noh implosion.
MIT



