]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
A useful static method for structured meshes.
authorgeay <anthony.geay@cea.fr>
Tue, 29 Apr 2014 09:44:00 +0000 (11:44 +0200)
committergeay <anthony.geay@cea.fr>
Tue, 29 Apr 2014 09:44:00 +0000 (11:44 +0200)
src/MEDCoupling/MEDCouplingStructuredMesh.cxx
src/MEDCoupling/MEDCouplingStructuredMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 5c5e4be8c60ca1625489efd1a69aaa7efb7cfa68..b5a8fb2ca6ba38fd27d446820eebb012bd906ed0 100644 (file)
@@ -643,6 +643,34 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh
   }
 }
 
+/*!
+ * This method retrieves the number of entities (it can be cells or nodes) given a range in compact standard format
+ * used in methods like BuildExplicitIdsFrom,IsPartStructured.
+ *
+ * \sa BuildExplicitIdsFrom,IsPartStructured
+ */
+int MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat)
+{
+  int ret(1);
+  bool isFetched(false);
+  std::size_t ii(0);
+  for(std::vector< std::pair<int,int> >::const_iterator it=partCompactFormat.begin();it!=partCompactFormat.end();it++,ii++)
+    {
+      int a((*it).first),b((*it).second);
+      if(a<0 || b<0 || b-a<0)
+        {
+          std::ostringstream oss; oss << "MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt : invalid input at dimension " << ii << " !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+      if(b-a>0)
+        {
+          isFetched=true;
+          ret*=(b-a);
+        }
+    }
+  return isFetched?ret:0;
+}
+
 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg)
 {
   int nbOfCells(*nodeStBg-1);
@@ -866,7 +894,7 @@ std::vector<int> MEDCouplingStructuredMesh::getCellGridStructure() const
  * 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
+ * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom, MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt
  */
 bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int *stopIds, const std::vector<int>& st, std::vector< std::pair<int,int> >& partCompactFormat)
 {
@@ -955,10 +983,10 @@ bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int
 
 /*!
  * 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.
+ * If the range contains invalid values regarding sructure an exception will be thrown.
  *
  * \return DataArrayInt * - a new object.
- * \sa MEDCouplingStructuredMesh::IsPartStructured
+ * \sa MEDCouplingStructuredMesh::IsPartStructured, MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt
  */
 DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat)
 {
index 0729d59e12819f6a30926a9cf67c9273aa09f791..cd4295399067458d81dc9c4337baf063b115ca86 100644 (file)
@@ -74,6 +74,7 @@ namespace ParaMEDMEM
     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);
+    MEDCOUPLING_EXPORT static int DeduceNumberOfGivenRangeInCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat);
   private:
     static int GetNumberOfCellsOfSubLevelMesh(const std::vector<int>& cgs, int mdim);
     static void GetReverseNodalConnectivity1(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
index fbc3370fec890ca0eb6e7c0419f21db45a1a8912..b68019b0c2c50ef2af8a47f95e6a00aeac8e1b4e 100644 (file)
@@ -13524,6 +13524,9 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         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)])
+        self.assertEqual(12,MEDCouplingStructuredMesh.DeduceNumberOfGivenRangeInCompactFrmt(b))
+        self.assertEqual(8,MEDCouplingStructuredMesh.DeduceNumberOfGivenRangeInCompactFrmt([(1,5),(1,3),(2,2)]))
+        self.assertEqual(0,MEDCouplingStructuredMesh.DeduceNumberOfGivenRangeInCompactFrmt([(5,5),(3,3),(2,2)]))
         d20=DataArrayInt([1,2,3,4,12,11,13,14,21,22,23,24])
         a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
         self.assertTrue(not a)
index 3efdfc62fb8839024bbb315b68658f6aec0fcfba..c01b16184fc2b3b8245f659e0cb9317a78df4ab0 100644 (file)
@@ -2810,6 +2810,30 @@ namespace ParaMEDMEM
         return MEDCouplingStructuredMesh::BuildExplicitIdsFrom(tmp5,inp);
       }
 
+      static int DeduceNumberOfGivenRangeInCompactFrmt(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 !");
+        return MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(inp);
+      }
+
       static DataArrayInt *Build1GTNodalConnectivity(PyObject *li) throw(INTERP_KERNEL::Exception)
       {
         int szArr,sw,iTypppArr;