Jump to content
  • Advertisement
Sign in to follow this  
Bjrn

2d fluids, need advice

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

GOAL: I'm trying to make a prototype of a game, where the player tries to save cavemen from rising water/lava levels, by interacting with the cave structure to steer the liquids flow away, and buy enough time for the cavemen to move out of harms way. It's represented in 2d, viewed from side, within a cave environment. PRIMARE OBJECTIVE - Write some kind of fluid behavior, probably particle approach, 500-1000 particle tops. REQUIREMENTS - No need for advanced graphics at this point - No need for any kind of optimization SOURCE OF MATERIAL: I'm reading the paper same paper as I find almost everyone else working after, "Particle-based Fluid Simulation for Interactive Applications" by Müller et al. 2003. CONCLUSIONS A. The only forces acting on the particles is: * pressure * viscosity * internal fluid collision (particle to particle) * external fluid collision (particle to environment) * gravity * (surface tension, which I don't care about) B. pressure push particles away from each other, viscosity stabilizes them. C. A valid way to handle collisions (external and internal) is to: move objects out of each other, reflect their velocity with contact normal QUESTIONS: 1. Is it right to handle the particle to particle collision by moving them out of each other, isn't pressure force enough to make the move out of each other? 2. If this is all correct, isnt's all a matter of using different equations and the smoothing kernels for finding out the density, pressure and viscosity and then to update the velocity each frame? 3. Where can I find information about 2d kernels, as acording to this thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=451266, the kernels in the paper is for 3d simulation. 4. You think there is a simpler way to archieve what I'm trying to do that will yield sufficient results?

Share this post


Link to post
Share on other sites
Advertisement
ok, I have some experience with Smoothed Particle Hydrodynamics, so I'll do my best to answer your questions
Quote:

1. Is it right to handle the particle to particle collision by moving them out of each other, isn't pressure force enough to make the move out of each other?

No, the pressure force is not enough unfortunately. Even with the most advanced SPH codes, there exists this clumping instability (where particles clump despite being no attractive forces) and the most popular way of solving it is using a modified kernel function which effectively repels the particles if they get too close.

Quote:

2. If this is all correct, isnt's all a matter of using different equations and the smoothing kernels for finding out the density, pressure and viscosity and then to update the velocity each frame?

Yes, the once you have the acceleration then you can update the velocity (and positions) of all particles. The SPH algorithm is fundamentally quite simple.

Quote:

3. Where can I find information about 2d kernels, as acording to this thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=451266, the kernels in the paper is for 3d simulation.

Can't help you directly with this since I use different kernels with different normalisation constants. Basically you just have to take the basic function and integrate over all space (in 2-D). In this case, it is over a circular area of radius r,

i.e. I = int (2 pi r W(r,h) dr) between the limits r=0 and r=h

Calculate this expression for the integral and then to normalise W(r,h), just divide by this expression. I would have a try now myself, but I don't have the time.

Quote:

4. You think there is a simpler way to archieve what I'm trying to do that will yield sufficient results?

Don't know, but once you get the SPH algorithm working, it should be pretty flexible to work in most types of simulation. The only thing I would warn is that the smoothing length (h) has to be smaller than the width of any tunnels and walls in the cavern, otherwise you may not be modelling the fluid correctly and funny things can happen. However, there is no constraints on h, so you could make h a function of position.

A final point about SPH. You should be able to handle several hundred particles easy enough. The biggest expense in SPH is to find the neighbours of a particle (i.e. all the particles which lie within a radius of h). With several hundred particles, you could just sum over all particles; otherwise if you have more, you may need a more complicated data structure (e.g. a tree or linked lists), or the SPH computation will kill your performance.

Hope that helps :-)
Sergamer

Share this post


Link to post
Share on other sites
Regardless of the implementation you use, it may be handy to clarify your Conclusions:

Momentum is related to the flux of energy (e.g.: a moving particle has momentum).
Pressure is related to the flux of momentum (e.g.: momentum is transferred when particles collide).
Viscosity is related to the diffusion of momentum (e.g.: a particle's momentum bleeds away gradually while moving through honey, and this bled-out momentum disperses throughout the honey in a fluffy-expanding-cloud-like fashion).

These perspectives are documented well by the Navier-Stokes equations and the stress-energy tensor of general relativity.

I hope that's of some use, but perhaps it's not. :)

Share this post


Link to post
Share on other sites
I was somewhat tempted to try exactly what you're doing (2d fluid simulation using the Muller paper). If you make any progress, I'd definitely appreciate any tips you can offer.

Share this post


Link to post
Share on other sites
There's the source code to my implementation of this paper, if it helps:

http://www.rowlhouse.co.uk/water/

It's rather old now. The hardest things are probably (in no particular order):

* Efficient rendering
* Choosing parameters so that the simulation is stable, yet the fluid isn't too springy
* Preventing bunching up of particles at boundaries
* Interactions with rigid bodies

But it sounds like the right solution for your problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!