|
|
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...
--
...Ben Chambers
www.pacificwebguy.com
Post a reply to this message
|
|