OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
cpp_python_funct.h File Reference
#include <iostream>
#include <string>
#include <regex>
#include <array>
#include <set>
#include <utility>
#include <vector>
#include <limits>
#include <cmath>
#include <stdio.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  ComparePairs

Macros

#define max_line_length   500
#define max_num_lines   1000
#define max_code_length   max_line_length *max_num_lines
#define max_variable_length   100

Typedefs

typedef ssize_t My_ssize_t
typedef void * PyObject
typedef PyObject *(* T_PyDict_GetItemString) (PyObject *, const char *)
typedef int(* T_PyCallable_Check) (PyObject *)
typedef PyObject *(* T_PyTuple_New) (My_ssize_t)
typedef PyObject *(* T_PyFloat_FromDouble) (double)
typedef PyObject *(* T_PyObject_CallObject) (PyObject *, PyObject *)
typedef void(* T_Py_Initialize) ()
typedef void(* T_Py_Finalize) ()
typedef PyObject *(* T_PyImport_AddModule) (const char *)
typedef PyObject *(* T_PyModule_GetDict) (PyObject *)
typedef int(* T_PyRun_SimpleString) (const char *)
typedef int(* T_PyTuple_SetItem) (PyObject *, My_ssize_t, PyObject *)
typedef int(* T_PyList_SetItem) (PyObject *, My_ssize_t, PyObject *)
typedef void(* T_Py_DecRef) (PyObject *)
typedef void(* T_Py_IncRef) (PyObject *)
typedef double(* T_PyFloat_AsDouble) (PyObject *)
typedef int(* T_PyDict_SetItemString) (PyObject *, const char *, PyObject *)
typedef void(* T_PyErr_Fetch) (PyObject **, PyObject **, PyObject **)
typedef void(* T_PyErr_Display) (PyObject *, PyObject *, PyObject *)
typedef PyObject *(* T_PyErr_Occurred) ()
typedef int(* T_Py_IsInitialized) ()
typedef PyObject *(* T_PyObject_Str) (PyObject *)
typedef const char *(* T_PyUnicode_AsUTF8) (PyObject *)
typedef PyObject *(* T_PyDict_New) ()
typedef PyObject *(* T_PyList_New) (My_ssize_t)
typedef void(* T_PyErr_Clear) ()
typedef PyObject *(* T_PyLong_FromLong) (long int)
typedef PyObject *(* T_PyLong_FromVoidPtr) (void *)
typedef PyObject *(* T_PyUnicode_FromString) (const char *)
using KeywordPair = std::pair<int, const char*>
using KeywordPairs = std::set<std::pair<int, const char*>, ComparePairs>

Functions

template<typename T>
void load_function (void *h, const std::string &func_name, T &func_ptr, bool &python_initialized)
KeywordPair get_keyword_pair (const KeywordPairs &keywordPairs, size_t n)

Variables

constexpr int sensor_result_size = 2
T_Py_Initialize My_Initialize
T_Py_Finalize My_Finalize
T_PyDict_GetItemString MyDict_GetItemString
T_PyCallable_Check MyCallable_Check
T_PyTuple_New MyTuple_New
T_PyFloat_FromDouble MyFloat_FromDouble
T_PyObject_CallObject MyObject_CallObject
T_PyImport_AddModule MyImport_AddModule
T_PyModule_GetDict MyModule_GetDict
T_PyRun_SimpleString MyRun_SimpleString
T_PyTuple_SetItem MyTuple_SetItem
T_PyList_SetItem MyList_SetItem
T_Py_DecRef My_DecRef
T_Py_IncRef My_IncRef
T_PyFloat_AsDouble MyFloat_AsDouble
T_PyDict_SetItemString MyDict_SetItemString
T_PyErr_Fetch MyErr_Fetch
T_PyErr_Display MyErr_Display
T_PyErr_Occurred MyErr_Occurred
T_Py_IsInitialized My_IsInitialized
T_PyObject_Str MyObject_Str
T_PyUnicode_AsUTF8 MyUnicode_AsUTF8
T_PyDict_New MyDict_New
T_PyList_New MyList_New
T_PyErr_Clear MyErr_Clear
T_PyLong_FromLong MyLong_FromLong
T_PyLong_FromVoidPtr MyLong_FromVoidPtr
T_PyUnicode_FromString MyUnicode_FromString
constexpr std::array< const char *, 89 > ELEMENT_KEYWORDS

Macro Definition Documentation

◆ max_code_length

#define max_code_length   max_line_length *max_num_lines

Definition at line 51 of file cpp_python_funct.h.

◆ max_line_length

#define max_line_length   500

Definition at line 48 of file cpp_python_funct.h.

◆ max_num_lines

#define max_num_lines   1000

Definition at line 50 of file cpp_python_funct.h.

◆ max_variable_length

#define max_variable_length   100

Definition at line 52 of file cpp_python_funct.h.

Typedef Documentation

◆ KeywordPair

using KeywordPair = std::pair<int, const char*>

Definition at line 237 of file cpp_python_funct.h.

◆ KeywordPairs

using KeywordPairs = std::set<std::pair<int, const char*>, ComparePairs>

Definition at line 247 of file cpp_python_funct.h.

◆ My_ssize_t

typedef ssize_t My_ssize_t

Definition at line 45 of file cpp_python_funct.h.

◆ PyObject

typedef void* PyObject

Definition at line 56 of file cpp_python_funct.h.

◆ T_Py_DecRef

typedef void(* T_Py_DecRef) (PyObject *)

Definition at line 70 of file cpp_python_funct.h.

◆ T_Py_Finalize

typedef void(* T_Py_Finalize) ()

Definition at line 64 of file cpp_python_funct.h.

◆ T_Py_IncRef

typedef void(* T_Py_IncRef) (PyObject *)

Definition at line 71 of file cpp_python_funct.h.

◆ T_Py_Initialize

typedef void(* T_Py_Initialize) ()

Definition at line 63 of file cpp_python_funct.h.

◆ T_Py_IsInitialized

typedef int(* T_Py_IsInitialized) ()

Definition at line 77 of file cpp_python_funct.h.

◆ T_PyCallable_Check

typedef int(* T_PyCallable_Check) (PyObject *)

Definition at line 59 of file cpp_python_funct.h.

◆ T_PyDict_GetItemString

typedef PyObject *(* T_PyDict_GetItemString) (PyObject *, const char *)

Definition at line 58 of file cpp_python_funct.h.

◆ T_PyDict_New

typedef PyObject *(* T_PyDict_New) ()

Definition at line 80 of file cpp_python_funct.h.

◆ T_PyDict_SetItemString

typedef int(* T_PyDict_SetItemString) (PyObject *, const char *, PyObject *)

Definition at line 73 of file cpp_python_funct.h.

◆ T_PyErr_Clear

typedef void(* T_PyErr_Clear) ()

Definition at line 82 of file cpp_python_funct.h.

◆ T_PyErr_Display

typedef void(* T_PyErr_Display) (PyObject *, PyObject *, PyObject *)

Definition at line 75 of file cpp_python_funct.h.

◆ T_PyErr_Fetch

typedef void(* T_PyErr_Fetch) (PyObject **, PyObject **, PyObject **)

Definition at line 74 of file cpp_python_funct.h.

◆ T_PyErr_Occurred

typedef PyObject *(* T_PyErr_Occurred) ()

Definition at line 76 of file cpp_python_funct.h.

◆ T_PyFloat_AsDouble

typedef double(* T_PyFloat_AsDouble) (PyObject *)

Definition at line 72 of file cpp_python_funct.h.

◆ T_PyFloat_FromDouble

typedef PyObject *(* T_PyFloat_FromDouble) (double)

Definition at line 61 of file cpp_python_funct.h.

◆ T_PyImport_AddModule

typedef PyObject *(* T_PyImport_AddModule) (const char *)

Definition at line 65 of file cpp_python_funct.h.

◆ T_PyList_New

typedef PyObject *(* T_PyList_New) (My_ssize_t)

Definition at line 81 of file cpp_python_funct.h.

◆ T_PyList_SetItem

typedef int(* T_PyList_SetItem) (PyObject *, My_ssize_t, PyObject *)

Definition at line 69 of file cpp_python_funct.h.

◆ T_PyLong_FromLong

typedef PyObject *(* T_PyLong_FromLong) (long int)

Definition at line 83 of file cpp_python_funct.h.

◆ T_PyLong_FromVoidPtr

typedef PyObject *(* T_PyLong_FromVoidPtr) (void *)

Definition at line 84 of file cpp_python_funct.h.

◆ T_PyModule_GetDict

typedef PyObject *(* T_PyModule_GetDict) (PyObject *)

Definition at line 66 of file cpp_python_funct.h.

◆ T_PyObject_CallObject

typedef PyObject *(* T_PyObject_CallObject) (PyObject *, PyObject *)

Definition at line 62 of file cpp_python_funct.h.

◆ T_PyObject_Str

typedef PyObject *(* T_PyObject_Str) (PyObject *)

Definition at line 78 of file cpp_python_funct.h.

◆ T_PyRun_SimpleString

typedef int(* T_PyRun_SimpleString) (const char *)

Definition at line 67 of file cpp_python_funct.h.

◆ T_PyTuple_New

typedef PyObject *(* T_PyTuple_New) (My_ssize_t)

Definition at line 60 of file cpp_python_funct.h.

◆ T_PyTuple_SetItem

typedef int(* T_PyTuple_SetItem) (PyObject *, My_ssize_t, PyObject *)

Definition at line 68 of file cpp_python_funct.h.

◆ T_PyUnicode_AsUTF8

typedef const char *(* T_PyUnicode_AsUTF8) (PyObject *)

Definition at line 79 of file cpp_python_funct.h.

◆ T_PyUnicode_FromString

typedef PyObject *(* T_PyUnicode_FromString) (const char *)

Definition at line 85 of file cpp_python_funct.h.

Function Documentation

◆ get_keyword_pair()

KeywordPair get_keyword_pair ( const KeywordPairs & keywordPairs,
size_t n )

Definition at line 250 of file cpp_python_funct.h.

250 {
251 if (n >= keywordPairs.size()) {
252 std::cout<<"ERROR: Out of range access in elemental value for Python function."<<std::endl;
253 std::cout<<"Index: "<<n<<" Size: "<<keywordPairs.size()<<std::endl;
254 }
255 auto it = std::next(keywordPairs.begin(), n);
256 return *it;
257}
n

◆ load_function()

template<typename T>
void load_function ( void * h,
const std::string & func_name,
T & func_ptr,
bool & python_initialized )

Definition at line 104 of file cpp_python_funct.h.

105{
106 func_ptr = reinterpret_cast<T>(dlsym(h, func_name.c_str()));
107 if (func_ptr == nullptr)
108 {
109 const char *dlsym_error = dlerror();
110 std::cout << "Could not load " << func_name << ": " << dlsym_error << std::endl;
111 python_initialized = false;
112 }
113}
bool python_initialized

Variable Documentation

◆ ELEMENT_KEYWORDS

std::array<const char*, 89> ELEMENT_KEYWORDS
constexpr

Definition at line 145 of file cpp_python_funct.h.

145 {
146"ALPHA",
147"AMS",
148"BFRAC",
149"BULK",
150"COLOR",
151"DAM1",
152"DAM2",
153"DAM3",
154"DAMA",
155"DAMG",
156"DAMINI",
157"DENS",
158"DOMAIN",
159"DT",
160"EINT",
161"EINTM",
162"EINTV",
163"ENER",
164"ENTH",
165"ENTHM",
166"ENTHV",
167"EPSD",
168"EPSP",
169"FAIL",
170"FAILURE",
171"FILL",
172"FLAY",
173"FLDF",
174"FLDZ",
175"GROUP",
176"HC_DSSE_F",
177"HC_DSSE_Z",
178"HOURGLASS",
179"K",
180"M151DENS",
181"M151ENER",
182"M151PRES",
183"M151VFRAC",
184"MACH",
185"MASS",
186"MOMX",
187"MOMXY",
188"MOMXZ",
189"MOMY",
190"MOMYZ",
191"MOMZ",
192"NL_EPSD",
193"NL_EPSP",
194"NXTF",
195"OFF",
196"P",
197"PHI",
198"SCHLIEREN",
199"SIGEQ",
200"SIGX",
201"SIGXY",
202"SIGY",
203"SIGYZ",
204"SIGZ",
205"SIGZX",
206"SSP",
207"TDEL",
208"TDET",
209"TEMP",
210"THICK",
211"THIN",
212"TILLOTSON",
213"TSAIWU",
214"TVIS",
215"VDAM1",
216"VDAM2",
217"VDAM3",
218"VELX",
219"VELXY",
220"VELXZ",
221"VELY",
222"VELYZ",
223"VELZ",
224"VFRAC1",
225"VFRAC2",
226"VFRAC3",
227"VFRAC4",
228"VOLU",
229"VONM",
230"VORT",
231"VORTX",
232"VORTY",
233"VORTZ",
234"WPLA"
235};

◆ My_DecRef

T_Py_DecRef My_DecRef

Definition at line 128 of file cpp_python_funct.h.

◆ My_Finalize

T_Py_Finalize My_Finalize

Definition at line 117 of file cpp_python_funct.h.

◆ My_IncRef

T_Py_IncRef My_IncRef

Definition at line 129 of file cpp_python_funct.h.

◆ My_Initialize

T_Py_Initialize My_Initialize

Definition at line 116 of file cpp_python_funct.h.

◆ My_IsInitialized

T_Py_IsInitialized My_IsInitialized

Definition at line 135 of file cpp_python_funct.h.

◆ MyCallable_Check

T_PyCallable_Check MyCallable_Check

Definition at line 119 of file cpp_python_funct.h.

◆ MyDict_GetItemString

T_PyDict_GetItemString MyDict_GetItemString

Definition at line 118 of file cpp_python_funct.h.

◆ MyDict_New

T_PyDict_New MyDict_New

Definition at line 138 of file cpp_python_funct.h.

◆ MyDict_SetItemString

T_PyDict_SetItemString MyDict_SetItemString

Definition at line 131 of file cpp_python_funct.h.

◆ MyErr_Clear

T_PyErr_Clear MyErr_Clear

Definition at line 140 of file cpp_python_funct.h.

◆ MyErr_Display

T_PyErr_Display MyErr_Display

Definition at line 133 of file cpp_python_funct.h.

◆ MyErr_Fetch

T_PyErr_Fetch MyErr_Fetch

Definition at line 132 of file cpp_python_funct.h.

◆ MyErr_Occurred

T_PyErr_Occurred MyErr_Occurred

Definition at line 134 of file cpp_python_funct.h.

◆ MyFloat_AsDouble

T_PyFloat_AsDouble MyFloat_AsDouble

Definition at line 130 of file cpp_python_funct.h.

◆ MyFloat_FromDouble

T_PyFloat_FromDouble MyFloat_FromDouble

Definition at line 121 of file cpp_python_funct.h.

◆ MyImport_AddModule

T_PyImport_AddModule MyImport_AddModule

Definition at line 123 of file cpp_python_funct.h.

◆ MyList_New

T_PyList_New MyList_New

Definition at line 139 of file cpp_python_funct.h.

◆ MyList_SetItem

T_PyList_SetItem MyList_SetItem

Definition at line 127 of file cpp_python_funct.h.

◆ MyLong_FromLong

T_PyLong_FromLong MyLong_FromLong

Definition at line 141 of file cpp_python_funct.h.

◆ MyLong_FromVoidPtr

T_PyLong_FromVoidPtr MyLong_FromVoidPtr

Definition at line 142 of file cpp_python_funct.h.

◆ MyModule_GetDict

T_PyModule_GetDict MyModule_GetDict

Definition at line 124 of file cpp_python_funct.h.

◆ MyObject_CallObject

T_PyObject_CallObject MyObject_CallObject

Definition at line 122 of file cpp_python_funct.h.

◆ MyObject_Str

T_PyObject_Str MyObject_Str

Definition at line 136 of file cpp_python_funct.h.

◆ MyRun_SimpleString

T_PyRun_SimpleString MyRun_SimpleString

Definition at line 125 of file cpp_python_funct.h.

◆ MyTuple_New

T_PyTuple_New MyTuple_New

Definition at line 120 of file cpp_python_funct.h.

◆ MyTuple_SetItem

T_PyTuple_SetItem MyTuple_SetItem

Definition at line 126 of file cpp_python_funct.h.

◆ MyUnicode_AsUTF8

T_PyUnicode_AsUTF8 MyUnicode_AsUTF8

Definition at line 137 of file cpp_python_funct.h.

◆ MyUnicode_FromString

T_PyUnicode_FromString MyUnicode_FromString

Definition at line 143 of file cpp_python_funct.h.

◆ sensor_result_size

int sensor_result_size = 2
constexpr

Definition at line 54 of file cpp_python_funct.h.