Back to index

salome-med  6.5.0
Public Member Functions
MEDLoaderTest2.MEDLoaderTest Class Reference

List of all members.

Public Member Functions

def testMesh1DRW
def testMesh2DCurveRW
def testMesh2DRW
def testMesh3DSurfRW
def testMesh3DRW
def testFieldRW1
def testFieldRW2
def testFieldRW3
def testMultiMeshRW1
def testMesh3DSurfShuffleRW
def testMultiFieldShuffleRW1
def testWriteUMeshesRW1

Detailed Description

Definition at line 26 of file MEDLoaderTest2.py.


Member Function Documentation

Definition at line 67 of file MEDLoaderTest2.py.

00067 
00068     def testFieldRW1(self):
00069         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00070         MEDLoader.WriteFieldDep("Pyfile6.med",f1,False);
00071         f2=MEDLoader.ReadFieldCell("Pyfile6.med",f1.getMesh().getName(),0,f1.getName(),0,1);
00072         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00073         #
00074         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00075         MEDLoader.WriteFieldDep("Pyfile7.med",f1,False);
00076         f2=MEDLoader.ReadFieldNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3);
00077         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00078         pass

Definition at line 79 of file MEDLoaderTest2.py.

00079 
00080     def testFieldRW2(self):
00081         fileName="Pyfile8.med";
00082         VAL1=12345.67890314;
00083         VAL2=-1111111111111.;
00084         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00085         MEDLoader.WriteFieldDep(fileName,f1,False);
00086         f1.setTime(10.,8,9);
00087         f1.getArray().setIJ(0,0,VAL1);
00088         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00089         f1.setTime(10.14,18,19);
00090         f1.getArray().setIJ(0,0,VAL2);
00091         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00092         #retrieving time steps...
00093         f2=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.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.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         #ON NODES
00105         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00106         fileName2="Pyfile9.med";
00107         MEDLoader.WriteFieldDep(fileName2,f1,False);
00108         f1.setTime(110.,108,109);
00109         tmp=f1.getArray().getPointer();
00110         f1.getArray().setIJ(0,3,VAL1);
00111         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
00112         f1.setTime(210.,208,209);
00113         f1.getArray().setIJ(0,3,VAL2);
00114         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
00115         f2=MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),108,109);
00116         f1.setTime(110.,108,109);
00117         f1.getArray().setIJ(0,3,VAL1);
00118         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00119         f2=MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),2,3);
00120         f3=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00121         self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
00122         f2=MEDLoader.ReadFieldNode(fileName2,f1.getMesh().getName(),0,f1.getName(),208,209);
00123         f1.setTime(210.,208,209);
00124         f1.getArray().setIJ(0,3,VAL2);
00125         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
00126         pass

Definition at line 130 of file MEDLoaderTest2.py.

00130 
00131     def testFieldRW3(self):
00132         fileName="Pyfile11.med";
00133         VAL1=12345.67890314;
00134         VAL2=-1111111111111.;
00135         name1="AField";
00136         name3="AMesh1";
00137         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00138         f1.getMesh().setName(name3);
00139         f1.setName(name1);
00140         f1.setTime(10.,8,9);
00141         tmp=f1.getArray().getPointer();
00142         f1.getArray().setIJ(0,0,VAL1);
00143         MEDLoader.WriteFieldDep(fileName,f1,False);
00144         f1.setTime(10.14,18,19);
00145         f1.getArray().setIJ(0,0,VAL2);
00146         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00147         f1.getMesh().setName(name3);
00148         f1.setTime(10.55,28,29);
00149         f1.getArray().setIJ(0,0,3*VAL1);
00150         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00151         f1.setTime(10.66,38,39);
00152         f1.getArray().setIJ(0,0,3*VAL2);
00153         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00154         f1.setTime(10.77,48,49);
00155         f1.getArray().setIJ(0,0,4*VAL2);
00156         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00157         #ON NODES
00158         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00159         f1.setName(name1);
00160         f1.getMesh().setName(name3);
00161         f1.setTime(110.,8,9);
00162         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00163         f1.setTime(110.,108,109);
00164         tmp=f1.getArray().getPointer();
00165         f1.getArray().setIJ(0,3,VAL1);
00166         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00167         f1.setTime(210.,208,209);
00168         f1.getArray().setIJ(0,3,VAL2);
00169         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00170         #
00171         it1=MEDLoader.GetCellFieldIterations(fileName,name3,name1);
00172         self.assertEqual(5,len(it1));
00173         self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]);
00174         self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]);
00175         self.assertEqual(28,it1[2][0]); self.assertEqual(29,it1[2][1]);
00176         self.assertEqual(38,it1[3][0]); self.assertEqual(39,it1[3][1]);
00177         self.assertEqual(48,it1[4][0]); self.assertEqual(49,it1[4][1]);
00178         it3=MEDLoader.GetNodeFieldIterations(fileName,name3,name1);
00179         self.assertEqual(3,len(it3));
00180         self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]);
00181         self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]);
00182         self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]);
00183         #
00184         #
00185         f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9);
00186         self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13);
00187         f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19);
00188         self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13);
00189         f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,28,29);
00190         self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13);
00191         f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,38,39);
00192         self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13);
00193         f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,48,49);
00194         self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13);
00195         #
00196         f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,8,9);
00197         self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13);
00198         f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,108,109);
00199         self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13);
00200         f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,208,209);
00201         self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13);
00202         pass

Definition at line 27 of file MEDLoaderTest2.py.

00027 
00028     def testMesh1DRW(self):
00029         mesh=MEDLoaderDataForTest.build1DMesh_1();
00030         mesh.checkCoherency();
00031         MEDLoader.WriteUMeshDep("Pyfile1.med",mesh,False);
00032         mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile1.med",mesh.getName(),0);
00033         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00034         pass

Definition at line 35 of file MEDLoaderTest2.py.

00035 
00036     def testMesh2DCurveRW(self):
00037         mesh=MEDLoaderDataForTest.build2DCurveMesh_1();
00038         mesh.checkCoherency();
00039         MEDLoader.WriteUMeshDep("Pyfile2.med",mesh,False);
00040         mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile2.med",mesh.getName(),0);
00041         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00042         pass

Definition at line 43 of file MEDLoaderTest2.py.

00043 
00044     def testMesh2DRW(self):
00045         mesh=MEDLoaderDataForTest.build2DMesh_1();
00046         mesh.checkCoherency();
00047         MEDLoader.WriteUMeshDep("Pyfile3.med",mesh,False);
00048         mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile3.med",mesh.getName(),0);
00049         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00050         pass

Definition at line 59 of file MEDLoaderTest2.py.

00059 
00060     def testMesh3DRW(self):
00061         mesh=MEDLoaderDataForTest.build3DMesh_1();
00062         mesh.checkCoherency();
00063         MEDLoader.WriteUMeshDep("Pyfile5.med",mesh,False);
00064         mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile5.med",mesh.getName(),0);
00065         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00066         pass

Definition at line 51 of file MEDLoaderTest2.py.

00051 
00052     def testMesh3DSurfRW(self):
00053         mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
00054         mesh.checkCoherency();
00055         MEDLoader.WriteUMeshDep("Pyfile4.med",mesh,False);
00056         mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile4.med",mesh.getName(),0);
00057         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00058         pass

Definition at line 257 of file MEDLoaderTest2.py.

00257 
00258     def testMesh3DSurfShuffleRW(self):
00259         fileName="Pyfile15.med";
00260         mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
00261         renumber1=[2,5,1,0,3,4]
00262         mesh.renumberCells(renumber1,False);
00263         mesh.checkCoherency();
00264         MEDLoader.WriteUMeshDep(fileName,mesh,False);
00265         mesh_rw=MEDLoader.ReadUMeshFromFile(fileName,mesh.getName(),0);
00266         self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
00267         pass

Definition at line 268 of file MEDLoaderTest2.py.

00268 
00269     def testMultiFieldShuffleRW1(self):
00270         fileName="Pyfile17.med";
00271         m=MEDLoaderDataForTest.build3DMesh_2();
00272         self.assertEqual(20,m.getNumberOfCells());
00273         self.assertEqual(45,m.getNumberOfNodes());
00274         polys=[1,4,6]
00275         m.convertToPolyTypes(polys);
00276         renum=[1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11]
00277         m.renumberCells(renum,False);
00278         m.orientCorrectlyPolyhedrons();
00279         # Writing
00280         MEDLoader.WriteUMeshDep(fileName,m,False);
00281         f1Tmp=m.getMeasureField(False);
00282         f1=f1Tmp.buildNewTimeReprFromThis(ONE_TIME,False);
00283         f1.setTime(0.,1,2);
00284         f_1=f1.cloneWithMesh(True);
00285         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00286         f1.applyFunc("2*x");
00287         f1.setTime(0.01,3,4);
00288         f_2=f1.cloneWithMesh(True);
00289         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00290         f1.applyFunc("2*x/3");
00291         f1.setTime(0.02,5,6);
00292         f_3=f1.cloneWithMesh(True);
00293         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00294         # Reading
00295         its=[(1,2),(3,4),(5,6)];
00296         fs=MEDLoader.ReadFieldsOnSameMesh(ON_CELLS,fileName,f_1.getMesh().getName(),0,f_1.getName(),its);
00297         self.assertEqual(3,len(fs));
00298         self.assertTrue(fs[0].isEqual(f_1,1e-12,1e-12));
00299         self.assertTrue(fs[1].isEqual(f_2,1e-12,1e-12));
00300         self.assertTrue(fs[2].isEqual(f_3,1e-12,1e-12));
00301         pass

Definition at line 203 of file MEDLoaderTest2.py.

00203 
00204     def testMultiMeshRW1(self):
00205         fileName="Pyfile10.med";
00206         mesh1=MEDLoaderDataForTest.build3DMesh_1();
00207         part1=[1,2,4,13,15]
00208         mesh2=mesh1.buildPartOfMySelf(part1,True);
00209         mesh2.setName("mesh2");
00210         part2=[3,4,13,14]
00211         mesh3=mesh1.buildPartOfMySelf(part2,True);
00212         mesh3.setName("mesh3");
00213         mesh4=MEDCouplingUMesh.New();
00214         mesh4.setName("mesh4");
00215         mesh4.setMeshDimension(3);
00216         mesh4.allocateCells(1);
00217         conn=[0,11,1,3]
00218         mesh4.insertNextCell(NORM_TETRA4,4,conn[0:4])
00219         mesh4.finishInsertingCells();
00220         mesh4.setCoords(mesh1.getCoords());
00221         meshes=[mesh1,mesh2,mesh3,mesh4]
00222         mnane="3DToto";
00223         MEDLoader.WriteUMeshesPartitionDep(fileName,mnane,meshes,False);
00224         #
00225         mesh5=MEDLoader.ReadUMeshFromFile(fileName,mnane);
00226         mesh1.setName(mnane);
00227         part3=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
00228         mesh6=mesh5.buildPartOfMySelf(part3,True);
00229         mesh6.setName(mnane);
00230         self.assertTrue(mesh6.isEqual(mesh1,1e-12));
00231         grps=MEDLoader.GetMeshGroupsNames(fileName,mnane);
00232         self.assertEqual(4,len(grps));
00233         grps.index("mesh2");
00234         grps.index("mesh3");
00235         grps.index("mesh4");
00236         grps.index("3DMesh_1");
00237         #
00238         vec=["mesh2"];
00239         mesh2_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00240         self.assertTrue(mesh2_2.isEqual(mesh2,1e-12));
00241         vec=["mesh3"];
00242         mesh3_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00243         self.assertTrue(mesh3_2.isEqual(mesh3,1e-12));
00244         vec=["mesh4"];
00245         mesh4_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00246         self.assertTrue(mesh4_2.isEqual(mesh4,1e-12));
00247         vec=["3DMesh_1"];
00248         mesh1_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
00249         mesh1.setName("3DMesh_1");
00250         self.assertTrue(mesh1_2.isEqual(mesh1,1e-12));
00251         #
00252         vec=["Family_4","Family_2"];
00253         mesh2_2=MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec);
00254         mesh2_2.setName("mesh2");
00255         self.assertTrue(mesh2_2.isEqual(mesh2,1e-12));
00256         pass

Definition at line 302 of file MEDLoaderTest2.py.

00302 
00303     def testWriteUMeshesRW1(self):
00304         fileName="Pyfile18.med";
00305         m3d=MEDLoaderDataForTest.build3DMesh_2();
00306         pt=[0.,0.,-0.3]
00307         vec=[0.,0.,1.]
00308         nodes=m3d.findNodesOnPlane(pt,vec,1e-12);
00309         m2d=m3d.buildFacePartOfMySelfNode(nodes,True);
00310         renumber=[1,2,0,4,3]
00311         m2d.renumberCells(renumber,False);
00312         m2d.setName("ExampleOfMultiDimW");
00313         meshes=[m2d,m3d]
00314         MEDLoader.WriteUMeshes(fileName,meshes,False);
00315         m3d_bis=MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),0);
00316         self.assertTrue(not m3d_bis.isEqual(m3d,1e-12));
00317         m3d_bis.setName(m3d.getName());
00318         self.assertTrue(m3d_bis.isEqual(m3d,1e-12));
00319         m2d_bis=MEDLoader.ReadUMeshFromFile(fileName,m2d.getName(),-1);#-1 for faces
00320         self.assertTrue(m2d_bis.isEqual(m2d,1e-12));
00321         # Creation of a field on faces.
00322         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
00323         f1.setName("FieldOnFacesShuffle");
00324         f1.setMesh(m2d);
00325         array=DataArrayDouble.New();
00326         arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.]
00327         array.setValues(arr1,m2d.getNumberOfCells(),2);
00328         array.setInfoOnComponent(0,"plkj [mm]");
00329         array.setInfoOnComponent(1,"pqqqss [mm]");
00330         f1.setArray(array);
00331         tmp=array.setValues(arr1,m2d.getNumberOfCells(),2);
00332         f1.setTime(3.14,2,7);
00333         f1.checkCoherency();
00334         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
00335         f2=MEDLoader.ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7);
00336         self.assertTrue(f2.isEqual(f1,1e-12,1e-12));
        pass

The documentation for this class was generated from the following file: