Salome HOME
CheckDeepEquivalWith should also return OK with two empty meshes.
[modules/med.git] / src / MEDCoupling / MEDCouplingPointSet.cxx
index 72cb033ee60d50394eec3492b89b00a184d357f3..e3cbda93fe3d8da4024bb09b91a14b6ee5005042 100644 (file)
@@ -80,11 +80,10 @@ std::size_t MEDCouplingPointSet::getHeapMemorySizeWithoutChildren() const
   return MEDCouplingMesh::getHeapMemorySizeWithoutChildren();
 }
 
-std::vector<const BigMemoryObject *> MEDCouplingPointSet::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDCouplingPointSet::getDirectChildrenWithNull() const
 {
   std::vector<const BigMemoryObject *> ret;
-  if(_coords)
-    ret.push_back(_coords);
+  ret.push_back(_coords);
   return ret;
 }
 
@@ -1460,7 +1459,7 @@ void MEDCouplingPointSet::checkDeepEquivalWith(const MEDCouplingMesh *other, int
   int oldNbOfNodes=getNumberOfNodes();
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=m->buildPermArrayForMergeNode(prec,oldNbOfNodes,areNodesMerged,newNbOfNodes);
   //mergeNodes
-  if(!areNodesMerged)
+  if(!areNodesMerged && oldNbOfNodes != 0)
     throw INTERP_KERNEL::Exception("checkDeepEquivalWith : Nodes are incompatible ! ");
   const int *pt=std::find_if(da->getConstPointer()+oldNbOfNodes,da->getConstPointer()+da->getNbOfElems(),std::bind2nd(std::greater<int>(),oldNbOfNodes-1));
   if(pt!=da->getConstPointer()+da->getNbOfElems())
@@ -1472,12 +1471,19 @@ 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())
+  if (nbCells != other->getNumberOfCells())
     throw INTERP_KERNEL::Exception("checkDeepEquivalWith : some cells in other are not in this !");
+  int dan(da->getNumberOfTuples());
+  if (dan)
+    {
+      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->isEqualWithoutConsideringStr(*da2))
+        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();