Skip to content
Snippets Groups Projects
Commit 5a7695f3 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

add simpleFunctionPython

parent 3602100c
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "SPoint2.h" #include "SPoint2.h"
#include "simpleFunction.h" #include "simpleFunction.h"
#include "Octree.h" #include "Octree.h"
#include "MElement.h"
class GFace; class GFace;
typedef struct _CDLIST DListRecord, *DListPeek; typedef struct _CDLIST DListRecord, *DListPeek;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#endif #endif
#include "MVertex.h" #include "MVertex.h"
#include "MElement.h"
//#include "directions3D.h" //#include "directions3D.h"
#include "BackgroundMesh.h" #include "BackgroundMesh.h"
#include "intersectCurveSurface.h" #include "intersectCurveSurface.h"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define _SIMPLE_FUNCTION_H_ #define _SIMPLE_FUNCTION_H_
// FIXME: Numeric/ should not depend on Geo/ // FIXME: Numeric/ should not depend on Geo/
#include "MElement.h" class MElement;
template <class scalar> template <class scalar>
class simpleFunction { class simpleFunction {
......
#ifndef _SIMPLE_FUNCTION_PYTHON_H_
#define _SIMPLE_FUNCTION_PYTHON_H_
#include "Python.h"
#include "simpleFunction.h"
class simpleFunctionPython : public simpleFunction<double> {
PyObject *_pycallback;
public:
simpleFunctionPython(PyObject *callback):
_pycallback(callback)
{
Py_INCREF(_pycallback);
}
~simpleFunctionPython()
{
Py_DECREF(_pycallback);
}
double operator()(double x, double y, double z) const
{
PyObject *pyargs = Py_BuildValue("(ddd)", x, y, z);
PyObject *result = PyEval_CallObject(_pycallback, pyargs);
double r = 0;
if (result) {
int ok = PyArg_Parse(result, "d", &r);
if (not ok)
Msg::Error("The python function did not return a double.");
Py_DECREF(result);
}
else {
PyErr_Print();
Msg::Error("An error occurs in the python simple function.");
}
Py_DECREF(pyargs);
return r;
}
};
#endif
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <math.h> #include <math.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include "MElement.h"
#if (defined(unix) || defined(__unix)) && !defined(__AIX) #if (defined(unix) || defined(__unix)) && !defined(__AIX)
#define SYSTIMES #define SYSTIMES
#include <sys/times.h> #include <sys/times.h>
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "JacobianBasis.h" #include "JacobianBasis.h"
#include "fullMatrix.h" #include "fullMatrix.h"
#include "nodalBasis.h" #include "nodalBasis.h"
#include "simpleFunction.h"
#include "simpleFunctionPython.h"
#include "polynomialBasis.h" #include "polynomialBasis.h"
#include "pyramidalBasis.h" #include "pyramidalBasis.h"
%} %}
...@@ -18,8 +20,11 @@ ...@@ -18,8 +20,11 @@
%include "GaussIntegration.h" %include "GaussIntegration.h"
%include "JacobianBasis.h" %include "JacobianBasis.h"
%include "fullMatrix.h" %include "fullMatrix.h"
%include "simpleFunction.h"
%template(fullMatrixDouble) fullMatrix<double>; %template(fullMatrixDouble) fullMatrix<double>;
%template(fullVectorDouble) fullVector<double>; %template(fullVectorDouble) fullVector<double>;
%template(simpleFunctionDouble) simpleFunction<double>;
%include "simpleFunctionPython.h"
%include "nodalBasis.h" %include "nodalBasis.h"
%include "polynomialBasis.h" %include "polynomialBasis.h"
%include "pyramidalBasis.h" %include "pyramidalBasis.h"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment