
Real-time Navier-Stokes fire and smoke for games — Arakawa Jacobian + DST-I spectral Poisson solve, open source C# DLL
Most real-time "fluid" effects in games are not fluid simulations. They are particle systems with a noise texture. I wanted to see how close to real CFD you could get while staying at interactive frame rates on a CPU.
The result is Loucetius GCE — a 2D incompressible Navier-Stokes solver in vorticity-stream function form:
Numerical approach:
- Arakawa Jacobian for the nonlinear advection term (conserves both energy and enstrophy — this is why the simulation stays physically correct at long run times instead of accumulating numerical garbage)
- DST-I (Discrete Sine Transform type I) spectral Poisson solve to recover stream function from vorticity — exact machine precision solution every frame, not an iterative approximation
- Thom boundary conditions on solid walls
- Baroclinic torque source term driving thermally-generated vortices
- CFL-adaptive vorticity clipping for stability at high Reynolds numbers
What this gets you visually:
- Kelvin-Helmholtz roll-up instabilities appear naturally, no noise textures needed
- Correct vortex ring structure at the base of a flame
- Two flames merging into one plume with the right geometry
- Plume deflection and reattachment around obstacles
- Realistic pressure-driven expansion in explosions
The temperature, density, soot, and stream function fields are exposed as flat float arrays each frame — bind them directly to compute shaders or render textures.
Performance: Game preset (65x65) runs real-time, single core. Quality (129x129) around 100ms/step.
