Search code examples
physicsgame-physics

Smoothed Particle Hydrodynamics - Particle Density Estimation Issue


I'm currently writing an SPH Solver using CUDA on https://github.com/Mathiasb17/sph_opengl.

I have pretty good results and performances but in my mind they still seem pretty weird for some reason :

In some implementations, i saw that a particle does not contribute to its own internal forces (which would be 0 anyways due to the formulas), but it does contribute to its own density.

My simulations work "pretty fine" (i don't like "pretty fine", i want it perfect) and in my implementation a particle does not contribute to its own density.

Besides when i change the code so it does contribute to its own density, the resulting simulation becomes way too unstable (particles explode).

I asked this to a lecturer in physics based animation, he told me a particle should not contribute to its density, but did not give me specific details about this assertion.

Any idea of how it should be ?


Solution

  • As long as you calculate the density with the summation formula instead of the continuity equation, yes you need to do it with self-contribution.

    Here is why:

    SPH is an interpolation scheme, which allows you to interpolate a specific value in any position in space over a particle cloud. Any position means you are not restricted to evaluate it on a particle, but anywhere in space. If you do so, obviously you need to consider all particles within the influence radius. From this point of view, it is easy to see that interpolating a quantity at a particle's position does not influence its contribution.

    For other quantities like forces, where the derivative of some quantity is approximated, you don't need to apply self-contribution (that would lead to the evaluation of 0/0).

    To discover the source of the instability:

    • check if the kernel is normalised
    • are the stiffness of the liquid and the time step size compatible (for the weakly compressible case)?