NNPred: Deploying neural networks in computational fluid dynamics codes to facilitate data-driven modeling studies
Data-driven modeling has contributed significantly to the field of computational fluid dynamics (CFD), but integrating machine-learning (ML) models into a CFD workflow still remains to be a challenging task. In this paper, we introduce an interface library for the deployment of ML models in CFD codes. The library supports multiple ML backends with binary interface compatibility and provides flexible data input/output (I/O) methods to match the type and layout of the data between ML models and CFD codes. For the convenience of CFD users, the library provides application programming interfaces for two widely used languages (i.e., C++ and Fortran), simplifying the deployment and prediction to only a few lines of code. Two data-driven modeling cases are demonstrated, along with the implementation details of the library in open-source CFD codes (i.e., OpenFOAM and CFL3D). The first case presents a simple heat-transfer problem with assumed experimental data of unknown emissivity, where the basic use of the library in OpenFOAM is demonstrated by solving a diffusive equation with the source term modeled by various ML algorithms. The second case discusses the modeling of turbulence in channel flow, and applies an ML-integrated closure model in both OpenFOAM and CFL3D. In both software, the ML-RANS model reproduces almost identical results to the reference data and favorable extrapolation performance is maintained. In addition, the parallel efficiency is compared with the traditional closure model under the same homogeneous parallel architecture, and only limited additional cost is imposed by running the ML prediction. This library could benefit CFD researchers in rapidly testing data-driven models in their CFD solvers.