Lettuce: PyTorch-Based Lattice Boltzmann Framework

Mario Christopher Bedrunka, Dominik Wilde, Martin Kliemank, Dirk Reith, Holger Foysi, Andreas KrämerIsc Workshops 2021

Introduction

Computational Fluid Dynamics (CFD) has traditionally required high-performance, compiled C++ or CUDA code, creating a steep learning curve and making modifications difficult. While Python and Matlab are excellent for prototyping, they often lack the speed necessary for meaningful 3D research. Furthermore, bridging the gap between classical CFD solvers and modern machine learning (ML) frameworks often involves inefficient data-shuttling.

Lettuce is an open-source framework designed to address these challenges by implementing the Lattice Boltzmann Method (LBM) directly in PyTorch. By treating fluid simulations as differentiable operations within a deep learning infrastructure, Lettuce enables GPU-accelerated simulations with minimal Python code, facilitating the seamless integration of neural networks into the solver.

Methods

Lettuce utilizes the Lattice Boltzmann Method (LBM), which simulates fluid flow by tracking particle distributions on a grid rather than solving the Navier-Stokes equations directly. Building this on PyTorch offers three primary advantages:

  1. Native GPU Acceleration: Tensor operations are automatically vectorized and optimized for GPUs via CUDA.
  2. Automatic Differentiation (Autograd): The simulation becomes a differentiable graph, allowing for the computation of gradients with respect to input parameters without complex adjoint solvers.
  3. Neural Integration: Classical components, such as collision operators, can be replaced with neural networks and trained end-to-end.

The authors demonstrate this capability through a Neural Collision Model—a shallow neural network (530 parameters) that predicts optimal relaxation rates to maintain stability and accuracy on coarse grids.

Key Results and Validation

The framework was validated using several classic fluid benchmarks, including the Taylor-Green Vortex and Decaying Isotropic Turbulence.

Validation of energy dissipation rates across various Reynolds numbers (Re=100 to 3000) comparing Lettuce (-dk/dt) against reference data.

As shown in Figure 4, Lettuce accurately captures energy dissipation rates across a wide range of Reynolds numbers, matching reference data closely.

One of the most significant findings is the performance of the Neural LBM. While standard BGK (Bhatnagar-Gross-Krook) operators often fail to capture complex structures on low-resolution grids, the neural model maintains high accuracy.

Comparison of energy decay over time steps for various LBM models. The Neural LBM at $64 \times 64$ resolution (blue circles) demonstrates competitive accuracy against higher-resolution baselines.

Figure 5 illustrates that the Neural LBM at a resolution of $64 \times 64$ effectively tracks the energy decay of higher-resolution or more complex models, proving its utility for efficient, coarse-grained simulations. In terms of raw performance, Lettuce achieved up to 140 Million Lattice Updates Per Second (MLUPS) on an NVIDIA Tesla V100 in 2D.

Limitations and Future Work

While Lettuce provides a powerful middle ground for research, it currently faces limitations in compressible flow (high Mach numbers) due to standard LBM stencil constraints. Future work aims to implement distributed multi-GPU support via torch.distributed and explore neural collision models to mitigate errors in supersonic regimes.

Source Code: https://github.com/lettucecfd/lettuce

Summary updated

BibTeX
@inproceedings{bedrunka2021lettuce,
  author = {Mario Christopher Bedrunka and Dominik Wilde and Martin Kliemank and Dirk Reith and Holger Foysi and Andreas Krämer},
  title = {{Lettuce: PyTorch-Based Lattice Boltzmann Framework}},
  booktitle = {Isc Workshops},
  year = {2021},
  doi = {10.1007/978-3-030-90539-2\_3},
}
Figure