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

Tag Archives: SPH

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.

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.

Smoothed-Particle Hydrodynamics (SPH) is a method of simulating fluid flow. It is based on representing a fluid by a large number of discreet (individual) particles. Each particle has properties like position, pressure, density, mass, etc. The particles are fed through a bunch of equations that make them move in a fluid like flow.

Multiphase SPH is when you have 2 or more fluids with different densities etc (think oil and water) that flow around each other and clump together.

I have always had a fascination with simulating fluids. Over the years I have tried to understand SPH and have had many failed attempts at writing programs to do it (the basic formulas seem relatively simple, but getting the code to run stable without explosions and crashes is far from simple). Then I found this blog post by Tom Madams that had sample source code. With that I was finally able to get SPH working. It can still be fiddly to find a nice set of parameters to make a nice looking movie, but Tom’s code seems to be a great start. Thanks Tom!!