Published in the journal SoftwareX in December 2026, the study introduces a method designed to bridge the gap between high-level machine learning libraries and the compiled languages used in computational physics solvers. The primary objective of the tool is to allow researchers to embed artificial intelligence models directly into existing simulation codes without relying on external dependencies or complex application programming interfaces. This approach aims to reduce the computational overhead and integration effort typically associated with adding machine learning capabilities to scientific simulation software.
The motivation for developing CodeJeNN stems from the growing integration of machine learning into numerical schemes for partial differential equations and physical modeling. While modern neural network architectures are accessible through libraries such as Keras, TensorFlow, and PyTorch, embedding these models into physics solvers remains challenging. Most physics solvers are written in compiled languages like Fortran and C++ to ensure better resource control, whereas machine learning libraries are primarily based on Python. This disparity often adds computational overhead and requires significant implementation effort to integrate complex architectures into established codes. CodeJeNN addresses this by generating self-contained C++ code that reproduces the trained neural network, allowing users to optimize the source code directly without external dependencies.
The software operates by reading a saved model file from the Keras deep learning API and generating a C++ header file that contains all necessary parameters and functions. The code generation process involves loading the model, extracting parameters into a Python dictionary, reconstructing the model from input to output, and converting it into C++ format. This workflow ensures that the generated code is fully self-contained and inlined, minimizing external dependencies. The tool supports both Multi-Layer Perceptrons and Convolutional Neural Networks, which are common architectures in scientific computing. By producing raw source code, CodeJeNN enables users to incorporate the model into their solvers and further optimize the code if needed, providing a flexible and transparent integration process.
CodeJeNN is designed to be extensible, with each layer type implemented as an independent module. This modular structure allows users to support new architectures by adding the logic for missing layers without altering existing implementations. The tool supports a wide range of activation functions, including ReLU, Sigmoid, Tanh, and Softmax, as well as various layer types such as Dense, Convolutional, and Pooling layers. However, the software has certain limitations, primarily supporting only single-branch neural networks that operate on a single input tensor. It does not support multiple independent inputs or all configuration options available in the Keras API, such as certain regularizers. Dropout layers are skipped during code generation because they act as identity operations during inference, avoiding unnecessary computations.
To demonstrate the performance and accuracy of CodeJeNN, the researchers conducted benchmark tests comparing the inference speed and numerical accuracy of code-generated models against those created directly in Keras. The benchmarks included four model architectures: a small and a large Multi-Layer Perceptron, and a small and a large Convolutional Neural Network. These models varied in depth and total number of learnable parameters, ranging from approximately 11,000 to 843,000 parameters. All models were tested on a single CPU core using 32-bit floating-point precision. The results showed that CodeJeNN-generated models achieved inference times significantly faster than the optimized Keras backends, particularly for smaller models. For instance, the small MLP with approximately 18,000 parameters had an average inference time of 0.01 seconds with CodeJeNN, compared to 0.11 seconds with optimized PyTorch.
The numerical accuracy of the generated models was also evaluated by comparing layer-wise outputs with the Keras baseline. The study reported maximum absolute, mean absolute, and relative errors for each layer. The errors were found to be within acceptable tolerances, with relative errors consistently bounded near 32-bit floating-point precision limits. The final output layers produced smaller absolute errors compared to preceding hidden layers, indicating that the accumulation of numerical deviations remained insignificant for the overall model performance. This level of accuracy is sufficient for embedding trained models into established physics solvers, where the primary goal is to maintain close agreement with reference solutions while improving computational efficiency.
In addition to benchmarking, the researchers applied CodeJeNN to a practical computational fluid dynamics case involving a two-dimensional subsonic splitter-plate mixing layer simulation. The neural network was used to replace the viscosity model, which is typically calculated using Wilke’s mixing rule, in a hydrogen-air flow simulation using OpenFOAM and DetonationFOAM. The model mapped thermochemical state variables directly to viscosity, allowing for faster inference within the simulation. The neural network was trained on 10,000 random states and verified against the Wilke model over 2,000 independently sampled states. The mean error was 0.12%, with a maximum error of 8.12%, demonstrating the model’s ability to accurately approximate the viscosity function.
The simulation results showed that the neural network introduced minimal error into the flow field. The relative L2 error for x-velocity was 0.065%, and for temperature, it was 0.11%. Mean absolute errors were 0.100 m/s for x-velocity and 0.406 K for temperature. Localized maximum errors occurred within the high-gradient mixing layer immediately downstream of the splitter plate, but the absence of large-scale errors elsewhere indicated that the neural network preserved the overall flow evolution. This case study illustrates the potential of CodeJeNN to integrate neural networks into complex physics simulations, providing a robust method for replacing traditional constitutive models with data-driven surrogates.
The development of CodeJeNN also addresses the increasing reliance on large language models for integrating neural networks into computational physics codes. While LLMs can lower the barrier to entry, they introduce recurring costs associated with supplying project-specific context and regenerating infrastructure. CodeJeNN reduces this reliance by automatically generating self-contained inference code, thereby minimizing token consumption and user effort. The tool’s extensibility allows users to leverage LLMs to add new layer logic with substantially fewer tokens, providing a non-invasive workflow for generating new models.
Future work on CodeJeNN will include the integration of Spektral, a Graph Neural Network API for Keras, to support commonly used GNN layers such as message passing and attention-based graphing layers. The developers also plan to add additional activation functions and explore accelerating inference by exporting functions to low-level high-performance libraries like Eigen. These enhancements aim to broaden the applicability of CodeJeNN to a wider range of scientific computing tasks. The software is currently available on GitHub, providing researchers with access to the code, documentation, and tutorials for reproducing the benchmarks and case studies presented in the study.
The study highlights the importance of developing tools that facilitate the integration of machine learning into scientific simulations. By providing a simple and efficient method for generating C++ code from Keras models, CodeJeNN enables researchers to leverage the power of neural networks without the complexities of manual integration. The tool’s design prioritizes ease of integration and self-containment, making it a valuable resource for the computational physics community. As machine learning continues to play a larger role in scientific research, tools like CodeJeNN will be essential for bridging the gap between data-driven models and traditional numerical methods.
Subject of Research: CodeJeNN : A simple C++ neural network generator for physics applications
Article Title: CodeJeNN : A simple C++ neural network generator for physics applications
Article References: Arcities, J., Popov, P. P., Ching, E. J., Viswanath, K., & Johnson, R. F. (2026). CodeJeNN: A simple C++ neural network generator for physics applications. SoftwareX, 36, Article 103203. https://doi.org/10.1016/j.softx.2026.103203
Image Credits: AI Generated
DOI: 10.1016/j.softx.2026.103203
Keywords: CodeJeNN, simple, neural, network, generator, physics, applications, scientific research
News Source: Cassandra Pierce. (November 8, 2026). CodeJeNN Generates C++ Code for Physics Neural Networks. Scienmag.



