Salome HOME
Move medtool folder to MED base repository
[modules/med.git] / doc / tutorial / atestMEDCouplingRead.rst
1
2 .. _python_testMEDCouplingRead_solution:
3
4 Read med File
5 ~~~~~~~~~~~~~~~~~~~
6
7 ::
8
9         from MEDCoupling import *
10         from MEDLoader import *
11
12
13         medFileName = "MEDCoupling_cube3D.med"
14         MeshName = "3Dcube"
15         FieldName = "field"
16         Field2DName = "fieldBottomFace"
17
18         # Retrieving meshes
19         mesh3D = MEDLoader.ReadUMeshFromFile(medFileName,MeshName,0)
20         mesh2D = MEDLoader.ReadUMeshFromFile(medFileName,MeshName,-1)
21
22         # Retrieving fields
23         f = MEDLoader.ReadFieldCell(medFileName,mesh3D.getName(),0,FieldName,-1,-1)
24         f2 = MEDLoader.ReadFieldCell(medFileName,mesh2D.getName(),-1,Field2DName,-1,-1)
25
26         # Retrieving Coords Mesh
27         Coords3D = mesh3D.getCoords()
28         Values = Coords3D.getValuesAsTuple()
29
30         # Retrieving field value on 0 tuple
31         pos= Values[0]
32         res=f.getValueOn(pos)
33
34         # Verify if value is OK
35         bar = mesh3D.getBarycenterAndOwner()
36         x=bar.getIJ(1,1)
37         y=bar.getIJ(1,2)
38         z=bar.getIJ(1,3)
39
40         from math import *
41         d = sqrt(x*x+y*y+z*z)
42         sinus = sin(d)
43
44         if abs(res[0]-sinus)<1.e-5:
45                 print "OK"
46         else:
47                 print "KO"