Page MenuHome

Physically-based SPH solver
Closed, ResolvedPublicPATCH


The old SPH solver in Blender is based on a paper by S. Clavet et. al[1]. It is good for artistic animations, but is not very physically accurate.

This patch adds a new "classical" SPH fluid solver, based on research by Gingold and Monaghan[2]. The new solver is physically-based, so it should give more accurate simulations. This makes it more suitable for engineering work. However it is less expressive in some ways, so there is still a need for the old solver. There is therefore a check box in the UI to select which solver to use.

The new solver uses the same parameters as the old one, but it is important to note that the units are quite different: the particle mass, density and interaction radius have to be set just right to get the simulation to behave. For example, a 2mx2mx2m cube of water containing 1000 particles should have approximately the following values:
- Particle mass: 8.5 (kg)
- Stiffness: 30,000 (m^2/s^2)
- Interaction radius: 0.4 (m)
- Rest density: 1000 (kg/m^3)

Note that, with the new solver, these parameters may be specified in SI units. Good values for these can be worked out using a formula, so a more intuitive interface could be added in future. See the attached sph_classical_test.blend for an example.

The new solver has some other nice properties, e.g. particles tend to be more evenly-spaced, and don't stack up on each other on the walls when a container drains. Currently however, it is important to emit particles in a volume, not from a surface, or they will tend to clump together. It should be possible to improve this in future.

This solver is the work of John Mansour <>. The patch is based on parts of patches 29661 [3] and 29663 [4] - although this patch (sph_classical_r42811_1_svn.patch) may be applied directly to Blender trunk, r42811. This solver may be multithreaded as in 29663, but for simplicity it is not in this first version of the patch.

By making a contribution to this project, I certify that the contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file.

Signed-off-by: Alex Fraser <> on behalf of VPAC Ltd.

[1] S. Clavet, P. Beaudoin, and P. Poulin, “Particle-based viscoelastic fluid simulation,” in Proceedings of the 2005 ACM SIGGRAPH/Eurographics symposium on Computer animation, 2005, p. 228.
[2] R. A. Gingold and J. J. Monaghan, “Smoothed particle hydrodynamics; theory and application to non-spherical stars,” Monthly Notices of the Royal Astronomical Society, vol. 1977, pp. 375-389, Nov. 1977.

Event Timeline

Attempted to patch Trunk r42836 with sph_classical_r42811_1_svn.patch fails compiling
Compiling ==> 'fluiddensity.c'
source/blender/render/intern/source/fluiddensity.c:74:49: error: unknown type name 'FluidDensity'
source/blender/render/intern/source/fluiddensity.c: In function 'cache_fluiddensity':
source/blender/render/intern/source/fluiddensity.c:112:2: error: unknown type name 'FluidDensity'
source/blender/render/intern/source/fluiddensity.c:112:24: error: 'Tex' has no member named 'fd'

Went back to r42811 and tried again with the same issue.

Using scons on OSX 10.7.2 with custom built GCC4.6.1

Oh, that's weird - that file is in the other patch, [#29680] SPH Fluid Density texture. Are you sure you applied this one (classical SPH) to a clean trunk?

Ahh yes my mistake , sorry for the noise,

Attached is a new version of the patch which applies to trunk, r46757 (sph_classical_r46757_3_svn.patch). This version is should be nearly equivalent to the last, but a couple of unnecessary features were removed, and the source has been tidied up.

The GUI has been improved: the checkbox has been replaced with a list of solvers (in case more are added in future), and the parameters that aren't used by this solver are hidden when Classical is selected. One big improvement, and something that would be difficult with the old (DDR) solver, is that the rest spacing between particles is now shown in the GUI (see sphclassical_GUI.png). This number is calculated based on the rest density and mass. Knowing this number greatly simplifies setting up simulations.

Also attached is a .blend file demonstrating a dam break (sphclassical_dam_s0.02.blend), and a comparison of this dam break with the old DDR solver (dambreak_comparison.png). These results compare favourably with the experiments by Changhong Hu and Makoto Sueyoshi [1]. Notice that the demo file uses SI units: the liquid has a rest density of 1000km/m3 (water), and each particle weighs 0.008kg.

A video of a higher-resolution simulation is also attached (dambreak.ogv). The video is in slow motion: the total length of the video represents 1.2s of real time.


Oh yes, in dambreak_comparison.png, the "s=0.02" etc. under each column refers to the spacing between particles, i.e. the resolution of the simulation. The last column has higher resolution than the first two.

Hi Alex,
I'm new to the Blender dev community. I am currently doing a PhD in SPH (Engineering side) so I can help you out with some things if you want. But if you have John Mansour working for you I guess you already have somebody who is competent in the field.

Hi Arno!

Sadly John is no longer working with us. You're welcome to help out, if you like! Have you tried this patch? If you have time it would be great if you could have a look at it. I would like to get it accepted into trunk, and I think having a vote from another SPH expert would help.


Hi Alex,

I will be on a conference this week (SPH of course), organized by Monash. After that I have one week where I probably have little time to do any work on Blender. After that I'll have a look at your patch.

Btw. I found an interesting thread on the bullet page:
Nothing against your work (as I haven't even seen it) but an alternative to a Blender SPH solver would be to support the work of this guy and then include it in Blender as part of Bullet. And due to the GSOC by Sergey Reich, this could provide a great coupled physics engine for Blender. Let me know your thoughts.
It's just that one of the things that I immediately saw when starting to work with Blender is that there is speciallized physics, but hardly any coupling. E.g. Hair cannot react to a solid object. I think that is something that should change in the longer run. That is why I pointed out the bullet thread.


Attaching sphclassical_dam_s0.0?_grav.blend, which are better examples for the more stable version of the solver that is about to be committed to trunk.

Committed with some improvements, r52989.

Alex Fraser (z0r) changed the task status from Unknown Status to Resolved.Dec 16 2012, 8:23 AM

Could the information about this feature be put somewhere in the release notes?

We're not close to the release, but I'd like to keep these up to date for users that are testing new features.

Hi Brecht,

Yep, I'll do that. I've just made a demo animation at home; when it has been rendered I'll upload it and write some release notes.

Hi Alex,

I'm trying to understand the stiffness parameter, from a physicist point of view. I searched in Wikipedia and I found, but the units are different (N/m vs m²/s²). ¿Why do your stiffness parameter have those units? (I know in Wikipedia case it refers to a solid and in the this case it refers to a fluid, but I don't find neither other definition nor the relationship)

Also, in the release notes of version 2.66, it is wrote the mass parameter is the "Particle mass", and, by the example of that page, it seems that mass parameter refers to the particle system mass.



Hi Eduardo,

Thanks for checking out the solver!

I had a chat with John about this. The stiffness parameter is not like the one in solid mechanics, and is actually a measure of how incompressible the fluid is. The parameter sets the speed of sound (squared), i.e. (m/s)^2 or m^2/s^2. For a speed of sound of 10m/s, set stiffness to 100. If you want a typical maximum compressibility of about 10%, you need to set the sound speed 10 times higher than the typical velocities of the particles. Or you can just experiment until it looks right.

The mass parameter is indeed the mass of a single particle, not the whole system. The example on that page is for a 1x1x1m cube. The fluid is given a rest density of 1000kg/m^3 (like water), so to fill a 1x1x1m box we will need 1000kg of fluid. The system comprises 1000 particles, so each particle must have a mass of 1kg. The mass and rest density determine the spacing between particles when the system is at rest; the spacing in this case is cbrt(mass / density) = 10cm.


Hi Alex,

I didn't check your solver yet, but could you make sure that this information about the stiffness factor being c_0^2 is included in the tooltip or so?


Thanks, Alex, for your answer! It's very useful.

It seems that the units of stiffness were unintuitive, so I've changed them to just the speed of sound (revision r53724). Old files that used the classical SPH solver will need to have this parameter changed to sqrt(old value).

Thanks for your feedback about the parameters!

Arno, you're right that the units should be given in the tooltip. The trouble is that those parameters are shared by the DDR solver, which doesn't use the same units. I'm not sure what to do about this; maybe it's best to define completely new parameters for the classical solver. I'll think about it.