From b6f87cf1cfd1127778841d940fe1dc50f8af2304 Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 20 Sep 2013 07:50:43 +0000 Subject: [PATCH] Tricky bug fix in IntersectMeshes. --- src/MEDCoupling/MEDCouplingUMesh.cxx | 10 ++++++++++ src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index bd2f9b5dc..c04843cf7 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8372,6 +8372,16 @@ void MEDCouplingUMesh::IntersectDescending2DMeshes(const MEDCouplingUMesh *m1, c INTERP_KERNEL::QuadraticPolygon *pol2=MEDCouplingUMeshBuildQPFromMesh(m2Desc,candidates2,map2); candidates1[0]=i; INTERP_KERNEL::QuadraticPolygon *pol1=MEDCouplingUMeshBuildQPFromMesh(m1Desc,candidates1,map1); + // this following part is to avoid that a some remove nodes (for example due to a merge between pol1 and pol2) can be replaced by a newlt created one + // This trick garanties that Node * are discriminant + std::set nodes; + pol1->getAllNodes(nodes); pol2->getAllNodes(nodes); + std::size_t szz(nodes.size()); + std::vector< MEDCouplingAutoRefCountObjectPtr > nodesSafe(szz); + std::set::const_iterator itt(nodes.begin()); + for(std::size_t iii=0;iiiincrRef(); nodesSafe[iii]=*itt; } + // end of protection pol1->splitAbs(*pol2,map1,map2,offset1,offset2,candidates2,intersectEdge1[i],i,colinear2,subDiv2,addCoo); delete pol2; delete pol1; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 9ad66f093..43d1357aa 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -13869,6 +13869,26 @@ class MEDCouplingBasicsTest(unittest.TestCase): exp=DataArrayDouble([18.5,118.5,17.5,117.5,16.5,116.5,14.5,114.5,13.5,113.5,12.5,112.5],6,2) ; exp.setInfoOnComponents(["aa [km]","bbb [kJ]"]) self.assertTrue(f2.getArray().isEqual(exp,1e-13)) pass + + def testSwig2NonRegressionBugIntersectMeshes1(self): + src=MEDCouplingUMesh("src",2) + src.setCoords(DataArrayDouble([-2.5,-3,-2.5,3,2.5,3],3,2)) + src.allocateCells() + src.insertNextCell(NORM_TRI3,[0,1,2]) + # + trg=MEDCouplingUMesh("trg",2) + trg.setCoords(DataArrayDouble([-2.5,-3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095],10,2)) + trg.allocateCells() + trg.insertNextCell(NORM_QPOLYG,[2,1,0,5,3,7,8,6,4,9]) + # + a,b,c=MEDCouplingUMesh.Intersect2DMeshes(src,trg,1.0e-8) + a.mergeNodes(1e-8) + self.assertTrue(a.getCoords().isEqual(DataArrayDouble([-2.5,-3.,-2.5,3.,2.5,3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095,-1.2803687993289596,-1.5364425591947515,-1.8901843996644798,-2.2682212795973755,-1.81117884244736,-0.8483107924994473,-2.5,1.5,0.,3.,0.6098156003355202,0.7317787204026243],18,2),1e-12)) + self.assertTrue(a.getNodalConnectivity().isEqual(DataArrayInt([32,12,0,7,5,13,8,6,14,32,7,1,2,12,5,15,16,17,14,6]))) + self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,20]))) + self.assertTrue(b.isEqual(DataArrayInt([0,0]))) + self.assertTrue(c.isEqual(DataArrayInt([0,-1]))) + pass def setUp(self): pass -- 2.39.2