Salome HOME
Debug of MEDCouplingUMesh::areCellsIncludedInMe : now duplicated cells in mesh that...
authorAnthony Geay <anthony.geay@edf.fr>
Sun, 10 May 2020 21:25:25 +0000 (23:25 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Sun, 10 May 2020 21:25:25 +0000 (23:25 +0200)
src/MEDCoupling/MEDCouplingPointSet.cxx
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py

index 1a2f8e798b07039f3e5fe095cdadcb6a6311a57f..80be8194141da28c8d467ca3b137c0f7566d36d3 100755 (executable)
@@ -1354,12 +1354,11 @@ MEDCouplingPointSet *MEDCouplingPointSet::buildPartOfMySelfNode(const mcIdType *
  */
 DataArrayIdType *MEDCouplingPointSet::zipConnectivityTraducer(int compType, mcIdType startCellId)
 {
-  DataArrayIdType *commonCells=0,*commonCellsI=0;
+  DataArrayIdType *commonCells(nullptr),*commonCellsI(nullptr);
   findCommonCells(compType,startCellId,commonCells,commonCellsI);
   MCAuto<DataArrayIdType> commonCellsTmp(commonCells),commonCellsITmp(commonCellsI);
   mcIdType newNbOfCells=-1;
-  MCAuto<DataArrayIdType> ret=DataArrayIdType::ConvertIndexArrayToO2N(ToIdType(getNumberOfCells()),commonCells->begin(),commonCellsI->begin(),
-                                                                                                          commonCellsI->end(),newNbOfCells);
+  MCAuto<DataArrayIdType> ret=DataArrayIdType::ConvertIndexArrayToO2N(ToIdType(getNumberOfCells()),commonCells->begin(),commonCellsI->begin(),commonCellsI->end(),newNbOfCells);
   MCAuto<DataArrayIdType> ret2=ret->invertArrayO2N2N2O(newNbOfCells);
   MCAuto<MEDCouplingPointSet> self=buildPartOfMySelf(ret2->begin(),ret2->end(),true);
   shallowCopyConnectivityFrom(self);
index ca37145da76b8f489b8ab1505e485296b486e6cc..14c2e2b19cc8d12e6d446545cb226e629ff71785 100755 (executable)
@@ -1846,13 +1846,30 @@ bool MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int com
       oss << " !";
       throw INTERP_KERNEL::Exception(oss.str());
     }
-  MCAuto<DataArrayIdType> o2n=mesh->zipConnectivityTraducer(compType,nbOfCells);
-  arr=o2n->subArray(nbOfCells);
-  arr->setName(other->getName());
-  mcIdType tmp;
+  //
   if(other->getNumberOfCells()==0)
+  {
+    MCAuto<DataArrayIdType> dftRet(DataArrayIdType::New()); dftRet->alloc(0,1); arr=dftRet.retn(); arr->setName(other->getName());
     return true;
-  return arr->getMaxValue(tmp)<nbOfCells;
+  }
+  DataArrayIdType *commonCells(nullptr),*commonCellsI(nullptr);
+  mesh->findCommonCells(compType,nbOfCells,commonCells,commonCellsI);
+  MCAuto<DataArrayIdType> commonCellsTmp(commonCells),commonCellsITmp(commonCellsI);
+  mcIdType newNbOfCells=-1;
+  MCAuto<DataArrayIdType> o2n = DataArrayIdType::ConvertIndexArrayToO2N(ToIdType(mesh->getNumberOfCells()),commonCells->begin(),commonCellsI->begin(),commonCellsI->end(),newNbOfCells);
+  MCAuto<DataArrayIdType> p0(o2n->selectByTupleIdSafeSlice(0,nbOfCells,1));
+  mcIdType maxPart(p0->getMaxValueInArray());
+  bool ret(maxPart==newNbOfCells-1);
+  MCAuto<DataArrayIdType> p1(p0->invertArrayO2N2N2O(newNbOfCells));
+  // fill p1 array in case of presence of cells in other not in this
+  mcIdType *pt(p1->getPointer());
+  for(mcIdType i = maxPart ; i < newNbOfCells-1 ; ++i )
+    pt[i+1] = i+1;
+  //
+  MCAuto<DataArrayIdType> p2(o2n->subArray(nbOfCells));
+  p2->transformWithIndArr(p1->begin(),p1->end()); p2->setName(other->getName());
+  arr = p2.retn();
+  return ret;
 }
 
 /*!
index 10ddab0df3f959052f0c51f476fc4ee49ff37741..a0c376146b4b964fd2e82affe620a6d185fc56a1 100644 (file)
@@ -844,6 +844,37 @@ class MEDCouplingBasicsTest7(unittest.TestCase):
         self.assertTrue(m.deepCopy().zipConnectivityTraducer(1).isIota(3))
         self.assertTrue(m.deepCopy().zipConnectivityTraducer(2).isEqual(DataArrayInt([0,1,1])))
 
+    def testBugAreCellsIncludedIn1(self):
+        """
+        Non regression test: a.areCellsIncludedIn(b) was buggy when some cells in b were duplicated into a following specified policy.
+        """
+        coo = DataArrayDouble([0,1,2,3,4],5,1)
+        m = MEDCouplingUMesh("",1)
+        m.setCoords(coo)
+        m.allocateCells()
+        # m contains several duplicated cells - some of those duplicated cells will be in m1
+        for i in range(3):
+            m.insertNextCell(NORM_SEG2,[0,1])
+        for i in range(4):
+            m.insertNextCell(NORM_SEG2,[1,2])
+        for i in range(2):
+            m.insertNextCell(NORM_SEG2,[2,3])
+        for i in range(2):
+            m.insertNextCell(NORM_SEG2,[3,4])
+        #
+        bexp = DataArrayInt([0,1,2, 3,4,5,6, 9,10])
+        m1 = m[bexp]
+        #
+        a,b = m.areCellsIncludedIn(m1,0)
+        self.assertTrue(a)
+        self.assertTrue(b.isEqual(DataArrayInt([2,2,2, 6,6,6,6, 10,10])))
+        #
+        bexp2 = DataArrayInt([0,1,2, 3,4,0, 6, 9,10])
+        m2 = m[bexp2]
+        a,b = m.areCellsIncludedIn(m2,0)
+        self.assertTrue(a)
+        self.assertTrue(b.isEqual(DataArrayInt([2,2,2,6,6,2,6,10,10])))
+
     pass
 
 if __name__ == '__main__':