A general approach for running Python codes in OpenFOAM using an embedded pybind11 Python interpreter
Simon Rodriguez, Philip Cardiff (School of Mechanical, Materials Engineering, University College Dublin, Ireland)

TL;DR
This paper presents a versatile method to run Python code within OpenFOAM using pybind11, enabling seamless data exchange and execution without translating code, thus facilitating integration of Python-based tools in computational mechanics workflows.
Contribution
The paper introduces a general approach for embedding Python in OpenFOAM via pybind11, allowing direct execution and data transfer without code translation, which is novel and broadly applicable.
Findings
Successfully integrated Python code execution within OpenFOAM.
Demonstrated the approach with three practical test cases.
Showed improved flexibility for Python-based procedures in OpenFOAM.
Abstract
As the overlap between traditional computational mechanics and machine learning grows, there is an increasing demand for straight-forward approaches to interface Python-based procedures with C++-based OpenFOAM. This article introduces one such general methodology, allowing the execution of Python code directly within an OpenFOAM solver without the need for Python code translation. The proposed approach is based on the lightweight library pybind11, where OpenFOAM data is transferred to an embedded Python interpreter for manipulation, and results are returned as needed. Following a review of related approaches, the article describes the approach, with a particular focus on data transfer between Python and OpenFOAM, executing Python scripts and functions, and practical details about the implementation in OpenFOAM. Three complementary test cases are presented to highlight the functionality…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsMetal Forming Simulation Techniques · Adhesion, Friction, and Surface Interactions · Advanced Materials and Mechanics
