ChemGen: Code Generation for Multispecies Chemically Reacting Flow Simulations
This paper introduces ChemGen, a software package that uses code generation to integrate multispecies thermodynamics and chemical kinetics into C+-based computational physics codes. ChemGen aims to make chemical kinetics more accessible in existing simulation frameworks and help bridge the gap between combustion modeling and computational physics. The package employs the concept of decorators which enable flexible C++ code generation to target established software ecosystems. ChemGen generates code to evaluate thermodynamic properties, chemical source terms, and their analytical derivatives for Jacobian calculations. Also included are a variety of implicit time integration schemes, linear solvers, and preconditioners. The various components of Chemgen are verified by demonstrating agreement with Cantera and/or theoretical convergence rates. Finally, we integrate ChemGen into OpenFOAM and achieve a speedup over its native chemistry solver by approximately four times. ChemGen is an ongoing project released under the NRL Open License, a source-available license provided by the U.S. Naval Research Laboratory.
💡 Research Summary
ChemGen is a software framework that brings code generation to the integration of multispecies thermodynamics and detailed chemical kinetics within C++‑based computational physics applications. The authors identify four traditional strategies for adding chemistry to CFD codes—adapting legacy software, linking third‑party libraries such as Cantera, hand‑coding source terms, or using code‑generation tools. They argue that the fourth approach offers the best combination of extensibility, maintainability, and performance, especially for large‑scale reacting‑flow simulations where chemical source terms are stiff and Jacobian information is required for implicit time integration.
The core idea of ChemGen is a Python‑driven decorator system. Users describe a chemical mechanism (species, reactions, stoichiometry, thermodynamic polynomial coefficients, pressure‑dependence, etc.) in a high‑level, declarative form. ChemGen then automatically emits C++ header and source files that implement:
-
Thermodynamic property evaluation – Species‑wise heat‑capacity, enthalpy, internal energy, entropy, and Gibbs free energy are expressed as temperature polynomials derived from the NASA‑type coefficients. The code also provides analytical temperature derivatives (cp, cv, ∂h/∂T, etc.), which are essential for building the Jacobian of the governing equations.
-
Chemical source term and Jacobian – Forward and reverse rate constants are computed as functions of temperature, pressure, and mixture concentration. Production rates ωi are assembled from stoichiometric coefficients, and the framework automatically differentiates these expressions to produce an exact Jacobian matrix that satisfies mass conservation (Σi Wi ωi = 0).
-
Time‑integration, linear solvers, and preconditioners – ChemGen bundles a selection of implicit/explicit ODE/DAE integrators (Rosenbrock, BDF, etc.) with Krylov linear solvers (GMRES, BiCGStab) and optional preconditioners (ILU, Jacobian‑free Newton‑Krylov). The generated code can be called directly from a host CFD solver without any runtime interpretation overhead.
The paper presents the governing compressible Euler equations with a chemical source term, derives the temperature‑density coupling, and explains how Newton’s method (five iterations) solves the nonlinear relation between internal energy and temperature to a relative error of 1 × 10⁻⁸. Thermodynamic quantities are organized into polynomial coefficient tables (aik, bik, cik, dik, fik) that enable compile‑time constant propagation and in‑line evaluation.
Verification is performed against Cantera for both thermodynamic property values and reaction rates, showing agreement to machine precision. Jacobian correctness is confirmed by comparison with finite‑difference approximations, and the expected order of convergence (first‑, second‑, third‑order) is demonstrated for the supplied integrators.
A key performance study integrates ChemGen into OpenFOAM’s reacting‑flow solver. By replacing OpenFOAM’s native ODE‑based chemistry module with ChemGen‑generated source code, the authors achieve an average four‑fold reduction in wall‑clock time for a detonation benchmark, with peak speed‑ups of six times. The gains stem from (i) elimination of runtime parsing of reaction mechanisms, (ii) tightly‑packed memory access patterns in the generated C++ kernels, and (iii) the availability of an analytically exact Jacobian that accelerates Newton‑Krylov solves.
ChemGen is released under the NRL Open License (source‑available) and currently supports Python and C++. The authors outline future extensions: automatic generation of GPU kernels (CUDA/HIP), inclusion of non‑ideal gas equations of state, multiphase reaction models, and coupling with additional physics such as plasma or electromagnetics.
In summary, ChemGen provides a “code‑generation‑plug‑in” that bridges detailed chemical kinetics with high‑performance CFD frameworks. By delivering analytical Jacobians, a suite of implicit integrators, and seamless C++ integration, it improves productivity, numerical robustness, and computational efficiency compared with traditional hand‑coded or third‑party library approaches.
Comments & Academic Discussion
Loading comments...
Leave a Comment