The Fluid Simulator That Doesn’t Solve the Fluid Equations

The Fluid Simulator That Doesn’t Solve the Fluid Equations

不求解流体方程的流体模拟器

A hands-on Lattice Boltzmann Method tutorial: from statistical mechanics and kinetic theory to a C++ implementation and supercomputer scaling 格子玻尔兹曼方法(LBM)实战教程:从统计力学与动力学理论到 C++ 实现及超级计算机扩展

Ferran Alia | Jul 25, 2026 | 13 min read


The image above shows a Kármán vortex street (the alternating swirls that form behind any blunt object in fast-moving flow). You’ve seen this pattern trailing behind bridge pillars, airplane wings, and chimney stacks. It’s one of the most recognizable phenomena in fluid dynamics. I generated it without solving a single fluid equation.

上图展示了卡门涡街(在快速流动的流体中,钝体后方形成的交替漩涡)。你一定在桥墩、飞机机翼和烟囱后方见过这种图案。这是流体力学中最具辨识度的现象之一。而我生成它时,没有求解任何一个流体方程。

Instead, this Lattice Boltzmann Method (LBM) simulation treats fluid as what it actually is at the microscopic level: a statistical distribution of particles colliding with each other. The macroscopic behavior (vortices, pressure gradients, viscous damping) falls out as a consequence, not an input.

相反,这种格子玻尔兹曼方法(LBM)模拟将流体视为其在微观层面上的本质:即相互碰撞的粒子的统计分布。宏观行为(涡流、压力梯度、粘性阻尼)是作为结果自然涌现出来的,而非预先设定的输入。

LBM occupies a genuinely unusual position in computational physics, halfway between a molecular dynamics simulation and a Navier-Stokes solver, operating at the mesoscopic scale. In this article, I’ll derive it from first principles, implement it in ~200 lines of C++, and run it on the MareNostrum 5 supercomputer. The full source and a simplified Python/NumPy version are on GitHub.

LBM 在计算物理学中占据了一个非常独特的位置,它介于分子动力学模拟和纳维-斯托克斯(Navier-Stokes)求解器之间,运行在介观尺度上。在本文中,我将从第一性原理出发推导它,用约 200 行 C++ 代码实现它,并在 MareNostrum 5 超级计算机上运行。完整的源代码和一个简化的 Python/NumPy 版本已上传至 GitHub。

Quick take: LBM replaces the intractable Navier-Stokes PDE with a much simpler update rule on a discrete velocity lattice. The NS equations are recovered in the correct limit, not assumed. This makes LBM theoretically elegant, practically fast, and embarrassingly parallelizable. It works best in the low-Mach, subsonic regime, and becomes numerically unstable at very low viscosities.

简评: LBM 用离散速度网格上更简单的更新规则,取代了难以处理的纳维-斯托克斯偏微分方程(PDE)。NS 方程是在正确的极限条件下自然恢复出来的,而非预先假设的。这使得 LBM 在理论上优雅、在实践中快速,并且具有极高的并行性。它在低马赫数、亚音速状态下表现最佳,但在极低粘度下会出现数值不稳定。

Why the obvious approach is painful

为什么常规方法很痛苦

The standard route to fluid simulation goes through the Navier-Stokes equations, the macroscopic conservation laws that govern virtually everything we care about in fluid dynamics. They’re analytically intractable except in a handful of toy geometries, so in practice you discretize them on a mesh and solve numerically: Finite Volume, Finite Difference, or Finite Element methods.

流体模拟的标准路径是经过纳维-斯托克斯方程,即支配流体力学中我们所关心的几乎所有事物的宏观守恒定律。除了少数简单的几何形状外,它们在解析上是无法求解的,因此在实践中,你需要在网格上对其进行离散化并进行数值求解:即有限体积法、有限差分法或有限元法。

These work well, but they carry a hidden cost that compounds for complex geometries. For a curved boundary (a cylinder, a car body, a porous medium) you either need a body-fitted mesh that’s expensive to generate and hard to automate, or specialized stencil corrections near the wall. Every time the geometry changes, the mesh has to be regenerated. It’s an engineering problem layered on top of the physics problem. LBM sidesteps this almost entirely. The reason becomes clear once you understand where it starts.

这些方法效果不错,但对于复杂几何形状,它们会带来累积的隐性成本。对于弯曲边界(圆柱体、车身、多孔介质),你要么需要生成昂贵且难以自动化的贴体网格,要么需要在壁面附近进行专门的模板修正。每当几何形状改变,网格就必须重新生成。这相当于在物理问题之上又叠加了一个工程问题。而 LBM 几乎完全避开了这一点。一旦你理解了它的起点,原因就显而易见了。

A different starting point: statistical mechanics

不同的起点:统计力学

Instead of asking “what is the velocity field at this point?”, LBM asks “how many particles are moving in each direction at this point?” The central object is the single-particle distribution function $f(x, v, t)$. It tells you the expected number of particles near position $x$ moving with velocity $v$ at time $t$. The macroscopic fields we actually care about are just moments of $f$:

LBM 不问“该点的速度场是多少?”,而是问“在该点,每个方向上有多少粒子在运动?”其核心对象是单粒子分布函数 $f(x, v, t)$。它告诉你时间 $t$ 时,在位置 $x$ 附近以速度 $v$ 运动的预期粒子数。我们真正关心的宏观场只是 $f$ 的矩:

[ \rho(\mathbf{x},t) = m\int f, d^3v \qquad \rho,\mathbf{u}(\mathbf{x},t) = m\int \mathbf{v},f, d^3v ]

At global equilibrium (uniform density, no bulk flow) $f$ takes the familiar Maxwell-Boltzmann form:

在全局平衡状态下(密度均匀,无整体流动),$f$ 呈现出熟悉的麦克斯韦-玻尔兹曼形式:

[ f^{eq}(\mathbf{v}) = \frac{\rho}{(2\pi RT)^{D/2}} \exp!\left(-\frac{|\mathbf{v} – \mathbf{u}|^2}{2RT}\right) ]

Away from equilibrium, $f$ takes some other shape. The equation governing how it evolves is the Boltzmann equation:

偏离平衡态时,$f$ 会呈现其他形状。支配其演化的方程是玻尔兹曼方程:

[ \frac{\partial f}{\partial t} + \mathbf{v}\cdot\nabla_\mathbf{x} f = \Omega[f] ]

The left-hand side is pure transport: particles carry their velocity distribution as they stream through space. The right-hand side, $\Omega[f]$, is the collision operator that drives $f$ back toward $f^{eq}$ by redistributing particles among velocity classes. The problem is that $\Omega[f]$ is a five-dimensional integral over all possible collision partners and scattering angles, encoding the full microscopic collision physics. For any practical simulation, it’s completely intractable.

左侧是纯输运:粒子在空间中流动时携带其速度分布。右侧 $\Omega[f]$ 是碰撞算子,它通过在速度类之间重新分配粒子,将 $f$ 拉回 $f^{eq}$。问题在于 $\Omega[f]$ 是一个关于所有可能的碰撞对象和散射角的五维积分,编码了完整的微观碰撞物理。对于任何实际模拟来说,这都是完全无法处理的。

The one-line miracle: BGK

一行奇迹:BGK

In 1954, Bhatnagar, Gross and Krook proposed a brilliantly blunt simplification. Instead of modelling every collision in detail, just capture the net effect: collisions drive $f$ toward equilibrium at a rate proportional to how far from equilibrium it currently sits.

1954 年,Bhatnagar、Gross 和 Krook 提出了一种极其巧妙的简化方案。与其详细模拟每一次碰撞,不如只捕捉其净效应:碰撞以与当前偏离平衡程度成正比的速率,将 $f$ 推向平衡态。

[ \Omega[f] \approx -\frac{1}{\tau}\bigl(f – f^{eq}\bigr) ]

This is the BGK approximation, and it reduces an intractable five-dimensional integral to a scalar multiplication. The parameter $\tau$ is the relaxation time, meaning the average time the system takes to return to local equilibrium after a perturbation. Large $\tau$ means slow relaxation; small $\tau$ means fast.

这就是 BGK 近似,它将一个难以处理的五维积分简化为标量乘法。参数 $\tau$ 是弛豫时间,意味着系统在受到扰动后返回局部平衡所需的平均时间。$\tau$ 大意味着弛豫慢;$\tau$ 小意味着弛豫快。

What makes this more than a convenient hack is what $\tau$ means physically. Via the Chapman-Enskog expansion (a systematic perturbative analysis) you can prove that in the limit of small Knudsen number (many collisions per mean free path), the BGK equation recovers the Navier-Stokes equations exactly, with kinematic viscosity:

使这不仅仅是一个方便的“黑客手段”的原因在于 $\tau$ 的物理意义。通过 Chapman-Enskog 展开(一种系统的微扰分析),你可以证明在克努森数(Knudsen number)较小(每个平均自由程内发生多次碰撞)的极限下,BGK 方程可以精确恢复纳维-斯托克斯方程,其运动粘度为:

[ \nu = c_s^2!\left(\tau – \frac{1}{2}\right) ]

Note that this relation operates in dimensionless lattice units; converting to physical units requires a separate length and timescale calibration. But within the simulation, $\tau$ is the entire physical knob: turn it up for thick, viscous flow; push it toward 0.5 for high-Reynolds-number flow (though values below ~0.55 risk numerical instability). Crucially, this is why LBM is more than Navier-Stokes in disguise. The connection to NS is derived, not assumed: you’re solving a kinetic equation that provably converges to NS behavior in the appropriate limit. This is a very common theme in all of statistical mechanics.

注意,该关系式是在无量纲的格子单位下运行的;转换为物理单位需要单独的长度和时间尺度校准。但在模拟内部,$\tau$ 是唯一的物理调节旋钮:调大它以获得粘稠的流动;将其推向 0.5 以获得高雷诺数流动(尽管低于约 0.55 的值会有数值不稳定的风险)。至关重要的是,这就是为什么 LBM 不仅仅是纳维-斯托克斯方程的伪装。与 NS 的联系是推导出来的,而非假设的:你求解的是一个动力学方程,它在适当的极限下可证明会收敛到 NS 行为。这是统计力学中一个非常普遍的主题。

From continuous to discrete: the D2Q9 lattice

从连续到离散:D2Q9 格子

The BGK equation still lives in continuous velocity space. To simulate it we need a finite set of velocities. The approach is a Taylor expansion of $f^{eq}$ in powers of the bulk velocity $u$, valid when $u$ is small.

BGK 方程仍然存在于连续速度空间中。为了模拟它,我们需要一组有限的速度。其方法是对 $f^{eq}$ 进行关于整体速度 $u$ 的泰勒展开,这在 $u$ 很小时有效。