3D Gravity using OpenCL

Note: This is an older post and the gravity simulation code has since been updated. See here for the latest.

This post did have a bunch of benchmarks and times that were incorrect and have been removed. I was not comparing every particle to every other particle in the gravity calculations.

What is left of this post is still correct. The object counts are correct and there are millions of particles being shown. It is just the actual gravity calculations that were not complete.

Previous Results

Since I originally posted the following 3D gravity movies to YouTube…

…there were questions and some skepticism in the comments so hopefully this blog post helps clarify things. That skepticism about how I could possibly calculate these millions of objects at once was well founded.

Latest Results

Here is a movie with 3,000,000 particles.

Unfortunately YouTube’s compression ruined the movie quality a bit. Mostly due to the noisy/static like nature of the millions of particles. Not enough I frames and too many P frames. Here are a series of screenshots showing what the frames looked like before the compression.

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

To push it further, here is a rotating disk of 5,000,000 objects.

Again, here are some uncompressed screenshots.

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

Try It Yourself

If use Windows you can download Visions of Chaos and see the simulations run yourself. Here are a few quick steps to get you going;

1. Open Visions of Chaos
2. Select Mode->Gravity->3D Gravity to change into the 3D Gravity mode
3. The 3D Gravity Settings dialog will appear
4. Change the number of objects to 1,000,000
5. Change the Time step to 0.02
6. Change the Size of objects to 0.2
7. Check Create AVI frames if you want to create an AVI movie from the simulation
8. Click OK

Make sure you have the latest video card drivers so the OpenCL code runs as optimal as possible. For NVidia go here and for AMD go here.

Jason.

Using Multiphase Smoothed-Particle Hydrodynamics to show the emergence of Rayleigh-Taylor instability patterns

Rayleigh-Taylor Instability

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.

Nicole Sharp from FYFD has this into video to RT.

Simulating Rayleigh-Taylor Instability

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

Rayleigh-Taylor Instability

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.

Rayleigh-Taylor Instability

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

Rayleigh-Taylor Instability

Rayleigh-Taylor Instability

Mark J Stock uses his own fluid simulation code to create incredibly detailed RT examples like this

thunabrain has this example of using the GPU to simulate fluids showing RT

Real Life Rayleigh-Taylor Instabilities

Pouring milk into coffee leads to RT patterns. I took these with my phone so they are not as crisp as I would have liked.

Milk and coffee

Milk and coffee

Dropping ink into water also leads to RT patterns as in these photos by Alberto Seveso

Rayleigh-Taylor Instability

Rayleigh-Taylor Instability

Using SPH to simulate RT

I had some previous success with implementing Multiphase Smoothed-Particle Hydrodynamics so I was curious to see what sorts of RT like results the SPH code could create. I have now added the options to generate RT setups in the SPH mode of Visions of Chaos.

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.

Jason.