Introduction
Rationale for Med Memory
The Med data exchange model (DEM in English) is the format used in the Salome platform for communicating data between different components. It manipulates objects that describe the meshes underlying scientific computations and the value fields lying on these meshes. This data exchange can be achieved either through files using the Med-file formalism or directly through memory with the Med Memory (MEDMEM
) library.
The Med libraries are oganized in multiple layers:
- The MED file layer : C and Fortran API to implement mesh and field persistency.
- The MED Memory level C++ API to create and manipulate mesh and field objects in memory.
- Python API generated using SWIG which wraps the complete C++ API of the MED Memory
- CORBA API to simplify distributed computation inside SALOME (Server Side).
- MED Client classes to simplify and optimize interaction of distant objects within the local solver.
Thanks to Med Memory, any component can access a distant mesh or field object. Two codes running on different machines can thus exchange meshes and fields. These meshes and fields can easily be read/written in a Med file format, enabling access to the whole Salome suite of tools (CAD, meshing, Visualization, other components).
Outline
In this document, we describe the API of the Med Memory library (available in C++ and in Python). This document is intended for developers who are in charge of integrating existing applications in the Salome platform.
As will be seen in section Med Memory API, the API consists of very few classes:
- a general MED container : MED object,
- meshes : MESH ,
- structured meshes : GRID ,
- supports and derived classes : SUPPORT ,
- mesh generation tool : MESHING ,
- fields : FIELD ,
- drivers for reading and writing in MED, GIBI and VTK files.
All these are detailed in the following sections. The C++ formalism will be used for the description in these sections. Python syntax is very similar and is given in appendix medmem_sec_python.
Naming conventions
The naming conventions are rather straightforward, but the user familiar with the Med-File semantics may find that there are a few noticeable differences (see the following section).
- cell entity of dimension equal to the mesh dimension (1, 2 or 3).
- component in a field, represents a value that is available for each element of the support (for instance :
,
,
)).
- connectivity (descending) connectivity table expressing connectivity of dimension d elements in terms of list of dimension d-1 elements.
- connectivity (nodal) connectivity table expressing connectivity of dimension d elements in terms of list of nodes.
- constituent entity entity having a dimension smaller than that of the mesh.
- coordinates in a mesh, coordinates can be described by strings giving the names of the coordinates, the units of the coordinates, and the type of coordinates ('MED_CART', 'MED_SPHER' or 'MED_CYL').
- description string of characters used to describ an object without giving any access to a query method.
- dimension Med Memory discriminates the mesh dimension from the space dimension (a surface shape in 3D will have 2 as a mesh dimension).
- driver object attached to a mesh or a field to read (resp. write) data from (resp. to) a Med-file.
- edge entity of dimension 1 in a 2D mesh.
- element elementary component of a mesh (0D, 1D, 2D or 3D).
- entity category giving information on the dimension of elementary components of meshes : node, edge, face (only in 3D) or cell.
- face for 3D meshes, faces are the 2D entities.
- family support which is composed of a set of groups, which do not intersect each other, and which gives access to those groups.
- field array of integer, integer array, real or real array lying on a support (the dimension of the array of values for each element of the support is called the number of components). A field is uniquely defined by its name, its support, its iteration number and its order number. -1 is the default value of those two numbers.
- group support with additional access to parent families.
- iteration number] information attached to a field that expresses the number of the time step in the computation (-1 is its default value).
- name information attached to a mesh, support or field to name it and access to it.
- node entity of dimension 0.
- order number information attached to a field that expresses the number of an internal iteration inside a time step in the computation (-1 is its default value).
- support list of elements of the same entity.
- type category of an entity (triangle, segment, quadrangle, tetrahedron, hexahedron, etc...).
Differences with Med-File concepts
Though the MEDMEM library can recompute a descending connectivity from a nodal connectivity, MEDMEM drivers can only read MED files containing the nodal connectivities of the entities. In MEDMEM, constituent entities are stored as MED_FACE
or MED_EDGE
, whereas in MED File, they should be stored as MED_MAILLE
.
The field notion in MED File and MEDMEM is quite different. In MEDMEM a field is of course defined by its name, but also by its iteration number and its order number. In MED File a field is only flagged by its name. For instance, a temperature at times t=0.0 s, t=1.0 s, t=2.0 s will be considered as a single field in Med File terminology, while it will be considered as three distinct fields in the Med Memory sense.
Med Memory API
Conventions
- In this document, one refers to the main user documentation RefManualMedMemory where the variable
$MED_ROOT_DIR
(resp. $MED_SRC_DIR
) is the Med Memory directory installation (resp. sources directory).
- All numberings start at one (take care of array index !).
- When one gets a C (resp. C++) type array (resp. STL container) using a
{get
...} method, one should not modify the array. Access is in read only. To modify a such array (resp. STL container) use a {set
...} method.
- There are many couple of methods that have similar syntaxes (one singular and one plural). The plural method returns an array and the singular one returns one particular value in this array (see
double
getCoordinate(int i)
and double*
getCoordinates()
for example). Generally, only the plural version of the methods are documented in this report.
- Difference between local and global number in mesh element connectivity list : when one talks about an element number, one could see
quadrangle (
in quadrangles array : local numbering) or
element (
in all elements array : global numbering). These two numberings are equivalent only if one has only one geometric type.
Namespaces
Med Memory uses two namespaces : MEDMEM
which is the general namespace where the main classes are defined and MED_EN
which defines enums that can be used by an English-speaking programer.
Classes
At a basic usage level, the API consists in few classes which are located in the MEDMEM
C++ namespace (consult figure fig_UML_light which gives an UML diagram view of the main Med Memory classes)~:
- MED the global container;
- MESH the class containing 2D or 3D mesh objects;
- SUPPORT the class containing mainly a list of mesh elements;
- FIELD the class template containing list of values lying on a particular support.
UML diagram of basic Med Memory API classes
The API of those classes is quite sufficient for most of the component integrations in the Salome platform. The use of the Med Memory libraries may make easier the code coupling in the Salome framework. With these classes, it is possible to~:
- read/write meshes and fields from MED-files;
- create fields containing scalar or vectorial values on list of elements of the mesh;
- communicate these fields between different components;
- read/write such fields.
Note that on the figure fig_UML_light as well as on figure fig_UML that the MED container controls the life cycle of all the objects it contains~: its destructor will destroy all the objects it aggregates. On the other hand, the life cycle of mesh, support and field objects are independent. Destroying a support (resp. a field) will have no effect on the mesh (resp. support) which refers to it. But the user has to maintain the link~: a mesh aggregates a support which aggregates a field. If the user has to delete Med Memory objects, the field has to be deleted first, then the support and finally the mesh.
A more advanced usage of the Med Memory is possible through other classes. Figure fig_UML gives a complete view of the Med Memory API. It includes :
- GROUP a class inherited from the SUPPORT class used to create supports linked to mesh groups. It stores restricted list of elements used to set boundary conditions, initial values.
- FAMILY which is used to manipulate a certain kind of support which does not intersect each other; \ b MESHING which builds meshes from scratch, it can be used to transform meshes from a specific format to the MED format or to integrate a mesher within Salome platform (note that class does not add element or node to a mesh);
- GRID which enables the user to manipulate specific functions for structured grid.
UML diagram of Med Memory API classes
Enums
A few enums are defined in the MED_EN
namespace :
- an enum which describes the way node coordinates or field values are stored,
MED_FULL_INTERLACE
for arrays such that
;
MED_NO_INTERLACE
for arrays such that
;
MED_UNDEFINED_INTERLACE
, the undefined interlacing mode.
- an enum which describes the type of connectivity
MED_NODAL
for nodal connectivity;
MED_DESCENDING
for descending connectivity.
The user has to be aware of the fact that the Med Memory considers only meshes defined by their nodal connectivity. Nevertheless, the user may, after loading a file in memory, ask to the mesh object to calculate the descending connectivity.
- an enum which contains the different mesh entities,
medEntityMesh
, the entries of which being :
MED_CELL
MED_FACE
MED_EDGE
MED_NODE
MED_ALL_ENTITIES
In 3D (resp. 2D), the user has to be aware of the fact that only mesh entities MED_CELL
and MED_FACE
(resp. MED_EDGE
) are considered. In 1D, of course only mesh entities MED_CELL+
are considered. Using our naming convention (consult Naming conventions), in $1$ D mesh only node and cell are considered. In 2D mesh, only node, cell and edge are considered. Finally in 3D mesh only node}, cell and face are considered.
- The
medGeometryElement
enum which defines geometric types. The available types are linear and quadratic elements (consult RefManualMedMemory). The entries of this enum are quite self-explanatory :
MED_NONE
MED_POINT1
MED_SEG2
MED_SEG3
MED_TRIA3
MED_QUAD4
MED_TRIA6
MED_QUAD8
MED_TETRA4
MED_PYRA5
MED_PENTA6
MED_HEXA8
MED_TETRA10
MED_PYRA13
MED_PENTA15
MED_HEXA20
MED_POLYGON
MED_POLYHEDRA
MED_ALL_ELEMENTS
The connectivity of all these elements is defined in MED project Web page http://hammi.extra.cea.fr/static/MED/web_med/logiciels/med-2.3.1/doc/ .