Skip to content

andreypluzhnik/2DFluidSim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenGL Fluid Simulation

This is an interactive fluid simulation that I built on OpenGL.

Governing Equations

It solves the Navier-Stokes equation for a 2D incompressible fluid:

$$\frac{\partial u}{\partial t} = - (u \cdot \nabla)u + \gamma \nabla^2 u + \frac{\nabla p}{\rho} + F_{external}$$

Since the program so far only treats incompressible fluids, it is stipulated that the divergence of the velocity field vanishes, i.e.

$$\nabla \cdot u = 0$$

Solving the N-S Equations

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 $w$, which decomposes into $u$ and $\nabla p$, and subsequently subtract out $\nabla p$ to obtain $u = w - \nabla p$.

The intermediate field $w$ is calculated by 'splitting' the N-S equation into seperate terms and solving them w.r.t. $\frac{\partial u}{\partial t}$ sequentially in the order:

  • 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.

Vorticity Confinement

To capture fine scale fluctuations, the program considers the vorticity confinement term from Fedkiw et. al 2001 as an extra exernal force:

$$F_{conf} = \frac{\epsilon}{\lvert \eta \rvert} (\eta \times \omega)$$

Where $\omega = \nabla \times u$ and $\eta = \nabla \lvert \omega \rvert$.

Other Useful Resources

About

OpenGL 2D Fluids Simulation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published