Fractals, Cellular Automata, Chaos Theory, Science, Space, etc

Category Archives: Fluid

A long overdue and much requested feature in Visions of Chaos has been better support for multi core CPUs. Watching Visions of Chaos churn away calculating a long series of frames for a movie and only seeing one of your CPU cores in use can be frustrating.

Converting single threaded code into multi-threaded capable code is not exactly easy (depending on the algorithm some code is easier than others) but I have started converting some of the easier modes into multi-thread capable code.

Smoothed Particle Hydrodynamics (SPH) was one of the modes in Visions of Chaos that really needed a speed up. See here and here for my previous experiments with SPH.

This next screenshot shows all the 12 cores of an i7 being used for calculating the SPH formulas. Note that the actual displaying of the particles cannot be parallel so there is not 100% CPU utilization. As the particle count goes up (and the time it takes to calculate the million particles moving takes longer than the display time) the CPU usage jumps closer to 100% on all cores.

After conversion to multi-CPU capable code it was time to render some new 4K resolution SPH simulations. Once the particles count and resolution goes up to fill a 4K screen the times start to plummet again, but seeing these in full 4K resolution is really nice. The parts in the following movie used 1,000,000 SPH particles each which is double my previous particle counts.

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!

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.

Rayleigh-Taylor instability (RT) occurs when a less dense fluid is forced into a heavier fluid. If a heavier fluid is resting on a lighter fluid then gravity pulls the heavier down through the lighter fluid resulting in fingering, mushrooming and swirling patterns.

Here is an exmaple image courtesy of Wikipedia showing some steps from simulating RT.

This is a much more complex example from a supercomputer run at the Laboratory for Computational Science and Engineering, University of Minnesota. Also check out their movie gallery for more incredible fluid simulation examples.

RT patterns also emerge in supernova simulations like the following two images.

The following SPH RT simulations use approximately 500,000 discreet individual particles to make up the fluids. They are all full HD 1080p 1920×1080 60fps videos. It was very tedious to try various settings and wait for them to render. I spent the last few weeks tweaking code and (99.99% of that time) rendering test movies to see the changes before I was happy with the following three example movies.

The code is single threaded CPU only at this stage, so much patience was required for these movies.

For this first example the top half of the screen was filled with heavier purple particles and the lower half with lighter yellow particles. A very small random movement was added to each of the particles (just enough to stop a perfect grid of particles) and then the simulation was started. 73 hours (!!) later the calculations were completed for the 3000 frames making up the movie.

The next example took around 105 hours for the 4000 frames. This time three fluids are used. Heaviest on top, medium in the middle and lightest on the bottom.

And a final three fluid example that took 74 hours for the 3000 frames.

If you click the title text of the movies they will open in a new tab allowing them to be viewed in full screen HD resolution.