Running Python in OpenFOAM with pybind11

In Rodriguez and Cardiff (2022), a general approach to run Python codes in OpenFOAM was introduced, based on the header-only library pybind11. A Python interpreter is embedded in OpenFOAM and interacted with. The conceptual flowchart of the approach is shown in the figure below.

6 steps to communicate Python and OpenFOAM

Efficient data transfer is achieved by combining ctypes, NumPy's built-in support for ctypes and OpenFOAM's data (or cdata) functions for OpenFOAM Lists/Fields.

pythonPal hides the details related to ctypes, NumPy and data by offering higher-level methods to transfer data between OpenFOAM and Python and execute general Python code.