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

dg : conservation law python

parent 6f305a6e
No related branches found
No related tags found
No related merge requests found
...@@ -31,3 +31,15 @@ ...@@ -31,3 +31,15 @@
%include "polynomialBasis.h" %include "polynomialBasis.h"
%include "pyramidalBasis.h" %include "pyramidalBasis.h"
%include "BasisFactory.h" %include "BasisFactory.h"
%extend nodalBasis {
fullMatrix<double> F(const fullMatrix<double> &xi) {
fullMatrix<double> psi;
$self->f(xi, psi);
return psi;
}
fullMatrix<double> DF(const fullMatrix<double> &xi) {
fullMatrix<double> dpsi;
$self->df(xi, dpsi);
return dpsi;
}
}
...@@ -128,21 +128,17 @@ ...@@ -128,21 +128,17 @@
{ {
npy_intp dims[2] = {fm.size1(), fm.size2()}; npy_intp dims[2] = {fm.size1(), fm.size2()};
double *data = (double*)fm.getDataPtr(); double *data = (double*)fm.getDataPtr();
/*PyObject *array = PyArray_New(&PyArray_Type, 2, dims, NPY_DOUBLE, NULL, NULL, 0, NPY_ARRAY_F_CONTIGUOUS, NULL);
// copy data
memcpy((void*)PyArray_DATA(array), data, dims[0] * dims[1] * sizeof(double));*/
// do not copy data // do not copy data
PyObject *array = PyArray_New(&PyArray_Type, 2, dims, NPY_DOUBLE, NULL, (void*)data, 0, NPY_ARRAY_F_CONTIGUOUS, NULL); PyObject *array = PyArray_New(&PyArray_Type, 2, dims, NPY_DOUBLE, NULL, (void*)data, 0, NPY_ARRAY_F_CONTIGUOUS, NULL);
PyArray_UpdateFlags((PyArrayObject*)array, NPY_ARRAY_ALIGNED); PyArray_UpdateFlags((PyArrayObject*)array, NPY_ARRAY_ALIGNED);
/*if (fm.getOwnData()) { return array;
fm.setOwnData(false); }
%#if PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==6 PyObject *fullMatrix2PyArrayProxy(const fullMatrix<double> &fm)
PyObject *capsule = PyCObject_FromVoidPtr((void*)data, deleteCapsuleArray); {
%#else npy_intp dims[2] = {fm.size1(), fm.size2()};
PyObject *capsule = PyCapsule_New((void*) data, NULL, deleteCapsuleArray); double *data = (double*)fm.getDataPtr();
%#endif PyObject *array = PyArray_New(&PyArray_Type, 2, dims, NPY_DOUBLE, NULL, (void*)data, 0, NPY_ARRAY_F_CONTIGUOUS, NULL);
PyArray_SetBaseObject((PyArrayObject*)array, capsule); PyArray_UpdateFlags((PyArrayObject*)array, NPY_ARRAY_ALIGNED |NPY_ARRAY_WRITEABLE);
}*/
return array; return array;
} }
PyObject *fullVector2PyArrayProxy(fullVector<double> &fv) PyObject *fullVector2PyArrayProxy(fullVector<double> &fv)
...@@ -211,6 +207,10 @@ ...@@ -211,6 +207,10 @@
$result = fullMatrix2PyArrayConst(*$1); $result = fullMatrix2PyArrayConst(*$1);
} }
%typemap(out, fragment="fullMatrixConversion") fullMatrix<double>& {
$result = fullMatrix2PyArrayProxy(*$1);
}
%typemap(out, fragment="fullMatrixConversion") fullVector<double>& { %typemap(out, fragment="fullMatrixConversion") fullVector<double>& {
$result = fullVector2PyArrayProxy(*$1); $result = fullVector2PyArrayProxy(*$1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment