Back in September 2010 I was experimenting with Lattice Boltzmann Method (LBM) fluid flows.
At that time I managed to translate some (probably Fortran) LBM source code provided by the now defunct “LB Method” website (here is how LB Method looked around that time). The algorithms worked and did give me some nice results, but there were problems like lack of detail and pulsating colors due to my display routines scaling minimum and maximum velocities to a color palette.
Yesterday I was looking around for some new LBM source code and found Daniel Schroeder‘s LBM page here. Daniel graciously shares the source code for his applet so I was able to convert his main LBM algorithms into something I could use in Visions of Chaos. Many thanks Dan!
Dan’s code was based on code by Alexander Wagner which you can see here including a PDF describing the LBM processes.
Using Dan’s code/algorithms was much faster than my older code. It also allows me to render much more finer detailed fluids without causing the system to blow out. I can push the simulation parameters further. Dan’s method of coloring solved the pulsing colors issue my older code had and includes a really nice way of visualizing the “curl” of the flowing fluid. Tracer particles are also used to follow the velocity of the underlying fluid to give another way of visualizing the fluid flow. Once particles leave the right side of the screen they are buffered up until they fill up and can be reinjected to the left side of the flow. Tracer particles help seeing the vortices easier than shading alone.
With less memory requirements (another plus from Dan’s code) I was able to render some nice 4K resolution LBM flows. This movie must be watched at 4K if possible as the compression of lower resolutions cannot handle displaying the tracer particles.
Years after the above movie was made I was revisiting the code to try and speed it up a bit by adding multi-threading support. While doing this I found an error with the fluid collision code that caused incorrect results.
Have a look at the movie above and notice the initial part with flow past the three circles. The curl patterns should initially be symmetric around the circles. The background flow is an even speed from the left of the screen to the right. Going around the circle should make the same shaped curls above and below the circles. With a bit of tweaking I got the right bounce code working. The next movie shows the corrected code results.
For that movie the fluid is visualized using only tracer particles. Imagine a bunch of small confetti or glitter particles have been scattered on the fluid surface and are floating. As the fluid flows it drags the floating tracer particles along with it. This is a different way of seeing the curls and eddies the fluid forms as it flows past the various obstacles.
The next movie shows the fluid flow by displaying the curl of the fluid at each pixel location.
The new LBM code is now included with Visions of Chaos.
There are still some visual artifacts with this latest code and the maths can spontaneously explode crashing the simulation if the fluid speed is pushed too far or the viscosity is lowered too far. The downside here is that you cannot get very detailed flows. I will no doubt be revisiting LBM again in the future to experiment with new code and try to get more detailed (and faster) simulations running.