gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
simpleFunctionPython.h
Go to the documentation of this file.
1
// Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2
//
3
// See the LICENSE.txt file in the Gmsh root directory for license information.
4
// Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5
6
#ifndef SIMPLE_FUNCTION_PYTHON_H
7
#define SIMPLE_FUNCTION_PYTHON_H
8
9
#include "Python.h"
10
#include "
simpleFunction.h
"
11
12
class
simpleFunctionPython
:
public
simpleFunction
<double> {
13
PyObject *
_pycallback
;
14
15
public
:
16
simpleFunctionPython
(PyObject *callback) :
_pycallback
(callback)
17
{
18
Py_INCREF(
_pycallback
);
19
}
20
~simpleFunctionPython
() { Py_DECREF(
_pycallback
); }
21
double
operator()
(
double
x,
double
y,
double
z
)
const
22
{
23
PyObject *pyargs = Py_BuildValue(
"(ddd)"
, x, y,
z
);
24
PyObject *result = PyObject_CallObject(
_pycallback
, pyargs);
25
double
r = 0;
26
if
(result) {
27
int
ok = PyArg_Parse(result,
"d"
, &r);
28
if
(ok == 0)
Msg::Error
(
"The python function did not return a double."
);
29
Py_DECREF(result);
30
}
31
else
{
32
PyErr_Print();
33
Msg::Error
(
"An error occurs in the python simple function."
);
34
}
35
Py_DECREF(pyargs);
36
return
r;
37
}
38
};
39
40
#endif
Msg::Error
static void Error(const char *fmt,...)
Definition:
GmshMessage.cpp:482
simpleFunction
Definition:
GModel.h:30
simpleFunctionPython::~simpleFunctionPython
~simpleFunctionPython()
Definition:
simpleFunctionPython.h:20
simpleFunction.h
z
const double z
Definition:
GaussQuadratureQuad.cpp:56
simpleFunctionPython::_pycallback
PyObject * _pycallback
Definition:
simpleFunctionPython.h:13
simpleFunctionPython::simpleFunctionPython
simpleFunctionPython(PyObject *callback)
Definition:
simpleFunctionPython.h:16
simpleFunctionPython
Definition:
simpleFunctionPython.h:12
simpleFunctionPython::operator()
double operator()(double x, double y, double z) const
Definition:
simpleFunctionPython.h:21
src
numeric
simpleFunctionPython.h
Generated by
1.8.18