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

03/30/2022
by   Simón Rodríguez, et al.
0

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.

READ FULL TEXT

page 16

page 19

page 22

research
07/03/2019

libconform v0.1.0: a Python library for conformal prediction

This paper introduces libconform v0.1.0, a Python library for the confor...
research
01/08/2020

Comparing Python, Go, and C++ on the N-Queens Problem

Python currently is the dominant language in the field of Machine Learni...
research
03/17/2021

PythonFOAM: In-situ data analyses with OpenFOAM and Python

In this article, we outline the development of a general-purpose Python-...
research
03/21/2022

Delicatessen: M-Estimation in Python

M-estimation is a general statistical approach that simplifies and unifi...
research
07/13/2020

Meta-analysis parameters computation: a Python approach to facilitate the crossing of experimental conditions

Meta-analysis is a data aggregation method that establishes an overall a...
research
06/21/2021

Python computations of general Heun functions from their integral series representations

We present a numerical implementation in Python of the recently develope...
research
01/04/2023

Optimization of the Analysis of Vital Events Using Threads

Objective: Optimize the time of data analysis of Vital Events (births, d...

Please sign up or login with your details

Forgot password? Click here to reset