This is an interactive fluid simulation that I built on OpenGL.
It solves the Navier-Stokes equation for a 2D incompressible fluid:
Since the program so far only treats incompressible fluids, it is stipulated that the divergence of the velocity field vanishes, i.e.
The program follows an algorithm similar to the one laid out in Stam 1999. Essentially the Helmholtz Decomposition Theorem tells us that we can solve for a compressible field
The intermediate field
- advection
- diffusion
- external forces
Finally the incompressible flow is determined with the help of the aforementioned Helmholtz decomposition step.
Advection is performed with a semi-implicit scheme, which is explained in Stam 1999. Both diffusion and Helmholtz decomposition steps furnish second order linear PDEs which can be realized by sparse matrices. The program approximates them numerically using Jacobi iteration. There are other sparse matrix solvers out there: Conjugate Gradient Descent, Cholesky preconditioning and LU/QR decomposition, to name a few, but Jacobi iteration seems to do a good enough job to simulate a fluid like appearance.
To capture fine scale fluctuations, the program considers the vorticity confinement term from Fedkiw et. al 2001 as an extra exernal force:
Where
- GPU Gems 1
- Fluid Dynamics Book(Provides a discussion of Helmholtz Decomposition)
- Reference and Tutorial for OpenGL