Back to index

salome-med  6.5.0
MEDLoaderTest.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 
00021 import MEDLoader
00022 import unittest
00023 from math import pi,e,sqrt
00024 from MEDLoaderDataForTest import MEDLoaderDataForTest
00025 
00026 class MEDLoaderTest(unittest.TestCase):
00027     def testMesh1DRW(self):
00028         mesh=MEDLoaderDataForTest.build1DMesh_1();
00029         mesh.checkCoherency();
00030         MEDLoader.MEDLoader.WriteUMesh("Pyfile1.med",mesh,True);
00031         mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile1.med",mesh.getName(),0);
00032         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00033         pass
00034 
00035     def testMesh2DCurveRW(self):
00036         mesh=MEDLoaderDataForTest.build2DCurveMesh_1();
00037         mesh.checkCoherency();
00038         MEDLoader.MEDLoader.WriteUMesh("Pyfile2.med",mesh,True);
00039         mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile2.med",mesh.getName(),0);
00040         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00041         pass
00042 
00043     def testMesh2DRW(self):
00044         mesh=MEDLoaderDataForTest.build2DMesh_1();
00045         mesh.checkCoherency();
00046         MEDLoader.MEDLoader.WriteUMesh("Pyfile3.med",mesh,True);
00047         mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile3.med",mesh.getName(),0);
00048         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00049         pass
00050 
00051     def testMesh3DSurfRW(self):
00052         mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
00053         mesh.checkCoherency();
00054         MEDLoader.MEDLoader.WriteUMesh("Pyfile4.med",mesh,True);
00055         mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile4.med",mesh.getName(),0);
00056         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00057         pass
00058 
00059     def testMesh3DRW(self):
00060         mesh=MEDLoaderDataForTest.build3DMesh_1();
00061         mesh.checkCoherency();
00062         MEDLoader.MEDLoader.WriteUMesh("Pyfile5.med",mesh,True);
00063         mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile("Pyfile5.med",mesh.getName(),0);
00064         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00065         pass
00066 
00067     def testFieldRW1(self):
00068         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00069         MEDLoader.MEDLoader.WriteField("Pyfile6.med",f1,True);
00070         f2=MEDLoader.MEDLoader.ReadFieldCell("Pyfile6.med",f1.getMesh().getName(),0,f1.getName(),0,1);
00071         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00072         #
00073         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00074         MEDLoader.MEDLoader.WriteField("Pyfile7.med",f1,True);
00075         f2=MEDLoader.MEDLoader.ReadFieldNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3);
00076         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00077         self.assertRaises(Exception,MEDLoader.MEDLoader.ReadFieldCell,"Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3);
00078         pass
00079 
00080     def testFieldRW2(self):
00081         fileName="Pyfile8.med";
00082         VAL1=12345.67890314;
00083         VAL2=-1111111111111.;
00084         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00085         MEDLoader.MEDLoader.WriteField(fileName,f1,True);
00086         f1.setTime(10.,8,9);
00087         f1.getArray().setIJ(0,0,VAL1);
00088         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00089         f1.setTime(10.14,18,19);
00090         f1.getArray().setIJ(0,0,VAL2);
00091         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00092         #retrieving time steps...
00093         f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),8,9);
00094         f1.setTime(10.,8,9);
00095         f1.getArray().setIJ(0,0,VAL1);
00096         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00097         f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),0,1);
00098         f3=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00099         self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
00100         f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),18,19);
00101         f1.setTime(10.14,18,19);
00102         f1.getArray().setIJ(0,0,VAL2);
00103         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00104         #test of throw on invalid (dt,it)
00105         self.assertRaises(Exception,MEDLoader.MEDLoader.ReadFieldCell,fileName,f1.getMesh().getName(),0,f1.getName(),28,19);
00106         #ON NODES
00107         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00108         fileName2="Pyfile9.med";
00109         MEDLoader.MEDLoader.WriteField(fileName2,f1,True);
00110         f1.setTime(110.,108,109);
00111         tmp=f1.getArray().getPointer();
00112         f1.getArray().setIJ(0,3,VAL1);
00113         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
00114         f1.setTime(210.,208,209);
00115         f1.getArray().setIJ(0,3,VAL2);
00116         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
00117         f2=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),108,109);
00118         f1.setTime(110.,108,109);
00119         f1.getArray().setIJ(0,3,VAL1);
00120         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00121         f2=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),2,3);
00122         f3=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00123         self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
00124         f2=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),208,209);
00125         f1.setTime(210.,208,209);
00126         f1.getArray().setIJ(0,3,VAL2);
00127         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00128         pass
00129 
00130     #
00131     # Multi field in a same file, but this field has several
00132     #
00133     def testFieldRW3(self):
00134         fileName="Pyfile11.med";
00135         VAL1=12345.67890314;
00136         VAL2=-1111111111111.;
00137         name1="AField";
00138         name3="AMesh1";
00139         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00140         f1.getMesh().setName(name3);
00141         f1.setName(name1);
00142         f1.setTime(10.,8,9);
00143         tmp=f1.getArray().getPointer();
00144         f1.getArray().setIJ(0,0,VAL1);
00145         MEDLoader.MEDLoader.WriteField(fileName,f1,True);
00146         f1.setTime(10.14,18,19);
00147         f1.getArray().setIJ(0,0,VAL2);
00148         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00149         f1.getMesh().setName(name3);
00150         f1.setTime(10.55,28,29);
00151         f1.getArray().setIJ(0,0,3*VAL1);
00152         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00153         vec=MEDLoader.MEDLoader.GetMeshNamesOnField(fileName,name1);
00154         f1.setTime(10.66,38,39);
00155         f1.getArray().setIJ(0,0,3*VAL2);
00156         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00157         f1.setTime(10.77,48,49);
00158         f1.getArray().setIJ(0,0,4*VAL2);
00159         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00160         #ON NODES
00161         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00162         f1.setName(name1);
00163         f1.getMesh().setName(name3);
00164         f1.setTime(110.,8,9);
00165         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00166         f1.setTime(110.,108,109);
00167         tmp=f1.getArray().getPointer();
00168         f1.getArray().setIJ(0,3,VAL1);
00169         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00170         f1.setTime(210.,208,209);
00171         f1.getArray().setIJ(0,3,VAL2);
00172         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00173         #
00174         it1=MEDLoader.MEDLoader.GetCellFieldIterations(fileName,name3,name1);
00175         self.assertEqual(5,len(it1));
00176         self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]);
00177         self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]);
00178         self.assertEqual(28,it1[2][0]); self.assertEqual(29,it1[2][1]);
00179         self.assertEqual(38,it1[3][0]); self.assertEqual(39,it1[3][1]);
00180         self.assertEqual(48,it1[4][0]); self.assertEqual(49,it1[4][1]);
00181         it3=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name3,name1);
00182         self.assertEqual(3,len(it3));
00183         self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]);
00184         self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]);
00185         self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]);
00186         #
00187         #
00188         f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9);
00189         self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13);
00190         f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19);
00191         self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13);
00192         f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,28,29);
00193         self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13);
00194         f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,38,39);
00195         self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13);
00196         f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,48,49);
00197         self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13);
00198         #
00199         f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,8,9);
00200         self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13);
00201         f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,108,109);
00202         self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13);
00203         f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,208,209);
00204         self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13);
00205         pass
00206 
00207     def testMultiMeshRW1(self):
00208         fileName="Pyfile10.med";
00209         mesh1=MEDLoaderDataForTest.build3DMesh_1();
00210         part1=[1,2,4,13,15]
00211         mesh2=mesh1.buildPartOfMySelf(part1,True);
00212         mesh2.setName("mesh2");
00213         part2=[3,4,13,14]
00214         mesh3=mesh1.buildPartOfMySelf(part2,True);
00215         mesh3.setName("mesh3");
00216         mesh4=MEDLoader.MEDCouplingUMesh.New();
00217         mesh4.setName("mesh4");
00218         mesh4.setMeshDimension(3);
00219         mesh4.allocateCells(1);
00220         conn=[0,11,1,3]
00221         mesh4.insertNextCell(MEDLoader.NORM_TETRA4,4,conn[0:4])
00222         mesh4.finishInsertingCells();
00223         mesh4.setCoords(mesh1.getCoords());
00224         meshes=[mesh1,mesh2,mesh3,mesh4]
00225         mnane="3DToto";
00226         MEDLoader.MEDLoader.WriteUMeshesPartition(fileName,mnane,meshes,True);
00227         #
00228         mesh5=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,mnane);
00229         mesh1.setName(mnane);
00230         part3=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
00231         mesh6=mesh5.buildPartOfMySelf(part3,True);
00232         mesh6.setName(mnane);
00233         self.assertTrue(mesh6.isEqual(mesh1,1e-12));
00234         grps=MEDLoader.MEDLoader.GetMeshGroupsNames(fileName,mnane);
00235         self.assertEqual(4,len(grps));
00236         grps.index("mesh2");
00237         grps.index("mesh3");
00238         grps.index("mesh4");
00239         grps.index("3DMesh_1");
00240         #
00241         vec=("mesh2",);
00242         mesh2_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00243         self.assertTrue(mesh2_2.isEqual(mesh2,1e-12));
00244         vec=["mesh3"];
00245         mesh3_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00246         self.assertTrue(mesh3_2.isEqual(mesh3,1e-12));
00247         vec=["mesh4"];
00248         mesh4_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00249         self.assertTrue(mesh4_2.isEqual(mesh4,1e-12));
00250         vec="3DMesh_1";
00251         mesh1_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00252         mesh1.setName("3DMesh_1");
00253         self.assertTrue(mesh1_2.isEqual(mesh1,1e-12));
00254         #
00255         vec=["Family_4","Family_2"];
00256         mesh2_2=MEDLoader.MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec);
00257         mesh2_2.setName("mesh2");
00258         self.assertTrue(mesh2_2.isEqual(mesh2,1e-12));
00259         #
00260         ret=MEDLoader.MEDLoader.GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1");
00261         self.assertEqual(4,len(ret));
00262         self.assertEqual(ret[0],"Family_1");
00263         self.assertEqual(ret[1],"Family_2");
00264         self.assertEqual(ret[2],"Family_3");
00265         self.assertEqual(ret[3],"Family_4");
00266         #
00267         ret1=MEDLoader.MEDLoader.GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_2");
00268         self.assertEqual(2,len(ret1));
00269         self.assertEqual(ret1[0],"3DMesh_1");
00270         self.assertEqual(ret1[1],"mesh2");
00271         pass
00272 
00273     def testFieldProfilRW1(self):
00274         fileName="Pyfile12.med";
00275         mesh1=MEDLoaderDataForTest.build3DMesh_1();
00276         da,b,newNbOfNodes=mesh1.mergeNodes(1e-12);
00277         MEDLoader.MEDLoader.WriteUMesh(fileName,mesh1,True);
00278         part1=[1,2,4,13,15]
00279         mesh2=mesh1.buildPartOfMySelf(part1,True);
00280         mesh2.setName(mesh1.getName());#<- important for the test
00281         #
00282         nbOfCells=mesh2.getNumberOfCells();
00283         self.assertEqual(5,nbOfCells);
00284         f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME);
00285         f1.setName("VectorFieldOnCells");
00286         f1.setMesh(mesh2);
00287         array=MEDLoader.DataArrayDouble.New();
00288         array.alloc(nbOfCells,2);
00289         f1.setArray(array);
00290         arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.]
00291         array.setValues(arr1,nbOfCells,2);
00292         f1.setTime(3.14,2,7);
00293         f1.checkCoherency();
00294         #
00295         MEDLoader.MEDLoader.WriteField(fileName,f1,False);#<- False important for the test
00296         #
00297         f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
00298         tt=MEDLoader.MEDLoader.GetTypesOfField(fileName,f1.getMesh().getName(),f1.getName());
00299         self.assertEqual(tt,[MEDLoader.ON_CELLS]);
00300         f2.checkCoherency();
00301         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00302         #
00303         pass
00304 
00305     def testFieldGaussRW1(self):
00306         fileName="Pyfile13.med";
00307         f1=MEDLoaderDataForTest.buildVecFieldOnGauss_1();
00308         MEDLoader.MEDLoader.WriteField(fileName,f1,True);
00309         f2=MEDLoader.MEDLoader.ReadField(MEDLoader.ON_GAUSS_PT,fileName,f1.getMesh().getName(),0,f1.getName(),1,5);
00310         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00311         pass
00312 
00313     def testFieldGaussNERW1(self):
00314         fileName="Pyfile14.med";
00315         f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
00316         MEDLoader.MEDLoader.WriteField(fileName,f1,True);
00317         f2=MEDLoader.MEDLoader.ReadField(MEDLoader.ON_GAUSS_NE,fileName,f1.getMesh().getName(),0,f1.getName(),1,5);
00318         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00319         pass
00320 
00321     def testMesh3DSurfShuffleRW(self):
00322         fileName="Pyfile15.med";
00323         mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
00324         renumber1=[2,5,1,0,3,4]
00325         mesh.renumberCells(renumber1,False);
00326         mesh.checkCoherency();
00327         MEDLoader.MEDLoader.WriteUMesh(fileName,mesh,True);
00328         mesh_rw=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,mesh.getName(),0);
00329         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00330         pass
00331 
00332     def testMultiFieldShuffleRW1(self):
00333         fileName="Pyfile17.med";
00334         m=MEDLoaderDataForTest.build3DMesh_2();
00335         self.assertEqual(20,m.getNumberOfCells());
00336         self.assertEqual(45,m.getNumberOfNodes());
00337         polys=[1,4,6]
00338         m.convertToPolyTypes(polys);
00339         renum=[1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11]
00340         m.renumberCells(renum,False);
00341         m.orientCorrectlyPolyhedrons();
00342         # Writing
00343         MEDLoader.MEDLoader.WriteUMesh(fileName,m,True);
00344         f1Tmp=m.getMeasureField(False);
00345         f1=f1Tmp.buildNewTimeReprFromThis(MEDLoader.ONE_TIME,False);
00346         f1.setTime(0.,1,2);
00347         f_1=f1.cloneWithMesh(True);
00348         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00349         f1.applyFunc("2*x");
00350         f1.setTime(0.01,3,4);
00351         f_2=f1.cloneWithMesh(True);
00352         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00353         f1.applyFunc("2*x/3");
00354         f1.setTime(0.02,5,6);
00355         f_3=f1.cloneWithMesh(True);
00356         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00357         # Reading
00358         its=[(1,2),(3,4),(5,6)];
00359         fs=MEDLoader.MEDLoader.ReadFieldsOnSameMesh(MEDLoader.ON_CELLS,fileName,f_1.getMesh().getName(),0,f_1.getName(),its);
00360         self.assertEqual(3,len(fs));
00361         self.assertTrue(fs[0].isEqual(f_1,1e-12,1e-12));
00362         self.assertTrue(fs[1].isEqual(f_2,1e-12,1e-12));
00363         self.assertTrue(fs[2].isEqual(f_3,1e-12,1e-12));
00364         pass
00365 
00366     def testWriteUMeshesRW1(self):
00367         fileName="Pyfile18.med";
00368         m3d=MEDLoaderDataForTest.build3DMesh_2();
00369         pt=[0.,0.,-0.3]
00370         vec=[0.,0.,1.]
00371         nodes=m3d.findNodesOnPlane(pt,vec,1e-12);
00372         m2d=m3d.buildFacePartOfMySelfNode(nodes,True);
00373         renumber=[1,2,0,4,3]
00374         m2d.renumberCells(renumber,False);
00375         m2d.setName("ExampleOfMultiDimW");
00376         meshes=[m2d,m3d]
00377         MEDLoader.MEDLoader.WriteUMeshes(fileName,meshes,True);
00378         m3d_bis=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),0);
00379         self.assertTrue(not m3d_bis.isEqual(m3d,1e-12));
00380         m3d_bis.setName(m3d.getName());
00381         self.assertTrue(m3d_bis.isEqual(m3d,1e-12));
00382         m2d_bis=MEDLoader.MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),-1);#-1 for faces
00383         self.assertTrue(m2d_bis.isEqual(m2d,1e-12));
00384         # Creation of a field on faces.
00385         f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME);
00386         f1.setName("FieldOnFacesShuffle");
00387         f1.setMesh(m2d);
00388         array=MEDLoader.DataArrayDouble.New();
00389         arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.]
00390         array.setValues(arr1,m2d.getNumberOfCells(),2);
00391         array.setInfoOnComponent(0,"plkj [mm]");
00392         array.setInfoOnComponent(1,"pqqqss [mm]");
00393         f1.setArray(array);
00394         tmp=array.setValues(arr1,m2d.getNumberOfCells(),2);
00395         f1.setTime(3.14,2,7);
00396         f1.checkCoherency();
00397         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00398         f2=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7);
00399         self.assertTrue(f2.isEqual(f1,1e-12,1e-12));
00400         pass
00401 
00402     def testFieldNodeProfilRW1(self):
00403         fileName="Pyfile19.med";
00404         fileName2="Pyfile20.med";
00405         m=MEDLoaderDataForTest.build2DMesh_1();
00406         nbOfNodes=m.getNumberOfNodes();
00407         MEDLoader.MEDLoader.WriteUMesh(fileName,m,True);
00408         f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME);
00409         f1.setName("VFieldOnNodes");
00410         f1.setMesh(m);
00411         array=MEDLoader.DataArrayDouble.New();
00412         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.]
00413         array.setValues(arr1,nbOfNodes,2);
00414         f1.setArray(array);
00415         array.setInfoOnComponent(0,"tyty [mm]");
00416         array.setInfoOnComponent(1,"uiop [MW]");
00417         f1.setTime(3.14,2,7);
00418         f1.checkCoherency();
00419         arr2=[1,4]
00420         f2=f1.buildSubPart(arr2);
00421         f2.getMesh().setName(f1.getMesh().getName());
00422         MEDLoader.MEDLoader.WriteField(fileName,f2,False);#<- False important for the test
00423         #
00424         f3=MEDLoader.MEDLoader.ReadFieldNode(fileName,f2.getMesh().getName(),0,f2.getName(),2,7);
00425         f3.checkCoherency();
00426         self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
00427         #
00428         arr3=[1,3,0,5,2,4]
00429         f2.renumberNodes(arr3);
00430         MEDLoader.MEDLoader.WriteUMesh(fileName2,m,True);
00431         MEDLoader.MEDLoader.WriteField(fileName2,f2,False);#<- False important for the test
00432         f3=MEDLoader.MEDLoader.ReadFieldNode(fileName2,f2.getMesh().getName(),0,f2.getName(),2,7);
00433         f3.checkCoherency();
00434         self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
00435         #
00436         pass
00437 
00438     def testFieldNodeProfilRW2(self):
00439         fileName="Pyfile23.med";
00440         mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
00441         MEDLoader.MEDLoader.WriteUMesh(fileName,mesh,True);
00442         #
00443         f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME);
00444         f1.setName("FieldMix");
00445         f1.setMesh(mesh);
00446         arr2=[1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
00447               1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.];
00448         array=MEDLoader.DataArrayDouble.New();
00449         array.setValues(arr2,12,2);
00450         f1.setArray(array);
00451         array.setInfoOnComponent(0,"plkj [mm]");
00452         array.setInfoOnComponent(1,"pqqqss [mm]");
00453         tmp=array.getPointer();
00454         f1.setTime(3.17,2,7);
00455         #
00456         renumArr=[3,7,2,1,5,11,10,0,9,6,8,4]
00457         f1.renumberNodes(renumArr);
00458         f1.checkCoherency();
00459         MEDLoader.MEDLoader.WriteField(fileName,f1,False);#<- False important for the test
00460         f2=MEDLoader.MEDLoader.ReadFieldNode(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
00461         self.assertTrue(f2.isEqual(f1,1e-12,1e-12));
00462         #
00463         pass
00464 
00465     def testMixCellAndNodesFieldRW1(self):
00466         fileName="Pyfile21.med";
00467         mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
00468         f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME);
00469         f1.setName("FieldMix");
00470         f1.setMesh(mesh);
00471         array=MEDLoader.DataArrayDouble.New();
00472         f1.setArray(array);
00473         arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.]
00474         array.setValues(arr1,6,2);
00475         array.setInfoOnComponent(0,"plkj [mm]");
00476         array.setInfoOnComponent(1,"pqqqss [mm]");
00477         f1.setTime(3.14,2,7);
00478         f1.checkCoherency();
00479         #
00480         f2=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME);
00481         f2.setName("FieldMix");
00482         f2.setMesh(mesh);
00483         array=MEDLoader.DataArrayDouble.New();
00484         f2.setArray(array);
00485         arr2=[1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
00486               1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.]
00487         array.setValues(arr2,12,2)
00488         array.setInfoOnComponent(0,"plkj [mm]");
00489         array.setInfoOnComponent(1,"pqqqss [mm]");
00490         f2.setTime(3.14,2,7);
00491         f2.checkCoherency();
00492         #
00493         MEDLoader.MEDLoader.WriteField(fileName,f1,True);
00494         ts=MEDLoader.MEDLoader.GetTypesOfField(fileName,f1.getMesh().getName(),f1.getName());
00495         self.assertEqual(1,len(ts));
00496         self.assertEqual(MEDLoader.ON_CELLS,ts[0]);
00497         fs=MEDLoader.MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName());
00498         self.assertEqual(1,len(fs));
00499         self.assertTrue(fs[0]=="FieldMix");
00500         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f2);
00501         fs=MEDLoader.MEDLoader.GetAllFieldNamesOnMesh(fileName,f1.getMesh().getName());
00502         self.assertEqual(1,len(fs));
00503         self.assertTrue(fs[0]=="FieldMix");
00504         #
00505         ts=MEDLoader.MEDLoader.GetTypesOfField(fileName,f1.getMesh().getName(),f1.getName());
00506         self.assertEqual(2,len(ts));
00507         self.assertEqual(MEDLoader.ON_NODES,ts[0]);
00508         self.assertEqual(MEDLoader.ON_CELLS,ts[1]);
00509         #
00510         f3=MEDLoader.MEDLoader.ReadFieldNode(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
00511         self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
00512         f3=MEDLoader.MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
00513         self.assertTrue(f3.isEqual(f1,1e-12,1e-12));
00514         #
00515         pass
00516 
00517     def testGetAllFieldNamesRW1(self):
00518         fileName="Pyfile22.med";
00519         mesh=MEDLoaderDataForTest.build2DMesh_2();
00520         f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_NODES,MEDLoader.ONE_TIME);
00521         f1.setName("Field1");
00522         f1.setTime(3.44,5,6);
00523         f1.setMesh(mesh);
00524         f1.fillFromAnalytic(2,"x+y");
00525         MEDLoader.MEDLoader.WriteField(fileName,f1,True);
00526         f1.setTime(1002.3,7,8);
00527         f1.fillFromAnalytic(2,"x+77.*y");
00528         MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00529         f1.setName("Field2");
00530         MEDLoader.MEDLoader.WriteField(fileName,f1,False);
00531         f1.setName("Field3");
00532         mesh.setName("2DMesh_2Bis");
00533         MEDLoader.MEDLoader.WriteField(fileName,f1,False);
00534         f1=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME);
00535         f1.setName("Field8");
00536         f1.setTime(8.99,7,9);
00537         f1.setMesh(mesh);
00538         f1.fillFromAnalytic(3,"3*x+y");
00539         MEDLoader.MEDLoader.WriteField(fileName,f1,False);
00540         fs=MEDLoader.MEDLoader.GetAllFieldNames(fileName);
00541         self.assertEqual(4,len(fs));
00542         self.assertTrue(fs[0]=="Field1");
00543         self.assertTrue(fs[1]=="Field2");
00544         self.assertTrue(fs[2]=="Field3");
00545         self.assertTrue(fs[3]=="Field8");
00546         pass
00547     pass
00548 
00549 unittest.main()