Naughter Software Logo

FluidSim v1.0 An implementation of Jos Stam's Fluid Dynamics for Games paper

I recently came across The Coding Train's video about Fluid Simulation and thought I would like to implement it in C++ and on Windows. FluidSim is a C++ port / implementation of the code from the "Real-Time Fluid Dynamics for Games" paper from Jos Stam on which the Coding Train video is based. FluidSim is a freeware MFC Windows application which uses Direct2D to draw the simulation.

 

Screen Captures

When you run up the FluidSim application you should see a black client area in the application which represents the simulation space. By default the simulation will use a grid of 64 by 64 cells with each cell size represented as ten pixels square. The frames per second value is shown in the top left of the client area. The FluidSim code uses a simple WM_TIMER to implement the simulation loop. The grayscale color of each cell is used to represent how much material is in each cell of the simulation. You can use the menu item "View -> Clear" to reset the simulation to its initial default state.

 

To deposit "material" into the simulation hold down the right mouse button. What you should see is the pixels around the mouse turn white and the material should start "diffusing" into the surrounding cells:

FluidSim capture 1 

 

You can introduce velocity to the simulation by holding down and dragging with the left mouse button. This will introduce changes to the velocity field part of the simulation in the direction of the mouse drag. What you should then see is the "material" swirling around the simulation space:

FluidSim capture 2

FluidSim capture 3

 

To change the settings of the simulation you can use the menu item "View -> Simulation Properties". This shows a standard dialog which allows various settings to be modified:

FluidSim capture 4

The "Cell count" value represents the number of cells on each side of the square simulation space. The "Force" value represents the amount of velocity introduced to the simulation when using the left mouse button. The "Diffusion" value represents how quickly the material will diffuse into surrounding cells. The "Viscosity" value represents the "thickness" or stickiness of the fluid. The "cell size" value is the size in pixels of each cell in the simulation. The "Source" value represents the amount of material introduced to the simulation when using the right mouse button. The "dt" value represents the step size of the simulation. Finally if you check the checkbox "Show Velocity Field", then the vector field which moves the material around the simulation as well as the density of the material in the simulation is drawn. Showing the velocity field provides a better view as to how the material moves around the simulation space and evolves over time.

 

An example showing the velocity field:

FluidSim capture 5

 

The enclosed zip file contains the MFC source code and x86 precompiled binary for the FluidSim application.

 

Copyright

 

Updates

V1.0 (24 March 2019)