Model of an Incompressible Fluid

This project is a spin-off from the modelling work I did for my undergraduate dissertation. The model aims to represent an incompressible fluid, in a computationally quick but physically realistic manner.

The water is simulated using a vector field, the arrows represent the direction and speed of flow at a particular point in the simulation and the particles act as tracers for individual molecules of the fluid.

The method I used is based on work done by Jos Stam, his original document can be found here.

Try it yourself: FluidApp.jar

Source code (MIT License): Github

View Image View Image View Image View Image


If you are having trouble running the program, please try this quick guide.

What Am I Looking At?

An example of an almost incompressible fluid is water. This program is only in two dimensions so imagine you are looking through the side of a very thin tank of water, the blue dots are like small beads which neither float or sink in the water, they only move when the water around them moves. The arrows are like threads stuck to the glass, when the water flows over them, they point in the direction of the flow, the stronger the flow, the bigger the arrows get.

There are a set number of particles (blue dots) in the water, however they don't take up any space, they can be on top of each other, so if they are all in the same place, they fill only a single pixel of the screen and can be very hard to see.

The Interface

A quick run through of what each button and slider does:

  • To interact with the fluid, simply click and drag the mouse cursor through the model.
  • Vector line Density: This only controls how many of the vectors are drawn, it doesn't change the number of vectors being modelled.
  • Time between Calculations (s): This adds a delay, in seconds, between each step of the model, this slows the speed at which the model is calculated and drawn.
  • Iterations of linear solving: This variable is more complex. If your computer can handle it, 6 is a good value. Anything below 6 results in unrealistic and less interesting behaviour of the fluid however on older computers it might be necessary to turn it down as it is a major bottleneck.
  • Particle diffusion: If the fluid is completely still, the particles (blue dots) wouldn't move anywhere, also sometimes they can all bunch up on top of each other. To prevent this we can give them a small amount of random movement each step of the simulation. This variable represents the maximum number of pixels a particle might move in the x and y dimension each step.
  • Particle brightness: Allows the choice of a particle colour between white and blue.

Devlopment Log

~ July 2014 ~

While I logged a lot of my progress alongside my dissertation, it was actually based on marine plankton ecology. This means that fluid dynamics was a small part of the project and the majority of the information in my log book is irrelevant to this application.

I did my main model in 3D but to help me implement the fluid dynamics a I used 2D testing environment which I extracted and made more user friendly, the result of which is this project.

I intend to clean the project up further, adding options to make all of the edges solid, or wrap them all, and also to allow the user to specify how good their machine is, and adjust the size of the matrix and the number of particles accordingly.

Try it yourself: FluidApp.jar

View Image View Image
  • In this version the horizontal axis wraps around, that is the left side is directly connected to the right one.
  • The vertical axis doesn't wrap the flow but it does wrap the particles.