Loading video...

Video Failed to Load

Go Home

A common optimization to real-time fluid simulations in computer graphics is to use a "Multigrid" algorithm to acceleration the solver. This process is often fraught with pitfalls, and there are few references on the expected result. This aims to serve as one such reference.

42,263 views • 3 years ago •via X (Twitter)

15 Comments

Morten Vassvik's profile picture
Morten Vassvik3 years ago

First disclaimer: This thread: - is not a tutorial on how to implement a Multigrid solver - does not contain advice on how to tune such an algorithm - does not explain what the common pitfalls are or how to solve them A base level of familiarity and understanding is expected

Morten Vassvik's profile picture
Morten Vassvik3 years ago

Instead, this thread serves as a reference of what things should look like if implemented correctly free of bugs, based on a sensible set of default parameters. In particular, we will look at convergence rates in a coarse manner for a few different setups.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

The TLDR: The residual/divergence should reduce approximately by an order of magnitude (10x) per V-cycle for a MAC-grid type simulation with open boundaries. This result is mostly input-independent. This is not the optimal result, but is a baseline for more complex variants.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

Incorrect and buggy implementations will still converge faster than plain Jacobi iterations, but it will be far less efficient and less consistent than what's presented here.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

As shown in the first tweet of this thread the case study here is a 256x256 grid with a small square source that injects velocity towards the right and also injects density for visualization purposes. The video pauses on the snapshots we'll study in the later posts.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

There are three grid levels: 256x256, 128x128 and 64x64, respectively. We use 1 pre-smooth and 4 post-smooth iterations (omega 0.8), and 64 SOR half-iterations on the coarse grid solve (omega 1.86). There are between 0 and 8 V-cycles. We use 32-bit floats for the precision.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

First we'll look at the initial time step. The velocity inside the square point to the right and the of the velocity is zero. The resulting velocity field is reminiscent of the magnetic field from a bar magnet, which ultimately is what makes the fluid curl as it moves.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

First to explain the color scheme: On the upper left is the velocity field, it uses 0.5 + 0.5*v as colors like a typical flowmap The upper right has the density field The lower left shows the Pressure field The lower right shows the Divergence/Residual field

Morten Vassvik's profile picture
Morten Vassvik3 years ago

The color scheme on the pressure and divergence/residuals is logarithmic (base 10) and relative. Each color level represent one order of magnitude (10x). White represents values 10 times larger than the orange values, which are 10 times larger than the cyan values, and so on

Morten Vassvik's profile picture
Morten Vassvik3 years ago

In other words, if a color changes from orange to cyan, or from cyan to purple, or from purple to yellow, and so on, it means the values there decreased by approximately one order of magnitude The maximum and average divergence/residual are also presented as text

Morten Vassvik's profile picture
Morten Vassvik3 years ago

In the first few V-cycles the residual/divergence mostly reduces by an order of magnitude, matching the earlier descriptions. Eventually parts of the solution converges with some hot spots left that requires more work until eventually floating point precision is reached.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

Next we'll look at a later snapshot, after 80 or so time steps, where the characteristic initial vortex have appeared. The convergence trend is overall the same as in the previous case.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

Lastly, after 640 steps, where we have a characteristic vortex street emerging.

Morten Vassvik's profile picture
Morten Vassvik3 years ago

To emphasize the input-independent nature(i.e. relative to the initial divergence), here's all the gifs side by side (rip compression?) Direct link to full sized gif: And also a link to all the raw image files and videos:

Matt Figdore's profile picture
Matt Figdore2 years ago

This is the biggest productivity cheat code right now. Kiss reading documents goodbye. You can get an instant summary of any document with this tool.

Related Videos

Introducing ALE-Bench, ALE-Agent! Towards Automating Long-Horizon Algorithm Engineering for Hard Optimization Problems Blog: Paper: ALE-Bench is a coding benchmark primarily focused on hard optimization (NP-hard) problems. We developed this benchmark with AtCoder Inc., a leading coding contest platform company. What makes ALE-Bench unique is its focus on hard optimization problems that demand long-horizon and creative reasoning. It’s open-ended, in the sense that true optima are out of reach (NP-hard) and scores can continuously improve. We believe this benchmark has the potential to become one of the key benchmarks for reasoning and coding in the next generation. ALE-Agent is our end-to-end agent that we specifically designed for this challenging domain. In fact, our ALE-Agent has already built an impressive track record in the wild! In May 2025, our agent participated in a live AtCoder Heuristic Competition (AHC), alongside 1,000 other participants in real-time. AHC is considered to be one of the most challenging coding competitions in this domain. Our ALE-Agent achieved an impressive ranking of 21st out of 1,000 human participants in the competition (top 2%), marking a turning point for AI discovery of solutions to hard optimization problems with a wide spectrum of important real world applications such as logistics, routing, packing, factory production planning, power-grid balancing. We look forward to applying this technology to real industrial optimization opportunities. Building on the insights from this study, Sakana AI will continue to tackle the challenge of developing AI with even greater algorithm engineering capabilities. ALE-Bench Dataset: ALE-Bench Code: This research was conducted in collaboration with AtCoder Inc. (AtCoder). We are deeply grateful for their outstanding expertise and contributions in optimization and algorithms, which were invaluable in providing data, analyzing results, and enabling our AI agent’s participation in their contests.

Sakana AI

237,195 views • 1 year ago