Simple Fluid

This simulation attempts to simulate a fluid in a computationally inexpensive way (in comparison to more accurate methods). The aim here is to recreate a fluid's behaviour for aesthetic and educational purposes. This is a recreation of Jos Stam's method of fluid simulation for games.


This real-time simulation is computationally complex and may induce unresponsiveness on lower-end devices




In order to introduce fluid at a particular location, just touch the canvas


Display Controls



Turning this 'on' will introduce fluid at a constant rate, in the center of the container


Force Field Controls



Explanation

We're essentially trying to solve the Navier-Stokes equations in a simpler way:

\[ \frac{\partial \rho}{\partial t} = -(\vec{u} \cdot \nabla) \rho + \kappa \nabla^2 \rho + S \] \[ \frac{\partial \vec{u}}{\partial t} = -(\vec{u} \cdot \nabla) \vec{u} + \nu \nabla^2 \vec{u} + \vec{F} \]

The first equation tells us how fluid density \(\rho\) behaves. The first term on the RHS says that density 'flows' according to the velocity field \( \vec{u} \) (this process is called advection). The second term represents diffusion of fluid whereas the third term accounts for sources and sinks.

The second equation lays down the behaviour of the velocity field \( \vec{u} \). The first term on the RHS says that the velocity field advects on the basis of itself (this can be intrepreted as flow of momentum). The second term represents the diffusion of momentum (due to viscosity). The third term represents external forces acting on the fluid.

In addition to these two equations, we also need to make sure that the velocity field is mass conserving. This correction is achieved by using the result of Hodge decomposition, which states that every velocity field is the sum of a mass conserving field and a gradient field. Hence, if we subtract the gradient from our velocity field, we will get a mass conserving velocity field.




Note:
  1. The boundary condition is closed. It has not been implemented properly (yet). If fluid is introduced in the corner from which a velocity field originates, then the densities blow up. Clear the simulation if this happens.


Developed by ChanRT | Fork me at GitHub