Lab
Airfoil flow toy
A small interactive fluid simulation written in C++ with raylib and compiled to the web. It is not a serious CFD solver, but it does give a visual taste of velocity fields, pressure, viscosity, and air moving around airplane-ish shapes.
It is highly recommended to be on a desktop or laptop since the demo doesn’t work on mobile at all :/
Why this exists
Shoutout Schlafen for the inspiration behind this demo.
I do not pretend that aerodynamics is my wheelhouse. But planes are cool, and fluids are cool. The terrifying Navier-Stokes equations are relevant to this little demo. I will not get into too much detail on them, but one of the Millennium Prize Problems concerns them so I’d recommend checking that out. See this page on P vs. NP for an introduction to a Millenium problem I actually understand (kinda).
The equation in the background
The incompressible Navier-Stokes equations are often written schematically as
Here is the velocity field. At each point in space, the fluid has a direction and a speed. The term describes how that velocity changes over time. The nonlinear term is advection: the fluid carries its own motion along with it. The pressure term pushes fluid away from high-pressure regions, and the viscosity term smooths out sharp changes in the flow.
The second equation, , says that the fluid is incompressible. Roughly speaking, fluid is not allowed to magically appear or disappear. If it flows into a small region, it has to flow out somewhere else. To be perfectly honest I do not really understand why this is used in airfoil theory when the gases in the atmosphere ceirtainly are compressible, but I think it has something to do with air being incompressible enough in this context.
Faithfulness of the simulation
This demo is Navier-Stokes-inspired, but should not be taken to be a faithful engineering simulation.
It does use several conceptual pieces. Internally, it evolves a two-dimensional velocity field on a grid. Each frame performs advection, a viscosity/diffusion step, an approximate pressure solve, and a projection step that tries to reduce divergence. It also has approximate boundary conditions around the obstacle. That is enough for the simulation to look neat. So despite having, in my opinion, come pretty close to mimicing the look of e.g. XFOIL, this demo is not even in the same league when it comes to realism.
The simulation is implemented in C++ with raylib, compiled to WebAssembly, and embedded into this page through a TypeScript component.