Abstract
Gyselalib++ provides the mathematical building blocks to construct kinetic or gyrokinetic plasma simulation codes in C++, simulating a distribution function discretised in phase space on a fixed grid. It relies on the Discrete Domain Computation (DDC) library to statically type the discretisation dimensions, thus preventing many common sources of errors. Via DDC, Gyselalib++ also leverages the Kokkos framework, ensuring performance portability across various CPU and GPU architectures. The library provides a variety of tools including semi-Lagrangian advection operators, quadrature rules, and solvers for elliptic and hyperbolic partial differential equations (PDEs).
Introduction
Simulating plasmas for magnetic confinement fusion devices, such as ITER, requires immense computational resources. Due to low collisionality, researchers often employ gyrokinetic models, which reduce the dimensionality of the problem from 6D to 5D by averaging out high-frequency particle gyromotion. Historically, the Fortran-based GYSELA code was the standard for simulating the core region of a tokamak. However, as the field moves toward simulating more complex geometries—such as the turbulent edge regions, D-shaped plasmas, or stellarators—the limitations of monolithic legacy codebases have become apparent. Modifying these codes is error-prone, and porting them to modern GPU-based exascale architectures is a significant challenge. Gyselalib++ was developed to provide a modular, mathematically safe, and hardware-portable foundation for next-generation plasma simulations.
Methodology and Architecture
Gyselalib++ is designed as a reusable C++ library rather than a standalone application. Its architecture focuses on three main pillars:
1. Static Typing for Grid Safety
The library utilizes the Discrete Domain Computation (DDC) library to encode grid information directly into the C++ type system. By making the discretisation dimensions part of the field's type, the compiler can catch common indexing errors—such as mixing up different grids or incompatible memory layouts—at compile time. This "compile-time physics checking" significantly reduces the debugging burden for researchers.
2. Performance Portability via Kokkos
To ensure that simulations can run efficiently on both multi-core CPUs and various GPU architectures, Gyselalib++ integrates the Kokkos framework. Kokkos abstracts the hardware layer, allowing the same mathematical code to be compiled for different backends without manual optimization for each specific chip architecture.
3. Template-Enforced Mathematics
The library uses C++ template programming to enforce the correctness of implemented equations. Operators are expressed in tensor notation, ensuring accuracy across non-orthonormal coordinate systems. If a specific operator requires an orthonormal grid, static assertions in the code will trigger a compiler error if a user attempts to apply it to an incompatible geometry.
Mathematical Toolkit
Gyselalib++ provides a comprehensive suite of numerical tools:
- Advection Operators: Support for both Eulerian and semi-Lagrangian schemes.
- Numerical Quadrature: Rules for integrating distribution functions.
- PDE Solvers: Tools for solving elliptic and hyperbolic partial differential equations, essential for calculating self-consistent electromagnetic fields.
- Finite Difference Methods: Standard tools for spatial discretisation.
Validation and Real-World Application
The primary result of this work is the deployment of a robust software architecture. Gyselalib++ has already demonstrated its utility in several ways:
- VOICE Code Migration: The library was used to completely rewrite the VOICE plasma simulation code in C++, modernizing its codebase and enabling GPU support.
- Physics Testbeds: The authors have implemented standard physics test cases, including 2D and 4D MPI-parallelized Landau damping, bump-on-tail instability, and guiding-centre models. These serve as validated benchmarks for mathematicians and physicists developing new numerical methods.
Conclusion
By shifting from a monolithic Fortran approach to a modular C++ library, Gyselalib++ enables rapid development and testing of new plasma simulation models. Its emphasis on compile-time safety and performance portability makes it a critical tool for the fusion community as it prepares for the exascale era. Future work will focus on expanding the library's capabilities to handle increasingly complex magnetic geometries, such as X-points and stellarator configurations.
Summary updated