Salome HOME
d47408e446bf754dcc91aaf9a1f01dbaa7c499de
[modules/med.git] / doc / doxygen / input / medloader / MEDLoaderAdvancedAPI.dox
1
2 /*!
3 \page MEDLoaderAdvancedAPIPage Advanced MEDLoader API.
4
5 [TOC]
6
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.
11
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.
15
16 \section AdvMEDLoaderBasics Some of basics of advanced API
17
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
20 explained here.
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().
23
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
29 and MED_QUAD4.
30
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).
35
36 - Besides notion of \c meshDimRelToMax there is notion of \c meshDimRelToMaxExt.
37 \c meshDimRelToMaxExt is simply an extension of \c meshDimRelToMax for
38 nodes.
39
40 The parameter of \c meshDimRelToMaxExt appears in
41 \ref ParaMEDMEM::MEDFileUMesh "umesh advanced API" of %MEDLoader with the following semantics.
42
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
46 most {1,0,-1,-2,-3}.
47 1 stands for node and 0,-1,-2,-3 has exactly the
48 same semantic than those described in \c meshDimRelToMax
49 before.
50
51 - A parameter that also often appears in advanced %MEDLoader API is \c renum.
52 This parameter is set to \c
53 true by default.
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
57 %MEDLoader.
58
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.
66
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
76   exception is thrown.
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.
81
82 \section AdvMEDLoaderAPIMeshesRW Dealing with Meshes with advanced API.
83
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
87 instance.
88
89 \subsection AdvMEDLoaderAPIMeshReading Reading a mesh.
90
91 The class that incarnates Read/Write mesh in MED file is ParaMEDMEM::MEDFileUMesh.
92
93 First of all, like basic %MEDLoader API, only MEDfile files whose version >= 2.2 are able
94 to be read with advanced API.
95
96 To read a mesh having the name \c meshName in file \c fileName the
97 following simple code has to be written :
98
99 \code
100
101 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName,meshName);
102
103 \endcode
104
105 If the user do not know the name of the mesh inside MED file
106 'fileName' the following code should be written :
107
108 \code
109
110 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName);
111
112 \endcode
113
114 In this case the first mesh (in MED file sense) found in \c fileName
115 file will be loaded.
116
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
121 that can be invalid.
122
123 \n
124
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
130
131
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
137
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
143
144 - Retrieving family field array :
145 Method \c getFamilyFieldAtLevel retrieves for a specified extended level the
146 family id of each cell or node.
147
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
151 be thrown.
152
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.
157
158 \anchor AdvMEDLoaderAPIMeshReadingSampl
159
160 Here is a \ref cpp_mcumesh_loadfile "C++ example" illustrating a typical use of \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" instance.
161
162 \subsection AdvMEDLoaderAPIMeshWriting Writing a mesh.
163
164 The use is very symmetric to reading part. It is possible to either
165 build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
166 scratch, or to work with an existing instance coming from a loading
167 from a file.
168
169 One important point is that coordinates of a mesh are shared by all
170 cells whatever their level. That's why the
171 \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble" instance
172 should be shared by all \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" used in input parameter of
173 set* methods. If the user intends to build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
174 scratch, a call to \c setCoords should be done first.
175
176
177 Generally speaking traduce get* methods with set* methods have corresponding write semantic.
178
179 Some differences still exist :
180
181 - \c setMeshAtLevel, \c setMeshAtLevelOld simply call \c setMeshAtLevelGen with repectively \c newOrOld parameter
182 set to true and false. These methods specify if a renumbering computation is needed or not. \c setMeshAtLevelOld is faster
183 than \c setMeshAtLevel because no renumbering computation is done. If the user is not warranty about the order of its meshes to enter
184 it is better to use \c setMeshAtLevel method.
185
186 - Groups definition : Groups constitution is time consuming because of the store mode chosen by MED file. Groups definition
187 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
188 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
189 set to the desired group name. If not an exception will be thrown, because MED file does not support groups with no name.
190
191 \anchor AdvMEDLoaderAPIMeshWritingSampl
192
193 Here is a \ref cpp_mcumesh_writefile "C++ example".
194
195
196 \section AdvMEDLoaderAPIFieldRW Dealing with Fields with advanced API.
197
198 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".
199
200 Here the list of classes in %MEDLoader advanced API top down sorted :
201
202 - Level 0 : ParaMEDMEM::MEDFileFields
203 - Level -1 : ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA
204 - Level -2 : ParaMEDMEM::MEDFileField1TSWithoutSDA
205 - Level -3 : ParaMEDMEM::MEDFileFieldPerMesh (present only for backward compatibility MED file 2.2)
206 - Level -4 : ParaMEDMEM::MEDFileFieldPerMeshPerType
207 - Level -5 : ParaMEDMEM::MEDFileFieldPerMeshPerTypePerDisc
208
209
210 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
211 in level -2 (ParaMEDMEM::MEDFileField1TSWithoutSDA)  in which each leaf (level -5) of MED file field
212 points to range [\a start, \a end).
213
214 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
215 (ParaMEDMEM::MEDFileField1TS and ParaMEDMEM::MEDFileFieldMultiTS) in advanced API is the result of a subclass of a data class
216 (respectively ParaMEDMEM::MEDFileField1TSWithoutSDA, ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA) and an instance of ParaMEDMEM::MEDFileFieldGlobsReal representing the shared data arrays (SDA)
217 at a specified scope inside the MED file.
218
219 \subsection AdvMEDLoaderAPIFieldR Reading a field
220
221 \subsubsection AdvMEDLoaderAPIFieldRC Reading a field defined on all entities
222
223 Fields defined on all entities are the most used and common fields in MED file world.
224
225 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.
226
227 Here is a \ref py_mcfield_loadfile_allentities "Python example".
228
229 \subsubsection AdvMEDLoaderAPIFieldRP Reading a partial field
230
231 Here is a \ref py_mcfield_loadfile_partial "Python example".
232
233
234 \subsection AdvMEDLoaderAPIFieldW Writing a field
235
236 \subsubsection AdvMEDLoaderAPIFieldWC Writing a field defined on all entities
237
238 Fields defined on all entities are the most used and common fields in MED file world.
239
240 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.
241
242 Here is a \ref py_mcfield_writefile_allentities "Python example".
243
244 \subsubsection AdvMEDLoaderAPIFieldWP Writing a partial field
245
246 Here is a \ref py_mcfield_writefile_partial "Python example".
247
248 */