+ def testSwig2Intersect2DMeshWith1DLine17(self):
+ """ Single colinear intersection - a deltaShiftIndex() was improperly tested. """
+ eps = 1.0e-12
+ mesh = MEDCouplingUMesh('dummy_layer', 2)
+ coo = DataArrayDouble([(-0.5,-0.5),(-0.5,0.5),(0.5,0.5),(0.5,-0.5),(-0.25,-0.25),(-0.25,0.25),(0.25,0.25),(0.25,-0.25)])
+ mesh.setCoords(coo)
+ c = DataArrayInt([5, 4, 5, 6, 7, 5, 0, 1, 5, 4, 5, 1, 2, 3, 0, 4, 7, 6, 5])
+ cI = DataArrayInt([0, 5, 10, 19])
+ mesh.setConnectivity(c, cI)
+ m_line = MEDCouplingUMesh('segment', 1)
+ coo = DataArrayDouble([(-0.5,0.5),(-0.25,0.25)])
+ m_line.setCoords(coo)
+ c = DataArrayInt([1, 0, 1])
+ cI = DataArrayInt([0, 3])
+ m_line.setConnectivity(c, cI)
+ a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(mesh, m_line, eps)
+ self.assertEqual(mesh.getNodalConnectivity().getValues(),a.getNodalConnectivity().getValues())
+ self.assertEqual(mesh.getNodalConnectivityIndex().getValues(),a.getNodalConnectivityIndex().getValues())
+ self.assertEqual([1,1,5],b.getNodalConnectivity().getValues())
+ self.assertEqual(m_line.getNodalConnectivityIndex().getValues(),b.getNodalConnectivityIndex().getValues())
+ self.assertTrue([0,1,2], c.getValues())
+ self.assertEqual([2,1], d.getValues())
+
+ def testSwig2Intersect2DMeshWith1DLine18(self):
+ """ Rare case: a *closed* line used as a tool, with the closing point inside a 2D cell ... """
+ eps = 1.0e-8
+ m_2d = MEDCouplingUMesh('Plan_IJ_IK_JK', 2)
+ coo = DataArrayDouble([(-2.55102,0.510204),(-1.53061,0.510204),(-0.510204,0.510204),(0.510204,0.510204),(1.53061,0.510204),(2.55102,0.510204),
+ (-2.55102,1.53061),(-1.53061,1.53061),(-0.510204,1.53061),(0.510204,1.53061),(1.53061,1.53061),(2.55102,1.53061),(-2.55102,2.55102),
+ (-1.53061,2.55102),(-0.510204,2.55102),(0.510204,2.55102),(1.53061,2.55102),(2.55102,2.55102)])
+ m_2d.setCoords(coo)
+ c = DataArrayInt([4, 1, 0, 6, 7, 4, 2, 1, 7, 8, 4, 3, 2, 8, 9, 4, 4, 3, 9, 10, 4, 5, 4, 10, 11, 4, 7, 6, 12, 13, 4, 8, 7, 13, 14, 4,
+ 9, 8, 14, 15, 4, 10, 9, 15, 16, 4, 11, 10, 16, 17])
+ cI = DataArrayInt([0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50])
+ m_2d.setConnectivity(c, cI)
+ m_2d.checkConsistency()
+
+ m_1d = MEDCouplingUMesh('Slice3DSurf', 1)
+ coo = DataArrayDouble([(0.578179,2.05076),(-1.06484,1.77411),(1.16576,1.86369),(1.52253,1.65688),(-1.69839,1.14578),(1.7736,0.942747)])
+ m_1d.setCoords(coo)
+ c = DataArrayInt([1, 0, 1, 1, 1, 4, 1, 4, 5, 1, 5, 3, 1, 3, 2, 1, 2, 0])
+ cI = DataArrayInt([0, 3, 6, 9, 12, 15, 18])
+ m_1d.setConnectivity(c, cI)
+ m_1d.checkConsistency()
+
+ res2D, res1D, m1, m2 = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m_2d, m_1d, eps)
+ res1D.writeVTK("/tmp/res1d.vtu")
+ self.assertEqual(20, res2D.getNumberOfCells())
+ self.assertEqual(res2D.getNodalConnectivity().getValues(),[4, 7, 6, 12, 13, 5, 10, 9, 32, 18, 20, 21, 33, 5, 15, 16, 33, 21, 20, 18, 32, 5, 9, 8, 31, 32, 5, 14, 15, 32, 31, 5, 8, 26, 19, 31, 5, 7, 13, 14, 31, 19, 26, 5, 24, 26, 8, 27,
+ 25, 5, 2, 1, 25, 27, 5, 7, 26, 24, 5, 25, 22, 24, 5, 1, 0, 6, 7, 24, 22, 25, 5, 8, 9, 28, 27, 5, 3, 2, 27, 28, 5, 9, 10, 29, 28, 5, 4, 3, 28, 29, 5, 10, 30, 23, 29, 5, 11, 5, 4, 29, 23, 30, 5, 10, 33, 30, 5, 16, 17, 11, 30, 33])
+ self.assertEqual(res2D.getNodalConnectivityIndex().getValues(),[0, 5, 13, 21, 26, 31, 36, 43, 49, 54, 58, 62, 70, 75, 80, 85, 90, 95, 102, 106, 112])
+ self.assertEqual(res1D.getNodalConnectivity().getValues(),[1, 18, 32, 1, 32, 31, 1, 31, 19, 1, 19, 26, 1, 26, 24, 1, 24, 22, 1, 22, 25, 1, 25, 27, 1, 27, 28, 1, 28, 29, 1, 29, 23, 1, 23, 30, 1, 30, 33, 1, 33, 21, 1, 21, 20, 1, 20, 18])
+ self.assertEqual(res1D.getNodalConnectivityIndex().getValues(),[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48])
+ self.assertEqual(m1.getValues(), [5, 8, 8, 7, 7, 6, 6, 1, 1, 1, 0, 0, 2, 2, 3, 3, 4, 4, 9, 9])
+ self.assertEqual(m2.getValues(), [1, 2, 3, 4, 5, 6, 5, 6, 7, 9, 10, 11, 10, 11, 7, 8, 12, 13, 14, 15, 16, 17, 16, 17, 18, 19, 1, 2, 1, 2, 1, 2])
+
+ def testSwig2Intersect2DMeshWith1DLine19(self):
+ """ Intersection arc of circle / segment was not properly detecting tangent cases """
+ eps=1.0e-5 # was working at 1.0e-8, but should also really work with 1.0e-5
+ mesh = MEDCouplingUMesh('layer_1', 2)
+ coo = DataArrayDouble([(55.4,3.7239),(61.4,7.188),(61.4,13.943),(49.55,7.1014),
+ (61.4,10.5655),(58.4,5.45595),(52.475,5.41265),(55.475,10.5222),
+ (56.9,9.34),(56.3343,7.97431),(56.9,7.74),(57.4657,7.97431),(59.4328,7.58116),
+ (55.8672,5.84911), (0.,0.)])
+ mesh.setCoords(coo)
+ c = DataArrayInt([32, 0, 3, 2, 1, 11, 9, 6, 7, 4, 12, 8, 13])
+ cI = DataArrayInt([0, 13])
+ mesh.setConnectivity(c, cI)
+ tool = MEDCouplingUMesh('segment', 1)
+ coo = DataArrayDouble([(-166.611,-119.951),(269.611,131.902)])
+ tool.setCoords(coo)
+ c = DataArrayInt([1, 0, 1])
+ cI = DataArrayInt([0, 3])
+ tool.setConnectivity(c, cI)
+
+ res2D, res1D, m1, m2 = MEDCouplingUMesh.Intersect2DMeshWith1DLine(mesh, tool, eps)
+
+ self.assertEqual(res2D.getNodalConnectivity().getValues(),[32, 19, 17, 3, 2, 18, 20, 33, 34, 35, 36, 37, 38, 32, 1, 11, 20, 18, 39, 40, 41, 42, 32, 9, 0, 17, 19, 29, 30, 31, 32])
+ self.assertEqual(res2D.getNodalConnectivityIndex().getValues(),[0, 13, 22, 31])
+ self.assertEqual(res1D.getNodalConnectivity().getValues(),[1, 15, 17, 1, 17, 19, 1, 19, 20, 1, 20, 18, 1, 18, 16])
+ self.assertEqual(res1D.getNodalConnectivityIndex().getValues(),[0, 3, 6, 9, 12, 15])
+ self.assertEqual(m1.getValues(), [0, 0, 0])
+ self.assertEqual(m2.getValues(), [-1, -1, 0, 2, -1, -1, 0, 1, -1, -1])
+
+ def testSwig2Intersect2DMeshWith1DLine20(self):
+ """ A line intersecting a cell more than 3 times was triggering an internal error. """
+ mesh = MEDCouplingUMesh('merge', 2)
+ coo = DataArrayDouble([(0,0),(0,9),(3,9),(3,0),(0,1),(2,1),(0,2),(2,2),(3,3),(1,3),(3,4),(1,4),(0,5),(2,5),(0,6),(2,6),(3,7),(1,7),(3,8),(1,8)])
+ mesh.setCoords(coo)
+ c = DataArrayInt([5, 3, 0, 4, 5, 7, 6, 12, 13, 15, 14, 1, 2, 18, 19, 17, 16, 10, 11, 9, 8]) # offset 20
+ cI = DataArrayInt([0, 21])
+ mesh.setConnectivity(c, cI)
+
+ tool = MEDCouplingUMesh('tool', 1)
+ coo = DataArrayDouble([(1.5, 9.5), (1.5, 1.5)]) # line crossing 4 times
+ tool.setCoords(coo)
+ c = DataArrayInt([NORM_SEG2,0,1])
+ cI = DataArrayInt([0, 3])
+ tool.setConnectivity(c, cI)
+
+ eps=1.0e-4 # not the pb here
+ res2D, res1D, resToSelf, mapLeftRight = MEDCouplingUMesh.Intersect2DMeshWith1DLine(mesh, tool, eps)
+ self.assertEqual(res1D.getNodalConnectivity().getValues(),[1, 20, 25, 1, 25, 26, 1, 26, 27, 1, 27, 24, 1, 24, 23, 1, 23, 28, 1, 28, 29, 1, 29, 22, 1, 22, 21])
+ self.assertEqual(res1D.getNodalConnectivityIndex().getValues(),[0, 3, 6, 9, 12, 15, 18, 21, 24, 27])
+ self.assertEqual(res2D.getNodalConnectivity().getValues(),[5, 2, 18, 26, 25, 5, 13, 15, 24, 27, 16, 10, 28, 23, 5, 8, 3, 0, 4, 5, 7, 22, 29, 5, 6, 12, 23, 28, 11, 9, 29, 22, 5, 14, 1, 25, 26, 19, 17, 27, 24])
+ self.assertEqual(res2D.getNodalConnectivityIndex().getValues(),[0, 5, 14, 23, 32, 41])
+
+ self.assertEqual(resToSelf.getValues(), [0, 0, 0, 0, 0])
+ self.assertEqual(mapLeftRight.getValues(), [-1, -1, 0, 4, -1, -1, 1, 4, -1, -1, 1, 3, -1, -1, 2, 3, -1, -1])
+ pass
+
+ def testSwig2Intersect2DMeshWith1DLine21(self):
+ """ A line intersecting a cell very close to one of its node (collinearity not detected) """
+ eps=1.0e-5 # was working at 1.0e-8, but should also really work with 1.0e-5
+ mesh = MEDCouplingUMesh('mesh', 2)
+ coo = DataArrayDouble([(110.65324,180.56968),(112.01128,182.78580),(113.36932,185.00192),(118.27200,181.90669),(118.27200,178.79852),(118.27200,175.67380)])
+ mesh.setCoords(coo)
+ c = DataArrayInt([NORM_QUAD4, 0, 1, 4, 5, NORM_QUAD4, 1, 2, 3, 4])
+ cI = DataArrayInt([0, 5, 10])
+ mesh.setConnectivity(c, cI)
+
+ tool = MEDCouplingUMesh('tool', 1)
+ coo = DataArrayDouble([(0.0, 182.78400), (182.78400, 182.78400)])
+ tool.setCoords(coo)
+ c = DataArrayInt([NORM_SEG2,0,1])
+ cI = DataArrayInt([0, 3])
+ tool.setConnectivity(c, cI)
+
+ res2D, res1D, resToSelf, mapLeftRight = MEDCouplingUMesh.Intersect2DMeshWith1DLine(mesh, tool, eps)
+ self.assertEqual(res1D.getNodalConnectivity().getValues(), [1, 6, 1, 1, 1, 8, 1, 8, 9, 1, 9, 7])
+ self.assertEqual(res1D.getNodalConnectivityIndex().getValues(),[0, 3, 6, 9, 12])
+ self.assertEqual(res2D.getNodalConnectivity().getValues(), [5, 0, 1, 8, 4, 5, 5, 1, 2, 9, 8, 5, 3, 4, 8, 9])
+ self.assertEqual(res2D.getNodalConnectivityIndex().getValues(),[0, 6, 11, 16])
+
+ self.assertEqual(resToSelf.getValues(), [0, 1, 1])
+ self.assertEqual(mapLeftRight.getValues(), [-1, -1, 1, 0, 1, 2, -1, -1])
+
+ def testSwig2Intersect2DMeshWith1DLine22(self):
+ """ Simple check that an execption is thrown if 1D mesh is not a single line (one point
+ connected to more than 2 edges. """
+ m2 = MEDCouplingCMesh.New()
+ da = DataArrayDouble(3)
+ da.iota()
+ m2.setCoords(da, da)
+ m2 = m2.buildUnstructured()
+ m1,_,_,_,_ = m2.buildDescendingConnectivity() # m1 will have it central point connected to 4 edges
+ # MEDCouplingUMesh.Intersect2DMeshWith1DLine(m2, m1, 1.0e-8)
+ self.assertRaises(InterpKernelException, MEDCouplingUMesh.Intersect2DMeshWith1DLine, m2, m1, 1.0e-8)
+