Salome HOME
DataArrayDouble::getIdsNotInRange, DataArrayInt::getIdsNotInRange
[modules/med.git] / src / MEDCoupling_Swig / MEDCouplingBasicsTest.py
index b560dbafbae48c50c42e7723e27b7cd74f12a247..b820e91921deaa34f0354fcbeb9a23f5a3c98abf 100644 (file)
@@ -8443,6 +8443,24 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertEqual(expected4,m12.getNodalConnectivityIndex().getValues());
         pass
 
+    def testUMeshTessellate2DCurve1(self):
+        # A quarter of circle:
+        mcoords = [0.4,0.0,   0.0,-0.4,   0.283,-0.283]
+        mconnec = [0,1,2]
+
+        m1 = MEDCouplingUMesh.New()
+        m1.setMeshDimension(1)
+        m1.allocateCells(1)
+        m1.insertNextCell(NORM_SEG3, mconnec)
+
+        myCoords = DataArrayDouble.New(mcoords, 3, 2)
+        m1.setCoords(myCoords)
+        
+        m2 = m1.deepCpy()
+        m2.tessellate2DCurve(0.1)
+        # If the following raises, the test will fail automatically:
+        m2.checkCoherency1(0.0) # eps param not used
+
     def testIntersect2DMeshesTmp4(self):
         m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
         m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
@@ -13850,6 +13868,82 @@ 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 testSwig2MeshOrientCorrectly2DCells1(self):
+        m=MEDCouplingUMesh("mesh",2)
+        coo=DataArrayDouble([1.,0.,0.5,-0.1,0.,1.,0.,0.,0.07,0.5,0.59,0.5],6,2)
+        m.setCoords(coo)
+        m.allocateCells()
+        m.insertNextCell(NORM_TRI6,[3,0,2,1,5,4])
+        m.insertNextCell(NORM_QPOLYG,[3,0,2,1,5,4])
+        self.assertTrue(DataArrayDouble([-0.58093333350930543,-0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
+        m.changeSpaceDimension(3)
+        m.orientCorrectly2DCells([0.,0.,-1.],False)
+        #
+        m.checkCoherency()
+        self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([6,3,2,0,4,5,1, 32,3,2,0,4,5,1])))
+        self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,7,14])))
+        m.changeSpaceDimension(2)
+        self.assertTrue(DataArrayDouble([0.58093333350930543,0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
+        pass
+
+    def testSwig2Hexa8HavingFacesWarped1(self):
+        """ This test is bases on a "error" of interpolation detected. After investigation cell #3 of src is warped that leads to the fact that when trg is 
+        intersected with src the sum of intersection volume is greater than the volume of the trg cell.
+        A test that can be done is to split the cell #3 of src into tetrohedrons and by summing all the volumes it does not fit the volume computed of cell#3 unsplitted (expect for
+        GENERAL_24).
+        """
+        srcCoo=DataArrayDouble([0.15694071546650565,0.09383333333333337,6.920842121738133,0.15774332475430292,0.185486666666667,6.920682472824616,0.1585459340420992,0.27713999999999994,6.9205228239111,0.07427195882345167,0.05782666666666668,6.937285959830335,0.06343673343819695,0.11347333333333297,6.939441220162809,0.05260150805294228,0.16911999999999996,6.941596480495282,0.014076262238703396,0.04800666666666667,6.949259628344076,0.014076262238703396,0.07092000000000007,6.949259628344076,0.15407499632681992,0.09383333333333338,6.897607484780063,0.15489234394181514,0.18548666666666702,6.897567331066572,0.15570969155680933,0.27714,6.897527177353081,0.06988819198237989,0.05782666666666669,6.901743317269663,0.05885399917995321,0.11347333333333298,6.9022853924017955,0.047819806377526586,0.16912,6.902827467533927,0.0085871208577874,0.048006666666666684,6.9047548457815076,0.0085871208577874,0.07092000000000008,6.9047548457815076,0.153883333333333,0.09383333333333338,6.820902,0.154701666666667,0.18548666666666702,6.820902,0.15551999999999996,0.27714,6.820902,0.06959499999999999,0.05782666666666669,6.820902,0.058547499999999975,0.11347333333333298,6.820902,0.04749999999999999,0.16912,6.820902],22,3)
+        src=MEDCouplingUMesh("TBmesh3D",3) ; src.setCoords(srcCoo)
+        src.allocateCells()
+        src.insertNextCell(NORM_HEXA8,[0,1,4,3,8,9,12,11])
+        src.insertNextCell(NORM_HEXA8,[1,2,5,4,9,10,13,12])
+        src.insertNextCell(NORM_HEXA8,[4,5,7,6,12,13,15,14])
+        src.insertNextCell(NORM_HEXA8,[8,9,12,11,16,17,20,19])
+        src.insertNextCell(NORM_HEXA8,[9,10,13,12,17,18,21,20])
+        src.checkCoherency2()
+        # trg is useless here but I keep it in case of MEDCouplingRemapper were expected to do something about warped NORM_HEXA8
+        trgCoo=DataArrayDouble([0.0960891897852753,0.105088620541845,6.8598,0.0599574480546212,0.118434267436059,6.8598,0.113514510609589,0.14874473653263,6.8598,0.0831322609794463,0.167319109733883,6.8598,0.0960891897852753,0.105088620541845,6.92146666666667,0.0599574480546212,0.118434267436059,6.92146666666667,0.113514510609589,0.14874473653263,6.92146666666667,0.0831322609794463,0.167319109733883,6.92146666666667],8,3)
+        trg=MEDCouplingUMesh("MESH",3) ; trg.setCoords(trgCoo)
+        trg.allocateCells()
+        trg.insertNextCell(NORM_HEXA8,[0,1,3,2,4,5,7,6])
+        #
+        srcFace=src.buildDescendingConnectivity()[0]
+        conn=MEDCoupling1SGTUMesh(srcFace).getNodalConnectivity() ; conn.rearrange(4)
+        eqFaces=srcFace.computePlaneEquationOf3DFaces()
+        nodeIdInCell=3
+        e=(srcFace.getCoords()[conn[:,nodeIdInCell]]*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# e represent the error between the expected 'a*X+b*Y+c*Z+d' in eqFaces and 0. Closer e to 0. is closer the 4th point is to the plane built with the 3 first points
+        lambd=-e/(eqFaces[:,:3]**2).sumPerTuple()
+        pts=lambd*eqFaces[:,:-1]+srcFace.getCoords()[conn[:,nodeIdInCell]]#pts represent the projection of the last points of each NORM_QUAD4 to the plane defined by the 3 first points of the NORM_QUAD4 cell
+        shouldBeZero=(pts*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# this line is useless only to be sure that pts are on the plane.
+        check=(pts-srcFace.getCoords()[conn[:,nodeIdInCell]]).magnitude() # check contains the distance of the last point to its plane
+        idsToTest=check.getIdsNotInRange(0.,1e-10)
+        self.assertTrue(idsToTest.isEqual(DataArrayInt([17,18,19,20,22,23,24])))
+        idsToTest2=idsToTest.getIdsNotInRange(18,22)
+        self.assertTrue(idsToTest2.isEqual(DataArrayInt([0,4,5,6])))
+        idsToTest2.rearrange(2)
+        self.assertTrue(idsToTest2.sumPerTuple().isEqual(DataArrayInt([4,11])))
+        pass
 
     def setUp(self):
         pass