]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Adding 4 new tests for the Intersect2DWith1DMesh function.
authorabn <adrien.bruneton@cea.fr>
Thu, 11 Dec 2014 13:24:37 +0000 (14:24 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 18 Dec 2014 13:52:13 +0000 (14:52 +0100)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index f9c16dcbfd8fa186c86f9b10e6dfb830d2b122ca..9f0b7abcd3edd5fd42f42c47f5a2349086d70aec 100644 (file)
@@ -9372,8 +9372,8 @@ MEDCouplingUMesh *BuildMesh2DCutFrom(double eps, int cellIdInMesh2D, const MEDCo
   const int *cdescPtr(mesh2DDesc->getNodalConnectivity()->begin()),*cidescPtr(mesh2DDesc->getNodalConnectivityIndex()->begin());
   //
   std::vector<int> allEdges;
-  std::vector< MEDCouplingAutoRefCountObjectPtr<INTERP_KERNEL::Edge> > allEdgesPtr;
-  for(const int *it(descBg);it!=descEnd;it++)
+  std::vector< MEDCouplingAutoRefCountObjectPtr<INTERP_KERNEL::Edge> > allEdgesPtr; // for each sub edge in splitMesh2D the uncut Edge object of the original mesh2D
+  for(const int *it(descBg);it!=descEnd;it++) // for all edges in the descending connectivity of the 2D mesh in relative Fortran mode
     {
       int edgeId(std::abs(*it)-1);
       std::map< MEDCouplingAutoRefCountObjectPtr<INTERP_KERNEL::Node>,int> m;
index 1178b5846fa33ef7b05759e185a1aae3355a548c..b1f76686af1234e666784df9e0b0b1d32580b933 100644 (file)
@@ -15667,24 +15667,24 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         pass
 
     def testSwig2Intersect2DMeshWith1DLine2(self):
-         """A basic test with colinearity between m1 and m2 and the last cell of m2 outside m1."""
-         i=MEDCouplingIMesh("mesh",2,[5,5],[0.,0.],[1.,1.])
-         m1=i.buildUnstructured()
-         m2=MEDCouplingUMesh("mesh",1) ; m2.setCoords(DataArrayDouble([0.5,2.,2.25,2.,2.5,2.,2.75,2.,3.,2.,4.,2.,5.,2.],7,2)) ; m2.allocateCells()
-         for i in xrange(6):
-             m2.insertNextCell(NORM_SEG2,[i,i+1])
-             pass
-         a,b,c,d=MEDCouplingUMesh.Intersect2DMeshWith1DLine(m1,m2,1e-12)
-         self.assertTrue(a.getNodalConnectivity().isEqual(DataArrayInt([4,1,0,5,6,4,2,1,6,7,4,3,2,7,8,4,4,3,8,9,4,16,15,20,21,4,17,16,21,22,4,18,17,22,23,4,19,18,23,24,5,6,5,10,25,11,5,7,6,11,12,5,8,7,12,26,27,28,13,5,9,8,13,14,5,11,25,10,15,16,5,12,11,16,17,5,13,28,27,26,12,17,18,5,14,13,18,19])))
-         self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,46,51,59,64,70,75,83,88])))
-         self.assertTrue(b.getNodalConnectivity().isEqual(DataArrayInt([1,25,11,1,11,12,1,12,26,1,26,27,1,27,28,1,28,13,1,13,14,1,14,31])))
-         self.assertTrue(b.getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24])))
-         self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
-         self.assertTrue(a.getCoords()[:25].isEqual(m1.getCoords(),1e-12))
-         self.assertTrue(a.getCoords()[25:].isEqualWithoutConsideringStr(m2.getCoords(),1e-12))
-         self.assertTrue(c.isEqual(DataArrayInt([0,1,2,3,12,13,14,15,4,5,6,7,8,9,10,11])))
-         self.assertTrue(d.isEqual(DataArrayInt([(12,8),(13,9),(14,10),(14,10),(14,10),(14,10),(15,11),(-1,-1)])))
-         pass
+        """A basic test with colinearity between m1 and m2 and the last cell of m2 outside m1."""
+        i=MEDCouplingIMesh("mesh",2,[5,5],[0.,0.],[1.,1.])
+        m1=i.buildUnstructured()
+        m2=MEDCouplingUMesh("mesh",1) ; m2.setCoords(DataArrayDouble([0.5,2.,2.25,2.,2.5,2.,2.75,2.,3.,2.,4.,2.,5.,2.],7,2)) ; m2.allocateCells()
+        for i in xrange(6):
+            m2.insertNextCell(NORM_SEG2,[i,i+1])
+            pass
+        a,b,c,d=MEDCouplingUMesh.Intersect2DMeshWith1DLine(m1,m2,1e-12)
+        self.assertTrue(a.getNodalConnectivity().isEqual(DataArrayInt([4,1,0,5,6,4,2,1,6,7,4,3,2,7,8,4,4,3,8,9,4,16,15,20,21,4,17,16,21,22,4,18,17,22,23,4,19,18,23,24,5,6,5,10,25,11,5,7,6,11,12,5,8,7,12,26,27,28,13,5,9,8,13,14,5,11,25,10,15,16,5,12,11,16,17,5,13,28,27,26,12,17,18,5,14,13,18,19])))
+        self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,46,51,59,64,70,75,83,88])))
+        self.assertTrue(b.getNodalConnectivity().isEqual(DataArrayInt([1,25,11,1,11,12,1,12,26,1,26,27,1,27,28,1,28,13,1,13,14,1,14,31])))
+        self.assertTrue(b.getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24])))
+        self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
+        self.assertTrue(a.getCoords()[:25].isEqual(m1.getCoords(),1e-12))
+        self.assertTrue(a.getCoords()[25:].isEqualWithoutConsideringStr(m2.getCoords(),1e-12))
+        self.assertTrue(c.isEqual(DataArrayInt([0,1,2,3,12,13,14,15,4,5,6,7,8,9,10,11])))
+        self.assertTrue(d.isEqual(DataArrayInt([(12,8),(13,9),(14,10),(14,10),(14,10),(14,10),(15,11),(-1,-1)])))
+        pass
 
     def testSwig2Intersect2DMeshWith1DLine3(self):
         """m2 fully included in cell #12. of m1"""
@@ -15882,6 +15882,173 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertEqual([0, 0], c.getValues())
         self.assertEqual([-1, -1, 0, 1, -1, -1], d.getValues())
 
+    def testSwig2Intersect2DMeshWith1DLine11(self):
+        """ Quad line re-entering a square cell """
+        eps = 1.0e-8
+        m = MEDCouplingUMesh("box", 2)
+        m.setCoords(DataArrayDouble([-1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0],4,2))
+        c, cI = [NORM_POLYGON, 0, 1, 2, 3], [0, 5]
+        m.setConnectivity(DataArrayInt(c), DataArrayInt(cI))
+        m.checkCoherency()
+        coords2 = [0.0, 1.3, -1.3, 0.0, -0.6, 0.6, 0.0, -1.3, -0.5, -0.5]
+        connec2, cI2 = [NORM_SEG3, 0, 1, 2, NORM_SEG3, 1, 3, 4], [0,4,8]
+        m_line = MEDCouplingUMesh.New("seg", 1)  
+        m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+        m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
+        
+#         m_line2 = m_line.deepCpy()
+#         m2 = m.deepCpy()
+#         m_line2.tessellate2DCurve(0.1)
+#         m2.tessellate2D(0.1)
+#         m_line2.writeVTK("/tmp/m1d_11.vtu")
+#         m2.writeVTK("/tmp/m2d_11.vtu")
+        
+        a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
+#         a.mergeNodes(1.0e-8)
+#         a.tessellate2D(0.1)
+#         b.tessellate2DCurve(0.1)
+#         a.writeVTK("/tmp/m2d_fine_11.vtu")
+#         b.writeVTK("/tmp/m1d_fine_11.vtu")
+        
+        self.assertEqual([], a.getNodalConnectivity().getValues())
+        self.assertEqual([], a.getNodalConnectivityIndex().getValues())
+        self.assertEqual([], b.getNodalConnectivity().getValues())
+        self.assertEqual([], b.getNodalConnectivityIndex().getValues())
+        self.assertTrue(a.getCoords()[:8].isEqual(m.getCoords(),1e-12))
+        self.assertTrue(a.getCoords()[8:10].isEqual(m_line.getCoords(),1e-12))
+        coo_tgt = DataArrayDouble([])
+        self.assertTrue(a.getCoords().isEqualWithoutConsideringStr(coo_tgt, 1.0e-12))
+        self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
+        self.assertEqual([], c.getValues())
+        self.assertEqual([], d.getValues())
+        pass
+
+    def testSwig2Intersect2DMeshWith1DLine12(self):
+        """ Two squares one in the other intersected by an horizontal line """
+        eps = 1.0e-8
+        m = MEDCouplingUMesh("boxbox", 2)
+        m.setCoords(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],8,2))
+        c = [NORM_POLYGON, 4, 5, 6, 7, NORM_POLYGON, 0, 1, 5, 4, NORM_POLYGON, 1, 2, 3, 0, 4, 7, 6, 5]
+        cI = [0, 5, 10, 19]
+        m.setConnectivity(DataArrayInt(c), DataArrayInt(cI))
+        m.checkCoherency()
+        coords2 = [-1.0, 0.25, 1.0, 0.25]
+        connec2, cI2 = [NORM_SEG2, 0, 1], [0,3]
+        m_line = MEDCouplingUMesh.New("seg", 1)  
+        m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+        m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
+#         m_line.writeVTK("/tmp/m1d_12.vtu")
+#         m.writeVTK("/tmp/m2d_12.vtu")
+        
+        a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
+#         a.writeVTK("/tmp/m2d_fine_12.vtu")
+#         b.writeVTK("/tmp/m1d_fine_12.vtu")
+        
+        self.assertEqual([], a.getNodalConnectivity().getValues())
+        self.assertEqual([], a.getNodalConnectivityIndex().getValues())
+        self.assertEqual([], b.getNodalConnectivity().getValues())
+        self.assertEqual([], b.getNodalConnectivityIndex().getValues())
+        self.assertTrue(a.getCoords()[:8].isEqual(m.getCoords(),1e-12))
+        self.assertTrue(a.getCoords()[8:10].isEqual(m_line.getCoords(),1e-12))
+        coo_tgt = DataArrayDouble([])
+        self.assertTrue(a.getCoords().isEqualWithoutConsideringStr(coo_tgt, 1.0e-12))
+        self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
+        self.assertEqual([], c.getValues())
+        self.assertEqual([], d.getValues())
+        pass
+
+    def testSwig2Intersect2DMeshWith1DLine13(self):
+        """ A square (side length) in a circle intersected by a simple horizontal line """
+        import math
+        eps = 1.0e-8
+        m = MEDCouplingUMesh("boxcircle", 2)
+        sq2 = math.sqrt(2.0)
+        soth = (sq2+1.0)/2.0
+        coo = [2.0, 0.0, sq2, sq2, 0.0, 2.0, -sq2, sq2, -2.0, 0.0, -sq2, -sq2, 0.0, -2.0, sq2, -sq2, -1.0, -1.0, -1.0, 1.0, 1.0, 
+         1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, -1.0, -soth, soth, soth,soth]
+        coo = DataArrayDouble(coo); coo.rearrange(2) 
+        m.setCoords(coo)
+        c = [NORM_QPOLYG, 8, 9, 10, 11, 12, 13, 14, 15, NORM_QPOLYG, 3, 1, 10, 9, 2, 17, 13, 16, NORM_QPOLYG, 1, 7, 5, 3, 9, 8, 11, 10, 0, 6, 4, 16, 12, 15, 14, 17]
+        cI = [0, 9, 18, 35]
+        m.setConnectivity(DataArrayInt(c), DataArrayInt(cI))
+        m.checkCoherency()
+        coords2 = [-2.0, 1.0, 2.0, 1.0]
+        connec2, cI2 = [NORM_SEG2, 0, 1], [0,3]
+        m_line = MEDCouplingUMesh.New("seg", 1)  
+        m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+        m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
+#         m_line2 = m_line.deepCpy()
+#         m2 = m.deepCpy()
+#         m_line2.tessellate2DCurve(0.1)
+#         m2.tessellate2D(0.05)
+#         m_line2.writeVTK("/tmp/m1d_13.vtu")
+#         m2.writeVTK("/tmp/m2d_13.vtu")
+        
+        a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
+#         a.mergeNodes(1.0e-8)
+#         a.tessellate2D(0.1)
+#         b.tessellate2DCurve(0.1)
+#         a.writeVTK("/tmp/m2d_fine_13.vtu")
+#         b.writeVTK("/tmp/m1d_fine_13.vtu")
+        
+        self.assertEqual([], a.getNodalConnectivity().getValues())
+        self.assertEqual([], a.getNodalConnectivityIndex().getValues())
+        self.assertEqual([], b.getNodalConnectivity().getValues())
+        self.assertEqual([], b.getNodalConnectivityIndex().getValues())
+        self.assertTrue(a.getCoords()[:8].isEqual(m.getCoords(),1e-12))
+        self.assertTrue(a.getCoords()[8:10].isEqual(m_line.getCoords(),1e-12))
+        coo_tgt = DataArrayDouble([])
+        self.assertTrue(a.getCoords().isEqualWithoutConsideringStr(coo_tgt, 1.0e-12))
+        self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
+        self.assertEqual([], c.getValues())
+        self.assertEqual([], d.getValues())
+        pass
+
+    def testSwig2Intersect2DMeshWith1DLine14(self):
+        """ A circle in a circle intersected by a simple horizontal line, not tangent to the circles """
+        eps = 1.0e-8
+        m = MEDCouplingUMesh("boxcircle", 2)
+        coo = [2.0, 0.0, 1.4142135623730951, 1.414213562373095, 0.0, 2.0, -1.414213562373095, 1.4142135623730951, -2.0, 0.0, -1.4142135623730954, -1.414213562373095, 0.0, -2.0, 
+               1.4142135623730947, -1.4142135623730954, 1.0, 0.0, 0.7071067811865476, 0.7071067811865475, 0.0, 1.0, -0.7071067811865475, 0.7071067811865476, -1.0, 0.0, -0.7071067811865477, -0.7071067811865475, 
+               0.0, -1.0, 0.7071067811865474, -0.7071067811865477, 1.060660171779821, -1.0606601717798214, -1.0606601717798214, -1.0606601717798212]
+        coo = DataArrayDouble(coo); coo.rearrange(2) 
+        m.setCoords(coo)
+        c = [NORM_QPOLYG, 15, 13, 11, 9, 14, 12, 10, 8, NORM_QPOLYG, 7, 5, 13, 15, 6, 17, 14, 16, NORM_QPOLYG, 5, 3, 1, 7, 15, 9, 11, 13, 4, 2, 0, 16, 8, 10, 12, 17]
+        cI = [0, 9, 18, 35] 
+        m.setConnectivity(DataArrayInt(c), DataArrayInt(cI))
+        m.checkCoherency()
+        coords2 = [-2.0, 0.0, 2.0, 0.0]
+        connec2, cI2 = [NORM_SEG2, 0, 1], [0,3]
+        m_line = MEDCouplingUMesh.New("seg", 1)  
+        m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2))
+        m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2))
+#         m_line2 = m_line.deepCpy()
+#         m2 = m.deepCpy()
+#         m_line2.tessellate2DCurve(0.1)
+#         m2.tessellate2D(0.1)
+#         m_line2.writeVTK("/tmp/m1d_14.vtu")
+#         m2.writeVTK("/tmp/m2d_14.vtu")
+        
+        a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps)
+#         a.mergeNodes(1.0e-8)
+#         a.tessellate2D(0.1)
+#         b.tessellate2DCurve(0.1)
+#         a.writeVTK("/tmp/m2d_fine_14.vtu")
+#         b.writeVTK("/tmp/m1d_fine_14.vtu")
+        
+        self.assertEqual([], a.getNodalConnectivity().getValues())
+        self.assertEqual([], a.getNodalConnectivityIndex().getValues())
+        self.assertEqual([], b.getNodalConnectivity().getValues())
+        self.assertEqual([], b.getNodalConnectivityIndex().getValues())
+        self.assertTrue(a.getCoords()[:8].isEqual(m.getCoords(),1e-12))
+        self.assertTrue(a.getCoords()[8:10].isEqual(m_line.getCoords(),1e-12))
+        coo_tgt = DataArrayDouble([])
+        self.assertTrue(a.getCoords().isEqualWithoutConsideringStr(coo_tgt, 1.0e-12))
+        self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer())
+        self.assertEqual([], c.getValues())
+        self.assertEqual([], d.getValues())
+        pass
+
     def testOrderConsecutiveCells1D1(self):
         """A line in several unconnected pieces:"""
         m2 = MEDCouplingUMesh.New("bla", 1)