InteractiveComputerGraphics / PositionBasedDynamics

PositionBasedDynamics is a library for the physically-based simulation of rigid bodies, deformable solids and fluids.
MIT License
1.9k stars 358 forks source link

PBF cohesion/surface tension #80

Closed asbjornlystrup closed 4 years ago

asbjornlystrup commented 4 years ago

Hi, I'm thinking about converting your PBF to a 2D GPGPU solution for a game I'm working on. Looking at the demo, there seems to be a lack of cohesion/surface tension effects, and I was wondering if this is just a missing constraint or if a different model would be needed. Before I discovered this repository, I was planning to implement the liquids in "Unified Particle Physics for Real-Time Applications" as I found them very appealing in the FleX video: https://youtu.be/fuvfpveaacY?t=12 You can see quite defined puddles forming from surface tension there for example. Do you have any info and pointers for what's missing/has to be changed to achieve the same result?

Thank you so much for maintaining and keeping this open source!

janbender commented 4 years ago

In my PBF implementation I use pressure clamping which is not used in the original paper. The surface tension effects there come from an undesired error at the free surface. This surface tension effects cannot be controlled. I would recommend to implement a more sophisticated surface tension method, e.g. the one of Becker et al. 2007. Take a look at our open-source fluid simulation framework (also supporting 2D simulations):

https://github.com/InteractiveComputerGraphics/SPlisHSPlasH

There you will find the implementation of 3 different surface tension models. Btw. we also have an open-source GPU neighborhood search which might help you.

asbjornlystrup commented 4 years ago

Thanks for the reply. And I didn't notice that repository. Nice work!

Just to be sure, when you say original paper, are you referring to the first PBF paper? And do you mean that it's that paper that is error-based or the implementation in this repository? The PBF method in "Unified Particle Physics for Real-Time Applications" uses a modified version of the original PBF, with cohesion/surface tension from Akincki et al.'s "Versatile surface tension and adhesion for sph fluids" from 2013. The one of Becker et al. looks good too. I will see what fits best.

I have implemented an SPH simulation with GPU neighborhood search based on http://www.fluids3.com/. Looking for incompressible methods is what eventually had me stumble upon position-based dynamics. I implemented my neighborhood search with counting sort because this presentation from 2014 mentioned it as faster than radix sort (if your use case only requires a fixed-size rectangle): http://on-demand.gputechconf.com/gtc/2014/presentations/S4117-fast-fixed-radius-nearest-neighbor-gpu.pdf I see you've referenced it in the cuNSearch repository, but you're using thrust's sort as far as I can tell. Since my game is 2D, the amount of cells is relatively small. I would be interested in hearing your opinion on this. Do you think basic counting sort is better than thrust's sort implementation in my case? (Considering I'm only simulating within a somewhat small grid.) And do you happen to know the trade-offs between state-of-the-art bitonic sort vs. radix sort? I assume thrust is using some sort of bitonic sort as they do comparisons, but not sure.

janbender commented 4 years ago

The Akinic surface tension works fine. Check our SPlisHSPlasH framework if you want to test it. There we implemented it and it should also work in 2D.

asbjornlystrup commented 4 years ago

I will take a look, thanks!