Salome HOME
MEDMEM suppression
[tools/medcoupling.git] / doc / doxygen / medloader.dox
1 /*!
2 \page medloader MEDLoader
3
4 [TOC]
5
6 \section MEDLoaderIntro Introduction
7
8 \ref medloader "MEDLoader" is a package in charge of loading from a file or write to a file
9 in MED format a \ref medcoupling data structure. The fact that these
10 functionalities are not merged in \ref medcoupling is explained by a
11 willingness of reducing as much as possible the dependancies of \ref medcoupling libraries.
12
13 As a MED file can combine several \ref medcoupling aspects in one (for exemple meshes in
14 MED file on different mesh dimension with families and groups) the API
15 of \ref medloader "MEDLoader" is much more rich than simply read and write.
16
17 \ref MEDCouplingMeshesPage "MEDCoupling mesh" is \b not as rich as a MED file mesh, and a \ref MEDCouplingFieldsPage "MEDCoupling field" is \b not as rich as a MED file field.
18 But it is possible to emulate with a very good fidelity a MED file mesh and a MED file field with a collection of MEDCoupling instances for each.
19
20 \section MEDLoader2Approaches Two approaches are available in MEDLoader : Advanced API, Basic API
21
22 \ref medloader "MEDLoader" module offers two different approaches to perform Read/Write from/to MED file.
23
24 - \ref MEDLoaderAdvApproach "advanced API approach"
25 - \ref MEDLoaderBasicApproach "basic API apprach"
26
27 Whatever the approach(es) you choose, it is advisable to know main concepts of MED files \ref MEDLoaderMainC "that are quickly reminded here."
28
29 \subsection MEDLoaderAdvApproach Advanced API approach
30
31 \subpage MEDLoaderAdvancedAPIPage "A specific page dedicated to the advanced API is available here".
32
33 This approach is the most close to MED file. By using this advanced API approach the user will manipulates classes that represents MED file concepts.
34
35 It implies that the user should be informed about the \ref MEDLoaderMainC "MED file concepts", that do not exist in \ref medcoupling "MEDCoupling". For example :
36
37 - group/family in meshes
38 - profiles in fields
39
40 This is typically the case for a user that wants to precisely set/get mesh/group/family groups set on different level.
41
42 *That's why a set of classes representing a memory representation of MED file concepts are proposed by advanced API approach.*
43
44 *So All information contained in file is represented in advanced API class instances.*
45
46 The level of coherency check is variable across methods, to let to the user the maximal capacity of modification of its MED file data in memory.
47
48 This API is particulary recommended :
49
50 1. For users that want to repare a MED file (invalid family ids, invalid mesh dimension, mismatch of family ids, numbering cells/nodes array modification)
51 2. For users that want to operate directly on complex MED file objects (split of MED files for example, duplication of nodes).
52
53 \subsection MEDLoaderBasicApproach Basic API approach
54
55 \subpage MEDLoaderBasicAPIPage "A specific page dedicated to the basic API is available here".
56
57 This approach is less close to MED file concepts, but closer to \ref MEDCouplingMainConc "MEDCoupling concepts".
58
59 So, basic API, is simpler as show method MEDLoader::WriteUMesh that needs no special knowledge needed of MED file concepts to interact with MED files.
60
61 This API is in the form of a list of public static methods a class ParaMEDMEM::MEDLoader.
62
63 This simplicity has a cost, the I/O are not (cannot be) optimized.
64
65 As MED file concepts are more complex than MEDCoupling concepts, this approach is not the most relevant for specific MED file objects read/write.
66
67 - Manipulation of multi level MED file mesh is not easy to manipulate with basic approach
68
69 - Manipulation of partial fields in not easy to manipulate too with basic approach
70
71
72 \subsection MEDLoaderCohabitationApproach Cohabitation of the two approaches
73
74 The two approaches are \b NOT opposed, they are compatible each other so it is possible to mix them.
75
76 Typically it it is possible to read rich information of a complex MED file using advanced API in read mode, and write a simpler MED file model
77 coming from a post treatement of the complex input MED file data to a simple output MED file using basic API for writing.
78
79 \section MEDLoaderMainC Main concepts of MED files
80
81 Here we will describes some of basic concepts of MED files in order to
82 use the best methods proposed by \ref medloader "MEDLoader API".
83
84 \subsection BasicMEDLoaderAPIGen Basics in MED files
85
86 First of all **MEDLoader will not read MED files whose version is strictly lower than 2.2.**
87
88 For new comers in MED file world some of basics principles are recalled in the following graphic : 
89
90 \image html MEDFileConcepts.png "Resumed MED file concepts"
91
92 Inside the parenthesis, there is multiplicity :
93
94 - + stands for [1,inf)
95 - * stands for [0,inf)
96 - ? stands for 0 or 1
97
98 Each box are **independant in MED file format during read write session.**
99
100 **Boxes instances are linked each other only by red arrows using string as discriminating key.** It implies that empty names in basic concepts objects of MED file are forbidden.
101
102 There can be as many instance of boxes as wanted in a MED file.
103
104 **As it can be seen in MED file world, fields and meshes are sorted by geometric type**.
105
106 This specificity leads to a constraint during writing phase because some mesh operations may modify significantly the organization of geometric types during mesh/field operations.
107 \n Here some of operation that can alter the geometric type order of cells :
108
109 - aggregation of meshes
110 - aggregation of fields
111 - extraction of a part of meshes
112 - extraction of a part of fields
113 - partial polyhedrization of meshes
114 - unpolyhedronization of meshes
115
116 \section MEDLoaderCommonVoc Vocabulary used in MEDLoader
117
118 \subsection MEDLoaderCommonVocRelMeshDimMesh Relative mesh dimension in meshes
119
120 As it has been seen \ref BasicMEDLoaderAPIGen "above", all big arrays in fields and meshes (execpted coordinates) are sorted by geometric type, without any awareness of the dimension.
121
122 For example an unstructured mesh in MED file world can lie simultaneously on MED_TRI3, MED_POINT1, MED_POLYHED, MED_TETRA4..., \ref MEDCouplingMeshes "which is impossible in MEDCoupling" for manipulation reasons.
123
124 To connect the MED file world to the MEDLoader/MEDCoupling world the notion of **relative mesh dimension** has been introduced in \ref medloader "MEDLoader".
125
126 This concept of **relative mesh dimension** is used frequently in the \ref medloader "MEDLoader both APIs" ( \ref MEDLoaderBasicAPIPage "basic" and \ref MEDLoaderAdvancedAPIPage "advanced").
127
128 To explain the semantic of **relative mesh dimension** let's take the example of a mesh called \a myMesh in a MED file, containing MED_TRI3, MED_POINT1, MED_POLYHED, MED_TETRA4.
129
130 For each geometric type on which \a myMesh is defined the mesh dimension are :
131
132 - MED_TRI3 -> mesh dimension=2
133 - MED_POINT1 -> mesh dimension=0
134 - MED_POLYHED -> mesh dimension=3
135 - MED_TETRA4 -> mesh dimension=3
136
137 The mesh dimension of \a myMesh is equal to 3 ( \f max(2,0,3,3) ). The **relative mesh dimension** is equal to the difference between mesh dimension of geometic type and the mesh dimension
138 of the whole MED file dimension. It leads to the following **relative mesh dimension** :
139
140 - MED_TRI3 -> **relative mesh dimension** = -1
141 - MED_POINT1 -> **relative mesh dimension** = -3
142 - MED_POLYHED -> **relative mesh dimension** = 0
143 - MED_TETRA4 -> **relative mesh dimension** = 0
144
145 In \ref medloader "MEDLoader" all geometric information are then grouped relative dimension per relative dimension. It leads to the following geometric sorting of 
146 MED file data structure of \a myMesh :
147
148 - Level 0
149   - MED_TETRA4
150   - MED_POLYHED
151 - Level -1
152   - MED_TRI3
153 - Level -2
154   - nothing -> level **not** available for \a myMesh
155 - Level -3
156   - MED_POINT1
157
158 The mesh dimension of \a myMesh is 3. The relative mesh dimensions available are 0, -1 and -3.
159
160 \subsection MEDLoaderCommonVocRelMeshDimField Relative mesh dimension in fields
161
162 As it has been seen previously in \ref MEDLoaderCommonVocRelMeshDimMesh "for meshes", the values of fields are sorted by levels too.
163
164 The principle is the same than those explained for meshes. The only difference is in the fact that it is possible for fields on cell and fields on
165
166 gauss points that mesh dimension of underlying mesh of a field is not always (but very often) equal to the dimension of geometric types on which this field is defined.
167
168 So it is advised, to compare the non empty level of a field **and** of its underlying mesh before trying to request heavy data from a MED file.
169
170 \subsection MEDLoaderCommonVocIterationOrder Iteration and order in MED file
171
172 As seen \ref BasicMEDLoaderAPIGen "above", fields in MED file can be defined on different time steps.
173
174 But there is a **major difference** with \ref medcoupling MEDCoupling concept in time steps. \ref medcoupling MEDCoupling is focused to the float value of time for interpolation reason.
175
176 \ref medloader MEDLoader and MED file are focused on pair of integer to precise a specific time steps.
177
178 This difference of point of view can be seen in the API where the order of returned parameters in python differs from MEDCouplingFieldDouble::getTime to MEDFileField1TS::getTime.
179
180 In MED file and so in \ref medloader MEDLoader the time steps are identified by a pair of integers called :
181
182 - iteration
183 - order
184
185 Order refers to sub iteration id, that is by default set to -1 in case of non use. A physical time with float type is attached to this pair of integer.
186
187 */
188
189 /*!
190 \page MEDLoaderBasicAPIPage Basic MEDLoader API.
191
192 [TOC]
193
194 The aim of this page is to present basic API of MEDLoader. The goal of
195 this basic API is to perform a read or a write in one shot without any
196 internal state. That's why the basic API of MEDLoader offers \b only \b static methods whose method names have the first
197 character in capital. You are intended to use these methods. The following
198 chapters will try to describe in details some of important ones.
199
200 The basic idea of MEDLoader is to exploite as much as possible MED
201  file capabilities to store MEDCoupling data file in a MED file and 
202 reversely to load from a MED file into a MEDCoupling data structure.
203 Basically, the info on components of ParaMEDMEM::DataArrayDouble
204
205 instances are stores into components and units into MED files. The
206 name of meshes and fields are used by MEDLoader to use it as this into
207 MED file. A field f with \ref ParaMEDMEM::MEDCouplingTimeDiscretization
208 "time discretization" set to ONE_TIME, the value of
209 \c f->getTime(time,iteration,order) are used by MEDLoader to store
210 to identify the field into MED file. All strings used by MEDLoader to
211 use it into MED file should fulfill the rules of MED file where length
212 are limited. 
213 That's why the user should be aware of these constaints when trying to read/write a MED file using MEDLoader. 
214 MEDLoader tries to manage that by protecting the user by throwing exceptions when the rules are not followed.
215
216 \section BasicMEDLoaderBasicAPIGlobalInfo Retrieving tiny global information from MED files using basic API
217
218 The MEDLoader::CheckFileForRead method will perform the check of that before any attempt of read.
219 A field is also discriminated by its name. The method MEDLoader::GetCellFieldNamesOnMesh and MEDLoader::GetNodeFieldNamesOnMesh are available to know all fields
220 respectively on cells and on nodes lying on a specified mesh.
221
222  A field is defined by several time steps discriminated by a pair of int
223 (iteration,order). It is \b not possible to store 2 time steps of a same
224 field having the same iteration and order
225 number. The floatting point value attached on this couple of ids (iteration,order) is only present for information.
226 Static methods MEDLoader::GetCellFieldIterations and
227 MEDLoader::GetNodeFieldIterations return a vector of pair containing
228 each respectively iteration and order.
229
230 A time step of a field lyies on one \b or \b more mesh(es) specified by its \b or \b their name. A time step of a field in
231 MED file could be defined on point \b and on cell \b and, \b or on gauss points \b and, \b or on point per element.
232
233 This recalled specificities of MED file explains that it is necessary to specify each time, at field-read time, the type of field, the iteration and order number the mesh you are interested in.
234
235 Let's recall basic principles that explains some of the aspect of MEDLoade API.
236 \anchor MEDLoaderMeshNameConstraint MED file can contain several meshes. These meshes are
237 discriminated by their names (two meshes could not have the same
238 names). By the same way a MED file can contain several fields in MED.
239 So MEDLoader propose to you the MEDLoader::GetMeshNames method to
240 discover all the mesh names contained in your file.
241
242 \section BasicMEDLoaderBasicAPIMesh Reading and writing meshes in MED files using basic API
243
244 In MED file meshes could combine in one unstructured mesh cells that
245 have different dimension. For example it is possible to mix
246 MED_TETRA4, MED_TRIA6, MED_SEG2, MED_POINT1, MED_POLYGON,
247 MED_POLYHEDRA in a same mesh. In MEDCouplingUMesh such a mix is not
248 allowed as described \ref MEDCouplingUMeshes "here". So to \b read such mesh it
249 is important to know which meshdimension you are interested to. In API
250 the parameter \b meshDimRelToMax discreminates the meshdim you are
251 interested to relatively to the maximal dimension of cells contained
252 in the mesh in file.
253
254 Let's take 2 examples :
255
256 - If you have a mesh called "MyMesh" in file "file1.med" with
257 MED_POLYGON, MED_TRI3, MED_SEG2 and MED_SEG3 : The max dimension of
258 cells is 2 (for MED_POLYGON and MED_TRI3). So if you want exclusively
259 cells with type MED_POLYGON and MED_TRI3 you should use :
260
261 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_9
262
263 If you are interested in MED_SEG2 and MED_SEG3 you should use :
264
265 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_10
266
267 The method MEDLoader::ReadUMeshDimFromFile could
268 help you to have this mesh dimension.
269 \anchor MEDLoaderExample2
270 - Consider an another mesh called "Example2" in file "file2.med"
271 containing MED_POLYHEDRA, MED_TETRA4, MED_QUAD8, MED_TRI6, MED_SEG2
272 and MED_POINT1. In this case you will have :
273
274 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_8
275
276 To get 3D cells (MED_POLYHEDRA and MED_TETRA4) you should type :
277
278 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_7
279
280 To get 2D cells (MED_TRI6 and MED_QUAD8) you should type :
281
282 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_4
283
284 To get 1D cells (MED_SEG2) you should type :
285
286 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_5
287
288 And finally for 0D cells (MED_POINT1) you will write :
289
290 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_6
291
292 To finish this subsection, it is important to know that MEDLoader
293 takes into account of the cell numbers stored in a mesh of a med
294 file. This renumbering allows MEDLoader to conserve the order of
295 MEDCoupling cells into the file. So if the renumbering of cells in MED
296 file is not correct an exception will be thrown.
297
298 \subsection BasicMEDLoaderAPIPoMesh Part of meshes in MED files
299
300 A mesh contains one or more families on nodes and/or on cells. A family is a partition
301 (mathematical sense) of the mesh it lies to. A family can be described
302 by an integer field on \b all nodes and on \b all cells of a same mesh.
303 All cells and nodes having the same ids defines this family. This id
304 is called the familyId. A family is discriminated by its id. MED file
305 attach a name to its id to be more userfriendly. So by construction, 2 different
306 families could not share anything. The user can retrieve all the
307 families names available on a mesh with the static method MEDLoader::GetMeshFamiliesNames.
308
309 A group is a set of families. So groups can overlap each other,
310 contrary to families. Groups are also discriminated by a name. As for
311 families the static method to retrieves the groups of a specified mesh is MEDLoader::GetMeshGroupsNames.
312
313 MEDLoader allows you to retrieve the
314 corresponding "part of meshes" thanks to static methods
315 MEDLoader::ReadUMeshFromFamilies and MEDLoader::ReadUMeshFromGroups.
316 This method allows you to combine several families and groups in the
317 same returned mesh.
318
319 \subsection BasicMEDLoaderAPIField Reading a field at one time step in MED files
320
321 A field at one time step on one mesh, with one entity (cell, node)
322 lies on all mesh on on a part of it. In this last case a definition of
323 a profile is needed. Even if the notions of profile on mesh and group
324 on mesh could appear close, these two concepts are totally
325 disconnected in MED file.
326 The aspect of profile is managed by MEDLoader, thats why this
327 aspect does not appear in the MEDLoader API.
328 So to retrieve a field on 3D cell called "F1Cell" in example file
329 \ref MEDLoaderExample2 "file2.med (seen in meshes section)" on a mesh "Example2" on time
330 step defined by iteration number 2 and iteration 3 the request will be :
331
332 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_12
333
334 To retrive the same field (same iteration) on 2D cells only the call will be : 
335
336 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_13
337
338 \subsection MEDLoaderMEDFieldsRead Reading several field time steps at a time in MED files
339
340 It is possible with MEDLoader to read several time steps of a field at
341 a time.
342 The advantage with this approach is to avoid to read and load several
343 time a same mesh. This is typically recommanded to use the following
344 code when you desire to load all time steps of a field on cell "myField" lying on
345 same mesh "mesh1" in one shot :
346
347 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_11
348
349 \section MEDLoaderWriteMain Writing a MED file with MEDLoader
350
351 As MED file does, MEDLoader write process separates clearly
352 meshes from fields. The reason is that a common use case in write mode
353 is to write in a first time a mesh and then writes several time steps
354 of a same field in appended mode.
355
356 The fact that the write process is rarely in a one shot put a
357 constraint on API to precise to MEDLoader if you intend
358 to append data to an existing file, or if you want to create a new
359 file from scratch. This explains the presence of boolean parameter \b
360 writeFromScratch in API of MEDLoader starting with \b
361 MEDLoader::Write* .
362
363 If \b writeFromScratch parameter is set to \b true and if the file
364 already exists the file will be crashed and replaced by the new
365 corresponding data. If \b writeFromScratch parameter is set to \b false and if the
366 file does \b not \b exist the new file is created, but if the file
367 exists MEDLoader will enter in appended mode.
368
369 Two classes of MEDLoader write methods exists when \b writeFromScratch
370 is set to \b false :
371
372 -  Methods \b MEDLoader::Write*Dep : The write operation is performed without any question in file. The
373    responsability is let to the user because the MED file could be
374    corrupted. The advantage of this method is that it is faster
375    because no check is done.
376 - Methods \b MEDLoader::Write* : MEDLoader will not corrupt your file
377    by always trying to append data. The consequence of that is that a
378    read of part (and data processing) of MED file could be needed before any attempt of
379    writing. So these methods could be in some cases much time and memory consuming.
380
381 The behaviour of MEDLoader when \b writeFromScratch is set to false will be precised
382 for each \b MEDLoader::Write* methods is the next subsections.
383
384 \subsection MEDLoaderWriteMesh Writing one mesh in a MED file with MEDLoader
385
386 The first think to know is that MEDLoader is using the \b meshName in
387 ParaMEDMEM::MEDCouplingMesh instance to put it in MED file.
388
389 As explained in previous section \ref MEDLoaderMeshNameConstraint "here",
390 a mesh in MED file is discriminated by a name, so the \b meshName
391 \b should \b be \b non \b empty. If it is the case an
392 INTERP_KERNEL::Exception will be thrown.
393
394 To write one mesh \b myMesh with name \b "myMeshName" in a MED file \b "wfile1.med" the following code should be typed :
395
396 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_1
397
398 With the previous code, if "wFile1.med" file existed the file is
399 crashed and will contain after the call only the content of myMesh
400 instance.
401
402 If you desire to append a mesh in "wFile1.med" you should type :
403
404 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_2
405
406 With the previous code, if the "wFile1.med" had already a mesh called "myMeshName" an
407 INTERP_KERNEL::Exception will be thrown.
408
409 \subsection MEDLoaderWriteMeshes Writing several meshes in a MED file with MEDLoader
410
411 It could be interesting to write several meshes in one shot. Two
412 possiblities are possible :
413
414 - Write several instances of ParaMEDMEM::MEDCouplingUMesh
415   lying \b on \b same \b coords \b with \b different \b mesh \b dimension. In this case the
416   use of MEDLoader::WriteUMeshes is the method you should
417   use. Typically this method should be used to write such of file
418   defined \ref MEDLoaderExample2 "here".
419   This method first checks that all instances share the same
420   ParaMEDMEM::DataArrayDouble instance as coords. If not an
421   INTERP_KERNEL::Exception will be thrown and an invocation on
422   ParaMEDMEM::MEDCouplingPointSet::tryToShareSameCoords will be necessary.
423
424 - Write a partition of meshes having \b same \b mesh \b dimension, that is to say a set of
425   groups and families from given meshes. As in the previous case the
426   check of same coords will be done (if not an INTERP_KERNEL::Exception is
427   thrown). After this step this method will
428   merge (by concerving the order in input) and will simplify the
429   merged mesh. After this operation, the groups will be constituted by
430   assigning the groups names with the conresponding names of
431   instance. That's why all meshes have to have a not empty name and
432   different each other. The method to use in this case is
433   MEDLoader::WriteUMeshesPartition.
434
435 For these 2 described methods the semantic of \b writeFromScratch when
436 \b false is the same, that is to say : no writing
437 (INTERP_KERNEL::Exception thrown) will be done if the
438 file already exists and contains already a mesh with name 'meshName'
439 for MEDLoader::WriteUMeshesPartition method and the name of the first
440 of the vector of unstructured meshes passed as first parameter of
441 MEDLoader::WriteUMeshes.
442
443 \subsection MEDLoaderWriteField Writing one time step of a field in a MED file with MEDLoader
444
445 To write \b one \b time \b step of a field from scratch with MEDLoader is to
446 use MEDLoader::WriteField method. The behviour of this method depends
447 on the value of the \b writeFromScratch paramter :
448
449 - When \b writeFromScratch equals to \b true, this method performs two things, it
450 writes the underlying mesh and write the specified time step on it.
451
452 - When \b writeFromScatch equals to \b false, this method looks that
453   the underlying mesh exists (by looking the content of \c field->getMesh()->getName() ) in file. If not, the behaviour is the
454   same that previous case with \b writeFromScratch parameter set to
455   \b true. If the mesh already exists, MEDLoader reads the field and
456   tries to apply field on it. This operation could be rather time
457   consuming because a read operation is performed and a reorder
458   operation too. If the file already contains the same field at the
459   same time step (iteration and order ids) the corresponding time step
460   will be replaced by the field passed in parameter.
461
462 \subsection MEDLoaderWriteFields Writing several time steps of a field in a MED file with MEDLoader
463
464 To write a serie of time steps in a "file3.med" file lying on the same
465 unstructured mesh the typical code
466 to write is the following :
467
468 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_3
469
470 In the previous code, it is important to note that the values of pair
471 (iteration,order) should be different between two calls to avoid that
472 a call to MEDLoader::WriteFieldUsingAlreadyWrittenMesh overwrites a
473 previous call.
474 An another important thing is the fact that \c f->getMesh() does not be
475 modified.
476 This method of writing presents the big advantage to be fast, because
477 no check neither read is performed by this method. That's why contrary
478 to other MEDLoader::Write* method the parameter of \b writeFromScratch
479 is not needed here.
480
481 */
482
483 /*!
484 \page MEDLoaderAdvancedAPIPage Advanced MEDLoader API.
485
486 [TOC]
487
488 This method is much closer to MED file organization than \ref
489 MEDLoaderBasicAPI "basic MEDLoader API". All MED file
490 concepts are exposed to the user. As a consequence, this advanced
491 API is lead to change with MED file data model enhancement.
492
493 In reading mode, the user can scan entirely and directly the content of its MED file as it is organized in its MED file.
494 Inversely, in writing mode, the user can describe its data in the same
495 way that MED file does.
496
497 \section AdvMEDLoaderBasics Some of basics of advanced API
498
499 - Like basic %MEDLoader API there is a notion of \c meshDimRelToMax.
500 Each time This parameter appears in API, it will have the semantic
501 explain here.
502 The value of the parameter \c meshDimRelToMax is at most in {0,-1,-2,-3}. This relative value specifies a level
503 relative to value returned by  ParaMEDMEM::MEDFileMesh::getMeshDimension().
504
505 A mesh containing MED_TETRA4, MED_TRI3, MED_QUAD4 and MED_POINT1 has a meshDimension
506 equal to 3. For \c meshDimRelToMax equal to 0 the user will
507 deal with cells whose type has a dimension equal to 3+0, that is to
508 say here MED_TETRA4. For \c meshDimRelToMax equal to -1 the user will
509 deal with cells witch dimension equal to 3-1 that is to say MED_TRI3
510 and MED_QUAD4.
511
512 An important method is ParaMEDMEM::MEDFileUMesh::getNonEmptyLevels() method. It returns all
513 non empty levels available. In the previous example, this method will
514 return {0,-1,-3}. -2 does not appear because no cells with dimension
515 equal to 1 (3-2) appear in MED file mesh (no MED_SEG2 not MED_SEG3).
516
517 - Besides notion of \c meshDimRelToMax there is notion of \c meshDimRelToMaxExt.
518 \c meshDimRelToMaxExt is simply an extension of \c meshDimRelToMax for
519 nodes.
520
521 The parameter of \c meshDimRelToMaxExt appears in
522 \ref ParaMEDMEM::MEDFileUMesh "umesh advanced API" of %MEDLoader with the following semantics.
523
524 Some of MED file concepts are available both for cells and
525 nodes, (for example families, groups, numbering ) that's why for a simpler API this
526 concept has been introduced. \c meshDimRelToMaxExt parameter can take a value in at
527 most {1,0,-1,-2,-3}.
528 1 stands for node and 0,-1,-2,-3 has exactly the
529 same semantic than those described in \c meshDimRelToMax decribed
530 before.
531
532 - A parameter that also often appears in advanced %MEDLoader API is \c renum.
533 This parameter by default in advanced %MEDLoader API is set to \c
534 true.
535 This parameter indicates if the user intend to take into account
536 of the renumbering array of cells of the current MED file mesh.
537 If no renumbering array is defined, this parameter is ignored by
538 %MEDLoader.
539
540 If such renumbering exists and the \c renum parameter is
541 set to \c true, then the renumbering is taken into account. This is
542 exactly the behaviour of \ref MEDLoader::ReadUMeshFromFile "basic MEDLoader API".
543 If the user expects to ignore this renumbering even in case of
544 presence of renumbering array, false should be passed to \c renum
545 parameter. \b The \b parameter \b renum \b should \b be \b set \b with
546 \b cauton \b for \b users \b concerned \b by \b cells \b orders.
547
548 - A laster important parameter is the \c mode during writing. The
549   available values for the parameter \c mode are :
550   - 2 : for a write from scratch. If file already exists, file will be
551   erased and replace by the content of the instance on which \c write
552   method has been calles.
553   - 1 : If the file does not exists equivalent to 2. If file already
554   exists, the write is done on APPEND mode. That is to say that no
555   data loss will occur. But in case that an element with same ids than
556   current instance already exists, the content is not written and an
557   exception is thrown.
558   - 0 : If the file does not exists equivalent to 2. If file already
559   exists write without any question. If an element with same ids
560   existed previously the content is overwritten by the content of the
561   current instance, that can lead to a file corruption.
562
563 \section AdvMEDLoaderAPIMeshesRW Dealing with Meshes with advanced API.
564
565 Contrary to the basic %MEDLoader API, here after reading process, the user
566 has to deal with a new instance of class that fits the MED file model.
567 To access to a MEDCoupling mesh the user should request this class
568 instance.
569
570 \subsection AdvMEDLoaderAPIMeshReading Reading a mesh.
571
572 The class that incarnates Read/Write mesh in MED file is ParaMEDMEM::MEDFileUMesh.
573
574 First of all, like basic %MEDLoader API, only MEDfile files whose version >= 2.2 are able
575 to be read with advanced API.
576
577 To read a mesh having the name \c meshName in file \c fileName the
578 following simple code has to be written :
579
580 \code
581
582 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName,meshName);
583
584 \endcode
585
586 If the user do not know the name of the mesh inside MED file
587 'fileName' the following code should be written :
588
589 \code
590
591 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName);
592
593 \endcode
594
595 In this case the first mesh (in MED file sense) found in \c fileName
596 file will be loaded.
597
598 Now the user can ask for mesh dimension of of \c myMedMesh instance by
599 calling \c myMedMesh->getMeshDimension(). This method returns the
600 highest level of present cell in MED file mesh \c myMedMesh.
601 This returned integer is computed and \b not those contained in MED file
602 that can be invalid.
603
604 \n
605
606 - Retrieving a mesh at a specified relative level \c meshDimRelToMax=mdrm : simply call
607   - \c myMedMesh->getMeshAtLevel(mdrm)
608   - or \c myMedMesh->getLevel0Mesh() or \c
609   myMedMesh->getLevelM1Mesh(), or \c myMedMesh->getLevelM2Mesh()
610   depending on the value of mdrm
611
612
613 - Retrieving a family at a specified level :
614   - Either an array of node/cell id
615     - \c getFamilyArr method or \c getFamiliesArr
616   - Or on \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" form by calling
617     - \c getFamily method or \c getFamilies
618
619 - Retrieving a group at a specified level :
620   - Either an array of node/cell id
621     - \c getGroupArr method or \c getGroupsArr
622   - Or on \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" form by calling
623     - \c getGroup method or \c getGroups
624
625 - Retrieving family field array :
626 Method \c getFamilyFieldAtLevel retrieves for a specified extended level the
627 family id of each cell or node.
628
629 - Retrieving renumbering array :
630 Method \c getNumberFieldAtLevel returns, if it exists for a specified extended level, the
631 family id of each cell or node. If it does not exist an exception will
632 be thrown.
633
634 An important point is that families and groups are \b not sorted in
635 MED file. No sort is stored in MED file explicitely for Groups and
636 Families. Advanced %MEDLoader API, uses the same order than underlying
637 mesh at specified level.
638
639 \subsection AdvMEDLoaderAPIMeshReadingSampl Sample of reading a mesh.
640
641 Here a typical use of \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" instance.
642
643 \code
644
645 const char fileName[]=...;
646 const char meshName[]=...;
647 MEDFileUMesh *medmesh=MEDFileUMesh::New(fileName,meshName);
648 std::vector<int> nel=medmesh->getNonEmptyLevels();
649 if(nel.size()<1)
650   throw INTERP_KERNEL::Exception("The test is not good for my file ! Expecting a multi level mesh to play with !");
651 MEDCouplingUMesh *m0=medmesh->getMeshAtLevel(nel[1],false);
652 MEDCouplingUMesh *g1=medmesh->getGroup(nel[1],"mesh2",false);
653 DataArrayInt *dag1=medmesh->getGroupArr(nel[1],"mesh2",false);
654 MEDCouplingUMesh *g1bis=m0->buildPartOfMySelf(dag1->getConstPointer(),dag1->getConstPointer()+dag1->getNbOfElems());
655 g1bis->setName(dag1->getName());
656 if(!g1->isEqual(g1bis,1e-12))
657   throw INTERP_KERNEL::Exception("hmmmm :g1 and g1bis should be equal...");
658 //
659 dag1->decrRef();
660 g1->decrRef();
661 m0->decrRef();
662 medmesh->decrRef();
663
664 \endcode
665
666 \subsection AdvMEDLoaderAPIMeshWriting Writing a mesh.
667
668 The use is very symetric to reading part. It is possible to either
669 build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
670 scratch, or to work with an existing instance coming from a loading
671 from a file.
672
673 One important point is that coordinates of a mesh are shared by all
674 cells whatever their level. That's why the
675 \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble" instance
676 should be shared by all \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" used in input parameter of
677 set* methods. If the user intend to build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
678 scratch, a call to \c setCoords should be done first.
679
680
681 Generally speaking traduce get* methods with set* methods have corresponding write semantic.
682
683 Some differences still exist :
684
685 - \c setMeshAtLevel, \c setMeshAtLevelOld simply call \c setMeshAtLevelGen with repectively \c newOrOld parameter
686 set to true and false. These method specifies if a renumbering computation is needed or not. \c setMeshAtLevelOld is faster
687 than \c setMeshAtLevel because no renumbering computation is done. If the user is not warranty about the order of its meshes to enter
688 it is better to use \c setMeshAtLevel method.
689
690 - Groups definition : Groups constitution is time consuming because of the stored mode chosen by MED file to store them. Groups definition
691 lead to a partition computation which is time/mem consuming that's why groups should be defined at once and not with addGroup one by one that will lead to
692 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
693 set to the desired group name. If not an exception will be thrown, because MED file does not support groups with no name.
694
695 \subsection AdvMEDLoaderAPIMeshWritingSampl Sample of writing a mesh.
696
697 \code
698
699 MEDCouplingUMesh *m=...; //m is a mesh with meshDim=2 spaceDim=2
700 MEDCouplingUMesh *m1=...; //m1 is a mesh with meshDim=1 spaceDim=2 same coords than m
701 MEDCouplingUMesh *m2=...; //m2 is a mesh with meshDim=0 spaceDim=2 same coords than m
702 MEDFileUMesh *mm=MEDFileUMesh::New();
703 mm->setName("mm");//name needed to be non empty
704 mm->setDescription("Description mm");
705 mm->setCoords(m1->getCoords());
706 mm->setMeshAtLevel(-1,m1,false);
707 mm->setMeshAtLevel(0,m,false);
708 mm->setMeshAtLevel(-2,m2,false);
709 DataArrayInt *g1=DataArrayInt::New();
710 g1->alloc(2,1);
711 g1->setName("G1");
712 const int val1[2]={1,3};
713 std::copy(val1,val1+2,g1->getPointer());
714 DataArrayInt *g2=DataArrayInt::New();
715 g2->alloc(3,1);
716 g2->setName("G2");
717 const int val2[3]={1,2,3};
718 std::copy(val2,val2+3,g2->getPointer());
719 //
720 std::vector<const DataArrayInt *> grps(2);
721 grps[0]=g1; grps[1]=g2;
722 mm->setGroupsAtLevel(0,grps,false);
723 //
724 g2->decrRef();
725 g1->decrRef();
726 //
727 mm->write(2);
728
729
730 \endcode
731
732 \section AdvMEDLoaderAPIFieldRW Dealing with Fields with advanced API.
733
734 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".
735
736 Here the list of classes in %MEDLoader advanced API top down sorted :
737
738 - Level 0 : ParaMEDMEM::MEDFileFields
739 - Level -1 : ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA
740 - Level -2 : ParaMEDMEM::MEDFileField1TSWithoutSDA
741 - Level -3 : ParaMEDMEM::MEDFileFieldPerMesh (present only for backward compatibility MED file 2.2)
742 - Level -4 : ParaMEDMEM::MEDFileFieldPerMeshPerType
743 - Level -5 : ParaMEDMEM::MEDFileFieldPerMeshPerTypePerDisc
744
745
746 In each level in tree of the the cyan box of field is represented by a class. The only difference is that values are grouped in a single big array located 
747 in level -2 (ParaMEDMEM::MEDFileField1TSWithoutSDA)  in which each leaves (level -5) of MED file field
748 point to using a range [\a start, \a end).
749
750 As different time steps of a same field and different field inside a MED file can shared or not profiles (yellow box) and Locatization (red box) a manipulable field classes instance
751 (ParaMEDMEM::MEDFileField1TS and ParaMEDMEM::MEDFileFieldMultiTS) in advanced API are the result of a subclass of a data class
752 (respectively ParaMEDMEM::MEDFileField1TSWithoutSDA, ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA) and a instance of ParaMEDMEM::MEDFileFieldGlobsReal representing the shared data arrays (SDA)
753 at a specified scope inside the MED file.
754
755 \subsection AdvMEDLoaderAPIFieldR Reading a field
756
757 \subsubsection AdvMEDLoaderAPIFieldRC Reading a field defined on all entity
758
759 Fields defined on all entity are the most used and common fields in MED file world.
760
761 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.
762
763 Let's read a field on all entity called \a fieldName lying on a mesh called \a meshName in a MED file called \a fname at a iteration defined on time step defined
764 by \a iteration and \a order.
765
766 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_1
767
768 To read it there are 3 main approaches :
769
770 - Use ParaMEDMEM::MEDFileField1TS class :
771
772 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_3
773
774 - Use ParaMEDMEM::MEDFileFieldMultiTS class :
775
776 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_4
777
778 - Use iteration ParaMEDMEM::MEDFileFieldMultiTS class :
779
780 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_5
781
782 \subsubsection AdvMEDLoaderAPIFieldRP Reading a partial field
783
784 Let's read a partial field called \a fieldName lying on a mesh called \a meshName in a MED file called \a fname at a iteration defined on time step defined
785 by \a iteration and \a order.
786
787 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_1
788
789 Fields defined partially on a meshes can been read using 2 main approaches :
790
791 - Either the user wants to retreave it's field in %MEDCoupling sense, that is to say for interpolation, to evaluate such field on different points...
792 \n In this mode the link with the whole mesh is not useful for the user
793
794 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_3
795
796 - Or the user wants to retrieve the binding (cell ids or node ids) with the whole mesh on which the partial field lies partially on.
797
798 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_4
799
800 \ref medcoupling "MEDCoupling" allows to make bridges between the approaches. For example \a pfl \ref ParaMEDMEM::DataArrayInt "DataArrayInt instance" retrieved directly
801 from the file in the second approach can be retrived starting from first approach.
802
803 Starting from mesh \a firstApproachMesh of read field in first approach \a fread, whith the whole mesh \a wholeMesh the profile \a pflComputed can be computed :
804
805 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_5
806
807 Inversely, it is possible to rebuild field obtained in first apprach starting from second approach :
808
809 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_6
810
811 \subsection AdvMEDLoaderAPIFieldW Writing a field
812
813 \subsubsection AdvMEDLoaderAPIFieldWC Writing a field defined on all entity
814
815 Fields defined on all entity are the most used and common fields in MED file world.
816
817 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.
818
819 Let's write a cell field on all entity called \a fieldName lying on a mesh called \a meshName in a MED file called \a fname at a iteration defined on time step defined
820 by \a iteration and \a order.
821
822 \snippet MEDLoaderExamplesTest.py PySnippetWriteFieldOnAllEntity1_2
823
824 We can see here that the necessity to deal with both mesh and field to write a field is exposed by the API. The mesh write mode is 2 to tell to MED file that is file already exists to scratch it.
825 The mode of write is 0 to simply add to the file the field specific part.
826
827 \subsubsection AdvMEDLoaderAPIFieldWP Writing a partial field
828
829 \snippet MEDLoaderExamplesTest.py PySnippetWriteFieldPartial1_2
830
831 To write a partial field \a f can have a **null mesh**, because the link with mesh is made given the entry of \a mm MEDFileField1TS::setFieldProfile method.
832
833
834 */
835