Tuesday, March 20, 2012





Playing with phase separation in a lattice-Boltzmann fluid simulator I wrote recently. Lattice-Boltzmann sims are very easy to write, and if you ever wanted to write a fluid sim, but find the math daunting, they're a good place to get started. They have other virtues (and limitations) beyond ease of implementation. For instance, it's very easy to simulate multiple phases and immiscible fluids with an LB sim.

For the second two pictures, I tweaked the sim so that the fluid flow favours the x- and y-axis directions.

6 Comments:

Blogger Dan Sayers said...

Wow, pretty stuff Kevin. Is it possible to run the sim in real-time? Know of any good links for a tutorial for getting Lattice-Boltzmann stuff up and running? Thanks

5:38 AM  
Blogger The Method Artist said...

Hi Dan,

The book I used is pretty good: "Lattice Boltzmann Modeling: An Introduction for Geoscientists and Engineers". There's pseudocode in the book for most things, and some (rather crap) C code on the publisher's site. I found it helpful to read some introductory papers too. I wrote the sim in OpenCL, and it works in decent real-time at 256x256 on a recent-model macbook pro. I was actually a bit disappointed with the performance. I suspect it's possible to get much better performance out of the hardware. I plan to rewrite it using shaders, FBO's etc (i.e., the way we supposedly don't need to now that OpenCL is here) to see if it is any faster.

I may release my code in a month or so. The only reason I'm not is that it's rather sloppy, and not very fast.

Kevin

5:52 AM  
Blogger Dan Sayers said...

That sounds great Kevin, thanks - I'll have a look.

Just curious - why do the bottom two pictures fade to grey rather than continuing the fluid sim to white as in the top picture?

6:01 AM  
Blogger The Method Artist said...

It's just how I was thresholding values. For the initial conditions, I just set the fluid amount as a smooth gradient from top to bottom plus some noise. I was experimenting with different values initial conditions, and in the latter two cases, the value at the bottom converted to gray. So what you're seeing actually corresponds to the physical behaviour being modelled: it corresponds to fluid condensing from a vapour state (gray) into the fluid state (white).

6:48 AM  
Blogger IntrinsicFX said...

Inspiring work Kevin. Seeing some ideas, could this be used for some realtime effects on data/image input? I guess that was a leading question.. I'm currently slow at reading feeds, but nice to catch up now and then, you got some nice dev & experiments going on, and I guess I've got more reading to do! Let me know if you ever consider making some more realtime effects and maybe collab/present through vjfx.com, just thinking loud :) And if you'd ever be interested in making a guest-blog too, when/if I manage to get vjfx.com to be more "current" and active perhaps, I do hope to. Keep experimenting and inspiring, that's where flow is i.m.o. :)

5:15 PM  
Blogger The Method Artist said...

Hey Thomas,

Thanks for that! These work okay in realtime, at around 256x256. I wrote them in OpenCL, and was a little underwhelmed by the performance. I have a hunch that if I rewrote them as shaders, they would be quicker. As is, they don't work the hardware very hard. My hunch is that silky smooth framerates at 512x512 should be possible on middle-of-the-road hardware.

I like the idea of doing some kind of collab in future -- the next month or so will be crazy for me, since we're moving to NZ, but once the dust settles, we should definitely talk some more!

7:53 PM  

Post a Comment

<< Home