Page 1 of 1

GPU-based Smoothed Particle Hydrodynamics

Posted: Sun Aug 01, 2010 5:57 pm
by thegeek
Hi, I would like to show you my implementation of SPH (Smoothed Particle Hydrodynamics) using CUDA.
This work is part of my masters thesis in Computer Science at NTNU (Norwegian University of Science and Technology).
I have created a SPH library that uses the power of the GPU (through CUDA) to simulate fluids with extremely high performance ("real-time").
In addition I have created a small demo application that uses Ogre to render the simulation interactively.
The application (and library) supports simple "wall" boundaries as well as "terrain" boundaries. The terrain is rendered using Ogre's excellent new terrain component.

ImageImage

The video below is the "real-time" performance when running on an NVIDIA GTX 470 (more details in the youtube video itself)


I have not seen many projects like this where CUDA/GPU computations are rendered in real-time using Ogre, and as such it might be useful for other people here:)
At the moment only OpenGL works well, though all the code that deals with the CUDA and Ogre integration was made for Direct3D9 to work as well. Unfortunately there are some bugs when using D3D9 (one in the particle shader, and one that makes D3D/Cuda very slow).

Full code can be found here: http://code.google.com/p/gpusphsim/

I hope someone can make use of this, I feel obligated to contribute as much as possible back to this great project:)
Øystein Krog

EDIT; added some quick captures of the flowing snow avalanche simulations:


Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Sun Aug 01, 2010 7:24 pm
by koirat
Impressive. Nice work.
Fluid dynamics is always so spectacular!. Loves it.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Mon Aug 02, 2010 12:57 am
by DavlexDesign
G'day ???
I didn't want to say geek.
Now that's something that's really nice,
Would you have a problem with me maybe using some of this for my planet engine (river dynamics mainly) ?
I have a river system in there already, but something like this could just make the difference for the look and feel of the rivers and water falls.

Alex

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Mon Aug 02, 2010 2:31 am
by cybereality
Very cool. Have you thought about doing any volume rendering to make it look more like water?

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Mon Aug 02, 2010 5:31 pm
by thegeek
DavlexDesign wrote:G'day ???
I didn't want to say geek.
Now that's something that's really nice,
Would you have a problem with me maybe using some of this for my planet engine (river dynamics mainly) ?
I have a river system in there already, but something like this could just make the difference for the look and feel of the rivers and water falls.
Hehe, I embrace my geekness:) Feel free to use the code, that's why I uploaded it;P
cybereality wrote:Very cool. Have you thought about doing any volume rendering to make it look more like water?
More advanced rendering is certainly something I considered, but I decided to focus on SPH itself so as to limit the scope of my thesis (and because of time constraints;P)
I think the new CUDA fluid sample from NVIDIA (also using SPH) is very interesting. They use a very lightweight (relatively) screen-space rendering technique which seems to produce very good results.
For some very good (implementation) details on this method see the pdf slides from NVIDIA: http://developer.download.nvidia.com/pr ... ffects.pdf

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Tue Aug 03, 2010 2:11 pm
by Xypher
Beautiful work, took me a moment to figure out the significance of your coloring scheme, lol.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Tue Aug 03, 2010 6:45 pm
by thegeek
Hehe, the coloring scheme in that video is a hue-based gradient based on the velocity of each particle.
The SPH library itself support other gradients, and you can apply the gradients to physical values of the fluid such as pressure, shear stress etc.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Sun Aug 15, 2010 8:25 pm
by Nefbrethilion
Hi,
last year I did a thesis on SPH myself. I can see it's based on the CUDA particles demo ;-)

What did you use as an acceleration structure? The same as the particles demo or maybe something else?

SPH is nice, and CUDA is fun. The movement of your water looks very good too. Congrats!

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Sun Aug 15, 2010 10:37 pm
by thegeek
Thank you, I am very happy I chose to work with CUDA and SPH, the combination is indeed very fun:)
Regarding the acceleration data structure I use the same acceleration structure as the particles demo ("hashed radix sorted uniform grid") (including cudpp/satish radix sorting).

It is also worth mentioning that a large part of my thesis is regarding the use of SPH to model flowing snow avalanches.
What I've shown here is from the "preproject" to my thesis where I implemented Mueller's SPH model and simulate "simple" water-like fluids only.

For my thesis I implemented a more advanced SPH model that more correctly calculates the stress tensor in the fluid.
Using this stress tensor and various (non-newtonian) rheological models it is possible to approximate the behavior of a wide range of fluids, in my case a flowing snow avalanche.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Wed Aug 18, 2010 12:01 pm
by Nefbrethilion
Interesting, do you have any movies of this flowing snow? :-)

Greets,

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Fri Aug 20, 2010 4:07 pm
by thegeek
A quick upload of some movies of the flowing snow simulation.
I hope to do some better captures if I ever find time;P


Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Fri Aug 20, 2010 4:10 pm
by jacmoe
Really impressive! :D

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Fri Aug 20, 2010 4:16 pm
by DanielSefton
Cool! I also think that would look really effective as lava :)

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Fri Aug 20, 2010 6:57 pm
by koirat
Great.

Do you know how precise is this simulation compared to the real life avalanche.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Sun Aug 22, 2010 8:59 pm
by thegeek
DanielSefton wrote:Cool! I also think that would look really effective as lava :)
Indeed, the model I used is in fact probably better used for other geomorphological flows, such as lava, mud flows, rock avalanches etc.
koirat wrote:Do you know how precise is this simulation compared to the real life avalanche.
I did not try to quantify the accuracy/precision of my simulation, indeed the focus of my thesis was not on the accuracy of the simulation, but on the performance of the SPH implementation. (I am a student of computer science, not physics;P).
Simulations of snow avalanches can be accurate, but many simulations employ other methods, such as statistics etc to compute the fallout zones. My approach was to use fluids dynamics, where the viscosity is non-newtonian (not constant), but a function of the shear stress. In this way the behavior of a flowing avalanche can be approximated by tuning the viscosity model.
However, in my thesis I focus a lot more on the performance aspect of SPH simulations (using GPUs). I implemented two different SPH models, one fairly "simple" model (the "water" model by Mueller, and a new "complex" model which uses techniques from several other SPH models. I found that even though the complex model requires a lot more calculations and data, the performance is still very good compared to CPU implementations, and that the performance of SPH on GPUs actually scale fairly well with the complexity of the simulation.
In the literature there are many examples of studies which use SPH for much more accurate simulations, with fairly good results. Compared to more "traditional" fluid simulations SPH is not considered as accurate, or mature, but there is a lot of work being done in this area since SPH has some very compelling attributes.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Mon Aug 23, 2010 11:59 am
by Nefbrethilion
Very interesting, and it was nice to see your avalanche simulation! I guess you can just render the particles as point sprites, just like in the first movie, to get this result? That's a benefit too: you don't really need to extract a surface :-)

The viscosity would be higher when the shear stress is higher, meaning that particles close to the terrain will slow down the movement of upper particles, which will experience less friction and thus flow less viscuous. Do I understand this right?

For the accuracy, SPH makes a lot of simplifications and will never, ever be able to predict flows. The biggest simplifications is ignoring all forces applied by particles "too far away". This speeds up the simulations incredibly but you lose detail. The application of SPH to fluids has been proposed originally by Muller, and is useful to create visual pleasing fluid like effects in realtime (exactly what we want in games or other interactive applications!). Don't forget that the method for avalanches here is not physically accurate either: it is a way to tweak the fluid simulation to look like an avalanche. Which is very clever, but don't "trust" these simulations to predict anything :-)

Again, congrats with your results, I'm impressed!

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Mon Aug 23, 2010 7:14 pm
by thegeek
Nefbrethilion wrote: Very interesting, and it was nice to see your avalanche simulation! I guess you can just render the particles as point sprites, just like in the first movie, to get this result? That's a benefit too: you don't really need to extract a surface
Yes, the simple shader used here actually works pretty well for snow;P
Nefbrethilion wrote: The viscosity would be higher when the shear stress is higher, meaning that particles close to the terrain will slow down the movement of upper particles, which will experience less friction and thus flow less viscuous. Do I understand this right?
In these simulations I actually did the opposite; the viscosity is less (flows easier) when the shear stress is higher. In this way the snow will "solidify" when the shear stresses are low (such as at the end of avalanche).
Nefbrethilion wrote: For the accuracy, SPH makes a lot of simplifications and will never, ever be able to predict flows. The biggest simplifications is ignoring all forces applied by particles "too far away". This speeds up the simulations incredibly but you lose detail. The application of SPH to fluids has been proposed originally by Muller, and is useful to create visual pleasing fluid like effects in realtime (exactly what we want in games or other interactive applications!). Don't forget that the method for avalanches here is not physically accurate either: it is a way to tweak the fluid simulation to look like an avalanche. Which is very clever, but don't "trust" these simulations to predict anything :-)

Again, congrats with your results, I'm impressed!
Thank you, however I am not so sure that SPH (and derivate algorithms) will never be able to predict flows. In fact I think it can be argued that some of the "improved" SPH models are pretty good even right now. There exist a very wide range of "corrections" to SPH that mitigate many of the weak points of SPH of improve accuracy a lot.
However my SPH implementations should probably not be used for flow prediction as they are right now;P
Mueller was also far from the first person to employ SPH for fluids, however he might have been (one of?) the first to do so in computer graphics.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Mon Aug 23, 2010 8:54 pm
by ecoumans
I think the new CUDA fluid sample from NVIDIA (also using SPH) is very interesting. They use a very lightweight (relatively) screen-space rendering technique which seems to produce very good results.
The NVIDIA screen-space rendering technique using blending of point sprites looks great from a distance but bad from closeup, see attached running that demo with the camera close-up.
Unless those 'blobby' artifacts are fixed this method doesn't seem useable in outside of a demo that keeps the camera at a distance from the fluid.
zoom_spheres.jpg
Here is another link that discusses various SPH rendering/surface reconstruction methods: http://www.rchoetzlein.com/theory/?p=129

It would be great to have some open source fast and good looking SPH rendering available.
Thanks!
Erwin

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Tue Aug 24, 2010 7:18 pm
by thegeek
That is the old screen-space rendering from NVIDIA, the new one seems a bit better?

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Tue Aug 24, 2010 8:36 pm
by ecoumans
The picture with the artifacts is from a very recent version. From a bigger distance (within the default limited range of the camera) it looks great.

Where is a link to the "new" one and where are details about the improvements?
Thanks,
Erwin

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Thu Aug 26, 2010 4:32 pm
by thegeek
Screen Space Fluid Rendering for Games, Simon Green, NVIDIA: http://developer.download.nvidia.com/pr ... ffects.pdf
Here is a video: http://www.youtube.com/watch?v=UYIPg8TEMmU
I'm not sure if this is newer than what you are referring to though.

Re: GPU-based Smoothed Particle Hydrodynamics

Posted: Sun Aug 29, 2010 11:30 pm
by vagrantpostman
Excellent work sir. I'm already going to my hand at an ingame render for use with things like SPH as it is; if I come up with anything good I'll post it up in a new thread ;P. Hopefully the two will go hand in hand.