Physically-based SPH solver #29681

Closed
opened 2011-12-23 02:24:25 +01:00 by Alex Fraser · 20 comments

%%%The old SPH solver in Blender is based on a paper by S. Clavet et. al- [x]. 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- [x]. 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 jmansour@vpac.org. The patch is based on parts of patches 29661 - [x] and 29663 - [x] - 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 adfries@vpac.org on behalf of VPAC Ltd.

%%%The old SPH solver in Blender is based on a paper by S. Clavet et. al- [x]. 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- [x]. 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 <jmansour@vpac.org>. The patch is based on parts of patches 29661 - [x] and 29663 - [x] - 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 <adfries@vpac.org> on behalf of VPAC Ltd. - [x] 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. - [x] 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. - [x] http://projects.blender.org/tracker/index.php?func=detail&aid=29661&group_id=9&atid=127 - [x] http://projects.blender.org/tracker/index.php?func=detail&aid=29663&group_id=9&atid=127 %%%
Author

Changed status to: 'Open'

Changed status to: 'Open'

%%%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%%%

%%%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%%%
Member

%%%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?%%%

%%%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, %%%

%%%Ahh yes my mistake , sorry for the noise, %%%
Author

%%%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 - [x]. 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.

%%%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 - [x]. 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. - [x] http://jmsa.hrbeu.edu.cn/OA/pdfdow.aspx?Type=pdf&FileName=a1eae5eb-26d5-47c8-92e4-800e160e3c12.pdf%%%
Author

%%%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.%%%

%%%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.
Cheers,
Arno%%%

%%%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. Cheers, Arno%%%
Author

%%%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.

Cheers,
Alex%%%

%%%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. Cheers, Alex%%%

%%%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: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=8154
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.

Cheers,
Arno%%%

%%%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: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=8154 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. Cheers, Arno%%%
Author

%%%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.%%%

%%%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.%%%
Author

%%%Committed with some improvements, r52989.%%%

%%%Committed with some improvements, r52989.%%%
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

%%%Could the information about this feature be put somewhere in the release notes?
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66

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

%%%Could the information about this feature be put somewhere in the release notes? http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66 We're not close to the release, but I'd like to keep these up to date for users that are testing new features.%%%
Member

%%%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 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 https://en.wikipedia.org/wiki/Stiffness, 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.

Thanks,

EduGuti%%%

%%%Hi Alex, I'm trying to understand the stiffness parameter, from a physicist point of view. I searched in Wikipedia and I found https://en.wikipedia.org/wiki/Stiffness, 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. Thanks, EduGuti%%%
Member

%%%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.

Cheers,
Alex%%%

%%%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. Cheers, Alex%%%

%%%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?

Cheers,
Arno%%%

%%%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? Cheers, Arno%%%

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

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

%%%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!%%%

%%%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!%%%
Author

%%%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.

Cheers,
Alex%%%

%%%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. Cheers, Alex%%%
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#29681
No description provided.