Salome HOME
Merge from V6_main 19/03/2013
[tools/medcoupling.git] / doc / doxygen / medmem.dox
1 /*!
2 \page medmem MEDMEM library
3
4 \section medmem_introduction Introduction
5 \subsection medmem_rationale Rationale for Med Memory
6
7 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 (\c %MEDMEM) library.
8
9 The Med libraries are oganized in multiple layers:
10 - The MED file layer : C and Fortran API to implement mesh and field persistency.
11 - The MED Memory level C++ API to create and manipulate mesh and field objects in memory.
12 - Python API generated using SWIG which wraps the complete C++ API of the MED Memory
13 - CORBA API to simplify distributed computation inside SALOME (Server Side).
14 - MED Client classes to simplify and optimize interaction of distant objects within the local solver.
15
16 Thanks to Med Memory, any component can access a distant mesh or field
17 object. Two codes running on different machines can thus exchange
18 meshes and fields. These meshes and fields can easily be read/written in a Med file
19 format, enabling access to the whole Salome suite of tools
20 (CAD, meshing, Visualization, other components).
21
22 \subsection medmem_outline Outline
23
24 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.
25
26 As will be seen in section \ref medmem_api, the API consists of very few classes:
27
28 - a MED-file browser : \ref MEDFILEBROWSER_class,
29 - meshes : \ref mesh ,
30 - structured meshes : \ref grid ,
31 - supports and derived classes : \ref support ,
32 - mesh generation tool : \ref meshing ,
33 - fields : \ref field ,
34 - \ref medmem_drivers "drivers for reading and writing" in MED, GIBI,
35 VTK, EnSight and Porflow files.
36
37 All these are detailed in the following sections. The C++ 
38 formalism will be used for the description in these sections.
39  Python syntax is very similar and is given in appendix \ref medmem_sec_python.
40
41 \subsection medmem_naming Naming conventions
42
43 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).
44
45 - \b cell entity of dimension equal to the mesh dimension (1, 2 or 3).
46 - \b component in a field, represents a value that is available for each element of the support (for instance : \f$ T \f$, \f$ v_x \f$, \f$ \sigma_{xy} \f$)).
47 - \b connectivity \b (descending) connectivity table expressing connectivity of dimension \a d elements in terms of list of dimension \a d-1 elements.
48 - \b connectivity \b (nodal) connectivity table expressing connectivity of dimension \a d elements in terms of list of nodes.
49 - \b constituent \b entity entity having a dimension smaller than that of the mesh.
50 - \b 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').
51 - \b description string of characters used to describ an object without giving any access to a query method.
52 - \b dimension Med Memory discriminates the mesh dimension from the space dimension (a surface shape in 3D will have 2 as a mesh dimension).
53 - \b driver object attached to a mesh or a field to read (resp. write) data from (resp. to) a Med-file.
54 - \b edge entity of dimension 1 in a 2D mesh.
55 - \b element  elementary component of a mesh (0D, 1D, 2D or 3D).
56 - \b entity category giving information on the dimension of elementary components of meshes : node, edge, face (only in 3D) or cell.
57 - \b face for 3D meshes, faces are the 2D entities.
58 - \b family support which is composed of a set of groups, which do not intersect each other, and which gives access to those groups.
59 - \b 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.
60 - \b group support with additional access to parent families.
61 - \b iteration number] information attached to a field that expresses the number of the time step in the computation (-1 is its default value).
62 - \b name information attached to a mesh, support or field to name it and access to it.
63 - \b node entity of dimension 0.
64 - \b order \b 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).
65 - \b support list of elements of the same entity.
66 - \b type category of an entity (triangle, segment, quadrangle, tetrahedron, hexahedron, etc...).
67
68
69 \subsection medmem_diff Differences with Med-File concepts
70 Though the %MEDMEM library can recompute a descending connectivity
71 from a nodal connectivity, %MEDMEM drivers can only read MED files containing the nodal
72 connectivities of the entities. 
73 In %MEDMEM, constituent entities are stored as \c MED_FACE
74 or \c MED_EDGE, whereas in %MED File, they should be stored as \c
75   MED_MAILLE. 
76
77 The field notion in %MED File and %MEDMEM is quite different. In %MEDMEM
78 a field is of course defined by its name, but also by its iteration
79 number and its order number. 
80 In %MED File a field is only flagged by its name. For instance,
81 a temperature at times \a t=0.0 s, \a t=1.0 s, \a 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.
82
83 \subsection medmem_drivers Drivers for reading and writing
84
85 MEDMEM supports data exchange in following formats:
86 - \b GIBI - reading and writing the mesh and the fields in ASCII format.
87 - \b VTK - writing the mesh and the fields in ASCII and binary formats.
88 - \b EnSight - reading and writing the mesh and the fields in EnSigth6 and EnSigth GOLD formats (ASCII and binary).
89 - \b PORFLOW - reading the mesh in ASCII format.
90
91 Limitation of length of names in GIBI format is overcome by storing names in the specific string pile of GIBI file.
92 This pile is used to map actual long names of the data objects to their shortened representation.
93
94 \section medmem_api Med Memory API
95
96 \subsection medmem_conventions Conventions
97
98 - In this document, one refers to the main user documentation
99 \ref RefManualMedMemory where the variable \c $MED_ROOT_DIR (resp.
100 \c $MED_SRC_DIR) is the Med Memory directory installation (resp. sources
101 directory).
102 - All numberings start at one (take care of array index !).
103 - When one gets a C (resp. C++) type array (resp. STL container) using a \c {get...} method, one should not modify the array. Access is in read only. To modify a such array (resp. STL container) use a \c {set...} method.
104 - There are many couple of methods that have similar syntaxes (one singular and one 
105 plural). The plural method returns an array and the singular one returns one 
106 particular value in this array (see \c double \c getCoordinate(int i)  and 
107 \c double* \c getCoordinates() for example). Generally, only the plural version
108 of the methods are documented in this report.
109 - Difference between local and global number in mesh element connectivity list : when one talks about an 
110 element number, one could see \f$ i^{th} \f$ quadrangle (\f$ i^{th} \f$ in quadrangles array : local numbering) or \f$ j^{th} \f$ element (\f$ j^{th} \f$ in all elements array : 
111 global numbering). These two numberings are equivalent only if one has only one 
112 geometric type.
113
114
115 \subsection namespaces  Namespaces
116
117 Med Memory uses two namespaces : \c MEDMEM which is the general 
118 namespace where the main classes are defined and \c MED_EN
119 which defines enums that can be used by an English-speaking 
120 programer.
121
122 \subsection classes Classes
123 At a basic usage level, the API consists in few classes which are located in
124 the \c MEDMEM C++ namespace (consult figure \ref fig_UML_light which gives
125 an UML diagram view of the main Med Memory classes):
126
127 - \b MEDFILEBROWSER the class provinding information on meshes and fields conatained in a MED file;
128 - \b MESH the class containing 2D or 3D mesh objects;
129 - \b SUPPORT the class containing mainly a list of mesh elements;
130 - \b FIELD the class template containing list of values lying on a particular support.
131
132 \anchor fig_UML_light
133 \image html UML_light.png " UML diagram of basic Med Memory API classes"
134 \image latex UML_light.eps " UML diagram of basic Med Memory API classes"
135
136
137 The API of those classes is quite sufficient for most of the component
138 integrations in the Salome platform. The use of the Med Memory libraries may
139 make easier the code coupling in the Salome framework. With these classes, it
140 is possible to:
141
142 - read/write meshes and fields from MED-files;
143 - create fields containing scalar or vectorial values on list of elements
144 of the mesh;
145 - communicate these fields between different components;
146 - read/write such fields.
147
148 Note that on the figure \ref fig_UML_light as well as on figure
149 \ref fig_UML the life cycle of mesh and field objects are independent. Destroying a field will have no effect on the mesh. 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.
150
151 A more advanced usage of the Med Memory is possible through other classes.
152 Figure \ref fig_UML gives a complete view of the Med Memory API. It includes :
153
154 - \b 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.
155 - \b FAMILY which is used to manipulate a certain kind of support which does not intersect each other.
156 - \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).
157 - \b GRID which enables the user to manipulate specific functions for structured grid.
158
159 \anchor fig_UML
160 \image html UML_small.png "UML diagram of Med Memory API classes"
161 \image latex UML_small.eps  "UML diagram of Med Memory API classes"
162
163
164 \subsection medmem_enums Enums
165 A few enums are defined in the \c MED_EN namespace :
166
167 - an enum which describes the way node coordinates or field values are stored,
168   - \c MED_FULL_INTERLACE for arrays such that \f$ x_1,y_1,z_1,x_2,y_2,z_2,\ldots,x_n,y_n,z_n \f$;
169   - \c MED_NO_INTERLACE for arrays such that \f$ x_1,x_2,\ldots,x_n,y_1,y_2,\ldots,y_n,z_1,z_2,\ldots,z_n \f$;
170   - \c MED_UNDEFINED_INTERLACE, the undefined interlacing mode.
171   .
172 - an enum which describes the type of connectivity
173   - \c MED_NODAL for nodal connectivity;
174   - \c MED_DESCENDING for descending connectivity.
175   .
176
177 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.
178
179 - an enum which contains the different mesh entities, \c medEntityMesh, the entries of which being :
180  - \c MED_CELL
181  - \c MED_FACE
182  - \c MED_EDGE
183  - \c MED_NODE
184  - \c MED_ALL_ENTITIES
185  .
186
187 In 3D (resp. 2D), the user has to be aware of the fact that only mesh
188 entities \c MED_CELL and  \c MED_FACE (resp. \c MED_EDGE) are
189 considered. In 1D, of course only mesh entities \c MED_CELL+ are considered. Using our naming convention (consult \ref medmem_naming), in $1$ D mesh
190 only \b node and \b cell are considered. In 2D mesh, only \b node,
191 \b cell and \b edge are considered. Finally in 3D mesh only
192 \b node, \b cell and \b face are considered.
193
194 - The \c medGeometryElement enum which defines geometric types. The
195 available types are linear and quadratic elements (consult
196 \ref RefManualMedMemory). The entries of this enum are quite
197 self-explanatory :
198   - \c MED_NONE
199   - \c MED_POINT1
200   - \c MED_SEG2
201   - \c MED_SEG3
202   - \c MED_TRIA3
203   - \c MED_QUAD4
204   - \c MED_TRIA6
205   - \c MED_QUAD8
206   - \c MED_TETRA4
207   - \c MED_PYRA5
208   - \c MED_PENTA6
209   - \c MED_HEXA8
210   - \c MED_TETRA10
211   - \c MED_PYRA13
212   - \c MED_PENTA15
213   - \c MED_HEXA20
214   - \c MED_POLYGON
215   - \c MED_POLYHEDRA
216   - \c MED_ALL_ELEMENTS
217   .
218 The connectivity of all these elements is defined in MED project Web page
219 http://hammi.extra.cea.fr/static/MED/web_med/logiciels/med-2.3.1/doc/ .
220
221
222 */
223
224 /*!
225 \page paramedmem ParaMEDMEM library
226
227
228 The ParaMEDMEM library is based on several classes that 
229 describe the coupling between two MPI-based parallel codes.
230
231 The classes that make up the API of the library are :
232 - communication interface : \ref comm_interface,
233 - definition of processor groups : \ref processor_group,
234 - Data Exchange Channel \ref dec, and its implementations :
235  - \ref interpkerneldec for a \ref InterpKerRemapGlobal based on intersecting elements volume computation,
236  - \ref overlapdec based on intersecting elems volume
237  computation when source and target meshes are on same process id
238
239 Given two groups of processors groupA (source) and groupB (target), the following code excerpt gives a typical use of the InterpKernelDEC class.
240
241     \code
242     ...
243     InterpKernelDEC dec(groupA, groupB);//creates the data exchange channel
244     dec.attachLocalField(field);//associate the local field
245     dec.synchronize();//builds the interpolation matrix
246     if (groupA.containsMyRank())
247     dec.recvData();//receive the target field
248     else if (groupB.containsMyRank())
249     dec.sendData();//send the source field
250     ...
251     \endcode
252 The generation of the \ref interpolationmatrix "interpolation matrix" and the corresponding matrix-vector products are performed either on the source, either on the target side. 
253
254 */
255
256
257 /*!
258 \page medmem_install Configuring and Installing MEDMEM from sources
259
260 The MEDMEM library can be configured in several manners so that it can run inside or outside the Salome platform. Also, partitioning and parallel functionalities are optional.
261
262 The sources of the library are located in the \a MED_SRC directory. 
263 The first step consists in preparing the configuration of the library :
264 \verbatim
265 cd ${MED_SRC}
266 ./build_configure
267 \endverbatim
268
269 This will create a MEDMEM library with link to the SALOME Kernel. If it is desirable to have a standalone version of the library to be used independently from SALOME, use :
270 \verbatim
271 cd ${MED_SRC}
272 ./build_configure --without-kernel
273 \endverbatim
274
275 The library can then be configured :
276 \verbatim
277 mkdir ../MED_BUILD
278 cd ../MED_BUILD
279 ../MED_SRC/configure --prefix=`pwd`/../MED_INSTALL
280 \endverbatim
281
282 This will configure the library without splitting functionalities. ParaMEDMEM will be compiled if an MPI version has been found.
283
284 The following options can be useful to configure MEDMEM :
285 - \a --enable-splitter=yes will trigger the compilation of the MEDSPLITTER tool,
286 - \a --with-metis=${METISDIR} will specify a location for the METIS library,
287 - \a --with-scotch=${SCOTCHDIR} will specify a location for the SCOTCH library,
288 - \a --with-med3=${MED3DIR} specifies a location for MED-file library,
289 - \a --with-hdf5=${HDF5DIR} specifies a location for the HDF5 library (must be the same as that used for the MED-file library)
290 - \a --with-lam=${LAMDIR} specifies an install path for a LAM MPI library,
291 - \a --with-mpich=${MPICHDIR} specifies an install path for a MPICH-1 library.
292 */