]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
Bug fix: checkDeepEquivalWith was not correclty checking cell connectivity equality.
authorabn <adrien.bruneton@cea.fr>
Tue, 3 Jun 2014 15:53:54 +0000 (17:53 +0200)
committergeay <anthony.geay@cea.fr>
Fri, 20 Jun 2014 13:21:35 +0000 (15:21 +0200)
src/MEDCoupling/MEDCouplingPointSet.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 72cb033ee60d50394eec3492b89b00a184d357f3..d44c666dc7e524a719a328d78459fe7318c1b454 100644 (file)
@@ -1473,11 +1473,25 @@ void MEDCouplingPointSet::checkDeepEquivalWith(const MEDCouplingMesh *other, int
   da=m->zipConnectivityTraducer(cellCompPol);
   int nbCells=getNumberOfCells();
   int maxId=-1;
-  if(nbCells!=0)
-    maxId=*std::max_element(da->getConstPointer(),da->getConstPointer()+nbCells);
-  pt=std::find_if(da->getConstPointer()+nbCells,da->getConstPointer()+da->getNbOfElems(),std::bind2nd(std::greater<int>(),maxId));
-  if(pt!=da->getConstPointer()+da->getNbOfElems())
-    throw INTERP_KERNEL::Exception("checkDeepEquivalWith : some cells in other are not in this !");
+  int dan = da->getNumberOfTuples();
+  if (dan)
+    {
+      if (dan & 1)
+        throw INTERP_KERNEL::Exception("checkDeepEquivalWith : some cells in other are not in this !");
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da1 = DataArrayInt::New(), da2 = DataArrayInt::New();
+      da1->alloc(dan/2,1); da2->alloc(dan/2,1);
+      std::copy(da->getConstPointer(), da->getConstPointer()+dan/2, da1->getPointer());
+      std::copy(da->getConstPointer()+dan/2, da->getConstPointer()+dan, da2->getPointer());
+      da1->sort(); da2->sort();
+      if (*da1->getConstPointer() != *da2->getConstPointer())
+        throw INTERP_KERNEL::Exception("checkDeepEquivalWith : some cells in other are not in this !");
+      if (dan > 2)
+        {
+          MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dsi1 = da1->deltaShiftIndex(), dsi2 = da2->deltaShiftIndex();
+          if (!(dsi1->isUniform(1) && dsi2->isUniform(1)))
+            throw INTERP_KERNEL::Exception("checkDeepEquivalWith : some cells in other are not in this !");
+        }
+    }
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellCor2=da->selectByTupleId2(nbCells,da->getNbOfElems(),1);
   nodeCor=nodeCor2->isIdentity()?0:nodeCor2.retn();
   cellCor=cellCor2->isIdentity()?0:cellCor2.retn();
index 0c3143afb35938c211545c73418e2dc0d5f7f8b4..bedf03ce64b75b722ab18dd87df66470f1ba71f8 100644 (file)
@@ -2770,6 +2770,18 @@ class MEDCouplingBasicsTest(unittest.TestCase):
             self.assertEqual(expected1[i],nodeCor.getIJ(i,0));
             pass
         pass
+      
+    def testSwig2CheckDeepEquivalWith1(self):
+        eps = 1.0e-8
+        mcart = MEDCouplingCMesh()
+        mcart.setCoordsAt(0, DataArrayDouble([0.0,1.5,2.0]))
+        mcart.setCoordsAt(1, DataArrayDouble([1.0,2.5,3.0,4.0]))
+        m = mcart.buildUnstructured()
+        m2 = m[1:m.getNumberOfCells()]
+        self.assertRaises(InterpKernelException, m.checkDeepEquivalWith, m2, 0, eps)
+        self.assertRaises(InterpKernelException, m.checkDeepEquivalWith, m2, 1, eps)
+        self.assertRaises(InterpKernelException, m.checkDeepEquivalWith, m2, 2, eps)
+        pass
 
     def testCopyTinyStringsFromOnFields(self):
         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();