On "Airfoil" (Patreon)
Content
Topic Selection
After finishing my article on bicycles, I investigated and then abandoned two potential topics for the next blog post. The time spent researching those two has contributed to the unfortunate gap of eleven months since my blog's previous installment. Thankfully, I don't think it was a total waste of time, as I may revisit those shelved concepts in future.
I originally considered writing about airfoils back in late 2020 when I bought John Bertin's "Aerodynamics for Engineers". Unfortunately, I found that book quite difficult, which discouraged me from writing about the topic at the time.
I don't exactly remember how it came back to me, but in the second half of 2023 I renewed my interest in lift explanations. This time around I bought John Anderson's "Fundamentals of Aerodynamics", which was much more approachable – this convinced me that I should write about airfoils.
This highlights one of the biggest struggles I have when researching any new topic – finding the right set of textbooks. It's hard to know a priori if a book that's recommended online will be any good. I personally prefer a more explanatory and welcoming style of writing, but many people seem to recommend more rigorous, but drier styles of prose.
Interestingly enough, after reading most of Anderson's book and getting a grasp on the concepts, Bertin's book turned out to be quite useful in elaborating on some of the topics in a different manner. The order and complexity of exposition clearly matters.
New Techniques
I always wanted to dabble with computational fluid dynamics (CFD) to simulate the flow of fluids. It's not difficult to find many impressive online demos of fluid simulations, but many of them focus on visual appeal, and they don't necessarily reflect the physical reality of the flow. They're also difficult to adapt to more arbitrary shapes of the bodies embedded in the flow.
For my article I went with two different techniques – finite difference method (FDM) and finite volume method (FVM). The former is used for all the viscosity demonstrations, and it runs fully on the GPU, using textures for storage of the state of the fluid. This means that the only shapes that can be relatively easily represented are rectangular in nature, which explains why I only simulate the flat plate and a cube in these flows.
The finite volume method is used to simulate all the flows around the airfoils. One benefit of this method is that it makes it relatively easy to express arbitrary geometry. For example, here's a mesh that is defined around the shape of a symmetric airfoil:
A trained practitioner in CFD modeling will likely scorn at the quality and resolution of this mesh, but my primary objective was getting dynamic simulations in the web browser, which limited the complexity of the methods that could be used.
On a technical note, I implemented the FVM method purely in JavaScript, and it was actually quite fun to squeeze as much performance out of it as possible. I even briefly looked at the assembly that V8 on godbolt.org generates for these functions, but that proved to be only minimally useful when optimizing the code. In many cases JavaScript can get quite fast, but doing proper high performance work in this language is like performing brain surgery with oven mittens on. I also did a quick and dirty implementation of a small part of those CFD codes in WebAssembly, but the hand-written WAST version was about as fast as the JavaScript one, so I didn't pursue this approach further.
All that said, the computational fluid dynamics part was the biggest time sink of this article. I started prototyping some very basic CFD codes quite early, and then over the course of next few months, I kept learning about these methods. Here's an early attempt at simulating the popular "lid-driven cavity flow":
In the end, I spent countless hours tweaking the meshes to get the expected results, or even to prevent the simulations from numerically exploding.
In hindsight, I'm glad I went through this process as I now understand how these methods work, at least on an elementary level, but if I knew how much work it would be, I might have chosen a different topic.
Explaining Lift
My primary inspiration for explaining the lift forces was McLean's "Understanding Aerodynamics". I particularly liked that the author strongly emphasizes the mutual relationship between the pressure and velocity fields. As McLean points out, so many other sources infer a one directional relationship between the two. For example, the common Bernoulli-based explanations of lift suggest that since the flow over the upper part of the airfoil is faster, the pressure has to drop and lift arises primarily as a result of that reduced pressure. These statements don't explain that the flow can only speed up because of the pressure differences. I very purposefully avoided mentioning Bernoulli's theorem to avoid these faulty, one-way connotations.
Similarly, I also didn't mention any of the more traditional, mathematical explanations like the Kutta–Joukowski theorem. That one rejoins the physical world with the Kutta condition, which boils down to the requirement that the flow has to smoothly leave the trailing edge of the airfoil. Unfortunately, while this condition works for bodies with sharp tails, it can't provide a definite placement of the flow's "exit" on any body with even gently rounded tails. For me this is a complete deal breaker – a good theory should work in most circumstances, and not just in a few, hand-picked cases.
As a side note, I personally find most of the aerodynamic theories from the early 20th century very unsatisfactory. They hand-wavily appeal to non-physical concepts like potential flow, or they try to forcibly bend abstract mathematical models to make them fit the real physics. I hope that in most engineering scenarios, these semi-functional ideas have been retired long ago and replaced with proper CFD modeling.
To be completely frank, I'm not fully content with how I explained the creation of a pressure field around an airfoil. I was very excited when I came up with the idea of building that pressure field step by step, but the reasoning I provide for why the negative regions above and below the airfoil arise isn't, at least to me, particularly convincing.
One could perhaps do a slightly better job by falling back to simplified CFD models and showing how each "cell" of the area around the airfoil has to ensure continuity of mass, and then explain that the pressure is there to help with that, but this approach still isn't completely satisfying.
Design
Most of the demonstrations in this article were driven by actual pressure and velocity data, which provided little opportunity for creative expression. Thankfully, I did manage to add some small flare to make some of the demos, hopefully, prettier.
For example, the tennis balls hitting the cardboard box drop realistic shadows, and they have seams on their surfaces:
These aren't just plain textures – I spent around an hour getting that procedurally-generated seam shape to look reasonably right. The solution turned out to be an intersection of two blobby shapes:
I also enjoyed working on the little grassy scene. It took a few iterations to settle on the colors and lengths of grass blades, tweak the shape of the leaves, and figure out a nice gradient for the color of the background. Here are some of the design revisions:
Finally, I also established a new scheme for unit conversions. In previous articles I used to have a single link hidden somewhere in the body of text, but some people would skip over that section and were stuck with units they didn't want. Now each "convertible" has a small toggle next to it, which makes the whole thing easier to use:
The Work
While this article is only the second longest, shorter than "Bicycle" by about 1000 words, it was by far the most labor-intensive. To shine some light on how long these things take, here's a brief timeline of major events on the road to getting this article shipped:
- July 15, 2023 – I ordered Anderson's Aerodynamics and a bunch of other books
- August 25, 2023 – I started writing some basic CFD codes and watching any lectures I could find
- November 05, 2023 – I officially created the new text file for "Airfoil" article
- February 26, 2024 – I finally finished
While the dates are somewhat artificially stretched as most of the work on these articles happens on weekends and some weekday evenings, it still took a lot of effort to complete the project. I severely underestimated the finickiness and complexity of CFD, but even on the literature front, the list of books I had to get and read at least partially, kept growing too:
When it came to choosing which subtopics to cover, I avoided the feature-creep of "Bicycle" – what you see in the article is almost exactly what I intended to write about when I begun the work. I do think that all the pieces fit relatively well together and provide a reasonable path through the subject matter.
Final Words
Overall I'm quite happy with how the whole thing turned out. I haven't seen that many interactive simulations of flows online, and it's quite fun to drop the markers into separated flow to see how they swirl around. I also hope that my approach of explaining how lift arises will help to dispel some of the common myths about it.