Bawar Jalal

Basic Fluid Simulation in C++ (Part 1)

So there's something which I've wanted to code for the longest time. Specifically, I remember it was during Computing A-Level, where we had to think of absolutely any software to code for our coursework. At the time, if I remember correctly we were encouraged to use the XNA Game Engine with C#, and it was also encouraged to create some sort of interactive software in order to get high marks in the assignment. I feel like it was at this point where my curiosity was sparked and I started to appreciate computer simulations. I really wanted to write a Fluid Sim, but upon realising that the maths and physics behind it wasn't as straightforward as I imagined it to be, I ended up creating an interactive comet simulation. I experimented with particle generation and also remember making my own UI for it.

Point is, I feel like since then (and that's well over a decade ago), I somehow still have it in the back of my mind that it would be cool to understand the maths behind fluids, and to demonstrate it in the form of a simulation. In theory I should now understand the building blocks behind it, given that I've studied it all at Uni, but you'd be surprised how little I actually remember. I also want to gain the intuition behind it, rather than just regurgitating formulas.

So that's the motivation behind what I've been doing for the past couple weeks.

I've been trying to write my own (very basic) fluid sim, and I decided to do it in C++ using SDL just to brush up on that too (and because it's fast).

I have kept hand-written notes as I've gone along, but I would like to distill that into this blog format, perhaps as a short series, just for my own reference, as writing really does help cement your understanding.

I have taken a very incremental step-by-step approach to it, starting first by developing a 1D wave simulator, then extending that to the 2D wave equation, of course encountering many hurdles along the way, each a significant learning point for me.

I am now at the point of attempting to digest the foundations and pre-requisites of the Navier-Stokes equations. I will also refer to some interesting and useful resources which have helped me along the way.

So buckle up, and get your notepad ready, because we're about to have some fun!