]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
MEDCouplingStructuredMesh.IsPartStructured MEDCouplingStructuredMesh.BuildExplicitIdsFrom
authorageay <ageay>
Tue, 23 Jul 2013 09:52:21 +0000 (09:52 +0000)
committerageay <ageay>
Tue, 23 Jul 2013 09:52:21 +0000 (09:52 +0000)
- behaviour modification MEDCouplingStructuredMesh::buildPartAndReduceNodes returns a structured mesh if possible to reduce the cost in memory

src/MEDCoupling/MEDCouplingCMesh.cxx
src/MEDCoupling/MEDCouplingCMesh.hxx
src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx
src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx
src/MEDCoupling/MEDCouplingStructuredMesh.cxx
src/MEDCoupling/MEDCouplingStructuredMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 0895a17cfc2fe192cddc42e09aed098de36568a5..6fdb51e6ff9cdd1ff747b1495f68d1fe7ad9886d 100644 (file)
@@ -325,6 +325,31 @@ void MEDCouplingCMesh::getNodeGridStructure(int *res) const
     res[i]=getCoordsAt(i)->getNbOfElems();
 }
 
+std::vector<int> MEDCouplingCMesh::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
+{
+  std::vector<int> ret(getMeshDimension());
+  getNodeGridStructure(&ret[0]);
+  return ret;
+}
+
+MEDCouplingStructuredMesh *MEDCouplingCMesh::buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const throw(INTERP_KERNEL::Exception)
+{
+  checkCoherency();
+  int dim(getMeshDimension());
+  if(dim!=(int)cellPart.size())
+    {
+      std::ostringstream oss; oss << "MEDCouplingCMesh::buildStructuredSubPart : the mesh dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> ret(dynamic_cast<MEDCouplingCMesh *>(deepCpy()));
+  for(int i=0;i<dim;i++)
+    {
+      MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(ret->getCoordsAt(i)->selectByTupleId2(cellPart[i].first,cellPart[i].second+1,1));
+      ret->setCoordsAt(i,tmp);
+    }
+  return ret.retn();
+}
+
 int MEDCouplingCMesh::getSpaceDimension() const
 {
   int ret=0;
index ef768835a6c56da7062fd469eb0b56d1fd1428ab..a6f8a182e6f0a4174020a101e5b9793d846e0d3b 100644 (file)
@@ -79,6 +79,8 @@ namespace ParaMEDMEM
     void getSplitCellValues(int *res) const;
     void getSplitNodeValues(int *res) const;
     void getNodeGridStructure(int *res) const;
+    std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
+    MEDCouplingStructuredMesh *buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const throw(INTERP_KERNEL::Exception);
     //serialisation-unserialization
     void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
     void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
index 6e93efb1262743f8a4a57dc4442bf7862cbd3ae9..11e84570a15dce981603f28dfff6edaa776c2f70 100644 (file)
@@ -341,6 +341,37 @@ std::vector<int> MEDCouplingCurveLinearMesh::getNodeGridStructure() const throw(
   return _structure;
 }
 
+MEDCouplingStructuredMesh *MEDCouplingCurveLinearMesh::buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const throw(INTERP_KERNEL::Exception)
+{
+  checkCoherency();
+  int dim(getMeshDimension());
+  std::vector<int> dims(getMeshDimension());
+  if(dim!=(int)cellPart.size())
+    {
+      std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::buildStructuredSubPart : the mesh dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  std::vector< std::pair<int,int> > nodePartFormat(cellPart);
+  for(std::vector< std::pair<int,int> >::iterator it=nodePartFormat.begin();it!=nodePartFormat.end();it++)
+    (*it).second++;
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1(BuildExplicitIdsFrom(getNodeGridStructure(),nodePartFormat));
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> ret(dynamic_cast<MEDCouplingCurveLinearMesh *>(deepCpy()));
+  const DataArrayDouble *coo(ret->getCoords());
+  if(coo)
+    {
+      MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo2(coo->selectByTupleIdSafe(tmp1->begin(),tmp1->end()));
+      ret->setCoords(coo2);
+    }
+  for(int i=0;i<dim;i++)
+    {
+      dims[i]=cellPart[i].second-cellPart[i].first+1;
+      if(dims[i]<1)
+        throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::buildStructuredSubPart : invalid input cellPart !");
+    }
+  ret->setNodeGridStructure(&dims[0],&dims[0]+dims.size());
+  return ret.retn();
+}
+
 void MEDCouplingCurveLinearMesh::getBoundingBox(double *bbox) const
 {
   if(!((const DataArrayDouble *)_coords))
index 047bac5ceae4f0d2b530d20a6a087ec83cfbdc74..c165d1fb0c6384bc234211361ed07678b46b2af8 100644 (file)
@@ -62,6 +62,7 @@ namespace ParaMEDMEM
     void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
     void setNodeGridStructure(const int *gridStructBg, const int *gridStructEnd) throw(INTERP_KERNEL::Exception);
     std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
+    MEDCouplingStructuredMesh *buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const throw(INTERP_KERNEL::Exception);
     // tools
     void getBoundingBox(double *bbox) const;
     MEDCouplingFieldDouble *getMeasureField(bool isAbs) const;
index ed497f7a64e355b33403a1eb31ef3fd084d16dc8..7878d83b6c35c33b3894dab41f374cd64b796d77 100644 (file)
@@ -303,10 +303,29 @@ MEDCouplingMesh *MEDCouplingStructuredMesh::buildPart(const int *start, const in
 
 MEDCouplingMesh *MEDCouplingStructuredMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const
 {
-  MEDCouplingUMesh *um=buildUnstructured();
-  MEDCouplingMesh *ret=um->buildPartAndReduceNodes(start,end,arr);
-  um->decrRef();
-  return ret;
+  std::vector<int> cgs(getCellGridStructure());
+  std::vector< std::pair<int,int> > cellPartFormat,nodePartFormat;
+  if(IsPartStructured(start,end,cgs,cellPartFormat))
+    {
+      MEDCouplingAutoRefCountObjectPtr<MEDCouplingStructuredMesh> ret(buildStructuredSubPart(cellPartFormat));
+      nodePartFormat=cellPartFormat;
+      for(std::vector< std::pair<int,int> >::iterator it=nodePartFormat.begin();it!=nodePartFormat.end();it++)
+        (*it).second++;
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1(BuildExplicitIdsFrom(getNodeGridStructure(),nodePartFormat));
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(DataArrayInt::New()); tmp2->alloc(getNumberOfNodes(),1);
+      tmp2->fillWithValue(-1);
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp3(DataArrayInt::New()); tmp3->alloc(tmp1->getNumberOfTuples(),1); tmp3->iota(0);
+      tmp2->setPartOfValues3(tmp3,tmp1->begin(),tmp1->end(),0,1,1);
+      arr=tmp2.retn();
+      return ret.retn();
+    }
+  else
+    {
+      MEDCouplingUMesh *um=buildUnstructured();
+      MEDCouplingMesh *ret=um->buildPartAndReduceNodes(start,end,arr);
+      um->decrRef();
+      return ret;
+    }
 }
 
 DataArrayInt *MEDCouplingStructuredMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
@@ -473,3 +492,162 @@ void MEDCouplingStructuredMesh::GetPosFromId(int nodeId, int meshDim, const int
       res[i]=pos;
     }
 }
+
+std::vector<int> MEDCouplingStructuredMesh::getCellGridStructure() const throw(INTERP_KERNEL::Exception)
+{
+  std::vector<int> ret(getNodeGridStructure());
+  std::transform(ret.begin(),ret.end(),ret.begin(),std::bind2nd(std::plus<int>(),-1));
+  return ret;
+}
+
+/*!
+ * This method states if given part ids [ \a startIds, \a stopIds) and a structure \a st returns if it can be considered as a structured dataset.
+ * If true is returned \a partCompactFormat will contain the information to build the corresponding part.
+ *
+ * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom
+ */
+bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int *stopIds, const std::vector<int>& st, std::vector< std::pair<int,int> >& partCompactFormat) throw(INTERP_KERNEL::Exception)
+{
+  int dim((int)st.size());
+  partCompactFormat.resize(dim);
+  if(dim<1 || dim>3)
+    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::isPartStructured : input structure must be of dimension in [1,2,3] !");
+  std::vector<int> tmp2(dim),tmp(dim),tmp3(dim),tmp4(dim); tmp2[0]=1;
+  for(int i=1;i<dim;i++)
+    tmp2[i]=tmp2[i-1]*st[i-1];
+  std::size_t sz(std::distance(startIds,stopIds));
+  if(sz==0)
+    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : empty input !");
+  GetPosFromId(*startIds,dim,&tmp2[0],&tmp[0]);
+  partCompactFormat.resize(dim);
+  for(int i=0;i<dim;i++)
+    partCompactFormat[i].first=tmp[i];
+  if(tmp[dim-1]<0 || tmp[dim-1]>=st[dim-1])
+    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : first id in input is not in valid range !");
+  if(sz==1)
+    {
+      for(int i=0;i<dim;i++)
+        partCompactFormat[i].second=tmp[i]+1;
+      return true;
+    }
+  GetPosFromId(startIds[sz-1],dim,&tmp2[0],&tmp3[0]);
+  for(int i=0;i<dim;i++)
+    {
+      if(tmp3[i]<0 || tmp3[i]>=st[i])
+        throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : last id in input is not in valid range !");
+      partCompactFormat[i].second=tmp3[i]+1;
+      tmp4[i]=partCompactFormat[i].second-partCompactFormat[i].first;
+      if(tmp4[i]<=0)
+        return false;
+    }
+  const int *w(startIds);
+  switch(dim)
+    {
+    case 3:
+      {
+        for(int i=0;i<tmp4[2];i++)
+          {
+            int a=tmp2[2]*(partCompactFormat[2].first+i);
+            for(int j=0;j<tmp4[1];j++)
+              {
+                int b=tmp2[1]*(partCompactFormat[1].first+j);
+                for(int k=0;k<tmp4[0];k++,w++)
+                  {
+                    if(partCompactFormat[0].first+k+b+a!=*w)
+                      return false;
+                  }
+              }
+          }
+        return true;
+      }
+    case 2:
+      {
+        for(int j=0;j<tmp4[1];j++)
+          {
+            int b=tmp2[1]*(partCompactFormat[1].first+j);
+            for(int k=0;k<tmp4[0];k++,w++)
+              {
+                if(partCompactFormat[0].first+k+b!=*w)
+                  return false;
+              }
+          }
+        return true;
+      }
+    case 1:
+      {
+        for(int k=0;k<tmp4[0];k++,w++)
+          {
+            if(partCompactFormat[0].first+k!=*w)
+              return false;
+          }
+        return true;
+      }
+    default:
+      throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IsPartStructured : internal error !");
+    }
+}
+
+/*!
+ * This method builds the explicit entity array from the structure in \a st and the range in \a partCompactFormat.
+ *If the range contains invalid values regarding sructure an exception will be thrown.
+ *
+ * \return DataArrayInt * - a new object.
+ * \sa MEDCouplingStructuredMesh::IsPartStructured
+ */
+DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat) throw(INTERP_KERNEL::Exception)
+{
+  if(st.size()!=partCompactFormat.size())
+    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : input arrays must have the same size !");
+  int nbOfItems(1);
+  std::vector<int> dims(st.size());
+  for(std::size_t i=0;i<st.size();i++)
+    {
+      if(partCompactFormat[i].first<0 || partCompactFormat[i].first>st[i])
+        throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 1 !");
+      if(partCompactFormat[i].second<0 || partCompactFormat[i].second>st[i])
+        throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 2 !");
+      if(partCompactFormat[i].second<=partCompactFormat[i].first)
+        throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 3 !");
+      dims[i]=partCompactFormat[i].second-partCompactFormat[i].first;
+      nbOfItems*=dims[i];
+    }
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
+  ret->alloc(nbOfItems,1);
+  int *pt(ret->getPointer());
+  switch(st.size())
+    {
+    case 3:
+      {
+        for(int i=0;i<dims[2];i++)
+          {
+            int a=(partCompactFormat[2].first+i)*st[0]*st[1];
+            for(int j=0;j<dims[1];j++)
+              {
+                int b=(partCompactFormat[1].first+j)*st[0];
+                for(int k=0;k<dims[0];k++,pt++)
+                  *pt=partCompactFormat[0].first+k+b+a;
+              }
+          }
+        break;
+      }
+    case 2:
+      {
+        for(int j=0;j<dims[1];j++)
+          {
+            int b=(partCompactFormat[1].first+j)*st[0];
+            for(int k=0;k<dims[0];k++,pt++)
+              *pt=partCompactFormat[0].first+k+b;
+          }
+        break;
+      }
+    case 1:
+      {
+        for(int k=0;k<dims[0];k++,pt++)
+          *pt=partCompactFormat[0].first+k;
+        break;
+      }
+    default:
+      throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : Dimension supported are 1,2 or 3 !");
+    }
+  return ret.retn();
+}
index 07c73d71ee4ef0ab43c692cf2bb153caaf902a03..9b18e21b64158ff7fcc0a3f46850263f2b773d61 100644 (file)
@@ -59,6 +59,11 @@ namespace ParaMEDMEM
     virtual void getNodeGridStructure(int *res) const = 0;
     virtual void getSplitCellValues(int *res) const = 0;
     virtual void getSplitNodeValues(int *res) const = 0;
+    virtual std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception) = 0;
+    std::vector<int> getCellGridStructure() const throw(INTERP_KERNEL::Exception);
+    virtual MEDCouplingStructuredMesh *buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const throw(INTERP_KERNEL::Exception) = 0;
+    static bool IsPartStructured(const int *startIds, const int *stopIds, const std::vector<int>& st, std::vector< std::pair<int,int> >& partCompactFormat) throw(INTERP_KERNEL::Exception);
+    static DataArrayInt *BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat) throw(INTERP_KERNEL::Exception);
   protected:
     MEDCouplingStructuredMesh();
     MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCpy);
index b727ddeb526bcb6b1495786aaae114d7a68d5741..7bd55b9a2f1f270d93b5c93737c529d6efeceb7a 100644 (file)
@@ -1867,7 +1867,7 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         
         cells2=[25, 26]
         partMesh2, arr1=mesh1.buildPartAndReduceNodes(cells2)
-        self.assertTrue(isinstance(partMesh2,MEDCouplingUMesh))
+        self.assertTrue(isinstance(partMesh2,MEDCouplingCMesh))
         self.assertEqual(2,partMesh2.getNumberOfCellsWithType(NORM_HEXA8));
         self.assertEqual(12,partMesh2.getNumberOfNodes());
         
@@ -13390,6 +13390,87 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertRaises(InterpKernelException,d.checkAllocated)
         pass
 
+    def testSwig2IsPartStructured1(self):
+        #dim 1
+        d10=DataArrayInt([2,3,4,5,6,7,8,9,10,11])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d10,[13])
+        self.assertTrue(a) ; self.assertEqual(b,[(2,12)])
+        d11=DataArrayInt([2,3,4,5,6,7,8,10,9,11])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d11,[13])
+        self.assertTrue(not a)
+        self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d10,[11])
+        #dim 2
+        st=[10,4]
+        d20=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+        self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,3)])
+        d20=DataArrayInt([1,2,3,4,12,11,13,14,21,22,23,24])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+        self.assertTrue(not a)
+        d20=DataArrayInt([1,2,3,4,11,12,13,15,21,22,23,24])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+        self.assertTrue(not a)
+        d21=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d21,st)
+        self.assertTrue(a) ; self.assertEqual(b,[(0,10),(0,4)])
+        d22=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44])
+        self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d22,st)
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d22,[10,5])
+        self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,5)])
+        #dim 3
+        d30=DataArrayInt([11,12,13,14,21,22,23,24,51,52,53,54,61,62,63,64])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d30,[10,4,2])
+        self.assertTrue(a) ; self.assertEqual(b,[(1,5),(1,3),(0,2)])
+        d31=DataArrayInt([11,12,13,14,21,22,24,23,51,52,53,54,61,62,63,64])
+        a,b=MEDCouplingStructuredMesh.IsPartStructured(d31,[10,4,2])
+        self.assertTrue(not a)
+        self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d30,[10,4,1])
+        pass
+
+    def testSwig2PartStructured1(self):
+        c=MEDCouplingCMesh() ; c.setName("toto")
+        arr0=DataArrayDouble(10); arr0.iota()
+        arr1=DataArrayDouble(4) ; arr1.iota(3)
+        c.setCoords(arr0,arr1)
+        self.assertEqual(c.getNodeGridStructure(),(10,4))
+        self.assertEqual(c.getCellGridStructure(),(9,3))
+        d20=DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])
+        self.assertEqual(27,c.getNumberOfCells())
+        self.assertEqual(40,c.getNumberOfNodes())
+        self.assertEqual(2,c.getMeshDimension())
+        c.checkCoherency()
+        #
+        arr2=MEDCouplingStructuredMesh.BuildExplicitIdsFrom([9,3],[(1,5),(0,3)])
+        self.assertTrue(arr2.isEqual(DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])))
+        # CMesh
+        c2=c.buildStructuredSubPart([(1,5),(0,3)])
+        c2.checkCoherency()
+        self.assertTrue(isinstance(c2,MEDCouplingCMesh))
+        self.assertEqual(12,c2.getNumberOfCells())
+        self.assertEqual(20,c2.getNumberOfNodes())
+        self.assertEqual(2,c2.getMeshDimension())
+        self.assertEqual("toto",c2.getName())
+        self.assertTrue(c2.getCoordsAt(0).isEqual(DataArrayDouble([1.,2.,3.,4.,5.]),1e-12))
+        self.assertTrue(c2.getCoordsAt(1).isEqual(DataArrayDouble([3.,4.,5.,6.]),1e-12))
+        #
+        a,b=c.buildPartAndReduceNodes(d20)
+        a.checkCoherency()
+        exp2=DataArrayInt([-1,0,1,2,3,4,-1,-1,-1,-1,-1,5,6,7,8,9,-1,-1,-1,-1,-1,10,11,12,13,14,-1,-1,-1,-1,-1,15,16,17,18,19,-1,-1,-1,-1])
+        self.assertTrue(exp2.isEqual(b))
+        self.assertTrue(isinstance(a,MEDCouplingCMesh))
+        self.assertTrue(a.buildUnstructured().isEqual(c.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
+        # CurveLinearMesh
+        c2=MEDCouplingCurveLinearMesh() ; c2.setName("toto")
+        c2.setCoords(c.buildUnstructured().getCoords())
+        c2.setNodeGridStructure([10,4])
+        c2.checkCoherency()
+        a,b=c2.buildPartAndReduceNodes(d20)
+        a.checkCoherency()
+        self.assertTrue(exp2.isEqual(b))
+        self.assertTrue(isinstance(a,MEDCouplingCurveLinearMesh))
+        self.assertTrue(a.buildUnstructured().isEqual(c2.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
+        pass
+
     def setUp(self):
         pass
     pass
index dad36a1bb894d0b91b5caeceb77f154c69fcae89..8cf917b1b2adace136792e8bf8e154ee12966b3d 100644 (file)
@@ -457,6 +457,8 @@ using namespace INTERP_KERNEL;
 %newobject ParaMEDMEM::MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords;
 %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::New;
 %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh;
+%newobject ParaMEDMEM::MEDCouplingStructuredMesh::buildStructuredSubPart;
+%newobject ParaMEDMEM::MEDCouplingStructuredMesh::BuildExplicitIdsFrom;
 %newobject ParaMEDMEM::MEDCouplingCMesh::New;
 %newobject ParaMEDMEM::MEDCouplingCMesh::clone;
 %newobject ParaMEDMEM::MEDCouplingCMesh::getCoordsAt;
@@ -2930,7 +2932,91 @@ 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);
+    virtual std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
+    std::vector<int> getCellGridStructure() const throw(INTERP_KERNEL::Exception);
     static INTERP_KERNEL::NormalizedCellType GetGeoTypeGivenMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception);
+    %extend
+    {
+      virtual MEDCouplingStructuredMesh *buildStructuredSubPart(PyObject *cellPart) const throw(INTERP_KERNEL::Exception)
+      {
+        int tmpp1=-1,tmpp2=-1;
+        std::vector<int> tmp=fillArrayWithPyListInt2(cellPart,tmpp1,tmpp2);
+        std::vector< std::pair<int,int> > inp;
+        if(tmpp2==2)
+          {
+            inp.resize(tmpp1);
+            for(int i=0;i<tmpp1;i++)
+              { inp[i].first=tmp[2*i]; inp[i].second=tmp[2*i+1]; }
+          }
+        else if(tmpp2==1)
+          {
+            if(tmpp1%2!=0)
+              throw INTERP_KERNEL::Exception("Wrap of MEDCouplingStructuredMesh.buildStructuredSubPart : invalid input size ! Must be even size !");
+            inp.resize(tmpp1/2);
+            for(int i=0;i<tmpp1/2;i++)
+              { inp[i].first=tmp[2*i]; inp[i].second=tmp[2*i+1]; }
+          }
+        else
+          throw INTERP_KERNEL::Exception("Wrap of MEDCouplingStructuredMesh.buildStructuredSubPart : invalid input size !");
+        return self->buildStructuredSubPart(inp);
+      }
+
+      static DataArrayInt *BuildExplicitIdsFrom(PyObject *st, PyObject *part) throw(INTERP_KERNEL::Exception)
+      {
+        int tmpp1=-1,tmpp2=-1;
+        std::vector<int> tmp=fillArrayWithPyListInt2(part,tmpp1,tmpp2);
+        std::vector< std::pair<int,int> > inp;
+        if(tmpp2==2)
+          {
+            inp.resize(tmpp1);
+            for(int i=0;i<tmpp1;i++)
+              { inp[i].first=tmp[2*i]; inp[i].second=tmp[2*i+1]; }
+          }
+        else if(tmpp2==1)
+          {
+            if(tmpp1%2!=0)
+              throw INTERP_KERNEL::Exception("Wrap of MEDCouplingStructuredMesh.BuildExplicitIdsFrom : invalid input size ! Must be even size !");
+            inp.resize(tmpp1/2);
+            for(int i=0;i<tmpp1/2;i++)
+              { inp[i].first=tmp[2*i]; inp[i].second=tmp[2*i+1]; }
+          }
+        else
+          throw INTERP_KERNEL::Exception("Wrap of MEDCouplingStructuredMesh.BuildExplicitIdsFrom : invalid input size !");
+        //
+        int szArr,sw,iTypppArr;
+        std::vector<int> stdvecTyyppArr;
+        const int *tmp4=convertObjToPossibleCpp1_Safe(st,sw,szArr,iTypppArr,stdvecTyyppArr);
+        std::vector<int> tmp5(tmp4,tmp4+szArr);
+        //
+        return MEDCouplingStructuredMesh::BuildExplicitIdsFrom(tmp5,inp);
+      }
+
+      static PyObject *IsPartStructured(PyObject *li, PyObject *st) throw(INTERP_KERNEL::Exception)
+      {
+        int szArr,sw,iTypppArr;
+        std::vector<int> stdvecTyyppArr;
+        const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr);
+        int szArr2,sw2,iTypppArr2;
+        std::vector<int> stdvecTyyppArr2;
+        const int *tmp2=convertObjToPossibleCpp1_Safe(st,sw2,szArr2,iTypppArr2,stdvecTyyppArr2);
+        std::vector<int> tmp3(tmp2,tmp2+szArr2);
+        std::vector< std::pair<int,int> > partCompactFormat;
+        bool ret0=MEDCouplingStructuredMesh::IsPartStructured(tmp,tmp+szArr,tmp3,partCompactFormat);
+        PyObject *ret=PyTuple_New(2);
+        PyObject *ret0Py=ret0?Py_True:Py_False; Py_XINCREF(ret0Py);
+        PyTuple_SetItem(ret,0,ret0Py);
+        PyObject *ret1Py=PyList_New(partCompactFormat.size());
+        for(std::size_t i=0;i<partCompactFormat.size();i++)
+          {
+            PyObject *tmp4=PyTuple_New(2);
+            PyTuple_SetItem(tmp4,0,PyInt_FromLong(partCompactFormat[i].first));
+            PyTuple_SetItem(tmp4,1,PyInt_FromLong(partCompactFormat[i].second));
+            PyList_SetItem(ret1Py,i,tmp4);
+          }
+        PyTuple_SetItem(ret,1,ret1Py);
+        return ret;
+      }
+    }
   };
 
   //== MEDCouplingCMesh
@@ -2985,7 +3071,6 @@ namespace ParaMEDMEM
     static MEDCouplingCurveLinearMesh *New(const char *meshName);
     MEDCouplingCurveLinearMesh *clone(bool recDeepCpy) const;
     void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
-    std::vector<int> getNodeGridStructure() const throw(INTERP_KERNEL::Exception);
     %extend {
       MEDCouplingCurveLinearMesh()
       {