From: Anthony Geay Date: Sun, 10 May 2020 21:25:25 +0000 (+0200) Subject: Debug of MEDCouplingUMesh::areCellsIncludedInMe : now duplicated cells in mesh that... X-Git-Tag: V9_5_0b1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f7fdff591a1830181499ba95e16ef25eb43e0140;p=tools%2Fmedcoupling.git Debug of MEDCouplingUMesh::areCellsIncludedInMe : now duplicated cells in mesh that appear in other mesh also is correctly managed --- diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index 1a2f8e798..80be81941 100755 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -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 commonCellsTmp(commonCells),commonCellsITmp(commonCellsI); mcIdType newNbOfCells=-1; - MCAuto ret=DataArrayIdType::ConvertIndexArrayToO2N(ToIdType(getNumberOfCells()),commonCells->begin(),commonCellsI->begin(), - commonCellsI->end(),newNbOfCells); + MCAuto ret=DataArrayIdType::ConvertIndexArrayToO2N(ToIdType(getNumberOfCells()),commonCells->begin(),commonCellsI->begin(),commonCellsI->end(),newNbOfCells); MCAuto ret2=ret->invertArrayO2N2N2O(newNbOfCells); MCAuto self=buildPartOfMySelf(ret2->begin(),ret2->end(),true); shallowCopyConnectivityFrom(self); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index ca37145da..14c2e2b19 100755 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1846,13 +1846,30 @@ bool MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int com oss << " !"; throw INTERP_KERNEL::Exception(oss.str()); } - MCAuto o2n=mesh->zipConnectivityTraducer(compType,nbOfCells); - arr=o2n->subArray(nbOfCells); - arr->setName(other->getName()); - mcIdType tmp; + // if(other->getNumberOfCells()==0) + { + MCAuto dftRet(DataArrayIdType::New()); dftRet->alloc(0,1); arr=dftRet.retn(); arr->setName(other->getName()); return true; - return arr->getMaxValue(tmp)findCommonCells(compType,nbOfCells,commonCells,commonCellsI); + MCAuto commonCellsTmp(commonCells),commonCellsITmp(commonCellsI); + mcIdType newNbOfCells=-1; + MCAuto o2n = DataArrayIdType::ConvertIndexArrayToO2N(ToIdType(mesh->getNumberOfCells()),commonCells->begin(),commonCellsI->begin(),commonCellsI->end(),newNbOfCells); + MCAuto p0(o2n->selectByTupleIdSafeSlice(0,nbOfCells,1)); + mcIdType maxPart(p0->getMaxValueInArray()); + bool ret(maxPart==newNbOfCells-1); + MCAuto 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 p2(o2n->subArray(nbOfCells)); + p2->transformWithIndArr(p1->begin(),p1->end()); p2->setName(other->getName()); + arr = p2.retn(); + return ret; } /*! diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 10ddab0df..a0c376146 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -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__':