pystencils+lbmpy: An Algebraic Language for Stencil-Based Numerical Methods

Stencil schemes are a family of numerical methods where the values of mathematical functions (fields) on a computational grid are updated via equations involving only values from neighboring grid primitives. Among them count classical finite-(difference/volume/element) approaches to solving PDEs, as well as the lattice Boltzmann method (LBM). The efficient evaluation of stencil operators is thus a critical building block for many numerical solvers. This lecture introduces the software packages pystencils and lbmpy, which together offer an algebraic toolbox for the design of stencil schemes in general, and lattice Boltzmann methods in particular. It will introduce the fundamental concepts of both packages, which attendees will later interactively explore, and apply to actual numerical problems, during the hands-on sessions. The centerpiece of pystencils is a purely algebraic language where grids, fields, and a stencil's equations are represented as symbolic objects. Based on the computer algebra system SymPy, users write numerical operations on a mathematical level of abstraction. Pystencils assists this process by offering auto-discretization for finite-difference and finite-volume schemes. Lbmpy extends the language with concepts specific to the LBM, and exposes interfaces for the definition of lattice Boltzmann methods by their mathematical components. Central to lbmpy is its algebraic engine, by which implementations of the key LBM operations (initialization, collide-stream, forcing, boundary conditions, etc) are automatically derived. It supports a wide range of LBM schemes, augmented by various boundary handling and forcing models. The algebraic operators written by the user and/or derived by lbmpy are finally passed to pystencils' code generation system, which transforms them into executable code targeting modern parallel CPUs and GPU accelerators. The code generator exploits available domain-specific knowledge to maximize the kernels' runtime efficiency on the available hardware, using transformations such as memory-friendly loop ordering; use of OpenMP and CPU vector intrinsics; and hierarchical reductions on GPU. Generated operator code can finally be employed to run simulations entirely within Python, where Pystencils supports the rapid prototyping of numerical methods through a runtime system based on NumPy and CuPy. Kernels may also be exported for use with external C++ code bases (such as the waLBerla framework) in order to build larger, production-grade simulation applications.

Authors

Institutions

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-10-06
DOI
https://doi.org/10.5281/zenodo.23191561
Primary Topic
Lattice Boltzmann Simulation Studies
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

pystencils+lbmpy: An Algebraic Language for Stencil-Based Numerical Methods

Frederik Hennig
Zenodo (CERN European Organization for Nuclear Research)
Lattice Boltzmann Simulation Studies
article

pystencils+lbmpy: An Algebraic Language for Stencil-Based Numerical Methods

Frederik Hennig
article en

Abstract

Stencil schemes are a family of numerical methods where the values of mathematical functions (fields) on a computational grid are updated via equations involving only values from neighboring grid primitives. Among them count classical finite-(difference/volume/element) approaches to solving PDEs, as well as the lattice Boltzmann method (LBM). The efficient evaluation of stencil operators is thus a critical building block for many numerical solvers. This lecture introduces the software packages pystencils and lbmpy, which together offer an algebraic toolbox for the design of stencil schemes in general, and lattice Boltzmann methods in particular. It will introduce the fundamental concepts of both packages, which attendees will later interactively explore, and apply to actual numerical problems, during the hands-on sessions. The centerpiece of pystencils is a purely algebraic language where grids, fields, and a stencil's equations are represented as symbolic objects. Based on the computer algebra system SymPy, users write numerical operations on a mathematical level of abstraction. Pystencils assists this process by offering auto-discretization for finite-difference and finite-volume schemes. Lbmpy extends the language with concepts specific to the LBM, and exposes interfaces for the definition of lattice Boltzmann methods by their mathematical components. Central to lbmpy is its algebraic engine, by which implementations of the key LBM operations (initialization, collide-stream, forcing, boundary conditions, etc) are automatically derived. It supports a wide range of LBM schemes, augmented by various boundary handling and forcing models. The algebraic operators written by the user and/or derived by lbmpy are finally passed to pystencils' code generation system, which transforms them into executable code targeting modern parallel CPUs and GPU accelerators. The code generator exploits available domain-specific knowledge to maximize the kernels' runtime efficiency on the available hardware, using transformations such as memory-friendly loop ordering; use of OpenMP and CPU vector intrinsics; and hierarchical reductions on GPU. Generated operator code can finally be employed to run simulations entirely within Python, where Pystencils supports the rapid prototyping of numerical methods through a runtime system based on NumPy and CuPy. Kernels may also be exported for use with external C++ code bases (such as the waLBerla framework) in order to build larger, production-grade simulation applications.

Zenodo (CERN European Organization for Nuclear Research)
Friedrich-Alexander-Universität Erlangen-Nürnberg (DE)
Openalex Percentile: Top 17%
Lattice Boltzmann Simulation Studies
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.