+ def testSwig2SortHexa8EachOther1(self):
+ """
+ testing MEDCoupling1SGTUMesh.sortHexa8EachOther method
+ """
+ coords1=DataArrayDouble([(-0.5,0.5,-0.5),(0.5,-0.5,-0.5),(-0.5,-0.5,0.5),(-0.5,-0.5,-0.5),(0.5,-0.5,0.5),(-0.5,0.5,0.5),(0.5,0.5,0.5),(0.5,0.5,-0.5)])
+ m1=MEDCouplingUMesh("m1",3) ; m1.setCoords(coords1)
+ m1.allocateCells() ; m1.insertNextCell(NORM_HEXA8,[7,1,3,0,6,4,2,5])
+ m1.checkCoherency()
+ #
+ m2=m1.deepCpy() ; m2.setName("m2")
+ #
+ trs=[[0.,0.,-1.],[0.,0.,1.],[1.,0.,0.],[0.,-1.,0.],[-1.,0.,0.],[0.,1.,0.]]
+ for i,t in enumerate(trs):
+ for j in xrange(64):
+ j2=(j//16) ; j1=((j%16)//4) ; j0=(j%4)
+ m11=m1.deepCpy()
+ m11.rotate([0.,0.,0.],[0.,0.,1.],float(j0)*pi/2)
+ m11.rotate([0.,0.,0.],[0.,1.,0.],float(j1)*pi/2)
+ m11.rotate([0.,0.,0.],[1.,0.,0.],float(j2)*pi/2)
+ m11.translate(t)
+ #
+ m=MEDCouplingUMesh.MergeUMeshes(m2,m11)
+ m.mergeNodes(1e-12)
+ self.assertEqual(12,m.getNumberOfNodes())
+ m=MEDCoupling1SGTUMesh(m)
+ m.sortHexa8EachOther()
+ tmp0=m.buildUnstructured().tetrahedrize(PLANAR_FACE_6)[0].buildUnstructured()
+ self.assertEqual(20,tmp0.computeSkin().getNumberOfCells())
+ pass
+ pass
+ pass
+
+ def testSwig2normMinComputeAbs1(self):
+ d=DataArrayDouble([4,-5,2,6.1,-7.33,1,-1,3e2,0.07,-0.009,-6,-1e30],4,3)
+ d.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0=d.computeAbs()
+ dExp=d.deepCpy() ; dExp.abs()
+ self.assertTrue(dExp.isEqual(d0,1e-12))
+ e=d0-DataArrayDouble([4,5,2,6.1,7.33,1,1,3e2,0.07,0.009,6,1e30],4,3)
+ self.assertAlmostEqual(0.,e.normMin(),13)
+ self.assertAlmostEqual(0.009,d.normMin(),13)
+ #
+ di=DataArrayInt([3,-12,5,6,14,16,-23,100,23,-1,0,-6],4,3)
+ di.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0i=di.computeAbs()
+ diExp=di.deepCpy() ; diExp.abs()
+ self.assertTrue(diExp.isEqual(d0i))
+ self.assertEqual([3,12,5,6,14,16,23,100,23,1,0,6],d0i.getValues())
+ pass
+
+ def testSwig2GetCellsContainingPointsForNonConvexPolygon1(self):
+ coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.,-0.5,0.,0.,0.5,0.,],7,2)
+ m=MEDCouplingUMesh("Intersect2D",2) ; m.setCoords(coo) ; m.allocateCells()
+ m.insertNextCell(NORM_POLYGON,[6,3,4,5])
+ m.insertNextCell(NORM_POLYGON,[4,0,1,2,6,5])
+ m.checkCoherency2()
+ #
+ self.assertTrue(m.getCellsContainingPoint((0.4,-0.4),1e-12).isEqual(DataArrayInt([0])))
+ self.assertTrue(m.getCellsContainingPoint((-0.4,-0.4),1e-12).isEqual(DataArrayInt([1])))
+ self.assertTrue(m.getCellsContainingPoint((0.,-0.4),1e-12).isEqual(DataArrayInt([0,1])))
+ pass
+
+ def testSwig2GetCellsContainingPointsForNonConvexPolygon2(self):
+ coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,-2.0816681711721685e-17,-2.0816681711721685e-17,-0.17677669529663687,0.1767766952966369,0.,0.5,0.5,0.,0.17677669529663684,-0.17677669529663692,0.17677669529663692,0.17677669529663684,-0.17677669529663692,-0.17677669529663687,0.,-0.5,-0.5,0.,0.33838834764831843,-0.3383883476483185,-0.33838834764831843,0.33838834764831843,-0.21213203435596423,0.21213203435596426,0.2121320343559642,-0.2121320343559643,0.21213203435596426,0.2121320343559642,-0.21213203435596423,-0.21213203435596428,0.3560660171779821,-0.35606601717798214,-0.35606601717798214,0.35606601717798214,0.19445436482630052,-0.19445436482630063,-0.19445436482630055,0.19445436482630057,0.,0.27],24,2)
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) ; m.allocateCells()
+ m.insertNextCell(NORM_QPOLYG,[8,5,4,9])
+ m.insertNextCell(NORM_QPOLYG,[5,8,4,10])
+ m.insertNextCell(NORM_QPOLYG,[16,8,5,15,21,9,22,17])
+ m.insertNextCell(NORM_QPOLYG,[15,1,2,3,16,20,6,7,19,17])
+ m.insertNextCell(NORM_QPOLYG,[15,5,8,16,22,10,21,18])
+ m.insertNextCell(NORM_QPOLYG,[16,3,0,1,15,19,11,12,20,18])
+ m.checkCoherency2()
+ self.assertTrue(m.getCellsContainingPoint([0.,0.27],1e-12).isEqual(DataArrayInt([2])))
+ pass
+
+ def testSwig2DAIGetIdsEqualTuple1(self):
+ da=DataArrayInt([0,7,1,2,4,1,2,1,1,2,0,1,2,1,5,1,1,2],9,2)
+ self.assertTrue(da.getIdsEqualTuple([1,2]).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple((1,2)).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple(DataArrayInt([1,2])).isEqual(DataArrayInt([1,4,8])))
+ da.rearrange(3)
+ self.assertRaises(InterpKernelException,da.getIdsEqualTuple,[1,2])# mismatch nb of compo (3) and nb of elts in input tuple (2)
+ self.assertTrue(da.getIdsEqualTuple([2,0,1]).isEqual(DataArrayInt([3])))
+ self.assertTrue(da.getIdsEqualTuple([2,0,7]).isEqual(DataArrayInt([])))
+ da.rearrange(1)
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(DataArrayInt([3,6,9,12,17])))
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(da.getIdsEqual(2)))
+ pass
+
+ def testSwig2GaussNEStaticInfo1(self):
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetWeightArrayFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.16666666666666666]),1e-12))
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetRefCoordsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.,0.,1.,0.,0.,1.]),1e-12))
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetLocsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.6666666666666667,0.16666666666666666,0.16666666666666666,0.6666666666666667]),1e-12))
+ pass
+
+ def testSwigReverseNodalConnOnStructuredMesh(self):
+ # 1D - standard
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 1D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(1) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 1D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(0) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn.isEqual(DataArrayInt([]))
+ rni.isEqual(DataArrayInt([0]))
+ # 2D - standard
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; arr2=DataArrayDouble(4) ; arr.iota()
+ c.setCoords(arr,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,8,4,5,8,9,5,6,9,10,6,7,10,11,7,11,8,8,9,9,10,10,11,11])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,26,30,34,38,40,41,43,45,47,48])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 2D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+ c.setCoords(arr,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ # 2D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+ c.setCoords(arr2,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ # 3D - standard
+ c=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(3) ; arr1.iota() ; arr2=DataArrayDouble(4) ; arr2.iota()
+ c.setCoords(arr0,arr1,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,4,5,5,6,6,7,7,0,8,0,1,8,9,1,2,9,10,2,3,10,11,3,11,0,4,8,12,0,1,4,5,8,9,12,13,1,2,5,6,9,10,13,14,2,3,6,7,10,11,14,15,3,7,11,15,4,12,4,5,12,13,5,6,13,14,6,7,14,15,7,15,8,16,8,9,16,17,9,10,17,18,10,11,18,19,11,19,8,12,16,20,8,9,12,13,16,17,20,21,9,10,13,14,17,18,21,22,10,11,14,15,18,19,22,23,11,15,19,23,12,20,12,13,20,21,13,14,21,22,14,15,22,23,15,23,16,16,17,17,18,18,19,19,16,20,16,17,20,21,17,18,21,22,18,19,22,23,19,23,20,20,21,21,22,22,23,23])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,25,27,29,31,32,34,38,42,46,48,52,60,68,76,80,82,86,90,94,96,98,102,106,110,112,116,124,132,140,144,146,150,154,158,160,161,163,165,167,168,170,174,178,182,184,185,187,189,191,192])))
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ pass
+
+ def testSwig2CellToNodeDiscretization1(self):
+ m=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(4) ; arr1.iota() ; m.setCoords(arr0,arr1)
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setTime(1.1,5,6)
+ arr=DataArrayDouble(12) ; arr.iota()
+ arr=DataArrayDouble.Meld(arr,arr+100.) ; arr.setInfoOnComponents(["aaa","bbb"])
+ f.setArray(arr)
+ f.checkCoherency()
+ #
+ ref=DataArrayDouble([0.,0.5,1.5,2.5,3.,2.,2.5,3.5,4.5,5.,6.,6.5,7.5,8.5,9.,8.,8.5,9.5,10.5,11.])
+ ref=DataArrayDouble.Meld(ref,ref+100.) ; ref.setInfoOnComponents(["aaa","bbb"])
+ f2=f.cellToNodeDiscretization()
+ f2.checkCoherency()
+ self.assertEqual(f2.getTime()[1:],[5,6])
+ self.assertAlmostEqual(f2.getTime()[0],1.1,15)
+ self.assertEqual(f2.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
+ self.assertTrue(f2.getArray().isEqual(ref,1e-12))
+ rn,rni=m.getReverseNodalConnectivity()
+ rni2=(rni.deltaShiftIndex()).convertToDblArr()
+ arr2=(f.getArray()[rn]).accumulatePerChunck(rni)/rni2
+ self.assertTrue(f2.getArray().isEqual(arr2,1e-12))
+ del f2
+ #
+ u=m.buildUnstructured() ; f.setMesh(u) ; del m
+ f3=f.cellToNodeDiscretization()
+ f3.checkCoherency()
+ self.assertEqual(f3.getTime()[1:],[5,6])
+ self.assertAlmostEqual(f3.getTime()[0],1.1,15)
+ self.assertEqual(f3.getMesh().getHiddenCppPointer(),u.getHiddenCppPointer())
+ self.assertTrue(f3.getArray().isEqual(ref,1e-12))
+ pass
+
+ def testSwig2GetMeshSpaceDimensionCMesh1(self):
+ c=MEDCouplingCMesh()
+ arr0=DataArrayDouble([0,1,2])
+ arr1=DataArrayDouble([0])
+ c.setCoords(arr0,arr0,arr0)
+ self.assertEqual(c.getMeshDimension(),3)
+ self.assertEqual(c.getSpaceDimension(),3)
+ #
+ c.setCoords(arr0,arr0,arr1)
+ self.assertEqual(c.getMeshDimension(),2)
+ self.assertEqual(c.getSpaceDimension(),3)
+ #
+ c.setCoords(arr0,arr0)
+ self.assertEqual(c.getMeshDimension(),2)
+ self.assertEqual(c.getSpaceDimension(),2)
+ #
+ c.setCoords(arr0,arr1)
+ self.assertEqual(c.getMeshDimension(),1)
+ self.assertEqual(c.getSpaceDimension(),2)
+ #
+ c.setCoords(arr0)
+ self.assertEqual(c.getMeshDimension(),1)
+ self.assertEqual(c.getSpaceDimension(),1)
+ #
+ c.setCoords(arr1)
+ self.assertEqual(c.getMeshDimension(),0)
+ self.assertEqual(c.getSpaceDimension(),1)
+ pass
+