# Looking for help with Smoothed Particle Hydrodynamics

## Recommended Posts

Hello,

I'm trying to add a very basic incompressible fluid simulation to my game; all i want to do is determine "given an pipe outputting pressure P at location X, what spaces are occupied by water?" I'm not too concerned with the other parts of flow.  So if anyone knows of any kernel functions that trade accuracy for speed/stability, that would be appreciated.

This is what I have so far:

Spoiler

The rectangles have 3 purposes: they are the containers for the liquid, determine if it is on screen, and they are the units used to divide it between threads.

I based it on this code: https://github.com/tizian/SPH-Water-Simulation

So these are the issues i'm having:

The first is that i'm not sure if my pressure values are good, I'm rendering the pressure with:

	void main()
{
float pressure = clamp(log2(v_pressure/800)/20.0, 0, 1);

vec2 p = gl_PointCoord.st * 2 - 1;
float c = min(length(p), 1);
fragColor = vec4(pressure, 1-pressure, 0, (1-c));
});

And I'm not sure if i should need to take a logarithm to see what the pressure is; is this normal?

Next is that i'm noticing that i have this straight line of particles at the bottom, and from what i can tell 1/3rd of the particles i spawn consistently form a straight line at the edges, is this normal?

I'm also not too sure of what the smoothing parameter used by the kernels is--it took me a while just to figure out it needs to be in meters--my best guess is that it's the sum of the radii of the 2 particles interacting. Is that right?

And finally, just that i can't figure out how to make it incompressible; i looked at a few papers like this one http://mmacklin.com/pbf_sig_preprint.pdf, where I couldn't really follow how the changes made helped solve the problem--to me it looks like they just didn't account for viscosity/gravity on alternating ticks--and this one: https://www.gdcvault.com/play/1012447/Go-With-the-Flow-Fluid Where I didn't understand how the repulsion force is any different from pressure, and it seems to me that will just make it more inclined to blow up. I'm hoping someone can ELI5 why either of these should work.

## Create an account

Register a new account

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011831
• ### Who's Online (See full list)

There are no registered users currently online

×