计算机科学 > 计算工程、金融与科学
[提交于 2022年3月30日]
标题:A general approach for running Python codes in OpenFOAM using an embedded pybind11 Python interpreter
查看原文 PDF 中文 PDF (下批处理) EasyResearch 阅读摘要: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.
提交历史
来自:Simon Antonio Rodriguez Luzardo[v1] 2022年3月30日 星期三 15:25:03 UTC