POV-Ray : Newsgroups : povray.off-topic : Liquid Physics : Re: Liquid Physics Server Time
1 Oct 2024 15:24:21 EDT (-0400)
  Re: Liquid Physics  
From: Kevin Wampler
Date: 31 Mar 2008 15:46:34
Message: <47f14daa$1@news.povray.org>
Assuming that you're writing this simulation for graphics purposes 
rather than physical simulation where accuracy is a major concern 
there's some other methods that you might consider.

First, a bit of terminology.  There's two main paradigms I'm aware of 
which are used to simulate fluids: Eulerian and Lagrangian.  In the 
Eulerian approach you consider what's happening in a small fixed piece 
of space and look at how that changes based on the pieces of space 
around it.  In the Lagrangian approach, on the other hand, you consider 
what happens to pieces of the fluid as they move around.  The approach 
you describe is then a Lagrangian approach.

As you've noticed, stability can be a problem when you integrate out 
these sorts of equations to determine how the fluid should move over 
time.  Changing the integration mechanism (such as to a Runge-Kutta 
integrator) or decreasing the time-step can help this to a degree, but 
there exist fluid simulation methods which are unconditionally stable. 
That is, the simulation will never `blow up' no matter what you do, even 
with very large time steps in the simulation.

Probably the simplest such technique is the "Stable Fluids" algorithm 
invented by Jos Stam.  It uses some concepts from both the Eulerian and 
Lagrangian viewpoints, and is this referred to as a "semi-Lagrangian" 
method.  There's a very easy to ready paper on the algorithm that even 
gives some code for how to implement it:

http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf

The algorithm itself should be also pretty easy to implement, and is 
also useful in a educational sense as it uses some interesting 
techniques (such as, iirc, explicitly projecting the flow onto a 
divergence-free space to achieve an incompressible flow).

There are also some fully particle based fluid simulation methods which 
are more similar to yours in their apploach, but I'm not aware of any 
which are as simple to implement as the stable fluids algorithm.  You 
can check out some early examples:

http://graphics.ethz.ch/Downloads/Publications/Papers/2003/mue03b/p_Mue03b.pdf
http://www.cs.utah.edu/vissim/papers/ParticleFluid/ParticleFluidsLowRes.pdf

Or see a more recent paper on such a method at:

http://graphics.stanford.edu/~barta/research/adams-sig07.pdf

I suspect implementing one of these methods (or one of the newer 
Eulerian / semi-Lagrangian ones) would be more work than you care to 
spend, but I think stable fluids should be pretty reasonable to do 
without a crazy amount of work.

Note, however, that all the stuff I mentioned is based on simulating the 
Navier-Stokes equations.  If you're only looking for something that 
looks sortof-kinda like a fluid rather than behaving as a proper fluid 
then there's probably all sorts of shortcuts and hacks you can do, and 
in this case I agree with scott's suggestions so I'd start playing 
around with using a better integrator and/or adding some sort of 
artificial dampening.




Chambers wrote:
> So, just for fun I'm writing a quick liquid simulation.  Because I like 
> liquids, and I'm learning C#, that's why :)
> 
> Anyway, I'm running into some problems with the simulation.  Namely, a 
> certain instability.  Here's what I'm doing:
> 
> For each particle, I loop through all the other particles (i=0..count-1, 
> j=i+1..count), and check the distance between them (I use some 
> additional bounding to speed things up, but that's not important to my 
> problem here).  I compute the forces the two particles place on each 
> other, and then add them to each particles' total "force" value.
> 
> Once I'm done computing interactions, I loop through all the particles, 
> add the force to the velocity, and reset the force to zero.
> 
> The way I see it (and granted, I've never written a liquid sim before), 
> there are two forces I need to deal with, pertaining to two stages that 
> occur when liquid particles collide:
> 
> 1) When the particles are farther apart, they attract each other.  This 
> weak attraction would be the driving force behind surface tension.
> 
> 2) When the particles are closer together, they push against each other. 
>  This force must be much stronger than the first in order to maintain 
> some volume.
> 
> Now, so far I'm only actually implementing the second force above. 
> However, what I see is that the particles tend to settle pretty quickly 
> to the floor, and then they clump together.  Apparently, the particles 
> on the outside "force" the particles in the middle of the clump closer 
> and closer, until they suddenly explode and things go flying everywhere.
> 
> I *think* the problem has to do with conservation of momentum.  I 
> naively dealt with that by halving the force applied to each particle in 
> a pair (one half of the force gets applied to each), but that's not 
> quite right, is it?  The momentum of each particle shouldn't simply be 
> split evenly with every individual particle it collides with... rather, 
> I'll need to collect a list of interactions, and split this particle's 
> momentum between *all* of those other particles...
> 
> If anyone else here has dealt with similar issues, I'd appreciate 
> knowing if I'm on the right track...
>


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.