From: Anthony Geay Date: Thu, 18 Jul 2019 05:58:01 +0000 (+0200) Subject: OK pour tests MEDLoaderTest[1,2,3].py X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=28a73875300d8e0996b9cab2eb99749fa70aae84;p=tools%2Fmedcoupling.git OK pour tests MEDLoaderTest[1,2,3].py --- diff --git a/src/MEDLoader/Swig/MEDLoaderDataForTest.py b/src/MEDLoader/Swig/MEDLoaderDataForTest.py index baa16f4be..e752c8ca8 100644 --- a/src/MEDLoader/Swig/MEDLoaderDataForTest.py +++ b/src/MEDLoader/Swig/MEDLoaderDataForTest.py @@ -773,3 +773,233 @@ def TestWriteUMeshesRW1(tester): f2=ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7); tester.assertTrue(f2.isEqual(f1,1e-12,1e-12)); pass + +def TestMultiFieldShuffleRW1(tester): + fileName="Pyfile17.med"; + m=MEDLoaderDataForTest.build3DMesh_2(); + tester.assertEqual(20,m.getNumberOfCells()); + tester.assertEqual(45,m.getNumberOfNodes()); + polys=[1,4,6] + m.convertToPolyTypes(polys); + renum=[1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11] + m.renumberCells(renum,False); + m.orientCorrectlyPolyhedrons(); + # Writing + WriteUMeshDep(fileName,m,False); + f1Tmp=m.getMeasureField(False); + f1=f1Tmp.buildNewTimeReprFromThis(ONE_TIME,False); + f1.setTime(0.,1,2); + f_1=f1.cloneWithMesh(True); + WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + f1.applyFunc("2*x"); + f1.setTime(0.01,3,4); + f_2=f1.cloneWithMesh(True); + WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + f1.applyFunc("2*x/3"); + f1.setTime(0.02,5,6); + f_3=f1.cloneWithMesh(True); + WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + # Reading + its=[(1,2),(3,4),(5,6)]; + fs=ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1.getMesh().getName(),0,f_1.getName(),its); + tester.assertEqual(3,len(fs)); + tester.assertTrue(fs[0].isEqual(f_1,1e-12,1e-12)); + tester.assertTrue(fs[1].isEqual(f_2,1e-12,1e-12)); + tester.assertTrue(fs[2].isEqual(f_3,1e-12,1e-12)); + +def GeneratePyfile13(tester): + fileName="Pyfile13.med"; + f1=MEDLoaderDataForTest.buildVecFieldOnGauss_1(); + WriteField(fileName,f1,True); + f2=ReadField(ON_GAUSS_PT,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); + tester.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + pass + +def GeneratePyfile14(tester): + fileName="Pyfile14.med"; + f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1(); + WriteField(fileName,f1,True); + tester.assertEqual([ON_GAUSS_NE],GetTypesOfField(fileName,'2DMesh_2','MyFieldOnGaussNE')) #Bug 22/5/2014 + f2=ReadField(ON_GAUSS_NE,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); + tester.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + + +def GeneratePyfile18(tester): + fileName="Pyfile18.med"; + m3d=MEDLoaderDataForTest.build3DMesh_2(); + pt=[0.,0.,-0.3] + vec=[0.,0.,1.] + nodes=m3d.findNodesOnPlane(pt,vec,1e-12); + m2d=m3d.buildFacePartOfMySelfNode(nodes,True); + renumber=[1,2,0,4,3] + m2d.renumberCells(renumber,False); + m2d.setName("ExampleOfMultiDimW"); + meshes=[m2d,m3d] + WriteUMeshes(fileName,meshes,True); + m3d_bis=ReadUMeshFromFile(fileName,m2d.getName(),0); + tester.assertTrue(not m3d_bis.isEqual(m3d,1e-12)); + m3d_bis.setName(m3d.getName()); + tester.assertTrue(m3d_bis.isEqual(m3d,1e-12)); + m2d_bis=ReadUMeshFromFile(fileName,m2d.getName(),-1);#-1 for faces + tester.assertTrue(m2d_bis.isEqual(m2d,1e-12)); + # Creation of a field on faces. + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setName("FieldOnFacesShuffle"); + f1.setMesh(m2d); + array=DataArrayDouble.New(); + arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.] + array.setValues(arr1,m2d.getNumberOfCells(),2); + array.setInfoOnComponent(0,"plkj [mm]"); + array.setInfoOnComponent(1,"pqqqss [mm]"); + f1.setArray(array); + tmp=array.setValues(arr1,m2d.getNumberOfCells(),2); + f1.setTime(3.14,2,7); + f1.checkConsistencyLight(); + WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + f2=ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7); + tester.assertTrue(f2.isEqual(f1,1e-12,1e-12)); + +def GeneratePyfile19(tester): + fileName="Pyfile19.med"; + fileName2="Pyfile20.med"; + m=MEDLoaderDataForTest.build2DMesh_1(); + nbOfNodes=m.getNumberOfNodes(); + WriteUMesh(fileName,m,True); + f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME); + f1.setName("VFieldOnNodes"); + f1.setMesh(m); + array=DataArrayDouble.New(); + arr1=[1.,101.,2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.] + array.setValues(arr1,nbOfNodes,2); + f1.setArray(array); + array.setInfoOnComponent(0,"tyty [mm]"); + array.setInfoOnComponent(1,"uiop [MW]"); + f1.setTime(3.14,2,7); + f1.checkConsistencyLight(); + arr2=[1,4] + f2=f1.buildSubPart(arr2); + f2.getMesh().setName(f1.getMesh().getName()); + WriteField(fileName,f2,False);#<- False important for the test + # + f3=ReadFieldNode(fileName,f2.getMesh().getName(),0,f2.getName(),2,7); + f3.checkConsistencyLight(); + tester.assertTrue(f3.isEqual(f2,1e-12,1e-12)); + # + arr3=[1,3,0,5,2,4] + f2.renumberNodes(arr3); + WriteUMesh(fileName2,m,True); + WriteField(fileName2,f2,False);#<- False important for the test + f3=ReadFieldNode(fileName2,f2.getMesh().getName(),0,f2.getName(),2,7); + f3.checkConsistencyLight(); + tester.assertTrue(f3.isEqual(f2,1e-12,1e-12)); + # + pass + +def GeneratePyfile7(tester): + f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); + WriteField("Pyfile6.med",f1,True); + f2=ReadFieldCell("Pyfile6.med",f1.getMesh().getName(),0,f1.getName(),0,1); + tester.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + # + f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); + WriteField("Pyfile7.med",f1,True); + f2=ReadFieldNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3); + tester.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + tester.assertRaises(Exception,ReadFieldCell,"Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3); + pass + +def GeneratePyfile12(tester): + fileName="Pyfile12.med"; + mesh1=MEDLoaderDataForTest.build3DMesh_1(); + da,b,newNbOfNodes=mesh1.mergeNodes(1e-12); + WriteUMesh(fileName,mesh1,True); + part1=[1,2,4,13,15] + mesh2=mesh1.buildPartOfMySelf(part1,True); + mesh2.setName(mesh1.getName());#<- important for the test + # + nbOfCells=mesh2.getNumberOfCells(); + tester.assertEqual(5,nbOfCells); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setName("VectorFieldOnCells"); + f1.setMesh(mesh2); + array=DataArrayDouble.New(); + array.alloc(nbOfCells,2); + f1.setArray(array); + arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.] + array.setValues(arr1,nbOfCells,2); + f1.setTime(3.14,2,7); + f1.checkConsistencyLight(); + # + WriteField(fileName,f1,False);#<- False important for the test + # + f2=ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); + tt=GetTypesOfField(fileName,f1.getMesh().getName(),f1.getName()); + tester.assertEqual(tt,[ON_CELLS]); + f2.checkConsistencyLight(); + tester.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + +def GeneratePyfile10(tester): + fileName="Pyfile10.med"; + mesh1=MEDLoaderDataForTest.build3DMesh_1(); + part1=[1,2,4,13,15] + mesh2=mesh1.buildPartOfMySelf(part1,True); + mesh2.setName("mesh2"); + part2=[3,4,13,14] + mesh3=mesh1.buildPartOfMySelf(part2,True); + mesh3.setName("mesh3"); + mesh4=MEDCouplingUMesh.New(); + mesh4.setName("mesh4"); + mesh4.setMeshDimension(3); + mesh4.allocateCells(1); + conn=[0,11,1,3] + mesh4.insertNextCell(NORM_TETRA4,4,conn[0:4]) + mesh4.finishInsertingCells(); + mesh4.setCoords(mesh1.getCoords()); + meshes=[mesh1,mesh2,mesh3,mesh4] + mnane="3DToto"; + WriteUMeshesPartition(fileName,mnane,meshes,True); + # + mesh5=ReadUMeshFromFile(fileName,mnane); + mesh1.setName(mnane); + part3=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] + mesh6=mesh5.buildPartOfMySelf(part3,True); + mesh6.setName(mnane); + tester.assertTrue(mesh6.isEqual(mesh1,1e-12)); + grps=GetMeshGroupsNames(fileName,mnane); + tester.assertEqual(4,len(grps)); + grps.index("mesh2"); + grps.index("mesh3"); + grps.index("mesh4"); + grps.index("3DMesh_1"); + # + vec=("mesh2",); + mesh2_2=ReadUMeshFromGroups(fileName,mnane,0,vec); + tester.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); + vec=["mesh3"]; + mesh3_2=ReadUMeshFromGroups(fileName,mnane,0,vec); + tester.assertTrue(mesh3_2.isEqual(mesh3,1e-12)); + vec=["mesh4"]; + mesh4_2=ReadUMeshFromGroups(fileName,mnane,0,vec); + tester.assertTrue(mesh4_2.isEqual(mesh4,1e-12)); + vec="3DMesh_1"; + mesh1_2=ReadUMeshFromGroups(fileName,mnane,0,vec); + mesh1.setName("3DMesh_1"); + tester.assertTrue(mesh1_2.isEqual(mesh1,1e-12)); + # + vec=["Family_-3","Family_-5"]; + mesh2_2=ReadUMeshFromFamilies(fileName,mnane,0,vec); + mesh2_2.setName("mesh2"); + tester.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); + # + ret=GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1"); + tester.assertEqual(4,len(ret)); + ref=['Family_-3','Family_-4','Family_-2','Family_-5'] + tester.assertIn(ref[0],ret); + tester.assertIn(ref[1],ret); + tester.assertIn(ref[2],ret); + tester.assertIn(ref[3],ret); + # + ret1=GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_-3"); + tester.assertEqual(2,len(ret1)); + tester.assertEqual(ret1[0],"3DMesh_1"); + tester.assertEqual(ret1[1],"mesh2"); diff --git a/src/MEDLoader/Swig/MEDLoaderTest1.py b/src/MEDLoader/Swig/MEDLoaderTest1.py index 4d88ec114..88ab6939d 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest1.py +++ b/src/MEDLoader/Swig/MEDLoaderTest1.py @@ -23,6 +23,7 @@ import MEDLoader import unittest from math import pi,e,sqrt from MEDLoaderDataForTest import MEDLoaderDataForTest,WriteInTmpDir +from MEDLoaderDataForTest import GeneratePyfile7,GeneratePyfile10,GeneratePyfile12,GeneratePyfile13,GeneratePyfile14,GeneratePyfile18,GeneratePyfile19 class MEDLoaderTest1(unittest.TestCase): @WriteInTmpDir @@ -72,16 +73,7 @@ class MEDLoaderTest1(unittest.TestCase): @WriteInTmpDir def testFieldRW1(self): - f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); - MEDLoader.WriteField("Pyfile6.med",f1,True); - f2=MEDLoader.ReadFieldCell("Pyfile6.med",f1.getMesh().getName(),0,f1.getName(),0,1); - self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); - # - f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1(); - MEDLoader.WriteField("Pyfile7.med",f1,True); - f2=MEDLoader.ReadFieldNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3); - self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); - self.assertRaises(Exception,MEDLoader.ReadFieldCell,"Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3); + GeneratePyfile7(self) pass @WriteInTmpDir @@ -215,122 +207,23 @@ class MEDLoaderTest1(unittest.TestCase): @WriteInTmpDir def testMultiMeshRW1(self): - fileName="Pyfile10.med"; - mesh1=MEDLoaderDataForTest.build3DMesh_1(); - part1=[1,2,4,13,15] - mesh2=mesh1.buildPartOfMySelf(part1,True); - mesh2.setName("mesh2"); - part2=[3,4,13,14] - mesh3=mesh1.buildPartOfMySelf(part2,True); - mesh3.setName("mesh3"); - mesh4=MEDLoader.MEDCouplingUMesh.New(); - mesh4.setName("mesh4"); - mesh4.setMeshDimension(3); - mesh4.allocateCells(1); - conn=[0,11,1,3] - mesh4.insertNextCell(MEDLoader.NORM_TETRA4,4,conn[0:4]) - mesh4.finishInsertingCells(); - mesh4.setCoords(mesh1.getCoords()); - meshes=[mesh1,mesh2,mesh3,mesh4] - mnane="3DToto"; - MEDLoader.WriteUMeshesPartition(fileName,mnane,meshes,True); - # - mesh5=MEDLoader.ReadUMeshFromFile(fileName,mnane); - mesh1.setName(mnane); - part3=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] - mesh6=mesh5.buildPartOfMySelf(part3,True); - mesh6.setName(mnane); - self.assertTrue(mesh6.isEqual(mesh1,1e-12)); - grps=MEDLoader.GetMeshGroupsNames(fileName,mnane); - self.assertEqual(4,len(grps)); - grps.index("mesh2"); - grps.index("mesh3"); - grps.index("mesh4"); - grps.index("3DMesh_1"); - # - vec=("mesh2",); - mesh2_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); - self.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); - vec=["mesh3"]; - mesh3_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); - self.assertTrue(mesh3_2.isEqual(mesh3,1e-12)); - vec=["mesh4"]; - mesh4_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); - self.assertTrue(mesh4_2.isEqual(mesh4,1e-12)); - vec="3DMesh_1"; - mesh1_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); - mesh1.setName("3DMesh_1"); - self.assertTrue(mesh1_2.isEqual(mesh1,1e-12)); - # - vec=["Family_-3","Family_-5"]; - mesh2_2=MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec); - mesh2_2.setName("mesh2"); - self.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); - # - ret=MEDLoader.GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1"); - self.assertEqual(4,len(ret)); - ref=['Family_-3','Family_-4','Family_-2','Family_-5'] - self.assertIn(ref[0],ret); - self.assertIn(ref[1],ret); - self.assertIn(ref[2],ret); - self.assertIn(ref[3],ret); - # - ret1=MEDLoader.GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_-3"); - self.assertEqual(2,len(ret1)); - self.assertEqual(ret1[0],"3DMesh_1"); - self.assertEqual(ret1[1],"mesh2"); + GeneratePyfile10(self) pass @WriteInTmpDir def testFieldProfilRW1(self): - fileName="Pyfile12.med"; - mesh1=MEDLoaderDataForTest.build3DMesh_1(); - da,b,newNbOfNodes=mesh1.mergeNodes(1e-12); - MEDLoader.WriteUMesh(fileName,mesh1,True); - part1=[1,2,4,13,15] - mesh2=mesh1.buildPartOfMySelf(part1,True); - mesh2.setName(mesh1.getName());#<- important for the test - # - nbOfCells=mesh2.getNumberOfCells(); - self.assertEqual(5,nbOfCells); - f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME); - f1.setName("VectorFieldOnCells"); - f1.setMesh(mesh2); - array=MEDLoader.DataArrayDouble.New(); - array.alloc(nbOfCells,2); - f1.setArray(array); - arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.] - array.setValues(arr1,nbOfCells,2); - f1.setTime(3.14,2,7); - f1.checkConsistencyLight(); - # - MEDLoader.WriteField(fileName,f1,False);#<- False important for the test - # - f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7); - tt=MEDLoader.GetTypesOfField(fileName,f1.getMesh().getName(),f1.getName()); - self.assertEqual(tt,[MEDLoader.ON_CELLS]); - f2.checkConsistencyLight(); - self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + GeneratePyfile12(self) # pass @WriteInTmpDir def testFieldGaussRW1(self): - fileName="Pyfile13.med"; - f1=MEDLoaderDataForTest.buildVecFieldOnGauss_1(); - MEDLoader.WriteField(fileName,f1,True); - f2=MEDLoader.ReadField(MEDLoader.ON_GAUSS_PT,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); - self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + GeneratePyfile13(self) pass @WriteInTmpDir def testFieldGaussNERW1(self): - fileName="Pyfile14.med"; - f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1(); - MEDLoader.WriteField(fileName,f1,True); - self.assertEqual([MEDLoader.ON_GAUSS_NE],MEDLoader.GetTypesOfField(fileName,'2DMesh_2','MyFieldOnGaussNE')) #Bug 22/5/2014 - f2=MEDLoader.ReadField(MEDLoader.ON_GAUSS_NE,fileName,f1.getMesh().getName(),0,f1.getName(),1,5); - self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + GeneratePyfile14(self) pass @WriteInTmpDir @@ -382,76 +275,12 @@ class MEDLoaderTest1(unittest.TestCase): @WriteInTmpDir def testWriteUMeshesRW1(self): - fileName="Pyfile18.med"; - m3d=MEDLoaderDataForTest.build3DMesh_2(); - pt=[0.,0.,-0.3] - vec=[0.,0.,1.] - nodes=m3d.findNodesOnPlane(pt,vec,1e-12); - m2d=m3d.buildFacePartOfMySelfNode(nodes,True); - renumber=[1,2,0,4,3] - m2d.renumberCells(renumber,False); - m2d.setName("ExampleOfMultiDimW"); - meshes=[m2d,m3d] - MEDLoader.WriteUMeshes(fileName,meshes,True); - m3d_bis=MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),0); - self.assertTrue(not m3d_bis.isEqual(m3d,1e-12)); - m3d_bis.setName(m3d.getName()); - self.assertTrue(m3d_bis.isEqual(m3d,1e-12)); - m2d_bis=MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),-1);#-1 for faces - self.assertTrue(m2d_bis.isEqual(m2d,1e-12)); - # Creation of a field on faces. - f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME); - f1.setName("FieldOnFacesShuffle"); - f1.setMesh(m2d); - array=MEDLoader.DataArrayDouble.New(); - arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.] - array.setValues(arr1,m2d.getNumberOfCells(),2); - array.setInfoOnComponent(0,"plkj [mm]"); - array.setInfoOnComponent(1,"pqqqss [mm]"); - f1.setArray(array); - tmp=array.setValues(arr1,m2d.getNumberOfCells(),2); - f1.setTime(3.14,2,7); - f1.checkConsistencyLight(); - MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7); - self.assertTrue(f2.isEqual(f1,1e-12,1e-12)); + GeneratePyfile18(self) pass @WriteInTmpDir def testFieldNodeProfilRW1(self): - fileName="Pyfile19.med"; - fileName2="Pyfile20.med"; - m=MEDLoaderDataForTest.build2DMesh_1(); - nbOfNodes=m.getNumberOfNodes(); - MEDLoader.WriteUMesh(fileName,m,True); - f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME); - f1.setName("VFieldOnNodes"); - f1.setMesh(m); - array=MEDLoader.DataArrayDouble.New(); - arr1=[1.,101.,2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.] - array.setValues(arr1,nbOfNodes,2); - f1.setArray(array); - array.setInfoOnComponent(0,"tyty [mm]"); - array.setInfoOnComponent(1,"uiop [MW]"); - f1.setTime(3.14,2,7); - f1.checkConsistencyLight(); - arr2=[1,4] - f2=f1.buildSubPart(arr2); - f2.getMesh().setName(f1.getMesh().getName()); - MEDLoader.WriteField(fileName,f2,False);#<- False important for the test - # - f3=MEDLoader.ReadFieldNode(fileName,f2.getMesh().getName(),0,f2.getName(),2,7); - f3.checkConsistencyLight(); - self.assertTrue(f3.isEqual(f2,1e-12,1e-12)); - # - arr3=[1,3,0,5,2,4] - f2.renumberNodes(arr3); - MEDLoader.WriteUMesh(fileName2,m,True); - MEDLoader.WriteField(fileName2,f2,False);#<- False important for the test - f3=MEDLoader.ReadFieldNode(fileName2,f2.getMesh().getName(),0,f2.getName(),2,7); - f3.checkConsistencyLight(); - self.assertTrue(f3.isEqual(f2,1e-12,1e-12)); - # + GeneratePyfile19(self) pass @WriteInTmpDir diff --git a/src/MEDLoader/Swig/MEDLoaderTest2.py b/src/MEDLoader/Swig/MEDLoaderTest2.py index b8cc624df..00b2469b0 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest2.py +++ b/src/MEDLoader/Swig/MEDLoaderTest2.py @@ -22,7 +22,8 @@ from MEDLoader import * import unittest from math import pi,e,sqrt -from MEDLoaderDataForTest import MEDLoaderDataForTest,WriteInTmpDir,TestWriteUMeshesRW1 +from MEDLoaderDataForTest import MEDLoaderDataForTest,WriteInTmpDir +from MEDLoaderDataForTest import TestWriteUMeshesRW1,TestMultiFieldShuffleRW1 class MEDLoaderTest2(unittest.TestCase): @WriteInTmpDir @@ -278,37 +279,7 @@ class MEDLoaderTest2(unittest.TestCase): @WriteInTmpDir def testMultiFieldShuffleRW1(self): - fileName="Pyfile17.med"; - m=MEDLoaderDataForTest.build3DMesh_2(); - self.assertEqual(20,m.getNumberOfCells()); - self.assertEqual(45,m.getNumberOfNodes()); - polys=[1,4,6] - m.convertToPolyTypes(polys); - renum=[1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11] - m.renumberCells(renum,False); - m.orientCorrectlyPolyhedrons(); - # Writing - WriteUMeshDep(fileName,m,False); - f1Tmp=m.getMeasureField(False); - f1=f1Tmp.buildNewTimeReprFromThis(ONE_TIME,False); - f1.setTime(0.,1,2); - f_1=f1.cloneWithMesh(True); - WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - f1.applyFunc("2*x"); - f1.setTime(0.01,3,4); - f_2=f1.cloneWithMesh(True); - WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - f1.applyFunc("2*x/3"); - f1.setTime(0.02,5,6); - f_3=f1.cloneWithMesh(True); - WriteFieldUsingAlreadyWrittenMesh(fileName,f1); - # Reading - its=[(1,2),(3,4),(5,6)]; - fs=ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1.getMesh().getName(),0,f_1.getName(),its); - self.assertEqual(3,len(fs)); - self.assertTrue(fs[0].isEqual(f_1,1e-12,1e-12)); - self.assertTrue(fs[1].isEqual(f_2,1e-12,1e-12)); - self.assertTrue(fs[2].isEqual(f_3,1e-12,1e-12)); + TestMultiFieldShuffleRW1(self) pass @WriteInTmpDir diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index fdb8bd222..4099e19e1 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -23,7 +23,8 @@ from MEDLoader import * import unittest import platform from math import pi,e,sqrt -from MEDLoaderDataForTest import MEDLoaderDataForTest,WriteInTmpDir,TestWriteUMeshesRW1 +from MEDLoaderDataForTest import MEDLoaderDataForTest,WriteInTmpDir +from MEDLoaderDataForTest import TestWriteUMeshesRW1,TestMultiFieldShuffleRW1,GeneratePyfile7,GeneratePyfile10,GeneratePyfile12,GeneratePyfile13,GeneratePyfile14,GeneratePyfile18,GeneratePyfile19 from distutils.version import LooseVersion import sys @@ -65,6 +66,7 @@ class StdOutRedirect(object): class MEDLoaderTest3(unittest.TestCase): @WriteInTmpDir def testMEDMesh1(self): + GeneratePyfile18(self) fileName="Pyfile18.med" mname="ExampleOfMultiDimW" medmesh=MEDFileMesh.New(fileName,mname) @@ -80,6 +82,7 @@ class MEDLoaderTest3(unittest.TestCase): @WriteInTmpDir def testMEDMesh2(self): + GeneratePyfile10(self) fileName="Pyfile10.med" mname="3DToto" outFileName="MEDFileMesh1.med" @@ -348,6 +351,7 @@ class MEDLoaderTest3(unittest.TestCase): #testing persistence of retrieved arrays @WriteInTmpDir def testMEDMesh5(self): + GeneratePyfile18(self) fileName="Pyfile18.med" mname="ExampleOfMultiDimW" medmesh=MEDFileUMesh.New(fileName,mname) @@ -459,6 +463,7 @@ class MEDLoaderTest3(unittest.TestCase): #emulation of pointe.med file. @WriteInTmpDir def testMEDField1(self): + TestMultiFieldShuffleRW1(self) mm=MEDFileMesh.New("Pyfile17.med") mm.write("Pyfile17_bis.med",2) ff=MEDFileFieldMultiTS("Pyfile17.med") @@ -484,6 +489,7 @@ class MEDLoaderTest3(unittest.TestCase): #profiles @WriteInTmpDir def testMEDField2(self): + GeneratePyfile19(self) mm=MEDFileMesh.New("Pyfile19.med") mm.write("Pyfile19_bis.med",2) ff=MEDFileFieldMultiTS.New("Pyfile19.med") @@ -494,6 +500,7 @@ class MEDLoaderTest3(unittest.TestCase): #gauss points @WriteInTmpDir def testMEDField3(self): + GeneratePyfile13(self) mm=MEDFileMesh.New("Pyfile13.med") mm.write("Pyfile13_bis.med",2) ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint") @@ -513,6 +520,7 @@ class MEDLoaderTest3(unittest.TestCase): #gauss NE @WriteInTmpDir def testMEDField4(self): + GeneratePyfile14(self) mm=MEDFileMesh.New("Pyfile14.med") mm.write("Pyfile14_bis.med",2) ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE") @@ -526,6 +534,7 @@ class MEDLoaderTest3(unittest.TestCase): # MEDField get/set on pointe.med @WriteInTmpDir def testMEDField5(self): + TestMultiFieldShuffleRW1(self) ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2) f=ff.getFieldAtLevel(ON_CELLS,0) f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2) @@ -548,12 +557,14 @@ class MEDLoaderTest3(unittest.TestCase): # MEDField get/set on profiles nodes @WriteInTmpDir def testMEDField6(self): + GeneratePyfile7(self) ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes") its=ff.getIterations() self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0) f2=ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1]) self.assertTrue(f.isEqual(f2,1e-12,1e-12)) + GeneratePyfile19(self) ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes") its=ff.getIterations() f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0) @@ -566,6 +577,7 @@ class MEDLoaderTest3(unittest.TestCase): # MEDField get/set on profiles cells @WriteInTmpDir def testMEDField7(self): + GeneratePyfile12(self) ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells") its=ff.getIterations() f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0) @@ -1067,6 +1079,7 @@ class MEDLoaderTest3(unittest.TestCase): @WriteInTmpDir def testMEDFieldBug1(self): + GeneratePyfile13(self) fname="Pyfile13.med" d=MEDFileData.New(fname) self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs()) @@ -1357,6 +1370,7 @@ class MEDLoaderTest3(unittest.TestCase): mm.write(fname,2) pass + @WriteInTmpDir def testBuildInnerBoundaryAlongM1Group2(self): fname="Pyfile45.med" m=MEDCouplingCMesh.New() @@ -1567,6 +1581,7 @@ class MEDLoaderTest3(unittest.TestCase): @WriteInTmpDir def testBasicConstructors(self): + GeneratePyfile18(self) fname="Pyfile18.med" TestWriteUMeshesRW1(self) m=MEDFileMesh.New(fname) @@ -2267,8 +2282,7 @@ class MEDLoaderTest3(unittest.TestCase): self.assertIn(fff[1, -1].getHeapMemorySize(), list(range(738 - 50, 838 + 30 + 4 * strMulFac))) pass - @WriteInTmpDir - def testCurveLinearMesh1(self): + def internalCurveLinearMesh1(self): fname="Pyfile55.med" mesh=MEDCouplingCurveLinearMesh(); mesh.setTime(2.3,4,5); @@ -2307,9 +2321,16 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(len(m1.getUnivName())!=0) self.assertTrue(m1.getMesh().isEqual(mesh,1e-12)) pass + + @WriteInTmpDir + def testCurveLinearMesh1(self): + self.internalCurveLinearMesh1() @WriteInTmpDir def testParameters1(self): + self.internalParameters1() + + def internalParameters1(self): fname="Pyfile56.med" m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh") mm=MEDFileCMesh() ; mm.setMesh(m) @@ -2681,9 +2702,12 @@ class MEDLoaderTest3(unittest.TestCase): pass pass pass - + @WriteInTmpDir def testInt32InMEDFileFieldStar1(self): + self.internalInt32InMEDFileFieldStar1() + + def internalInt32InMEDFileFieldStar1(self): fname="Pyfile63.med" f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); f1=f1.convertToIntField() @@ -3641,6 +3665,7 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))) pass + @WriteInTmpDir def testWRQPolyg1(self): fname="Pyfile72.med" m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells() @@ -6003,7 +6028,7 @@ class MEDLoaderTest3(unittest.TestCase): @WriteInTmpDir def testPickelizationOfMEDFileObjects2(self): # CMesh - self.testMEDMesh6() # generates MEDFileMesh5.med file + self.internalMEDMesh6() # generates MEDFileMesh5.med file mm=MEDFileMesh.New("MEDFileMesh5.med") self.assertTrue(isinstance(mm,MEDFileCMesh)) st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL) @@ -6011,14 +6036,14 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(isinstance(mm2,MEDFileCMesh)) self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12)) # CurveLinear - self.testCurveLinearMesh1() # generates Pyfile55.med + self.internalCurveLinearMesh1() # generates Pyfile55.med mm=MEDFileMesh.New("Pyfile55.med") self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh)) st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL) mm3=pickle.loads(st) self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh)) self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12)) - self.testInt32InMEDFileFieldStar1()# generates Pyfile63.med + self.internalInt32InMEDFileFieldStar1()# generates Pyfile63.med # MEDFileIntFieldMultiTS fs4=MEDFileFields("Pyfile63.med") ms4=MEDFileMeshes("Pyfile63.med") @@ -6034,7 +6059,7 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS)) self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0)) # MEDFileParameters - self.testParameters1()# generates Pyfile56.med + self.internalParameters1()# generates Pyfile56.med params=MEDFileParameters("Pyfile56.med") st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL) params7=pickle.loads(st) @@ -6337,6 +6362,7 @@ class MEDLoaderTest3(unittest.TestCase): @WriteInTmpDir def testFieldsLinearToQuadratic2(self): """Same than testFieldsLinearToQuadratic but with profile on NODES""" + GeneratePyfile18(self) fname="Pyfile118.med" arr=DataArrayDouble([0,1]) m=MEDCouplingCMesh();