# Navier-Stokes and forces

## Recommended Posts

Hi. I've managed to implement the NSE-solvers in Jos Stam's GDC03-paper "Real-Time Fluid Dynamics for Games" without too many problems, and managed to get rather interesting movements in te volumes by simply adding manual velocities to it. This is rather useless though, since the whole point of making this in the first place is to get a rater physically correct fluid. So i'm trying to figure out how to apply forces to this volume. When i'm thinking about it it doesn't seem that there's an easy way of sticking Newtons second into the system, and i can't really come up with any other alternatives :( So please, help? Edit: I think i've done it, although im not sure if it's correct. Wouldn't it be correct to simply add the forces to the velocity? I had totally missed the +F in the equation, just spotted it. And i surely get results when i add the forces. Tobias Karlsson Sweden [Edited by - tok_junior on September 1, 2004 7:35:59 AM]

##### Share on other sites
i dont completely understand what youre trying to say...

you managed to apply forces, but thats no good because you want to apply forces?

anyway, to make this usefull for games all youll have to do is set boundary conditions on the fluid according to your gameworld and objects, apply forces to your fluid according to moving objects, and optionally let the objects be influenced by the fluid flow.

experiment with setting arbitrary boundary conditions on the flow: i found this to be quite hard to get working quite right.

applying forces according to moving gameobjects shouldnt be that hard me thinks.

##### Share on other sites
I think you misread/misunderstood. I've applied velocities, not forces. And now i want to add forces instead.

##### Share on other sites
If you're willing to keep it simple and not let the objects influence the flow, then this seems like an easy problem...I'm ignorant of NSE...let me see...oh mathworld has it...well, it seems that you're basically working with a differentiable vector field that defines your velocity...why not just compute accelerations by differentiating w/respect to time, then you can multiply by mass to get forces, if that's what you want. Just keep in mind, you're talking about acceleration of fluid parcels, so you might multiply by the mass of a fluid parcel, which you can probably set arbitrarily. If the fluid parcel is infintesmal, you can then compute net forces on an object by integrating over the surfaces of the object in the fluid.

I suppose a more challenging problem would be to start with a scalar pressure field and kinematic velocity, and solve the differential equation for the velocity, but I can't imagine why you should happen to know these things for a game...

##### Share on other sites
Doesn't Jos's paper mention, explicitly, the addition of an external loading force? If not, then try this earlier paper on the same subject:

Stable Fluids

See especially equation 2 and Section 2.2, :).

##### Share on other sites
Yes, turned out to be very easy indeed.
Now the problem is my diffusion adds density to the system :(

EDIT:
Never mind, i really should start commenting out old lines before i insert the same lines in another place.
DOH!

##### Share on other sites
Quote:
 Original post by tok_juniorYes, turned out to be very easy indeed.Now the problem is my diffusion adds density to the system :(

Which I suspect is because of numerical error? If so, either use a better integrator, or just renormalise your density every few iterations. If not, then you've incorrectly implemented the computation.

Cheers,

Timkin

##### Share on other sites
Tim is correct in saying that a better integrator may help. But, it will not eliminate the diffusion entirely. The added diffusion, known in engineering CFD circles as artificial dissipation, is pretty much impossible to eliminate entirely. Actually, only in special cases, when you can achieve what is known as "perfect shift," can you fully eliminate such errors that creep in. The extra diffusion (and in some cases dispersion) is simply the Taylor Series truncation error inherent in the finite differences. The perfect shift condition is a very special case when the truncation error is exactly zero. I can refer you to some excellent books that explain this in good detail, if you'd like.

##### Share on other sites
I've noticed there's a major difference, it even looks as if nothing's added, if i use a high diffusion, say about 100.0. As I'm totally new to everything fluid, i have no idea what a normal diffusion-rate would be.
If someone could point at somewhere i can find rates for say water and smoke, i'd be a happy camper indeed. Or well, just giving me some general pointers on diffusion would work aswell.

By the way, as a first-time poster in this forum, i must say it's by far the best one i've seen on gamedev. Clean posts, and accurate information, especially by grhodes. Cudos to all of you, and thanks for helping out :)

##### Share on other sites
>>If someone could point at somewhere i can find rates
>>for say water and smoke, i'd be a happy camper indeed.
>>Or well, just giving me some general pointers on diffusion
>>would work aswell.

Well, if you are after realworld physical parameters, you should first check two things:

2.) you take fluid density into account. meaning that if you have a force field F, you use the formula v += F/density to add forces to the velocities (these density parameters are easily found even in high school textbooks).

But diffusion rates are a different thing... as people have pointed out, fluid simulation (and especially the semi-Lagrangian method) causes so much artificial diffusion to the velocity field that in practice, no diffusion is even needed. Actually, there exist even methods that try to fight back artificial diffusion of turbulence by using a specialized force (a technique called vorticity confinement).

So in brief, even if you had the most accurate diffusion parameters in the world, the diffusion will still be unrealistically high.

Of course, finding such parameters might be an interesting exercise.

- Mikko

##### Share on other sites
Oh, but i was talking about density-diffusion, not velocity-diffusion :)
And the reason i want to know along what lines the diffusion-rates should be is just that im curious, and that i would like to know if having it as 100 is very far from real.

##### Share on other sites
The same applies for density diffusion, too: the semi-Lagrangian advection you do on it already diffuses the density field so greatly that manual diffusion really is unuseful.

>> as 100

Well, I doubt that realworld diffusion constants are scalars... they probably have some unit, too. In order to use these unit-based (metric system) diffusion constants in your simulator, you need to make sure that your fluid sim is based on real temporal/spatial paramterers (timestep in seconds, grid sizing in meters), too.

(That's not to discourage you - just an important note if you really want realworld physical constants)

##### Share on other sites
Already using realworld units for everything.
I found a table of sorts that stated free-flowing water has a diffusion coefficient of 11Å, which means there's no way i'll be able to simulate that until i've found some way of decreasing the numerical errors. It also sucks that with a lower diffusion coefficient than about 100, density gets added to the system at a very noticable rate :(
Got any links to where i can find info on how to decrease the errors?

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628350
• Total Posts
2982211

• 10
• 9
• 24
• 11
• 9