
Written from
Manhattan, New York
Wrote this going to an in-person interview in New York. I didn't get the job...
Can we use a Box to Predict Vascular Surgery?
Motivation
Early last year, I chatted with Dr. Bobby Yanagawa, the head of cardiac surgery at St.Micheal’s Hospital in Toronto. Fun fact, I was born there! That wasn’t the reason we called though. I wanted to figure out how surgeons at one of Toronto’s largest hospitals predict blood flow in their patients before actually performing surgery on them.
Medicine is obviously going towards a more personalized future. When I was in grade 3, I got a rhinoplasty to fix my deviated septum and it didn’t work. It wasn’t because the surgeon was terrible, it was simply because they weren’t used to operating on children my age. Most of their previous knowledge for this surgery came from operating on adults, not a 9 year old. What if there was a way to predict the future of a surgery before it happens? That’s the problem we’re aimed to solve last year, and we decided to start with a huge problem area in this space, predicting blood flow.
Of course, that’s not a small ask. Being able to simulate the complicated physics of the way our blood behaves in our body is hard. Computational Fluid Dynamics (CFD) has been used as the best way to simulate blood flow for a long time, but traditional CFD solvers like OpenFOAM require hours of compute time per patient geometry [Morris 2016], preventing fast feedback to clinicians in time-sensitive clinical applications [Liang 2020].
But wait, let me slow down. Why do we care about this in the first place?
Every time your heart beats, blood rushes through your arteries and drags against the walls, like water flowing through a pipe. That friction is called wall shear stress, and it turns out to be a big deal. When blood flows smoothly, it keeps your artery walls healthy. But at spots where arteries branch or curve, blood can slow down and swirl around. Those low-friction zones? That's exactly where plaque starts to build up. If a surgeon, can see where these “danger” zones could occur before they commit to a surgery, we believe that will reduce the number of failed vascular surgeries.
Thanks to our amazing mentor Dr. Sean Peterson from UWaterloo’s Fluid Flow Group, we took an approach to this problem that had us building our solution from the simplest thing possible. So, when we actually inference on a real vascular structure, we can be assured the physics is sound.
Introducing the Humble Lid Driven Cavity…
The Lid Driven Cavity is the simplest problem in fluid dynamics, I’m sure most engineering students reading this have gone through this tutorial at least once when first learning Ansys. Effectively there’s a 2D box like above, and the top wall moves to a given direction. The flow inside the box is what we take a look at! Well, not exactly inside the box, we instead focused on the outsides of the box, at the walls. That’s where the wall in wall shear stress comes from. The idea is that the insides of a fluid domain influence the walls, so if we’re able to predict the walls with a high degree of accuracy, the insides are a natural byproduct of that.
Speaking about byproducts, shout out to my little brother’s laptop. It was used extensively to run all the CFD simulations to generate the data for our model. He did tell me the other day his laptop now has a 20 minute battery life. Huh, what a coincidence! (R.I.P Pranav’s laptop)
Dr.Peterson encouraged us to solve this problem with our first iterations of models on this simple problem: As the test data gets farther from the training data, how accurate is our model?
The Reynold’s number is a knob that describes how turbulent a fluid is. Higher Re → more turbulent!
Regardless, I ran 189 simulations for this Lid Driven Cavity problem, across 12 different box sizes and 21 different Reynold’s numbers. We choose the following sizes for our domains:
- 1 meter x 1 meter (Similar to the figure above!)
- 1 meter x 1.1 meter
- 1 meter x 1.2 meter
- 1 meter x 1.3 meter
- 1 meter x 1.4 meter
- 1 meter x 1.5 meter
- 1 meter x 1.6 meter
- 1 meter x 1.7 meter
- 1 meter x 1.8 meter
- 1 meter x 1.9 meter
- 1 meter x 2 meter
- 2 meter x 1 meter
- Trapezoid
I hope it’s obvious that we chose this way of creating data because it’s the easiest way to create perturbations in the data and see how the farthest data points in our set performs on our model.
Great, now what do we do with all this data?
We needed a way to map these unique geometries and flow patterns to a model. After a bunch of tinkering and experimenting (let me know if you want another blog post detailing our journey there!), we came across Graph Neural Networks. Instead of a grid or a point cloud, we represented each cavity boundary as a graph, roughly 500 nodes connected in a ring, one node per boundary point, edges linking each node to its neighbors going clockwise around the perimeter. This ring topology is a natural fit for a closed boundary: information propagates around the cavity the way shear stress actually does, node by node.
Each node got 10 physics features describing where it sits and what kind of wall it's on: its normalized coordinates, whether it's on the moving top wall or a stationary wall, how far along the boundary it is, and how close it is to a corner. No black-box feature extraction, every feature has a physical interpretation.
But here's the thing about fluid dynamics: the same geometry behaves completely differently at Re=200 versus Re=2000. The boundary mesh doesn't change, but the physics do. So we built a two-stream architecture:
- Stream 1 — Flow Encoder: Takes the Reynolds number and cavity dimensions, outputs a compact "context vector" summarizing the flow regime.
- Stream 2 — Geometry Encoder: Three layers of graph attention (GATConv) process the boundary mesh, learning how WSS varies spatially around the cavity.
The two streams are fused with a FiLM layer (Feature-wise Linear Modulation), instead of just concatenating the context and geometry representations, FiLM uses the flow context to multiplicatively scale the geometry features. Think of it like this: at low Reynolds numbers the model learns to dampen corner effects; at high Reynolds numbers it amplifies them. The flow conditions literally control how the geometry is interpreted.
Finally, a small Bayesian output head produces predictions with uncertainty estimates. because if we're eventually telling a surgeon where shear stress is dangerous, we should also be able to say how confident we are.
One more thing we had to solve: wall shear stress in these simulations spans seven orders of magnitude, from 10⁻¹⁴ to 10⁻⁵ Pa. A standard neural network loss function would completely ignore the small values while fixating on the large ones. We solved this with a sign-preserving log transform applied to the targets before training, and inverted it back at inference. Simple fix, enormous impact on the low-Re cases.
How did it perform?
We tested the model on Reynolds numbers it had never seen during training held out specifically to measure generalization. The results:
| Component | R² | RMSE (Pa) | MAE (Pa) | Median Error |
|---|---|---|---|---|
| WSS X | 0.995 | 4.81 × 10⁻⁸ | 1.99 × 10⁻⁸ | 3.8% |
| WSS Y | 0.990 | 3.77 × 10⁻⁸ | 1.65 × 10⁻⁸ | 6.4% |
| WSS Magnitude | 0.998 | 3.26 × 10⁻⁸ | 1.74 × 10⁻⁸ | 3.1% |
To put those numbers in perspective: we're missing by tens of nanopascals on stresses that live in the nanopascal range, the typical prediction lands within 3–6% of what the full CFD simulation would give you.
The whole model has 138,000 parameters, and we’re able to run inference on all of our 189 cases in a couple of minutes, compared to the couple of hours running all those cases will take using traditional CFD software.
There was one limitation: at very low Reynolds numbers (Re=100–150), the model struggled. At those flow rates, the shear stress signals are so weak they're practically zero across most of the boundary, there isn't enough variation to learn from. We flagged this early and designed our subsequent work around it.
So, we were able to answer how our model could perform as test data gets farther from the training data, it held up well across Reynold’s numbers, but super low Re flow was still a challenge.
From a Box to a Bifurcation
So this might come as a surprise to people, but there are no perfectly square 2D boxes in the human body! Shocker, I know. Now after building a ML surrogate for the simple Lid Driven Cavity, we had to move to something more realistic, a 3D vessel where the vessel splits into two:
It’s where arteries could be the most dangerous clinically. It’s where aneurysms form, where plaque accumulates fastests, and where surgical pybasses are attached. If we can predict WSS on a bifurcating vessel accurately, we might have something clinicians can actually use!
We ran a new set of simulations (this time on an AWS EC2 instance, my little brother Pranav’s laptop couldn’t handle Ansys running for 30 hours straight ). We generated 9 different meshes, varying the branch angles (the angle at which the two child vessels meet) by 30°, 45° and 60° and the size of the child vessels by 500mm, 750mm and 1000mm. We also updated the Reynold’s number by 100 → 2100 (steps of 100), bringing us to 189 simulations to train a new model on.
The surface mesh has roughly 40,000 nodes per simulation, eighty times larger than the Lid Driven Cavity boundary. Running these simulations, even on a T4 in a EC2 instance, took over 48 hours!
To build the actual model, we took everything from the cavity carried forward, and scaled it up:
- 10 physics features, now 3D: surface coordinates, surface normals, distance to the junction, arc length along the branch, and branch depth (parent vessel vs. daughter branch)
- GATv2Conv replacing GATConv: a stronger attention mechanism that conditions on both source and target node features before computing attention weights. Better at picking up the sharp WSS gradients at the bifurcation apex.
- 8 message-passing layers instead of 3: to propagate information across the much larger graph.
- A 3-layer Flow Encoder: the same concept as before, but with more capacity for the wider Re range.
The biggest single improvement came from something surprising: rotation augmentation.
Blood flow in a cylindrical vessel has azimuthal symmetry, if you rotate the entire geometry around the vessel axis by 15 degrees, the physics is identical, just oriented differently. So we did exactly that during training: for every simulation, we also trained on versions of it rotated by ±7.5° and ±15°. Five times the effective training data, all physically valid. WSS_Y, historically the hardest component to predict, improved dramatically.
And the results?
Here, we only care about the domain of the flow, which is in the Z axis! The X and Y axises have residuals that don’t impact behaviour at the wall at all.
| Component | R² | NRMSE |
|---|---|---|
| WSS Z | 0.964 | 0.091 |
| WSS Magnitude | 0.954 | 0.110 |
If you notice, we use NRMSE instead of RMSE above. This is because a bifurcation is a 3D geometry where WSS magnitudes vary dramatically across the surface, from near-zero in recirculation zones to very high at the junction apex. A raw RMSE in Pascals would be dominated by those peak values and result in something meaningless. Instead, we divide the RMSE by the range of the target values, giving us a normalized error that’s meaningful. Here on the Z-axis, our typical error is 9% of the full WSS range seen across the test set!
We also ensured that our model’s predictions can fit into a modern CFD workflow and the results are all exported in .foam format (OpenFOAM’s format). Here is a picture of our prediction (bottom) vs. the base line prediction (top) for the same mesh we have above!
Great, what’s next?
At the time of writing, we are continuing to improve the bifurcation model and move onto a real vascular structure. We will be using a carotid artery. Why?
Because it’s effectively a bifurcation! It’s also coincidentally one of the most surgically significant vessels in the body. It supplies our brain with blood, and scraping plaque out of the carotid (carotid endarterectomy) is a very common procedure. Predicting WSS patterns here could directly influence surgical planning.
We are currently prototyping our model with open source and private carotid artery repositories. Shout out to Dr. Aaron Fenster from Western University for having a massive dataset to us experiment with, and for Pepe et. al for providing an equally awesome open source dataset!