Back to index

salome-med  6.5.0
Advanced MEDLoader API.

This method is much closer to MED file organization than basic MEDLoader API.

All MED file concepts are exposed to the user. As a consequence, this advanced API is lead to change with MED file data model enhancement.

In reading mode, the user can scan entirely and directly the content of its MED file as it is organized in its MED file. Inversely, in writing mode, the user can describe its data in the same way that MED file does.

Some of basic parameters appearing in advanced API

A mesh containing MED_TETRA4, MED_TRI3, MED_QUAD4 and MED_POINT1 has a meshDimension equal to 3. For meshDimRelToMax equal to 0 the user will deal with cells whose type has a dimension equal to 3+0, that is to say here MED_TETRA4. For meshDimRelToMax equal to -1 the user will deal with cells witch dimension equal to 3-1 that is to say MED_TRI3 and MED_QUAD4.

An important method is getNonEmptyLevels() method. It returns all non empty levels available. In the previous example, this method will return {0,-1,-3}. -2 does not appear because no cells with dimension equal to 1 (3-2) appear in MED file mesh (no MED_SEG2 not MED_SEG3).

The parameter of meshDimRelToMaxExt appears in umesh advanced API of MEDLoader with the following semantics.

Some of MED file concepts are available both for cells and nodes, (for example families, groups, numbering ) that's why for a simpler API this concept has been introduced. meshDimRelToMaxExt parameter can take a value in at most {1,0,-1,-2,-3}. 1 stands for node and 0,-1,-2,-3 has exactly the same semantic than those described in meshDimRelToMax decribed before.

If such renumbering exists and the renum parameter is set to true, then the renumbering is taken into account. This is exactly the behaviour of basic MEDLoader API. If the user expects to ignore this renumbering even in case of presence of renumbering array, false should be passed to renum parameter. The parameter renum should be set with cauton for users concerned by cells orders.

Reading from a file with advanced API.

Contrary to the basic MEDLoader API, here after reading process, the user has to deal with a new instance of class that fits the MED file model. To access to a MEDCoupling mesh the user should request this class instance.

Reading a mesh.

The class that incarnates Read/Write mesh in MED file is ParaMEDMEM::MEDFileUMesh.

First of all, like basic MEDLoader API, only MEDfile files whose version >= 2.2 are able to be read with advanced API.

To read a mesh having the name meshName in file fileName the following simple code has to be written :

MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName,meshName);

If the user do not know the name of the mesh inside MED file 'fileName' the following code should be written :

MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName);

In this case the first mesh (in MED file sense) found in fileName file will be loaded.

Now the user can ask for mesh dimension of of myMedMesh instance by calling myMedMesh->getMeshDimension(). This method returns the highest level of present cell in MED file mesh myMedMesh. This returned integer is computed and not those contained in MED file that can be invalid.

An important point is that families and groups are not sorted in MED file. No sort is stored in MED file explicitely for Groups and Families. Advanced MEDLoader API, uses the same order than underlying mesh at specified level.

Sample of reading a mesh.

Here a typical use of MEDCouplingUMesh instance.

const char fileName[]=...;
const char meshName[]=...;
MEDFileUMesh *medmesh=MEDFileUMesh::New(fileName,meshName);
std::vector<int> nel=medmesh->getNonEmptyLevels();
  throw INTERP_KERNEL::Exception("The test is not good for my file ! Expecting a multi level mesh to play with !");
MEDCouplingUMesh *m0=medmesh->getMeshAtLevel(nel[1],false);
MEDCouplingUMesh *g1=medmesh->getGroup(nel[1],"mesh2",false);
DataArrayInt *dag1=medmesh->getGroupArr(nel[1],"mesh2",false);
MEDCouplingUMesh *g1bis=m0->buildPartOfMySelf(dag1->getConstPointer(),dag1->getConstPointer()+dag1->getNbOfElems());
  throw INTERP_KERNEL::Exception("hmmmm :g1 and g1bis should be equal...");

Writing a mesh.

The use is very symetric to reading part. It is possible to either build a MEDFileUMesh instance from scratch, or to work with an existing instance coming from a loading from a file.

One important point is that coordinates of a mesh are shared by all cells whatever their level. That's why the DataArrayDouble instance should be shared by all MEDCouplingUMesh used in input parameter of set* methods. If the user intend to build a MEDFileUMesh instance from scratch, a call to setCoords should be done first.

Generally speaking traduce get* methods with set* methods have corresponding write semantic.

Some differences still exist :

Sample of writing a mesh.

MEDCouplingUMesh *m=...; //m is a mesh with meshDim=2 spaceDim=2
MEDCouplingUMesh *m1=...; //m1 is a mesh with meshDim=1 spaceDim=2 same coords than m
MEDCouplingUMesh *m2=...; //m2 is a mesh with meshDim=0 spaceDim=2 same coords than m
MEDFileUMesh *mm=MEDFileUMesh::New();
mm->setName("mm");//name needed to be non empty
mm->setDescription("Description mm");
DataArrayInt *g1=DataArrayInt::New();
const int val1[2]={1,3};
DataArrayInt *g2=DataArrayInt::New();
const int val2[3]={1,2,3};
std::vector<const DataArrayInt *> grps(2);
grps[0]=g1; grps[1]=g2;