d=DataArrayInt([(50,49),(50,51),(51,52),(53,52),(53,54),(55,54),(55,56),(56,57),(58,57),(58,59),(60,59),(60,61),(61,62),(63,62),(63,64),(65,64),(65,66),(66,67)])
d.sortEachPairToMakeALinkedList()
self.assertTrue(d.isEqual(DataArrayInt([(49,50),(50,51),(51,52),(52,53),(53,54),(54,55),(55,56),(56,57),(57,58),(58,59),(59,60),(60,61),(61,62),(62,63),(63,64),(64,65),(65,66),(66,67)])))
+ d=DataArrayInt([(0,2),(1,2),(1,3)])
+ d.sortEachPairToMakeALinkedList()
+ self.assertTrue(d.isEqual(DataArrayInt([(0,2),(2,1),(1,3)])))
+ d=DataArrayInt([(0,2),(1,2),(3,1)])
+ d.sortEachPairToMakeALinkedList()
+ self.assertTrue(d.isEqual(DataArrayInt([(0,2),(2,1),(1,3)])))
+ d=DataArrayInt([(8,6062),(6062,472),(472,6292),(6292,960)])
+ d.sortEachPairToMakeALinkedList()
+ self.assertTrue(d.isEqual(DataArrayInt([(8,6062),(6062,472),(472,6292),(6292,960)])))
pass
def testSwig2DAIIsRange(self):
self.assertEqual(m2.getNodeGridStructure(),(3,4))
pass
+ def testRemoveIdsFromIndexedArrays1(self):
+ arr=DataArrayInt([101,102,103,201,202,203,204,301,501,502,503,504,505,601,602])
+ arrI=DataArrayInt([0,3,7,8,8,13,15])
+ # case where all elts in inputs are in
+ arr2=arr.deepCopy() ; arrI2=arrI.deepCopy()
+ self.assertTrue(MEDCouplingUMesh.RemoveIdsFromIndexedArrays([501,502],arr2,arrI2))
+ self.assertTrue(arr2.isEqual(DataArrayInt([101,102,103,201,202,203,204,301,503,504,505,601,602])))
+ self.assertTrue(arrI2.isEqual(DataArrayInt([0,3,7,8,8,11,13])))
+ # case where part of elts in inputs are in
+ arr2=arr.deepCopy() ; arrI2=arrI.deepCopy()
+ self.assertTrue(MEDCouplingUMesh.RemoveIdsFromIndexedArrays([504,507],arr2,arrI2))
+ self.assertTrue(arr2.isEqual(DataArrayInt([101,102,103,201,202,203,204,301,501,502,503,505,601,602])))
+ self.assertTrue(arrI2.isEqual(DataArrayInt([0,3,7,8,8,12,14])))
+ # case where no elts in inputs are in
+ arr2=arr.deepCopy() ; arrI2=arrI.deepCopy()
+ self.assertTrue(not MEDCouplingUMesh.RemoveIdsFromIndexedArrays([1,5,701],arr2,arrI2))
+ self.assertTrue(arr2.isEqual(arr))
+ self.assertTrue(arrI2.isEqual(arrI))
+ pass
+
+ def testFieldIntIsOnStage1(self):
+ """ My first test with field int."""
+ m=MEDCouplingCMesh()
+ m.setName("mesh")
+ arrX=DataArrayDouble([0,1,2,3])
+ m.setCoords(arrX,arrX)
+ f=MEDCouplingFieldInt(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayInt(8) ; arr.iota() ;f.setArray(arr)
+ self.assertRaises(InterpKernelException,f.checkConsistencyLight)
+ arr=DataArrayInt(9) ; arr.iota() ;f.setArray(arr)
+ f.checkConsistencyLight()
+ f.setTimeUnit("ms")
+ self.assertEqual(f.getTimeUnit(),"ms")
+ f.setTime(3.2,5,6)
+ a,b,c=f.getTime()
+ self.assertEqual(b,5)
+ self.assertEqual(c,6)
+ self.assertEqual(a,3.2,12)
+ pass
+
+ def testNoThrowOn1DGTU2UOnNullCells(self):
+ """ Non regression test : no throw when trying to convert 1DGTUMesh to UMesh on an empty mesh"""
+ m=MEDCoupling1DGTUMesh("",NORM_POLYGON) ; m.setCoords(DataArrayDouble([],0,3))
+ m.setNodalConnectivity(DataArrayInt([]),DataArrayInt([0]))
+ m=m.buildUnstructured()
+ pass
+
+ def testExplodeMeshIntoMicroEdges1(self):
+ """ test for new functionality MEDCouplingUMesh.explodeMeshIntoMicroEdges"""
+ m=MEDCouplingUMesh("mesh",2)
+ coo=DataArrayDouble([2,0,10,0,12,0,0,3,4,5,10,5,12,7,3,2.5,7,2.5,6,0,10,2.5,11,2.5,11,0,7,5],14,2)
+ m.setCoords(coo)
+ m.allocateCells()
+ # here a mix of quadratic, linear cells. Non conform but conform considering micro edges
+ m.insertNextCell(NORM_TRI6,[0,4,1,7,8,9])
+ m.insertNextCell(NORM_TRI6,[1,5,2,10,11,12])
+ m.insertNextCell(NORM_TRI6,[5,1,4,10,8,13])
+ m.insertNextCell(NORM_TRI3,[3,4,7])
+ m.insertNextCell(NORM_TRI3,[3,7,0])
+ m.insertNextCell(NORM_TRI3,[6,2,11])
+ m.insertNextCell(NORM_TRI3,[6,11,5])
+ m.insertNextCell(NORM_TRI3,[6,5,13])
+ m.insertNextCell(NORM_TRI3,[6,13,4])
+ edges,d,di,rd,rdi=m.explodeMeshIntoMicroEdges() # <- new method
+ self.assertTrue(MEDCoupling1SGTUMesh(edges).getNodalConnectivity().isEqual(DataArrayInt([0,7,7,4,4,8,8,1,1,9,9,0,1,10,10,5,5,11,11,2,2,12,12,1,4,13,13,5,3,4,7,3,0,3,6,2,11,6,5,6,13,6,4,6])))
+ self.assertEqual(edges.getCoords().getHiddenCppPointer(),coo.getHiddenCppPointer())
+ self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,7,6,3,2,12,13,14,1,15,15,0,16,17,9,18,18,8,19,19,13,20,20,12,21])))
+ self.assertTrue(di.isEqual(DataArrayInt([0,6,12,18,21,24,27,30,33,36])))
+ self.assertTrue(rd.isEqual(DataArrayInt([0,4,0,3,0,2,0,2,0,0,1,2,1,2,1,6,1,5,1,1,2,8,2,7,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rdi.isEqual(DataArrayInt([0,2,4,6,8,9,10,12,14,16,18,19,20,22,24,25,27,28,29,31,33,35,36])))
+ pass
+
+ def testFieldIntIsOnStage2(self):
+ """ Very important test to check that isEqual of MEDCouplingFieldInt is OK !"""
+ m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4]))
+ m1=m1.buildUnstructured() ; m1.setName("mesh")
+ f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setMesh(m1)
+ arr1=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr1.setInfoOnComponents(["aa","bbb"])
+ f1.setArray(arr1) ; f1.setName("f1") ; f1.setTime(2.,3,4)
+ #
+ m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4]))
+ m2=m2.buildUnstructured() ; m2.setName("mesh")
+ f2=MEDCouplingFieldInt(ON_CELLS) ; f2.setMesh(m2)
+ arr2=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr2.setInfoOnComponents(["aa","bbb"])
+ f2.setArray(arr2) ; f2.setName("f1") ; f2.setTime(2.,3,4)
+ #
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ f1.getArray()[:]*=2
+ self.assertTrue(not f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,0.))
+ f1.getArray()[:]/=2
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ #
+ f1.setName("F1")
+ self.assertTrue(not f1.isEqual(f2,1e-12,0.))
+ f1.setName("f1")
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ #
+ f1.getArray().setInfoOnComponents(["aa","bbbb"])
+ self.assertTrue(not f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,0.))
+ f1.getArray().setInfoOnComponents(["aa","bbb"])
+ self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ #
+ f3=f2.deepCopy()
+ self.assertTrue(f1.isEqual(f3,1e-12,0.))
+ #
+ for fd,expected in ((ON_NODES,False),(ON_CELLS,True)):
+ f4=MEDCouplingFieldInt(fd) ; f4.setMesh(m2) ; f4.setTime(2.,3,4)
+ arr4=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr4.setInfoOnComponents(["aa","bbb"])
+ f4.setArray(arr4) ; f4.setName("f1")
+ self.assertEqual(f1.isEqual(f4,1e-12,0.),expected)
+ pass
+ pass
+
+ def testDADSymmetry1(self):
+ arr=DataArrayDouble([2,3,4],1,3)
+ res=arr.symmetry3DPlane([0.,0.,0.],[0.,0.,2.])
+ self.assertTrue(res.isEqual(DataArrayDouble([2,3,-4],1,3),1e-14))
+ #
+ res=arr.symmetry3DPlane([-1000,100,-1],[0.,0.,2.])
+ self.assertTrue(res.isEqual(DataArrayDouble([2,3,-6],1,3),1e-14))
+ #
+ res=arr.symmetry3DPlane([0,0,0],[1.,0.,0.])
+ self.assertTrue(res.isEqual(DataArrayDouble([-2,3,4],1,3),1e-14))
+ #
+ res=arr.symmetry3DPlane([0,0,0],[0.,1.,0.])
+ self.assertTrue(res.isEqual(DataArrayDouble([2,-3,4],1,3),1e-14))
+ #
+ res=arr.symmetry3DPlane([0,0,0],[-1.,1.,0.])
+ self.assertTrue(res.isEqual(DataArrayDouble([3,2,4],1,3),1e-14))
+ #
+ plane=[5.,4.,-7.]
+ a=DataArrayDouble(DataArrayDouble.GiveBaseForPlane(plane))
+ self.assertAlmostEqual(DataArrayDouble.Dot(a[0],a[1]).magnitude()[0],0.,13)
+ self.assertAlmostEqual(DataArrayDouble.Dot(a[0],a[2]).magnitude()[0],0.,13)
+ self.assertAlmostEqual(DataArrayDouble.Dot(a[1],a[2]).magnitude()[0],0.,13)
+ coo=DataArrayDouble.Aggregate([10*a[0]+10*a[1],-10*a[0]+10*a[1],-10*a[0]-10*a[1],10*a[0]-10*a[1]])
+ m=MEDCouplingUMesh("",2) ; m.setCoords(coo) ; m.allocateCells()
+ m.insertNextCell(NORM_QUAD4,[0,1,2,3])
+ d,_=m.distanceToPoint(arr)
+ res=arr.symmetry3DPlane([0.,0.,0.],plane) #
+ d2,_=m.distanceToPoint(res)
+ self.assertAlmostEqual(abs(d-d2),0.,12)
+ self.assertAlmostEqual(DataArrayDouble.Dot(res-arr,a[0])[0],0.,12)
+ self.assertAlmostEqual(DataArrayDouble.Dot(res-arr,a[1])[0],0.,12)
+ self.assertAlmostEqual((res-arr).magnitude()[0]-2*d,0.,12)
+ self.assertTrue(res.isEqual(DataArrayDouble([2.666666666666667,3.5333333333333333,3.0666666666666666],1,3),1e-12))
+ pass
+
+ def testExtrudedMeshBuildUnstructured1(self):
+ """ Non reg test. ExtrudedMesh.buildUnstructured used to modify the coordinates of this. It used to lead to an extra amount of memory consumtion. The aim of the test here is to check that buildUnstructured method do not alter the content of the mesh"""
+ arr=DataArrayDouble(11) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr)
+ m=m.buildUnstructured()
+ faces=MEDCouplingCMesh() ; faces.setCoords(arr,arr)
+ faces=faces.buildUnstructured()
+ faces.setCoords(m.getCoords())
+ em=MEDCouplingMappedExtrudedMesh(m,faces,0)
+ self.assertTrue(em.buildUnstructured().isEqual(m,1e-12))
+ self.assertTrue(em.buildUnstructured().isEqual(m,1e-12)) # the bug was here ... buildUnstructured used to modify em ...
+ self.assertTrue(em.buildUnstructured().isEqual(m,1e-12)) # the bug was here ... buildUnstructured used to modify em ...
+ pass
+
+ def testExtrudedMeshFromCMesh1(self):
+ arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
+ mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ)
+ ex=MEDCouplingMappedExtrudedMesh(mesh3D)
+ self.assertTrue(ex.buildUnstructured().isEqual(mesh3D.buildUnstructured(),1e-12))
+ pass
pass
if __name__ == '__main__':