diff --git a/wrappers/gmshpy/gmshNumeric.i b/wrappers/gmshpy/gmshNumeric.i index 9fca5e851bb094b87bdcf7a1660c02f97e04bca8..bf281cbac662c28cd728b1e262ec4dca94ba8b33 100644 --- a/wrappers/gmshpy/gmshNumeric.i +++ b/wrappers/gmshpy/gmshNumeric.i @@ -31,3 +31,15 @@ %include "polynomialBasis.h" %include "pyramidalBasis.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; + } +} diff --git a/wrappers/gmshpy/gmshtypemaps.i b/wrappers/gmshpy/gmshtypemaps.i index 42a077fb8282755c8a929fce882b6a491784e659..22b493849f23b498da2a2055447ab909c1b3ec43 100644 --- a/wrappers/gmshpy/gmshtypemaps.i +++ b/wrappers/gmshpy/gmshtypemaps.i @@ -128,21 +128,17 @@ { npy_intp dims[2] = {fm.size1(), fm.size2()}; 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 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); - /*if (fm.getOwnData()) { - fm.setOwnData(false); - %#if PY_MAJOR_VERSION==2 && PY_MINOR_VERSION==6 - PyObject *capsule = PyCObject_FromVoidPtr((void*)data, deleteCapsuleArray); - %#else - PyObject *capsule = PyCapsule_New((void*) data, NULL, deleteCapsuleArray); - %#endif - PyArray_SetBaseObject((PyArrayObject*)array, capsule); - }*/ + return array; + } + PyObject *fullMatrix2PyArrayProxy(const fullMatrix<double> &fm) + { + npy_intp dims[2] = {fm.size1(), fm.size2()}; + double *data = (double*)fm.getDataPtr(); + 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 |NPY_ARRAY_WRITEABLE); return array; } PyObject *fullVector2PyArrayProxy(fullVector<double> &fv) @@ -211,6 +207,10 @@ $result = fullMatrix2PyArrayConst(*$1); } +%typemap(out, fragment="fullMatrixConversion") fullMatrix<double>& { + $result = fullMatrix2PyArrayProxy(*$1); +} + %typemap(out, fragment="fullMatrixConversion") fullVector<double>& { $result = fullVector2PyArrayProxy(*$1); }