Salome HOME
Fix: getCellsContainingPoints() in case of polyhedron with a face containing colinear...
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingRemapperCommon.i
index 3dc4fe2d8b8612f2c40de860211ac5b3ac0a6239..75422b88f9676ed1c7bee19b8daa6a44ea739757 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2017-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -26,6 +26,7 @@
 
 %{
 #include "MEDCouplingRemapper.hxx"
+#include <memory>
 %}
 
 %include "InterpolationOptions.hxx"
@@ -47,58 +48,74 @@ namespace MEDCoupling
     public:
       MEDCouplingRemapper();
       ~MEDCouplingRemapper();
-      int prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const std::string& method) throw(INTERP_KERNEL::Exception);
-      int prepareEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target) throw(INTERP_KERNEL::Exception);
-      void transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
-      void partialTransfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField) throw(INTERP_KERNEL::Exception);
-      void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
-      MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue) throw(INTERP_KERNEL::Exception);
-      MEDCouplingFieldDouble *reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
-      bool setOptionInt(const std::string& key, int value) throw(INTERP_KERNEL::Exception);
-      bool setOptionDouble(const std::string& key, double value) throw(INTERP_KERNEL::Exception);
-      bool setOptionString(const std::string& key, const std::string& value) throw(INTERP_KERNEL::Exception);
-      int getInterpolationMatrixPolicy() const throw(INTERP_KERNEL::Exception);
-      void setInterpolationMatrixPolicy(int newInterpMatPol) throw(INTERP_KERNEL::Exception);
+      int prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const std::string& method);
+      int prepareEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target);
+      void transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue);
+      void partialTransfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField);
+      void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue);
+      MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue);
+      MEDCouplingFieldDouble *reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue);
+      bool setOptionInt(const std::string& key, int value);
+      bool setOptionDouble(const std::string& key, double value);
+      bool setOptionString(const std::string& key, const std::string& value);
+      int getInterpolationMatrixPolicy() const;
+      void setInterpolationMatrixPolicy(int newInterpMatPol);
       //
-      int nullifiedTinyCoeffInCrudeMatrixAbs(double maxValAbs) throw(INTERP_KERNEL::Exception);
-      int nullifiedTinyCoeffInCrudeMatrix(double scaleFactor) throw(INTERP_KERNEL::Exception);
-      double getMaxValueInCrudeMatrix() const throw(INTERP_KERNEL::Exception);
-      int getNumberOfColsOfMatrix() const throw(INTERP_KERNEL::Exception);
-      static std::string BuildMethodFrom(const std::string& meth1, const std::string& meth2) throw(INTERP_KERNEL::Exception);
+      int nullifiedTinyCoeffInCrudeMatrixAbs(double maxValAbs);
+      int nullifiedTinyCoeffInCrudeMatrix(double scaleFactor);
+      double getMaxValueInCrudeMatrix() const;
+      int getNumberOfColsOfMatrix() const;
+      static std::string BuildMethodFrom(const std::string& meth1, const std::string& meth2);
       %extend
          {
-           PyObject *getCrudeMatrix() const throw(INTERP_KERNEL::Exception)
+           PyObject *getCrudeMatrix() const
            {
-             const std::vector<std::map<int,double> >& m=self->getCrudeMatrix();
+             const std::vector<std::map<mcIdType,double> >& m=self->getCrudeMatrix();
              std::size_t sz=m.size();
              PyObject *ret=PyList_New(sz);
              for(std::size_t i=0;i<sz;i++)
                {
-                 const std::map<int,double>& row=m[i];
+                 const std::map<mcIdType,double>& row=m[i];
                  PyObject *ret0=PyDict_New();
-                 for(std::map<int,double>::const_iterator it=row.begin();it!=row.end();it++)
-                   PyDict_SetItem(ret0,PyInt_FromLong((*it).first),PyFloat_FromDouble((*it).second));
+                 for(std::map<mcIdType,double>::const_iterator it=row.begin();it!=row.end();it++)
+                   {
+                     std::unique_ptr<PyObject,std::function<void(PyObject*)>> k(PyInt_FromLong((*it).first),[](PyObject *obj) { Py_XDECREF(obj); } ),v(PyFloat_FromDouble((*it).second),[](PyObject *obj) { Py_XDECREF(obj); } );
+                     PyDict_SetItem(ret0,k.get(),v.get());
+                   }
                  PyList_SetItem(ret,i,ret0);
                }
              return ret;
            }
 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
-           PyObject *getCrudeCSRMatrix() const throw(INTERP_KERNEL::Exception)
+           PyObject *getCrudeCSRMatrix() const
            {
              return ToCSRMatrix(self->getCrudeMatrix(),self->getNumberOfColsOfMatrix());
            }
+           static PyObject *ToCSRMatrix(PyObject *m, mcIdType nbOfCols)
+           {
+              std::vector<std::map<mcIdType,double> > mCpp;
+              convertToVectMapIntDouble(m,mCpp);
+              return ToCSRMatrix(mCpp,nbOfCols);
+           }
 #endif
-           void setCrudeMatrix(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const std::string& method, PyObject *m) throw(INTERP_KERNEL::Exception)
+           void setCrudeMatrix(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const std::string& method, PyObject *m)
            {
-             std::vector<std::map<int,double> > mCpp;
+             std::vector<std::map<mcIdType,double> > mCpp;
              if(isCSRMatrix(m))
                {
 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
                  PyObject *indptr(PyObject_GetAttrString(m,"indptr"));
                  PyObject *indices(PyObject_GetAttrString(m,"indices"));
                  PyObject *data(PyObject_GetAttrString(m,"data"));
-                 MCAuto<DataArrayInt> indptrPtr(MEDCoupling_DataArrayInt_New__SWIG_1(indptr,NULL,NULL));
-                 MCAuto<DataArrayInt> indicesPtr(MEDCoupling_DataArrayInt_New__SWIG_1(indices,NULL,NULL));
+                 MCAuto<DataArrayInt32> indptrPtr, indicesPtr;
+                 // csr_matrix.indptr and csr_matrix.indices are always dtype==int32
+// #if defined(MEDCOUPLING_USE_64BIT_IDS)
+//                  indptrPtr = MEDCoupling_DataArrayInt64_New__SWIG_1(indptr,NULL,NULL);
+//                  indicesPtr = MEDCoupling_DataArrayInt64_New__SWIG_1(indices,NULL,NULL);
+// #else
+                 indptrPtr = MEDCoupling_DataArrayInt32_New__SWIG_1(indptr,NULL,NULL);
+                 indicesPtr = MEDCoupling_DataArrayInt32_New__SWIG_1(indices,NULL,NULL);
+//#endif
                  MCAuto<DataArrayDouble> dataPtr(MEDCoupling_DataArrayDouble_New__SWIG_1(data,NULL,NULL));
                  convertCSR_MCDataToVectMapIntDouble(indptrPtr,indicesPtr,dataPtr,mCpp);
                  Py_XDECREF(data); Py_XDECREF(indptr); Py_XDECREF(indices);
@@ -111,9 +128,9 @@ namespace MEDCoupling
              self->setCrudeMatrix(srcMesh,targetMesh,method,mCpp);
            }
 
-           void setCrudeMatrixEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target, PyObject *m) throw(INTERP_KERNEL::Exception)
+           void setCrudeMatrixEx(const MEDCouplingFieldTemplate *src, const MEDCouplingFieldTemplate *target, PyObject *m)
            {
-             std::vector<std::map<int,double> > mCpp;
+             std::vector<std::map<mcIdType,double> > mCpp;
              convertToVectMapIntDouble(m,mCpp);
              self->setCrudeMatrixEx(src,target,mCpp);
            }