Salome HOME
Ajouts des tests
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingCommon.i
index 02ce39ffd26aeb73a1fc698368b3380a4a56a151..e8d5a9db85e5f77ca8b9e03a04022d5f2f4c9c9d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2017  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,6 @@
 //
 // Author : Anthony Geay (EDF R&D)
 
-%module MEDCoupling
-
 #ifdef WITH_DOCSTRINGS
 %include MEDCoupling_doc.i
 #endif
@@ -327,6 +325,7 @@ using namespace INTERP_KERNEL;
 %newobject MEDCoupling::MEDCouplingUMesh::conformize2D;
 %newobject MEDCoupling::MEDCouplingUMesh::conformize3D;
 %newobject MEDCoupling::MEDCouplingUMesh::colinearize2D;
+%newobject MEDCoupling::MEDCouplingUMesh::colinearizeKeepingConform2D;
 %newobject MEDCoupling::MEDCouplingUMesh::rearrange2ConsecutiveCellTypes;
 %newobject MEDCoupling::MEDCouplingUMesh::sortCellsInMEDFileFrmt;
 %newobject MEDCoupling::MEDCouplingUMesh::getRenumArrForMEDFileFrmt;
@@ -363,6 +362,7 @@ using namespace INTERP_KERNEL;
 %newobject MEDCoupling::MEDCouplingUMesh::getBoundingBoxForBBTreeFast;
 %newobject MEDCoupling::MEDCouplingUMesh::getBoundingBoxForBBTree2DQuadratic;
 %newobject MEDCoupling::MEDCouplingUMesh::getBoundingBoxForBBTree1DQuadratic;
+%newobject MEDCoupling::MEDCouplingUMesh::convertDegeneratedCellsAndRemoveFlatOnes;
 %newobject MEDCoupling::MEDCouplingUMeshCellByTypeEntry::__iter__;
 %newobject MEDCoupling::MEDCouplingUMeshCellEntry::__iter__;
 %newobject MEDCoupling::MEDCoupling1GTUMesh::New;
@@ -714,43 +714,36 @@ namespace MEDCoupling
            return ret;
          }
 
-         PyObject *getCellsContainingPoints(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception)
+         PyObject *getCellsContainingPointsLinearPartOnlyOnNonDynType(PyObject *p, int nbOfPoints, double eps) const throw(INTERP_KERNEL::Exception)
          {
-           MCAuto<DataArrayInt> elts,eltsIndex;
+           double val;
+           DataArrayDouble *a;
+           DataArrayDoubleTuple *aa;
+           std::vector<double> bb;
+           int sw;
            int spaceDim=self->getSpaceDimension();
-           void *da=0;
-           int res1=SWIG_ConvertPtr(p,&da,SWIGTYPE_p_MEDCoupling__DataArrayDouble, 0 |  0 );
-           if (!SWIG_IsOK(res1))
-             {
-               int size;
-               INTERP_KERNEL::AutoCPtr<double> tmp=convertPyToNewDblArr2(p,&size);
-               int nbOfPoints=size/spaceDim;
-               if(size%spaceDim!=0)
-                 {
-                   throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Invalid list length ! Must be a multiple of self.getSpaceDimension() !");
-                 }
-               self->getCellsContainingPoints(tmp,nbOfPoints,eps,elts,eltsIndex);
-             }
-           else
-             {
-               DataArrayDouble *da2=reinterpret_cast< DataArrayDouble * >(da);
-               if(!da2)
-                 throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Not null DataArrayDouble instance expected !");
-               da2->checkAllocated();
-               int size=da2->getNumberOfTuples();
-               int nbOfCompo=da2->getNumberOfComponents();
-               if(nbOfCompo!=spaceDim)
-                 {
-                   throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Invalid DataArrayDouble nb of components ! Expected same as self.getSpaceDimension() !");
-                 }
-               self->getCellsContainingPoints(da2->getConstPointer(),size,eps,elts,eltsIndex);
-             }
+           const char msg[]="Python wrap of MEDCouplingMesh::getCellsContainingPointsLinearPartOnlyOnNonDynType : ";
+           const double *pos=convertObjToPossibleCpp5_Safe(p,sw,val,a,aa,bb,msg,nbOfPoints,spaceDim,true);
+           MCAuto<DataArrayInt> elts,eltsIndex;
+           self->getCellsContainingPointsLinearPartOnlyOnNonDynType(pos,nbOfPoints,eps,elts,eltsIndex);
            PyObject *ret=PyTuple_New(2);
            PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(elts.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
            PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(eltsIndex.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
            return ret;
          }
 
+         PyObject *getCellsContainingPoints(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception)
+         {
+           auto getCellsContainingPointsFunc=[self](const double *a, int b,double c, MCAuto<DataArrayInt>& d, MCAuto<DataArrayInt>& e) { self->getCellsContainingPoints(a,b,c,d,e); };
+           return Mesh_getCellsContainingPointsLike(p,eps,self,getCellsContainingPointsFunc);
+         }
+
+         PyObject *getCellsContainingPointsLinearPartOnlyOnNonDynType(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception)
+         {
+           auto getCellsContainingPointsFunc=[self](const double *a, int b,double c, MCAuto<DataArrayInt>& d, MCAuto<DataArrayInt>& e) { self->getCellsContainingPointsLinearPartOnlyOnNonDynType(a,b,c,d,e); };
+           return Mesh_getCellsContainingPointsLike(p,eps,self,getCellsContainingPointsFunc);
+         }
+         
          PyObject *getCellsContainingPoint(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception)
          {
            double val;
@@ -966,12 +959,12 @@ namespace MEDCoupling
           return self->checkTypeConsistencyAndContig(code,idsPerType);
         }
 
-        PyObject *splitProfilePerType(const DataArrayInt *profile) const throw(INTERP_KERNEL::Exception)
+        PyObject *splitProfilePerType(const DataArrayInt *profile, bool smartPflKiller=true) const throw(INTERP_KERNEL::Exception)
         {
           std::vector<int> code;
           std::vector<DataArrayInt *> idsInPflPerType;
           std::vector<DataArrayInt *> idsPerType;
-          self->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
+          self->splitProfilePerType(profile,code,idsInPflPerType,idsPerType,smartPflKiller);
           PyObject *ret=PyTuple_New(3);
           //
           if(code.size()%3!=0)
@@ -1228,6 +1221,9 @@ namespace MEDCoupling
     
     void deletePack(const int i, const int j) throw(INTERP_KERNEL::Exception);
     
+    void deleteSimplePack(const int i) throw(INTERP_KERNEL::Exception);
+    void deleteSimplePacks(const DataArrayInt* idx) throw(INTERP_KERNEL::Exception);
+    
     %extend 
     {
       MEDCouplingSkyLineArray() throw(INTERP_KERNEL::Exception)
@@ -1311,6 +1307,13 @@ namespace MEDCoupling
           self->replaceSimplePack(idx, vpack.data(), vpack.data()+vpack.size());
         }
         
+      void replaceSimplePacks(const DataArrayInt* idx, PyObject *listePacks) throw(INTERP_KERNEL::Exception)
+        {
+          std::vector<const DataArrayInt*> packs;
+          convertFromPyObjVectorOfObj<const MEDCoupling::DataArrayInt*>(listePacks,SWIGTYPE_p_MEDCoupling__DataArrayInt,"DataArrayInt",packs);
+          self->replaceSimplePacks(idx, packs);
+        }
+        
       void replacePack(const int superIdx, const int idx, PyObject *pack) throw(INTERP_KERNEL::Exception)
         {
           std::vector<int> vpack;
@@ -1504,8 +1507,8 @@ namespace MEDCoupling
                DataArrayDoubleTuple *aa,*aa2;
                std::vector<double> bb,bb2;
                int sw;
-               const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 1st paramater for point.";
-               const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 2nd paramater for vector.";
+               const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 1st parameter for point.";
+               const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 2nd parameter for vector.";
                const double *p=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true);
                const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true);
                std::vector<int> nodes;
@@ -1523,8 +1526,8 @@ namespace MEDCoupling
                DataArrayDoubleTuple *aa,*aa2;
                std::vector<double> bb,bb2;
                int sw;
-               const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 1st paramater for point.";
-               const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 2nd paramater for vector.";
+               const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 1st parameter for point.";
+               const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 2nd parameter for vector.";
                const double *p=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true);
                const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true);
                std::vector<int> nodes;
@@ -1625,7 +1628,7 @@ namespace MEDCoupling
 
            virtual PyObject *findCommonCells(int compType, int startCellId=0) const throw(INTERP_KERNEL::Exception)
            {
-             DataArrayInt *v0=0,*v1=0;
+             DataArrayInt *v0(nullptr),*v1(nullptr);
              self->findCommonCells(compType,startCellId,v0,v1);
              PyObject *res = PyList_New(2);
              PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
@@ -1636,8 +1639,17 @@ namespace MEDCoupling
       
            virtual void renumberNodesInConn(PyObject *li) throw(INTERP_KERNEL::Exception)
            {
-             void *da=0;
-             int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 );
+             void *da(nullptr);
+             {
+               int res1(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__MapII, 0 |  0 ));
+               if(SWIG_IsOK(res1))
+                 {
+                   MapII *da2(reinterpret_cast<MapII *>(da));
+                   self->renumberNodesInConn(da2->data());
+                   return ;
+                 }
+             }
+             int res1(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 ));
              if (!SWIG_IsOK(res1))
                {
                  int size;
@@ -1646,7 +1658,7 @@ namespace MEDCoupling
                }
              else
                {
-                 DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da);
+                 DataArrayInt *da2(reinterpret_cast< DataArrayInt * >(da));
                  if(!da2)
                    throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !");
                  da2->checkAllocated();
@@ -1666,7 +1678,7 @@ namespace MEDCoupling
 
            virtual DataArrayInt *fillCellIdsToKeepFromNodeIds(PyObject *li, bool fullyIn) const
            {
-             DataArrayInt *ret=0;
+             DataArrayInt *ret(nullptr);
              //
              int szArr,sw,iTypppArr;
              std::vector<int> stdvecTyyppArr;
@@ -1941,6 +1953,7 @@ namespace MEDCoupling
     DataArrayInt *conformize2D(double eps) throw(INTERP_KERNEL::Exception);
     DataArrayInt *conformize3D(double eps) throw(INTERP_KERNEL::Exception);
     DataArrayInt *colinearize2D(double eps) throw(INTERP_KERNEL::Exception);
+    DataArrayInt *colinearizeKeepingConform2D(double eps) throw(INTERP_KERNEL::Exception);
     void shiftNodeNumbersInConn(int delta) throw(INTERP_KERNEL::Exception);
     std::vector<bool> getQuadraticStatus() const throw(INTERP_KERNEL::Exception);
     DataArrayInt *findCellIdsOnBoundary() const throw(INTERP_KERNEL::Exception);
@@ -1964,6 +1977,7 @@ namespace MEDCoupling
     void convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception);
     DataArrayInt *convertLinearCellsToQuadratic(int conversionType=0) throw(INTERP_KERNEL::Exception);
     void convertDegeneratedCells() throw(INTERP_KERNEL::Exception);
+    DataArrayInt *convertDegeneratedCellsAndRemoveFlatOnes() throw(INTERP_KERNEL::Exception);
     bool areOnlySimplexCells() const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getEdgeRatioField() const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getAspectRatioField() const throw(INTERP_KERNEL::Exception);
@@ -2381,6 +2395,14 @@ namespace MEDCoupling
           }
       }
 
+      void attractSeg3MidPtsAroundNodes(double ratio, PyObject *nodeIds) throw(INTERP_KERNEL::Exception)
+      {
+        int szArr,sw,iTypppArr;
+        std::vector<int> stdvecTyyppArr;
+        const int *nodeIdsPtr(convertIntStarLikePyObjToCppIntStar(nodeIds,sw,szArr,iTypppArr,stdvecTyyppArr));
+        self->attractSeg3MidPtsAroundNodes(ratio,nodeIdsPtr,nodeIdsPtr+szArr);
+      }
+
       PyObject *getLevArrPerCellTypes(PyObject *li) const throw(INTERP_KERNEL::Exception)
       {
         int sz;
@@ -2925,8 +2947,8 @@ namespace MEDCoupling
         DataArrayDoubleTuple *aa,*aa2;
         std::vector<double> bb,bb2;
         int sw;
-        const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 1st paramater for origin.";
-        const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 2nd paramater for vector.";
+        const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 1st parameter for origin.";
+        const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 2nd parameter for vector.";
         const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true);
         const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true);
         //
@@ -2948,8 +2970,8 @@ namespace MEDCoupling
         DataArrayDoubleTuple *aa,*aa2;
         std::vector<double> bb,bb2;
         int sw;
-        const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 1st paramater for origin.";
-        const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 2nd paramater for vector.";
+        const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 1st parameter for origin.";
+        const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 2nd parameter for vector.";
         const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true);
         const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true);
         //
@@ -2968,8 +2990,8 @@ namespace MEDCoupling
         DataArrayDoubleTuple *aa,*aa2;
         std::vector<double> bb,bb2;
         int sw;
-        const char msg[]="Python wrap of MEDCouplingUMesh::clipSingle3DCellByPlane : 1st paramater for origin.";
-        const char msg2[]="Python wrap of MEDCouplingUMesh::clipSingle3DCellByPlane : 2nd paramater for vector.";
+        const char msg[]="Python wrap of MEDCouplingUMesh::clipSingle3DCellByPlane : 1st parameter for origin.";
+        const char msg2[]="Python wrap of MEDCouplingUMesh::clipSingle3DCellByPlane : 2nd parameter for vector.";
         const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,3,true);
         const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,3,true);
         MCAuto<MEDCouplingUMesh> ret(self->clipSingle3DCellByPlane(orig,vect,eps));
@@ -2986,8 +3008,8 @@ namespace MEDCoupling
         DataArrayDoubleTuple *aa,*aa2;
         std::vector<double> bb,bb2;
         int sw;
-        const char msg[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 1st paramater for origin.";
-        const char msg2[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 2nd paramater for vector.";
+        const char msg[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 1st parameter for origin.";
+        const char msg2[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 2nd parameter for vector.";
         const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true);
         const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true);
         return self->getCellIdsCrossingPlane(orig,vect,eps);
@@ -3989,7 +4011,7 @@ namespace MEDCoupling
     ~MEDCouplingFieldT();
   };
 
-  %template(DTC3) MEDCoupling::MEDCouplingFieldT<double>;
+  %template(MEDCouplingFieldTdouble) MEDCoupling::MEDCouplingFieldT<double>;
   %template(MEDCouplingFieldTfloat) MEDCoupling::MEDCouplingFieldT<float>;
   %template(MEDCouplingFieldTint) MEDCoupling::MEDCouplingFieldT<int>;
   
@@ -4074,12 +4096,12 @@ namespace MEDCoupling
     double getMinValue() const throw(INTERP_KERNEL::Exception);
     double getAverageValue() const throw(INTERP_KERNEL::Exception);
     double norm2() const throw(INTERP_KERNEL::Exception);
-    double normMax() const throw(INTERP_KERNEL::Exception);
     //do not put a default value to isWAbs because confusion in python with overloaded getWeightedAverageValue method
     double getWeightedAverageValue(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception);
     double integral(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception);
     double normL1(int compId) const throw(INTERP_KERNEL::Exception);
     double normL2(int compId) const throw(INTERP_KERNEL::Exception);
+    double normMax(int compId) const throw(INTERP_KERNEL::Exception);
     DataArrayInt *findIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception);
     static MEDCouplingFieldDouble *MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception);
@@ -4343,6 +4365,13 @@ namespace MEDCoupling
         self->normL2(tmp);
         return convertDblArrToPyList<double>(tmp,sz);
       }
+      PyObject *normMax() const throw(INTERP_KERNEL::Exception)
+      {
+        int sz=self->getNumberOfComponents();
+        INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
+        self->normMax(tmp);
+        return convertDblArrToPyList<double>(tmp,sz);
+      }
       void renumberCells(PyObject *li, bool check=true) throw(INTERP_KERNEL::Exception)
       {
         int szArr,sw,iTypppArr;
@@ -4427,8 +4456,8 @@ namespace MEDCoupling
         std::vector<double> bb,bb2;
         int sw;
         int spaceDim=3;
-        const char msg[]="Python wrap of MEDCouplingFieldDouble::extractSlice3D : 1st paramater for origin.";
-        const char msg2[]="Python wrap of MEDCouplingFieldDouble::extractSlice3D : 2nd paramater for vector.";
+        const char msg[]="Python wrap of MEDCouplingFieldDouble::extractSlice3D : 1st parameter for origin.";
+        const char msg2[]="Python wrap of MEDCouplingFieldDouble::extractSlice3D : 2nd parameter for vector.";
         const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true);
         const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true);
         //