]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
swig of computeMeshRestrictionFromTupleIds
authorageay <ageay>
Thu, 21 Mar 2013 16:16:55 +0000 (16:16 +0000)
committerageay <ageay>
Thu, 21 Mar 2013 16:16:55 +0000 (16:16 +0000)
src/MEDCoupling/MEDCouplingFieldDiscretization.cxx
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 9ce55a5813c63378adc23cb83ed112cc55da38ed..50e84001560cfb6f67f85b4563be8e8618a64204 100644 (file)
@@ -1188,7 +1188,13 @@ void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(con
 {
   if(!mesh)
     throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds : NULL input mesh !");
-  throw INTERP_KERNEL::Exception("Not implemented yet !");
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New(); tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1);
+  std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer());
+  tmp->sort(true);
+  tmp=tmp->buildUnique();
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=buildNbOfGaussPointPerCellField();
+  nbOfNodesPerCell->computeOffsets2();
+  nbOfNodesPerCell->searchRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
 }
 
 /*!
@@ -1897,31 +1903,8 @@ void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(c
   tmp->sort(true);
   tmp=tmp->buildUnique();
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nbOfNodesPerCell=mesh->computeNbOfNodesPerCell();
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret0=DataArrayInt::New(); ret0->alloc(0,1);
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New(); ret1->alloc(0,1);
   nbOfNodesPerCell->computeOffsets2();
-  //
-  const int *tupEnd(tmp->end()),*offBg(nbOfNodesPerCell->begin()),*offEnd(nbOfNodesPerCell->end()-1);
-  const int *tupPtr(tmp->begin()),*offPtr(offBg);
-  while(tupPtr!=tupEnd && offPtr!=offEnd)
-    {
-      if(*tupPtr==*offPtr)
-        {
-          int i=offPtr[0];
-          while(i<offPtr[1] && (*tupPtr==(offPtr[0]+i)) && tupPtr!=tupEnd) { i++; tupPtr++; }
-          if(i==offPtr[1])
-            {
-              ret0->pushBackSilent((int)std::distance(offBg,offPtr));
-              ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr);
-              offPtr++;
-            }
-        }
-      else
-        { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; }
-    }
-  //
-  cellRestriction=ret0.retn();
-  trueTupleRestriction=ret1.retn();
+  nbOfNodesPerCell->searchRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction);
 }
 
 void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception)
index a4f968c6f33acff2e1623675dc05e9f792695ca4..c76049e980f3c86fc4a46424e31562888a2a8ef9 100644 (file)
@@ -8548,6 +8548,60 @@ void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception)
   declareAsNew();
 }
 
+/*!
+ * Returns two new DataArrayInt instances whose contents is computed from that of \a this and \a listOfIds arrays as follows.
+ * \a this is expected to be an offset format ( as returned by DataArrayInt::computeOffsets2 ) that is to say with one component
+ * and ** sorted strictly increasingly **. \a listOfIds is expected to be sorted ascendingly (not strictly needed for \a listOfIds).
+ * This methods searches in \a this, considered as a set of contiguous \c this->getNumberOfComponents() ranges, all ids in \a listOfIds
+ * filling completely one of the ranges in \a this.
+ *
+ * \param [in] listOfIds a list of ids that has to be sorted ascendingly.
+ * \param [out] rangeIdsFetched the range ids fetched
+ * \param [out] idsInInputListThatFetch contains the list of ids in \a listOfIds that are \b fully included in a range in \a this. So
+ *              \a idsInInputListThatFetch is a part of input \a listOfIds.
+ *
+ * \sa DataArrayInt::computeOffsets2
+ *
+ *  \b Example: <br>
+ *          - \a this : [0,3,7,9,15,18]
+ *          - \a listOfIds contains  [0,1,2,3,7,8,15,16,17]
+ *          - \a rangeIdsFetched result array: [0,2,4]
+ *          - \a idsInInputListThatFetch result array: [0,1,2,7,8,15,16,17]
+ * In this example id 3 in input \a listOfIds is alone so it do not appear in output \a idsInInputListThatFetch.
+ * <br>
+ */
+void DataArrayInt::searchRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const throw(INTERP_KERNEL::Exception)
+{
+  if(!listOfIds)
+    throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids is null !");
+  listOfIds->checkAllocated(); checkAllocated();
+  if(listOfIds->getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids must have exactly one component !");
+  if(getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : this must have exactly one component !");
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret0=DataArrayInt::New(); ret0->alloc(0,1);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New(); ret1->alloc(0,1);
+  const int *tupEnd(listOfIds->end()),*offBg(begin()),*offEnd(end()-1);
+  const int *tupPtr(listOfIds->begin()),*offPtr(offBg);
+  while(tupPtr!=tupEnd && offPtr!=offEnd)
+    {
+      if(*tupPtr==*offPtr)
+        {
+          int i=offPtr[0];
+          while(i<offPtr[1] && *tupPtr==i && tupPtr!=tupEnd) { i++; tupPtr++; }
+          if(i==offPtr[1])
+            {
+              ret0->pushBackSilent((int)std::distance(offBg,offPtr));
+              ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr);
+              offPtr++;
+            }
+        }
+      else
+        { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; }
+    }
+  rangeIdsFetched=ret0.retn();
+  idsInInputListThatFetch=ret1.retn();
+}
 
 /*!
  * Returns a new DataArrayInt whose contents is computed from that of \a this and \a
index def94305c6229486ee889b6b42bd35a889e8f03c..741c334b84e43e42e54db34804c41cfe692b6612 100644 (file)
@@ -510,6 +510,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void computeOffsets() throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void computeOffsets2() throw(INTERP_KERNEL::Exception);
+    MEDCOUPLING_EXPORT void searchRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception);
index a7228bd9542aaf249cdb8e20f3219ef5356fd4c8..c8c12558caefc7af6952eb2e51de29a5da3d3b0b 100644 (file)
@@ -11644,6 +11644,41 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertTrue(DataArrayDouble(f.normL2()).isEqual(DataArrayDouble([58.16846378340898,1046.1241521947334]),1e-12))
         pass
 
+    def testSwig2FieldDiscretizationComputeMeshRestrictionFromTupleIds1(self):
+        m=MEDCouplingDataForTest.build3DSurfTargetMesh_1()
+        f=MEDCouplingFieldDouble(ON_GAUSS_NE)
+        f.setMesh(m)
+        a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4,5,6,8,9,10,14,15,16,17])
+        self.assertTrue(a.isEqual(DataArrayInt([1,4])))
+        self.assertTrue(b.isEqual(DataArrayInt([4,5,6,14,15,16,17])))
+        a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),DataArrayInt([0,1,2,3,5,7,8,9,10,11,12,18]))
+        self.assertTrue(a.isEqual(DataArrayInt([0,2])))
+        self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,7,8,9])))
+        #
+        f=MEDCouplingFieldDouble(ON_CELLS)
+        f.setMesh(m)
+        a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4])
+        self.assertTrue(a.isEqual(DataArrayInt([3,4])))
+        self.assertTrue(b.isEqual(DataArrayInt([3,4])))
+        #
+        f=MEDCouplingFieldDouble(ON_NODES)
+        f.setMesh(m)
+        a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[1,2,3,4])
+        self.assertTrue(a.isEqual(DataArrayInt([1])))
+        self.assertTrue(b.isEqual(DataArrayInt([1,2,4])))
+        #
+        f=MEDCouplingDataForTest.buildFieldOnGauss_1()
+        a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[0,11,12,13,14,15,17,18,19,36,37,38,115,117,118,119,120,121,122,123,124,125])
+        self.assertTrue(a.isEqual(DataArrayInt([0,11,12,18,35])))
+        self.assertTrue(b.isEqual(DataArrayInt([0,11,12,13,14,15,36,37,38,117,118,119,120,121,122,123,124,125])))
+        #
+        d=DataArrayInt([0,3,7,9,15,18])
+        e=DataArrayInt([0,1,2,3,7,8,15,16,17])
+        a,b=d.searchRangesInListOfIds(e)
+        self.assertTrue(a.isEqual(DataArrayInt([0,2,4])))
+        self.assertTrue(b.isEqual(DataArrayInt([0,1,2,7,8,15,16,17])))
+        pass
+
     def setUp(self):
         pass
     pass