3 \page MEDLoaderAdvancedAPIPage Advanced MEDLoader API.
7 This method is much closer to MED file organization than \ref
8 MEDLoaderBasicAPI "basic MEDLoader API". All MED file
9 concepts are exposed to the user. As a consequence, this advanced
10 API is lead to change with MED file data model enhancement.
12 In reading mode, the user can scan entirely and directly the contents of its MED file as it is organized in its MED file.
13 Inversely, in writing mode, the user can describe its data in the same
14 way that MED file does.
16 \section AdvMEDLoaderBasics Some of basics of advanced API
18 - Like basic %MEDLoader API there is a notion of \c meshDimRelToMax.
19 Each time this parameter appears in API, it will have the semantic
21 The value of the parameter \c meshDimRelToMax is at most in {0,-1,-2,-3}. This relative value specifies a level
22 relative to the value returned by ParaMEDMEM::MEDFileMesh::getMeshDimension().
24 A mesh containing MED_TETRA4, MED_TRI3, MED_QUAD4 and MED_POINT1 has a meshDimension
25 equal to 3. For \c meshDimRelToMax equal to 0 the user will
26 deal with cells whose type has a dimension equal to 3+0, that is to
27 say here MED_TETRA4. For \c meshDimRelToMax equal to -1 the user will
28 deal with cells which dimension equals 3-1 that is to say MED_TRI3
31 An important method is ParaMEDMEM::MEDFileUMesh::getNonEmptyLevels(). It returns all
32 non empty levels available. In the previous example, this method will
33 return {0,-1,-3}. -2 does not appear because no cells with dimension
34 equal to 1 (3-2) appear in MED file mesh (no MED_SEG2, no MED_SEG3).
36 - Besides notion of \c meshDimRelToMax there is notion of \c meshDimRelToMaxExt.
37 \c meshDimRelToMaxExt is simply an extension of \c meshDimRelToMax for
40 The parameter of \c meshDimRelToMaxExt appears in
41 \ref ParaMEDMEM::MEDFileUMesh "umesh advanced API" of %MEDLoader with the following semantics.
43 Some of MED file concepts are available both for cells and
44 nodes (for example families, groups, numbering) ; that's why for a simpler API this
45 concept has been introduced. \c meshDimRelToMaxExt parameter can take a value in at
47 1 stands for node and 0,-1,-2,-3 has exactly the
48 same semantic than those described in \c meshDimRelToMax
51 - A parameter that also often appears in advanced %MEDLoader API is \c renum.
52 This parameter is set to \c
54 This parameter indicates if the user intends to take into account
55 the renumbering array of cells of the current MED file mesh.
56 If no renumbering array is defined, this parameter is ignored by
59 If such renumbering exists and the \c renum parameter is
60 set to \c true, then the renumbering is taken into account. This is
61 exactly the behaviour of \ref MEDLoader::ReadUMeshFromFile "basic MEDLoader API".
62 If the user expects to ignore this renumbering even in case of
63 presence of renumbering array, false should be passed to \c renum
64 parameter. \b The \b parameter \b renum \b should \b be \b set \b with
65 \b caution \b for \b users \b concerned \b by \b cells \b orders.
67 - A last important parameter is the \c mode during writing. The
68 available values for the parameter \c mode are :
69 - 2 : for a write from scratch. If file already exists, file will be
70 erased and replace by the content of the instance on which \c write
71 method has been called.
72 - 1 : If the file does not exists equivalent to 2. If file already
73 exists, the write is done on APPEND mode. That is to say that no
74 data loss will occur. But in case that an element with same ids than
75 current instance already exists, the content is not written and an
77 - 0 : If the file does not exists equivalent to 2. If file already
78 exists write without any question. If an element with same ids
79 existed previously the content is overwritten by the content of the
80 current instance, that can lead to a file corruption.
82 \section AdvMEDLoaderAPIMeshesRW Dealing with Meshes with advanced API.
84 Contrary to the basic %MEDLoader API, here after reading process, the user
85 has to deal with a new instance of class that fits the MED file model.
86 To access a MEDCoupling mesh user should request this class
89 \subsection AdvMEDLoaderAPIMeshReading Reading a mesh.
91 The class that incarnates Read/Write mesh in MED file is ParaMEDMEM::MEDFileUMesh.
93 First of all, like basic %MEDLoader API, only MEDfile files whose version >= 2.2 are able
94 to be read with advanced API.
96 To read a mesh having the name \c meshName in file \c fileName the
97 following simple code has to be written :
101 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName,meshName);
105 If the user do not know the name of the mesh inside MED file
106 'fileName' the following code should be written :
110 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName);
114 In this case the first mesh (in MED file sense) found in \c fileName
117 Now the user can ask for mesh dimension of of \c myMedMesh instance by
118 calling \c myMedMesh->getMeshDimension(). This method returns the
119 highest level of present cell in MED file mesh \c myMedMesh.
120 This returned integer is computed and \b not those contained in MED file
125 - Retrieving a mesh at a specified relative level \c meshDimRelToMax=mdrm : simply call
126 - \c myMedMesh->getMeshAtLevel(mdrm)
127 - or \c myMedMesh->getLevel0Mesh() or \c
128 myMedMesh->getLevelM1Mesh(), or \c myMedMesh->getLevelM2Mesh()
129 depending on the value of mdrm
132 - Retrieving a family at a specified level :
133 - Either an array of node/cell id
134 - \c getFamilyArr method or \c getFamiliesArr
135 - Or on \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" form by calling
136 - \c getFamily method or \c getFamilies
138 - Retrieving a group at a specified level :
139 - Either an array of node/cell id
140 - \c getGroupArr method or \c getGroupsArr
141 - Or on \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" form by calling
142 - \c getGroup method or \c getGroups
144 - Retrieving family field array :
145 Method \c getFamilyFieldAtLevel retrieves for a specified extended level the
146 family id of each cell or node.
148 - Retrieving renumbering array :
149 Method \c getNumberFieldAtLevel returns, if it exists for a specified extended level, the
150 family id of each cell or node. If it does not exist an exception will
153 An important point is that families and groups are \b not sorted in
154 MED file. No sort is stored in MED file explicitly for Groups and
155 Families. Advanced %MEDLoader API, uses the same order than underlying
156 mesh at specified level.
158 \anchor AdvMEDLoaderAPIMeshReadingSampl
161 Here is a \ref cpp_mcumesh_loadfile "C++ example" illustrating a typical use of \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" instance.
164 \subsection AdvMEDLoaderAPIMeshWriting Writing a mesh.
166 The use is very symmetric to reading part. It is possible to either
167 build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
168 scratch, or to work with an existing instance coming from a loading
171 One important point is that coordinates of a mesh are shared by all
172 cells whatever their level. That's why the
173 \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble" instance
174 should be shared by all \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" used in input parameter of
175 set* methods. If the user intends to build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
176 scratch, a call to \c setCoords should be done first.
179 Generally speaking traduce get* methods with set* methods have corresponding write semantic.
181 Some differences still exist :
183 - \c setMeshAtLevel, \c setMeshAtLevelOld simply call \c setMeshAtLevelGen with repectively \c newOrOld parameter
184 set to true and false. These methods specify if a renumbering computation is needed or not. \c setMeshAtLevelOld is faster
185 than \c setMeshAtLevel because no renumbering computation is done. If the user is not warranty about the order of its meshes to enter
186 it is better to use \c setMeshAtLevel method.
188 - Groups definition : Groups constitution is time consuming because of the store mode chosen by MED file. Groups definition
189 leads to a partition computation which is time/memory consuming ; that is why groups should be defined at once and not with addGroup one by one that will lead to
190 compute a partition for each appended group. One important point to note is that DataArrayInt instance given in input to define groups should have its name
191 set to the desired group name. If not an exception will be thrown, because MED file does not support groups with no name.
193 \anchor AdvMEDLoaderAPIMeshWritingSampl
196 Here is a \ref cpp_mcumesh_writefile "C++ example".
199 \section AdvMEDLoaderAPIFieldRW Dealing with Fields with advanced API.
201 In advanced API fields have been developed using divide and conquer pattern to reproduce with the maximal fidelity the MED file field concept \ref BasicMEDLoaderAPIGen "seen here".
203 Here the list of classes in %MEDLoader advanced API top down sorted :
205 - Level 0 : ParaMEDMEM::MEDFileFields
206 - Level -1 : ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA
207 - Level -2 : ParaMEDMEM::MEDFileField1TSWithoutSDA
208 - Level -3 : ParaMEDMEM::MEDFileFieldPerMesh (present only for backward compatibility MED file 2.2)
209 - Level -4 : ParaMEDMEM::MEDFileFieldPerMeshPerType
210 - Level -5 : ParaMEDMEM::MEDFileFieldPerMeshPerTypePerDisc
213 Each level in the tree representing a field (cyan box) is represented by a class. The only difference is that values are grouped in a single big array located
214 in level -2 (ParaMEDMEM::MEDFileField1TSWithoutSDA) in which each leaf (level -5) of MED file field
215 points to range [\a start, \a end).
217 As different time steps of a same field and different fields inside a MED file can share or not profiles (yellow box) and localization (red box) a manipulable field classes instance
218 (ParaMEDMEM::MEDFileField1TS and ParaMEDMEM::MEDFileFieldMultiTS) in advanced API is the result of a subclass of a data class
219 (respectively ParaMEDMEM::MEDFileField1TSWithoutSDA, ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA) and an instance of ParaMEDMEM::MEDFileFieldGlobsReal representing the shared data arrays (SDA)
220 at a specified scope inside the MED file.
222 \subsection AdvMEDLoaderAPIFieldR Reading a field
224 \subsubsection AdvMEDLoaderAPIFieldRC Reading a field defined on all entities
226 Fields defined on all entities are the most used and common fields in MED file world.
228 In this mode the user does **not** want to retrieve the entity ids of the constituting subsupport of the whole mesh because it has no sense.
231 Here is a \ref py_mcfield_loadfile_allentities "Python example".
234 \subsubsection AdvMEDLoaderAPIFieldRP Reading a partial field
237 Here is a \ref py_mcfield_loadfile_partial "Python example".
240 \subsection AdvMEDLoaderAPIFieldW Writing a field
242 \subsubsection AdvMEDLoaderAPIFieldWC Writing a field defined on all entities
244 Fields defined on all entities are the most used and common fields in MED file world.
246 In this mode the user do **not** want to retrieve the entity ids of the constituting subsupport of the whole mesh because it has no sense.
249 Here is a \ref py_mcfield_writefile_allentities "Python example".
252 \subsubsection AdvMEDLoaderAPIFieldWP Writing a partial field
255 Here is a \ref py_mcfield_writefile_partial "Python example".