8 The MEDLoader class also allows to read a med file.
10 We will use the case of the 3D cube in order to retrieve all meshes and fields along with value on one node.
12 Beginning of implementation
13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 To implement this exercice we use the python language script and import the MEDCoupling and MEDLoader parts of the MED module. We need also mathematical functions, so we import the python math module::
17 from MEDCoupling import *
18 from MEDLoader import *
22 Then define some variables::
24 medFileName = "MEDCoupling_cube3D.med"
27 Field2DName = "fieldBottomFace"
29 Retrieving 3D mesh and associated field
30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32 You need to use MEDLoader API in order to read med file. Read functions need to give the real dimension of the mesh to max.
33 This information is given by a number : 0,-1 or -2.
35 * 0 means the high dimension of the mesh
36 * -1 means the second high dimension of the mesh
38 and the iteration and order of the field. In our case, since there is no iteration, it's -1 for these 2 arguments::
40 mesh3D = MEDLoader.ReadUMeshFromFile(medFileName,MeshName,0)
41 f = MEDLoader.ReadFieldCell(medFileName,mesh3D.getName(),0,FieldName,-1,-1)
44 Retrieving 2D mesh and associated field
45 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47 Do the same thing for the 2D mesh and the associated field::
49 mesh2D = MEDLoader.ReadUMeshFromFile(...)
50 f2 = MEDLoader.ReadFieldCell(...)
52 Retrieving mesh coords
53 ~~~~~~~~~~~~~~~~~~~~~~
57 # Retrieving Coords Mesh
58 Coords3D = mesh3D.getCoords()
59 Values = Coords3D.getValuesAsTuple()
61 Retrieving field values
62 ~~~~~~~~~~~~~~~~~~~~~~~~
66 # Retrieving field value on 0 tuple
70 # Verify if value is OK
71 bar = mesh3D.computeCellCenterOfMass()
80 if abs(res[0]-sinus)<1.e-5:
88 :ref:`python_testMEDCouplingRead_solution`