]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Addition of optimized sublevel methods for structured meshes
authorgeay <anthony.geay@cea.fr>
Wed, 19 Mar 2014 14:29:01 +0000 (15:29 +0100)
committergeay <anthony.geay@cea.fr>
Wed, 19 Mar 2014 14:29:01 +0000 (15:29 +0100)
src/MEDCoupling/MEDCouplingStructuredMesh.cxx
src/MEDCoupling/MEDCouplingStructuredMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 98d336b5ce251738c752bd4ec21190ebb0fb781b..12d5d4efaa89822b94cfc18a1979dc7c45b4def0 100644 (file)
@@ -167,6 +167,15 @@ void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector<int>& c
     };
 }
 
+/*!
+ * This method returns the number of cells of unstructured sub level mesh, without building it.
+ */
+int MEDCouplingStructuredMesh::getNumberOfCellsOfSubLevelMesh() const
+{
+  std::vector<int> cgs(getCellGridStructure());
+  return GetNumberOfCellsOfSubLevelMesh(cgs,getMeshDimension());
+}
+
 /*!
  * See MEDCouplingUMesh::getDistributionOfTypes for more information
  */
@@ -278,7 +287,7 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile,
  */
 MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const
 {
-  int meshDim=getMeshDimension(); 
+  int meshDim(getMeshDimension());
   if(meshDim<0 || meshDim>3)
     throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim must be in [1,2,3] !");
   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
@@ -290,6 +299,26 @@ MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const
   return ret.retn();
 }
 
+/*!
+ * This method returns the unstructured mesh (having single geometric type) of the sub level mesh of \a this.
+ * This method is equivalent to computing MEDCouplingUMesh::buildDescendingConnectivity on the unstructurized \a this mesh.
+ * 
+ * The caller is to delete the returned mesh using decrRef() as it is no more needed. 
+ */
+MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTSubLevelMesh() const
+{
+  int meshDim(getMeshDimension());
+  if(meshDim<1 || meshDim>3)
+    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTSubLevelMesh : meshdim must be in [2,3] !");
+  MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
+  int ns[3];
+  getNodeGridStructure(ns);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivityOfSubLevelMesh(ns,ns+meshDim));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim-1)));
+  ret->setNodalConnectivity(conn); ret->setCoords(coords);
+  return ret.retn();
+}
+
 /*!
  * Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one.
  *  \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
@@ -537,7 +566,7 @@ void MEDCouplingStructuredMesh::GetReverseNodalConnectivity3(const std::vector<i
  */
 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd)
 {
-  std::size_t dim=std::distance(nodeStBg,nodeStEnd);
+  std::size_t dim(std::distance(nodeStBg,nodeStEnd));
   switch(dim)
     {
     case 0:
@@ -557,6 +586,20 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity(const int *no
     }
 }
 
+DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd)
+{
+  std::size_t dim(std::distance(nodeStBg,nodeStEnd));
+  switch(dim)
+    {
+    case 3:
+      return Build1GTNodalConnectivityOfSubLevelMesh3D(nodeStBg);
+    case 2:
+      return Build1GTNodalConnectivityOfSubLevelMesh2D(nodeStBg);
+    default:
+      throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh: only dimension in [2,3] supported !");
+    }
+}
+
 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg)
 {
   int nbOfCells(*nodeStBg-1);
@@ -616,6 +659,51 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int *
   return conn.retn();
 }
 
+DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh3D(const int *nodeStBg)
+{
+  std::vector<int> ngs(3);
+  int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1),n2(nodeStBg[2]-1); ngs[0]=n0; ngs[1]=n1; ngs[2]=n2;
+  int off0(nodeStBg[0]),off1(nodeStBg[0]*nodeStBg[1]);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+  conn->alloc(4*GetNumberOfCellsOfSubLevelMesh(ngs,3));
+  int *cp(conn->getPointer()),pos(0);
+  //X
+  for(int i=0;i<nodeStBg[0];i++)
+    for(int j=0;j<n1;j++)
+      for(int k=0;k<n2;k++,cp+=4)
+        { cp[0]=k*off1+j*off0+i; cp[1]=(k+1)*off1+j*off0+i; cp[2]=(k+1)*off1+(j+1)*off0+i; cp[3]=k*off1+(j+1)*off0+i; }
+  //Y
+  for(int j=0;j<nodeStBg[1];j++)
+    for(int i=0;i<n0;i++)
+      for(int k=0;k<n2;k++,cp+=4)
+        { cp[0]=k*off1+j*off0+i; cp[1]=(k+1)*off1+j*off0+i; cp[2]=(k+1)*off1+j*off0+(i+1); cp[3]=k*off1+j*off0+(i+1); }
+  //Z
+  for(int k=0;k<nodeStBg[2];k++)
+    for(int i=0;i<n0;i++)
+      for(int j=0;j<n1;j++,cp+=4)
+        { cp[0]=k*off1+j*off0+i; cp[1]=k*off1+j*off0+(i+1); cp[2]=k*off1+(j+1)*off0+(i+1); cp[3]=k*off1+(j+1)*off0+i; }
+  return conn.retn();
+}
+
+DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh2D(const int *nodeStBg)
+{
+  std::vector<int> ngs(2);
+  int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1); ngs[0]=n0; ngs[1]=n1;
+  int off0(nodeStBg[0]);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+  conn->alloc(2*GetNumberOfCellsOfSubLevelMesh(ngs,2));
+  int *cp(conn->getPointer()),pos(0);
+  //X
+  for(int i=0;i<nodeStBg[0];i++)
+    for(int j=0;j<n1;j++,cp+=2)
+      { cp[0]=j*off0+i; cp[1]=(j+1)*off0+i; }
+  //Y
+  for(int j=0;j<nodeStBg[1];j++)
+    for(int i=0;i<n0;i++,cp+=2)
+      { cp[0]=j*off0+i; cp[1]=j*off0+(i+1); }
+  return conn.retn();
+}
+
 /*!
  * Returns a cell id by its (i,j,k) index. The cell is located between the i-th and
  * ( i + 1 )-th nodes along X axis etc.
@@ -824,3 +912,19 @@ DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector<
     }
   return ret.retn();
 }
+
+int MEDCouplingStructuredMesh::GetNumberOfCellsOfSubLevelMesh(const std::vector<int>& cgs, int mdim)
+{
+  int ret(0);
+  for(int i=0;i<mdim;i++)
+    {
+      int locRet(1);
+      for(int j=0;j<mdim;j++)
+        if(j!=i)
+          locRet*=cgs[j];
+        else
+          locRet*=cgs[j]+1;
+      ret+=locRet;
+    }
+  return ret;
+}
index 73fc81b61de88b70d081c99a610244293f373388..90861fc9918bb0a9493371abac9cd08e9ab445cb 100644 (file)
@@ -56,8 +56,10 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildOrthogonalField() const;
     MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const;
     //some useful methods
+    MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *build1SGTSubLevelMesh() const;
     MEDCOUPLING_EXPORT int getCellIdFromPos(int i, int j, int k) const;
     MEDCOUPLING_EXPORT int getNodeIdFromPos(int i, int j, int k) const;
+    MEDCOUPLING_EXPORT int getNumberOfCellsOfSubLevelMesh() const;
     MEDCOUPLING_EXPORT virtual void getNodeGridStructure(int *res) const = 0;
     MEDCOUPLING_EXPORT virtual void getSplitCellValues(int *res) const = 0;
     MEDCOUPLING_EXPORT virtual void getSplitNodeValues(int *res) const = 0;
@@ -67,13 +69,17 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT static bool IsPartStructured(const int *startIds, const int *stopIds, const std::vector<int>& st, std::vector< std::pair<int,int> >& partCompactFormat);
     MEDCOUPLING_EXPORT static DataArrayInt *BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat);
     MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd);
+    MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd);
   private:
+    static int GetNumberOfCellsOfSubLevelMesh(const std::vector<int>& cgs, int mdim);
     static void GetReverseNodalConnectivity1(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
     static void GetReverseNodalConnectivity2(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
     static void GetReverseNodalConnectivity3(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
     static DataArrayInt *Build1GTNodalConnectivity1D(const int *nodeStBg);
     static DataArrayInt *Build1GTNodalConnectivity2D(const int *nodeStBg);
     static DataArrayInt *Build1GTNodalConnectivity3D(const int *nodeStBg);
+    static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh2D(const int *nodeStBg);
+    static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh3D(const int *nodeStBg);
   protected:
     MEDCOUPLING_EXPORT MEDCouplingStructuredMesh();
     MEDCOUPLING_EXPORT MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCpy);
index fd9391764478e2c960aabf7bc8f2cfcb4022b2f4..2ecaa6d5b444da57aa5d82721a33472bc613680b 100644 (file)
@@ -14515,6 +14515,21 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertTrue(arrOfDisc2.isEqual(coo,1e-12))
         pass
 
+    def testSwig2StructuredDesc1(self):
+        c=MEDCouplingCMesh()
+        arr0=DataArrayDouble(3) ; arr0.iota()
+        arr1=DataArrayDouble(4) ; arr1.iota()
+        arr2=DataArrayDouble(5) ; arr2.iota()
+        c.setCoords(arr0,arr1,arr2)
+        #
+        self.assertEqual(98,c.getNumberOfCellsOfSubLevelMesh())
+        m=c.build1SGTSubLevelMesh()
+        self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,12,15,3,12,24,27,15,24,36,39,27,36,48,51,39,3,15,18,6,15,27,30,18,27,39,42,30,39,51,54,42,6,18,21,9,18,30,33,21,30,42,45,33,42,54,57,45,1,13,16,4,13,25,28,16,25,37,40,28,37,49,52,40,4,16,19,7,16,28,31,19,28,40,43,31,40,52,55,43,7,19,22,10,19,31,34,22,31,43,46,34,43,55,58,46,2,14,17,5,14,26,29,17,26,38,41,29,38,50,53,41,5,17,20,8,17,29,32,20,29,41,44,32,41,53,56,44,8,20,23,11,20,32,35,23,32,44,47,35,44,56,59,47,0,12,13,1,12,24,25,13,24,36,37,25,36,48,49,37,1,13,14,2,13,25,26,14,25,37,38,26,37,49,50,38,3,15,16,4,15,27,28,16,27,39,40,28,39,51,52,40,4,16,17,5,16,28,29,17,28,40,41,29,40,52,53,41,6,18,19,7,18,30,31,19,30,42,43,31,42,54,55,43,7,19,20,8,19,31,32,20,31,43,44,32,43,55,56,44,9,21,22,10,21,33,34,22,33,45,46,34,45,57,58,46,10,22,23,11,22,34,35,23,34,46,47,35,46,58,59,47,0,1,4,3,3,4,7,6,6,7,10,9,1,2,5,4,4,5,8,7,7,8,11,10,12,13,16,15,15,16,19,18,18,19,22,21,13,14,17,16,16,17,20,19,19,20,23,22,24,25,28,27,27,28,31,30,30,31,34,33,25,26,29,28,28,29,32,31,31,32,35,34,36,37,40,39,39,40,43,42,42,43,46,45,37,38,41,40,40,41,44,43,43,44,47,46,48,49,52,51,51,52,55,54,54,55,58,57,49,50,53,52,52,53,56,55,55,56,59,58])))
+        self.assertEqual(NORM_QUAD4,m.getCellModelEnum())
+        #
+        self.assertTrue(MEDCouplingStructuredMesh.Build1GTNodalConnectivityOfSubLevelMesh([3,7]).isEqual(DataArrayInt([0,3,3,6,6,9,9,12,12,15,15,18,1,4,4,7,7,10,10,13,13,16,16,19,2,5,5,8,8,11,11,14,14,17,17,20,0,1,1,2,3,4,4,5,6,7,7,8,9,10,10,11,12,13,13,14,15,16,16,17,18,19,19,20])))
+        pass
+
     def setUp(self):
         pass
     pass
index eb4e14fcfac95b69b9ed8a9efda263ab69aa35ef..e7ebdf73a8f41397c9d7fcbd9bb0daba5343a5b8 100644 (file)
@@ -293,8 +293,10 @@ using namespace INTERP_KERNEL;
 %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh;
 %newobject ParaMEDMEM::MEDCouplingStructuredMesh::buildStructuredSubPart;
 %newobject ParaMEDMEM::MEDCouplingStructuredMesh::build1SGTUnstructured;
+%newobject ParaMEDMEM::MEDCouplingStructuredMesh::build1SGTSubLevelMesh;
 %newobject ParaMEDMEM::MEDCouplingStructuredMesh::BuildExplicitIdsFrom;
 %newobject ParaMEDMEM::MEDCouplingStructuredMesh::Build1GTNodalConnectivity;
+%newobject ParaMEDMEM::MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh;
 %newobject ParaMEDMEM::MEDCouplingCMesh::New;
 %newobject ParaMEDMEM::MEDCouplingCMesh::clone;
 %newobject ParaMEDMEM::MEDCouplingCMesh::getCoordsAt;
@@ -2730,10 +2732,12 @@ namespace ParaMEDMEM
   public:
     int getCellIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception);
     int getNodeIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception);
+    int getNumberOfCellsOfSubLevelMesh() const throw(INTERP_KERNEL::Exception);
     virtual std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
     std::vector<int> getCellGridStructure() const throw(INTERP_KERNEL::Exception);
     MEDCoupling1SGTUMesh *build1SGTUnstructured() const throw(INTERP_KERNEL::Exception);
     static INTERP_KERNEL::NormalizedCellType GetGeoTypeGivenMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception);
+    MEDCoupling1SGTUMesh *build1SGTSubLevelMesh() const throw(INTERP_KERNEL::Exception);
     %extend
     {
       virtual MEDCouplingStructuredMesh *buildStructuredSubPart(PyObject *cellPart) const throw(INTERP_KERNEL::Exception)
@@ -2798,6 +2802,14 @@ namespace ParaMEDMEM
         return MEDCouplingStructuredMesh::Build1GTNodalConnectivity(tmp,tmp+szArr);
       }
 
+      static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh(PyObject *li) throw(INTERP_KERNEL::Exception)
+      {
+        int szArr,sw,iTypppArr;
+        std::vector<int> stdvecTyyppArr;
+        const int *tmp(convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr));
+        return MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh(tmp,tmp+szArr);
+      }
+
       static PyObject *IsPartStructured(PyObject *li, PyObject *st) throw(INTERP_KERNEL::Exception)
       {
         int szArr,sw,iTypppArr;