# Smoothed Particle Hydrodynamics

This topic is 1126 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all!

.

I'm pretty much at my wit's end with SPH. I've implemented incompressible Eulerian fluid simulations before, but this is proving to be a bit more challenging.

.

So I just want to make sure I have everything down so that I'm not mistaking everything horribly. From what I understand, the algorithm for just basic SPH is:

for each particle
calculate density and pressure
for each particle
calculate gradient of pressure and apply it to the particle's velocity
apply gravity
for each particle
enforce boundary conditions


.

For calculating the density, I use the poly6 kernel:

$W( \vec{r} ) = \frac{315}{64 * \pi * h^9} (h^2 - |\vec{r}|^2)^3$

.

For calculating the pressure, I use the gradient of spikey kernel:

$W( \vec{r} ) = \frac{15}{\pi * h^6} (h - |\vec{r}|)^3$

$\nabla W( \vec{r} ) = - \frac{45 * (h - |\vec{r}|)^2}{\pi * h^6} * \frac{\vec{r}}{|\vec{r}|}$

.

For calculating pressure I use $$P = k * (\rho - \rho_0)$$ , although I've seen a bunch of references to a equation with an exponent of 7 floating around.

.

All of this checks out with what academic papers say, but in my current implementation, the particles immediately fall to the bottom of the screen and start squeezing together. I wish I had a video of it, but it happens so fast that OBS can't capture it.

.

I personally suspect that the gradient of the spikey kernel is is the issue, just based off of how the fluid clumps together in strange ways once all the particles fall to the bottom. I'm not applying any near-pressure, just to keep everything simple, but even without it the simulation shouldn't fall to the bottom in 0.5 seconds. Another thing I'm suspicious of is the k, rho_0, and h constants, because it's a little difficult to tune the simulation when it doesn't last very long

.

Does anyone have any experience with SPH who could lend some insight? I implemented this paper but it can't be implemented very easily on the GPU, which is why I'm interested in a more pure SPH approach, so insight on either one of these would be enormously helpful!

.

I'm attaching the code for anyone who could take the time to look over it. It's 1 file, a couple functions, nothing too big or too fancy fancy of data structures. All computations are O(n^2) and structures are not very optimized, just as a sanity-check.

.

##### Share on other sites

Hey,

there are some weird things about this. which doesn't mean they are wrong, just not what i would expect.

your gravity seems to depend on density. that seems strange, considering each particle's weight should always be the same. lets say 1000 particles weight one kilo, then 1000 particles really close to each other don't suddenly weight a ton.

looks a lot like https://github.com/finallyjustice/sphfluid, see here https://github.com/finallyjustice/sphfluid/blob/master/SPH_CPU_2D_v1/sph_system.cpp especially.
look at the gravity there, and the poly/spikey functions also.

and how the pressure is applied as a force.

there are some cool sph-gpu demos around, like: http://code.google.com/p/gpusphsim/

##### Share on other sites

That might be something I'm confused about. From what I understand, the Navier-Stokes equation takes the form

$$\rho(\frac{Du}{Dt}) = F_{pressure} + F_{grav} + F_{viscosity}$$ ,

which would imply that the gravity force IS dependent on the density of a particle, unless the density there is talking about the rest density. If that's the case, then I'm very confused.

And I'll look at those links, thanks!

##### Share on other sites

The density of an SPH particle can (and does) change, however the mass implicitly remains constant. This is required to enforce conservation, from this we conclude that the volume a particle represents actually varies with density. This fact about SPH is often missed when one relies on the particle interpretation, SPH particles are not rigid particles, they are overlapping volume elements.

Your gravity implementation is indeed incorrect if it includes a density term. Gravity should be implemented by applying an additional acceleration to the particle, which is determined as the particle mass multiplied by gravitational acceleration.

Without having looked at your code I cannot say whether this will solve all your problems.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 10
• 13
• 10
• 12
• 10
• ### Forum Statistics

• Total Topics
633001
• Total Posts
3009820
• ### Who's Online (See full list)

There are no registered users currently online

×