Sign in to follow this  
Inian

Fluid dynamics

Recommended Posts

Hey there. I'm currently working on a project in school where I want to simulate the internal workings of a fluid in a static environment. This is mainly for a submarine game where it will be used to add some extra feeling to the water without actually having any affect on the gameplay itself. Currently I have been looking at three different models for this type of simulation and have made very little progress deciding which one to go with. The models are: Navier-Stokes equations - Simulates everything perfectly but is slow to compute/implement. Lattice Boltzmann - Actually, I'm having trouble finding any info about this but I've heard it's heavy to implement/compute but it seems to be gaining ground in the simulation world. Cellular Automata - A very rough simulation that will need a lot of tweaking to make it look good, advanced behaviour (Coanda effect/turbulence) will be difficult to implement. But in general it's easy to get working on a rough scale and supposedly it's fast but somewhat memory consuming. I guess it's fairly obvious that CA is the one I feel is the most appropriate at the moment but I'd like to know if there are other ways of doing this that I have overlooked. Or if you think I am on the right track with CA. Cheers!

Share this post


Link to post
Share on other sites
Quote:
Original post by Inian
I'm currently working on a project in school where I want to simulate the internal workings of a fluid in a static environment. This is mainly for a submarine game where it will be used to add some extra feeling to the water without actually having any affect on the gameplay itself.


Since the fluid model is really icing on the cake, I don't think the models you are looking at a worth implementing. Don't get me wrong: if you are just interested in modelling the fluid for your own personal satisfaction, then full steam ahead! However, if you just want to convey the idea of fluid motion to the player these methods are overkill.

I'm really too sure though what you hope to convey to the user. I mean, the Coanda effect is hardly something that is going to affect a submarine, and even turbulence is generally going to be slight. Perhaps you could elaborate on what you want the user to experience?

Share this post


Link to post
Share on other sites
google for

fast stable fluids

there was a "pong" game a couple of weeks/months back on the gamedev image of the day - maybe you want to do something similar?

If you want to simulate the air/liquid interface as well then a particle method (e.g. smoothed particle hydrodynamics) might be appropriate.

2D or 3D is a big difference...

Share this post


Link to post
Share on other sites
To jjd:

Well, the fluid modelling part is what I am working on, the fact that it's for a game is just to have someone to evaluate my results. In the said game the fluid won't affect the submarine at all, I'm not sure what my client really wants it for but he was talking about alien corpses floating around or something like that. Actually it began with me wanting to model an outdoor scene with some hills and tree's and having leaves blow over the terrain and just look awesome, but I wasn't allowed to do this so now I'm making something for alien corpses in a submarine game. The reason I got interested in all of this is because the usual way to fake wind is with some form of cheesy vertexshader and a sin function. And being me I want something a little different, everyone else is doing HDR, fur shading and similar boring pretentios brown-nose projects and I want to be different choosing something that is tough and uncommon.

To MrRowl:

I have googled ;) a lot. So did this pong have an internal fluid sovler of sorts? Otherwise I don't see it's relevance. No, I don't want to simulate the air/water interface, just the internals of one fluid (Water mainly but I'm going to use it for Air also since they are fairly much the same on a larger scale.) I haven't seen any good fast implementations of smoothed particle hydrodynamics out there, the fastest was a 4 hour rendering of a 10 second animation... not really real-time if you ask me. If you have any links to solutions like this I'd love to see em though.

To twanvl:

WOW!!! Perfect! This is exactly what I am looking for! Thank you very much!

Share this post


Link to post
Share on other sites
Inian, Stam's papers are great, as is Mark Harris'.

I've converted Stam's source code from the paper into 3D, so if you are interested in that, I can pass you along a copy of it.

Share this post


Link to post
Share on other sites
Using the Stam method in 3d, be very careful about memory. For instance, if you try to use a 128x128x128 space, storing each of density and 3 components of velocity as floats, that's 32 megs of memory. And you could do something like 80 passes over this memory to resolve all the gauss-seidel relaxations. You'll be memory-bound in a heartbeat.

Don't get me wrong... this is a fine method. But I would still advise you to see how far you get with 2D first. Either that, or try to shift the location of the grid with the submarine so you don't have to compute more than a 64x64x64 section of fluids.

Share this post


Link to post
Share on other sites
I wrote my bachelor's thesis last semester based on Stam's article. Or specifically, on ways to optimize it. It's a great article, but don't just copy his code. It's horribly inefficient. [lol]

The very first fix should be to swap the loops when iterating through the array. His code does so column-major, which thrashes the CPU cache.

We made a bunch of other changes, and ended up with an 8x speedup.
Only problem is that we wrote our report in Danish, otherwise I'd send you a copy... [wink]

But PM me if you're interested in our code, or a description of what we changed.

Share this post


Link to post
Share on other sites
Quote:
Original post by jjd
However, if you just want to convey the idea of fluid motion to the player these methods are overkill.

I'm really too sure though what you hope to convey to the user. I mean, the Coanda effect is hardly something that is going to affect a submarine, and even turbulence is generally going to be slight. Perhaps you could elaborate on what you want the user to experience?


[imwithstupid] there's no 'I'm with' emoticon on GameDev.net; delete 'stupid'

here we go, grabbed some from CorvetteForum.com

Stam et al's methods are cool for smoke/turbulent-fluids-with-dye, etc., but for everything else, there are simpler + way (way*) faster methods. As jjd asked, what effect are you looking for?


*for example, a player caught in a whirlpool, simulated with advanced G.I.F (Generalized Inviscid Fluid) simulation:

Share this post


Link to post
Share on other sites
Quote:
Original post by Inian
I have googled ;) a lot.


I just gave the search terms because they not only result in the Jos Stam stuff (i.e. the twanvl link), but also comments on it.

Quote:
So did this pong have an internal fluid sovler of sorts?


Of course, else I wouldn't have mentioned it! It's here

Quote:
I haven't seen any good fast implementations of smoothed particle hydrodynamics out there, the fastest was a 4 hour rendering of a 10 second animation... not really real-time if you ask me. If you have any links to solutions like this I'd love to see em though.


It's only 2D, and probably not as fast as it could be, but there's mine. There's others too, some in 3D, some all on GPU etc (e.g. here). However, I suspect the grid-based approach is better for you.

Share this post


Link to post
Share on other sites
taby - I'd love a copy of the code you made, all help is welcome and being a programmer code is just so much my friend.

ajas95 - Yes I made some calculations myself on the matter and it grew very fast, I'm thinking of limiting the amount of grid sections in one direction to solve this though. But I don't know if this will produce proper results.

Spoonbender - Thanks for the warning. Actually I can read Danish and would very much love a copy of your thesis if available. Also I'd love a copy of your code and any despription available other than the thesis. (I'm somewhat partial to UML and state-/flowcharts if you have used anything like that)

John Schultz - Well what I am looking for is just a model for calculating how flow behaves with 1 fluid. An example would be lets say a cut out of the ocean a bit underwater, no air to deal with and no 'sides' just the ocean floor. I'm also going to neglect differences in heat/salidity etc and just assume all the water is the same and then 'push' water in from a point (a point can be an entire side) and have water exit somewhere (most likely the opposite side). To visualize that this is happening I'm going to add a set of particles (plankton maybe) to the entire scene and have them follow the flow showing it's presence. The particles/Submarine etc won't be affecting the flow at all, just the ocean floor and whatever large bedrock that is added(Probably not realistic but it is what my client wants).

MrRowl - Sorry I Was a bit harsh earlier, I'm actually not doing to well IRL and am very hostile/defensive and misread you. Thanks for the links and the input! And again sorry for being unfriendly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Inian
John Schultz - Well what I am looking for is just a model for calculating how flow behaves with 1 fluid. An example would be lets say a cut out of the ocean a bit underwater, no air to deal with and no 'sides' just the ocean floor. I'm also going to neglect differences in heat/salidity etc and just assume all the water is the same and then 'push' water in from a point (a point can be an entire side) and have water exit somewhere (most likely the opposite side). To visualize that this is happening I'm going to add a set of particles (plankton maybe) to the entire scene and have them follow the flow showing it's presence. The particles/Submarine etc won't be affecting the flow at all, just the ocean floor and whatever large bedrock that is added(Probably not realistic but it is what my client wants).


I wrote up some ideas regarding your desired sub/water/particle behavior here.

Share this post


Link to post
Share on other sites
Quote:
Original post by John Schultz
Quote:
Original post by Inian
John Schultz - Well what I am looking for is just a model for calculating how flow behaves with 1 fluid. An example would be lets say a cut out of the ocean a bit underwater, no air to deal with and no 'sides' just the ocean floor. I'm also going to neglect differences in heat/salidity etc and just assume all the water is the same and then 'push' water in from a point (a point can be an entire side) and have water exit somewhere (most likely the opposite side). To visualize that this is happening I'm going to add a set of particles (plankton maybe) to the entire scene and have them follow the flow showing it's presence. The particles/Submarine etc won't be affecting the flow at all, just the ocean floor and whatever large bedrock that is added(Probably not realistic but it is what my client wants).


I wrote up some ideas regarding your desired sub/water/particle behavior here.


Excellent article. A lot of the information explained in the article is presented from a different view than what I learned. An amazingly straight-forward reference, nice.

Share this post


Link to post
Share on other sites
Quote:
Original post by John Schultz

I wrote up some ideas regarding your desired sub/water/particle behavior here.


Very interesting indeed, although not exactly what I am looking for. It seems that I would myself have to add points in the world where vortices would emerge with this method, if not I have misunderstood.



After talking with my supervisor we decided that since there has already been soe nice models for this kind of simulation (and even ways to optimize them) that I would try and see if I couldn't find more and dish them out agains eachother making a comparison instead of just implementing one of them.

My first method would be the one made by Stam that Spoonbender optimized.

Also your particle method sounds interesting and I have seen several people use particles to simulate fluid flow. Although I have no name for this type of method I was wondering if anyone out there knows of one for internal fluid solving and what it is called. This would be my possible 2nd choice.

My third choice is the Cellular Automata mentioned in Game Programming Gems 3 although I have found very few people implementing this specific model (A kind of reverse engineering of Stams' method) and would appreciate it if anyone knows of any such project.



These are the methods I know of right now and my supervisor says I should have at least 4 but not more than 6. Does anyone know of any other ways of solving internal fluid dynimics in real-time? Do you think my first 3 choices are ok or should I not use them?

Anyway, I sppreciate all the responses people have given thus far and for all the help I have recieved.

Cheers!

Share this post


Link to post
Share on other sites
Quote:
Original post by Inian
Also your particle method sounds interesting and I have seen several people use particles to simulate fluid flow. Although I have no name for this type of method I was wondering if anyone out there knows of one for internal fluid solving and what it is called. This would be my possible 2nd choice.


The method suggested by John isn't really about simulating fluid flow, but about simulating the effects in a purely visual manner - so it's just a "sophisticated" and partly physically-based partical system like you'd find in many games. It's programmed from the top down (in a way) - you know the effects you want to see so you program the particle behaviours that would result in this.

The particle-based fluid simulation method used in physics engines like PhysX and Meqon is (almost certainly) based on a method called Smoothed Particle Hydrodynamics (though also called other things). It's programmed from the bottom up in that the behaviour of each particle is derived from an approximation of the Navier-Stokes equations - each term in those equations being expressed in terms of particle properties (and properties of the distribution of particles).

Consequently, there are two "particle methods" here, bringing your total up to 4 :)

Share this post


Link to post
Share on other sites
Quote:
Original post by taby
Excellent article. A lot of the information explained in the article is presented from a different view than what I learned. An amazingly straight-forward reference, nice.


Thanks, taby. I'll update the page from time to time, when I have time [smile].


Inian, if you have access to 3DSMax, you can test out some of the concepts (in pretty much real-time) using Vortex, Wave, Ripple, (etc.) SpaceWarps and particle systems. Other 3D packages will have similar systems (Maya, SoftImage, etc.).

In your analysis it will probably be useful to compute a metric based on CPU cost-per-pixel. Start with float-ops per pixel to get a basic idea, then benchmark (cache/memory, etc., will make a big difference).

More info on SF-CFD:

Quote:

If you use SF-CFD along with an implicit volume for the sub (ellipsoid or rounded cylinder), it will be intuitively easy to implement, visualize, and debug. If using macro particles (small rigid body spheres) you can increase apparent pixel density by rendering alpha-blended rotating billboards of hundreds or thousands of particles (a texture mapped sphere might also work OK, though the curvature may cause issues with the edges. In the case of the billboard: the texture map would be created with many particles of various sizes, alpha-densities, and have a roughly circular perimeter). Texture coordinate tricks can also be used to swirl and distort the rendered billboard (instead of a simple quad, use a grid with sufficient density to perturb the texture in a pleasing manner).


Googling for SF-CFD (Spatial Field CFD) may not turn up anything; I used the term to describe this system (may have been used before, perhaps not; may be a better term out there).

Whichever method use (could be hybrid), you may need to use some tricks to get the pixel density high enough to render and interact with in real time (and do so on common consumer hardware (unless you are developing for XB360/PS3 in which case you can go to town using the extra processors)). This brings to mind Aegia's fluid demos (HW accelerated): macro particles blended together with what appears to be 'blobby/implicit/meta-balls' rendering. A cool CFD demo and CFD in a real-time game engine are two different animals.

Share this post


Link to post
Share on other sites
Quote:
Original post by Inian
Also your particle method sounds interesting and I have seen several people use particles to simulate fluid flow. Although I have no name for this type of method I was wondering if anyone out there knows of one for internal fluid solving and what it is called. This would be my possible 2nd choice.


a method involving particles instead of a grid is most often referred to as a lagrangian method.

Share this post


Link to post
Share on other sites
Quote:
Original post by Eelco
Quote:
Original post by Inian
Also your particle method sounds interesting and I have seen several people use particles to simulate fluid flow. Although I have no name for this type of method I was wondering if anyone out there knows of one for internal fluid solving and what it is called. This would be my possible 2nd choice.


a method involving particles instead of a grid is most often referred to as a lagrangian method.


Lagrangian CFD particle system.
Hamiltonian CFD.
Lots of different ways to formulate and solve the problem. I would start with the simple and intuitive, and find out how far it scales (since you will more easily be able to tweak/tune/optimize/debug).

Share this post


Link to post
Share on other sites
Very interesting indeed. Then your (John) method will be a particle based method that is similar to CA which is grid based, both relying on the programmer to properly describe rules for the desired behaviour. These will make for an interesting comparison all by themselves in my opinion.

For the reason the Hamiltonian link was down right now but I did a quick google and looked it up, from what I could see it seems to be a method based on calculating curves. I'm on my way out right now so I only had a quick glance at it but it looks somewhat complicated to me.

So now I have 4 methods without counting any form hamiltonian solver.
1. Spoonbenders optimized version of Stams' solver. (Couldn't find any specific name for this method.)
2. SF-CFD.
3. CA.
4. Smoothed Patricle Hydrodynamics.

Is there any method you think I have missed and should add? Do you think I should add a Hamiltonian solver to the comparison?

Anyway, thanks again with all the help everyone.
/Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this