Saved in:
Bibliographic Details
Main Authors: Rodriguez, Simon, Cardiff, Philip
Format: Preprint
Published: 2022
Subjects:
Online Access:https://arxiv.org/abs/2203.16394
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917212750610432
author Rodriguez, Simon
Cardiff, Philip
author_facet Rodriguez, Simon
Cardiff, Philip
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2203_16394
institution arXiv
publishDate 2022
record_format arxiv
spellingShingle A general approach for running Python codes in OpenFOAM using an embedded pybind11 Python interpreter
Rodriguez, Simon
Cardiff, Philip
Computational Engineering, Finance, and Science
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.
title A general approach for running Python codes in OpenFOAM using an embedded pybind11 Python interpreter
topic Computational Engineering, Finance, and Science
url https://arxiv.org/abs/2203.16394