Box2D Forums

It is currently Thu Sep 02, 2010 3:48 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 97 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next
Author Message
 Post subject: Fluid Simulation
PostPosted: Sun Mar 16, 2008 11:34 pm 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 786
Erin and I briefly discussed what it would take to add liquids to the engine. It really isn't that difficult, if you didn't want to go through the trouble of adding particles to the engine first you could even just use non rotating circle objects for your water particles and then apply SPH forces to the neighbors, then wall collisions and all that good stuff would be built in. The trick is to optimize it integrate it with the broadphase so that you get overlap reports from further than the circle radius to use for SPH (SPH forces are somewhat long range, but you definitely don't want O(N^2) behavior if you're dealing with hundreds of particles). You might even be able to get away with just using a sensor shape and a solid shape (both circles) on the same body, I'm not sure. If someone wants to try it, that would be awesome, I'd be very interested to see how it ran, but I don't have the time at the moment to give it a go myself. Maybe a bit down the line, we'll see...


Top
 Profile  
 
 Post subject: Re: 2d physic engines comparison
PostPosted: Mon Mar 17, 2008 10:22 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2211
My thinking now is that the circle shape would be marked as fluid. Then a special b2Contact would be made for fluid circle vs everything else. The b2FluidContact would then just apply some special force and not add to the contact solver. Using the contact solver would slow it down a lot.


Top
 Profile  
 
 Post subject: Re: 2d physic engines comparison
PostPosted: Mon Mar 17, 2008 11:34 am 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 786
So a single fluid particle would then have two shapes attached to it, one a regular old solid circle with mass and all that, which collides as usual with everything, and the other a circle with an isFluid flag checked, that collides with nothing but generates a b2FluidContact that neither contributes to island formations or enters the contact solver, right?

One thing concerns me a bit: would this integrate well with CCD? Obviously the fluid particles should probably never be bullets, but around the edges of the fluid you're likely to hit a lot of static scenery, so CCD would be on by default for that, and the usual core shape shrinking won't help because an SPH particle must exert influence quite a bit further than its collision radius. Is there already a way in the engine to disable TOI checking for fluid shapes while leaving it on for the solid ones?


Top
 Profile  
 
 Post subject: Re: Fluid Simulation
PostPosted: Mon Mar 17, 2008 6:04 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2211
I don't think we need a solid circle, just the fluid circle. For fluid vs solid, we can just use some quick projection operation. For fluid-vs-fluid we use some repulsion force. In this case, CCD is not an issue. Of course we might get some tunneling of fluid in extreme cases. We can use simple ray casts for that if necessary.


Top
 Profile  
 
 Post subject: Re: Fluid Simulation
PostPosted: Wed Mar 19, 2008 1:41 am 
Offline

Joined: Tue Sep 18, 2007 6:17 am
Posts: 155
Location: Western Cape, South Africa
Fluids would be absolutely amazing!

Would you be able to factor adhesion and cohesion into the solver as well? So that water particles can clump when in mid air and slide down the sides of objects? Or would these features be too expensive?


Top
 Profile  
 
 Post subject: Re: Fluid Simulation
PostPosted: Wed Mar 19, 2008 7:04 am 
Offline

Joined: Tue Nov 06, 2007 1:38 pm
Posts: 55
Agree! i actually missed it in my current project, so i am just using a few solid circles. 8-)


Top
 Profile  
 
 Post subject: Re: Fluid Simulation
PostPosted: Wed Mar 19, 2008 7:42 am 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1908
Wahooney wrote:
Would you be able to factor adhesion and cohesion into the solver as well?

Cohesion would be a matter of of setting your fluid contact forces carefully, to be attractive at long ranges. Adhesion might be a bit more difficult.

I'm not sure you can get away with not using solid particles. It would be fine for simulating gasses, but people expect water to be incompressible (i.e. the total volume doesn't change much). If you were going to do nonsolid water particles properly, it would essentially be smoothed particle hydrodynamics, which is probably getting a bit heavyweight.


Top
 Profile  
 
 Post subject: Re: Fluid Simulation
PostPosted: Wed Mar 19, 2008 11:59 am 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 786
You can do a lot of things - cohesion is pretty easy by just tuning the force function. For stuff like adhesion you'd probably need to alter things a bit to attach breakable springs to objects on contact or something like that, but it's definitely doable. Not sure it would be something that would be added right away, but you could certainly mod it in.

SPH is not really all that heavyweight, despite the scary equations that define it. If you use a lookup table for the smoothing kernel it can be computed quite fast, and all those sums will generally just be over a few neighbors. Per pair you probably end up doing just about the same amount of work as for a normal contact.

As far as incompressibility, SPH attempts to model this through the forces. Finite step size makes the fluid end up somewhat compressible, but I think for a lot of purposes it's the best you can do. With solid cores you can bound the compressibility, but you don't want the cores to be too big or you're really simulating something more like sand than liquid. Sometimes you can achieve decent results this way, but you need to make sure there is variation in the sizes of your cores so that you don't get layers stacking up too neatly.


Top
 Profile  
 
 Post subject: Re: Fluid Simulation
PostPosted: Wed Mar 19, 2008 6:58 pm 
Offline

Joined: Mon Feb 25, 2008 6:33 am
Posts: 11
One thing i noticed while playing with phun is that it would be really sweet if the particles on the edges of a body of water broke up into smaller particles. For example with a dynamic-sized-particle system you could simulated larger bodies of water with big particles and when the water runs down something it would be smaller particles.

Is this something that would be possible or am I just wasting my keystrokes?


Top
 Profile  
 
 Post subject: Re: Fluid Simulation
PostPosted: Mon Mar 24, 2008 10:01 pm 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 786
I'm pretty sure some people have done SPH with dynamically sized particles, though I can't find a link right now. You'll probably have to add a few extra terms in the equations to account for the change in mass of each particle, and there would be some extra bookkeeping to handle, but conceptually it shouldn't be too awful.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 97 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group