论文标题

使用嵌入式Pybind11 Python解释器在OpenFOAM中运行Python代码的一般方法

A general approach for running Python codes in OpenFOAM using an embedded pybind11 Python interpreter

论文作者

Rodriguez, Simon, Cardiff, Philip

论文摘要

随着传统计算技工和机器学习之间的重叠,对基于C ++的基于C ++的OpenFOAM的基于Python的过程的直接方法的需求越来越不断增加。本文介绍了一种这样的通用方法,可以直接在OpenFOAM求解器中执行Python代码,而无需Python代码转换。提出的方法基于轻量级库Pybind11,在该图书馆中,OpenFOAM数据被转移到嵌入式Python解释器进行操作,并根据需要返回结果。经过对相关方法的回顾,本文描述了该方法,特别关注Python和OpenFOAM之间的数据传输,执行Python脚本和函数,以及有关OpenFOAM实现的实用详细信息。提出了三个互补的测试用例,以突出功能并证明不同数据传输方法的效果:一种基于Python的速度分布边界条件;用于原型制作的基于Python的求解器;以及用于执行现场计算的固体4FOAM的机器学习机械构造法类。

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 and demonstrate the effect of different data transfer approaches: a Python-based velocity profile boundary condition; a Python-based solver for prototyping; and a machine learning mechanical constitutive law class for solids4foam which performs field calculations.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源