]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Protection against infinite loop when computing residuals of invalid input mesh.
authorageay <ageay>
Fri, 14 Dec 2012 14:04:54 +0000 (14:04 +0000)
committerageay <ageay>
Fri, 14 Dec 2012 14:04:54 +0000 (14:04 +0000)
src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx
src/MEDCoupling/MEDCouplingUMesh.cxx

index b0ee4f1c2a4aeb9426135812efa49fa48d375c01..cda93691cd00f54f8465281824de5f1782661004 100644 (file)
@@ -29,6 +29,7 @@
 #include "NormalizedUnstructuredMesh.hxx"
 
 #include <fstream>
+#include <sstream>
 #include <iomanip>
 #include <cstring>
 #include <limits>
@@ -1144,7 +1145,12 @@ void QuadraticPolygon::ComputeResidual(const QuadraticPolygon& pol1, const std::
   std::list<QuadraticPolygon *> retPolsUnderContruction;
   std::list<Edge *> edgesInPol2OnBoundaryL(edgesInPol2OnBoundary.begin(),edgesInPol2OnBoundary.end());
   std::map<QuadraticPolygon *, std::list<QuadraticPolygon *> > pol1ZipConsumed;
-  while(!pol1Zip.empty() || !edgesInPol2OnBoundaryL.empty())
+  std::size_t maxNbOfTurn=edgesInPol2OnBoundaryL.size(),nbOfTurn=0,iiMNT=0;
+  for(std::list<QuadraticPolygon *>::const_iterator itMNT=pol1Zip.begin();itMNT!=pol1Zip.end();itMNT++,iiMNT++)
+    nbOfTurn+=(*itMNT)->size();
+  maxNbOfTurn=maxNbOfTurn*nbOfTurn; maxNbOfTurn*=maxNbOfTurn;
+  nbOfTurn=0;
+  while(nbOfTurn<maxNbOfTurn && ((!pol1Zip.empty() || !edgesInPol2OnBoundaryL.empty())))
     {
       for(std::list<QuadraticPolygon *>::iterator it1=retPolsUnderContruction.begin();it1!=retPolsUnderContruction.end();)
         {
@@ -1206,6 +1212,13 @@ void QuadraticPolygon::ComputeResidual(const QuadraticPolygon& pol1, const std::
           retPolsUnderContruction.push_back(tmp);
           pol1Zip.erase(pol1Zip.begin());
         }
+      nbOfTurn++;
+    }
+  if(nbOfTurn==maxNbOfTurn)
+    {
+      std::ostringstream oss; oss << "Error during reconstruction of residual of cell ! It appears that either source or/and target mesh is/are not conform !";
+      oss << " Number of turns is = " << nbOfTurn << " !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
   for(std::list<QuadraticPolygon *>::iterator it1=retPolsUnderContruction.begin();it1!=retPolsUnderContruction.end();it1++)
     {
index 115f27386cfe5e88393551dddbb0388bef26b122..3e9083a64af94199192cc624b2d9503caa20ae00 100644 (file)
@@ -6785,7 +6785,15 @@ void MEDCouplingUMesh::BuildIntersecting2DCellsFromEdges(double eps, const MEDCo
         }
       if(!edges1.empty())
         {
-          INTERP_KERNEL::QuadraticPolygon::ComputeResidual(pol1,edges1,edgesBoundary2,mapp,offset3,i,addCoordsQuadratic,cr,crI,cNb1,cNb2);
+          try
+            {
+              INTERP_KERNEL::QuadraticPolygon::ComputeResidual(pol1,edges1,edgesBoundary2,mapp,offset3,i,addCoordsQuadratic,cr,crI,cNb1,cNb2);
+            }
+          catch(INTERP_KERNEL::Exception& e)
+            {
+              std::ostringstream oss; oss << "Error when computing residual of cell #" << i << " in source/m1 mesh ! Maybe the neighbours of this cell in mesh are not well connected !\n" << "The deep reason is the following : " << e.what();
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
         }
       for(std::map<int,INTERP_KERNEL::Node *>::const_iterator it=mappRev.begin();it!=mappRev.end();it++)
         (*it).second->decrRef();