Salome HOME
Merge from V6_main 15/03/2013
[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 MEDMEM and MED file do, 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 (as MEDMEM does) 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 behaviour is as MEDMEM, that
373    is to say, the write is done without any question in file. The
374    responsability is let to the user because the MED file could be
375    corrupted. The advantage of this method is that it is faster
376    because no check is done.
377 - Methods \b MEDLoader::Write* : MEDLoader will not corrupt your file
378    by always trying to append data. The consequence of that is that a
379    read of part (and data processing) of MED file could be needed before any attempt of
380    writing. So these methods could be in some cases much time and memory consuming.
381
382 The behaviour of MEDLoader when \b writeFromScratch is set to false will be precised
383 for each \b MEDLoader::Write* methods is the next subsections.
384
385 \subsection MEDLoaderWriteMesh Writing one mesh in a MED file with MEDLoader
386
387 The first think to know is that MEDLoader is using the \b meshName in
388 ParaMEDMEM::MEDCouplingMesh instance to put it in MED file.
389
390 As explained in previous section \ref MEDLoaderMeshNameConstraint "here",
391 a mesh in MED file is discriminated by a name, so the \b meshName
392 \b should \b be \b non \b empty. If it is the case an
393 INTERP_KERNEL::Exception will be thrown.
394
395 To write one mesh \b myMesh with name \b "myMeshName" in a MED file \b "wfile1.med" the following code should be typed :
396
397 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_1
398
399 With the previous code, if "wFile1.med" file existed the file is
400 crashed and will contain after the call only the content of myMesh
401 instance.
402
403 If you desire to append a mesh in "wFile1.med" you should type :
404
405 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_2
406
407 With the previous code, if the "wFile1.med" had already a mesh called "myMeshName" an
408 INTERP_KERNEL::Exception will be thrown.
409
410 \subsection MEDLoaderWriteMeshes Writing several meshes in a MED file with MEDLoader
411
412 It could be interesting to write several meshes in one shot. Two
413 possiblities are possible :
414
415 - Write several instances of ParaMEDMEM::MEDCouplingUMesh
416   lying \b on \b same \b coords \b with \b different \b mesh \b dimension. In this case the
417   use of MEDLoader::WriteUMeshes is the method you should
418   use. Typically this method should be used to write such of file
419   defined \ref MEDLoaderExample2 "here".
420   This method first checks that all instances share the same
421   ParaMEDMEM::DataArrayDouble instance as coords. If not an
422   INTERP_KERNEL::Exception will be thrown and an invocation on
423   ParaMEDMEM::MEDCouplingPointSet::tryToShareSameCoords will be necessary.
424
425 - Write a partition of meshes having \b same \b mesh \b dimension, that is to say a set of
426   groups and families from given meshes. As in the previous case the
427   check of same coords will be done (if not an INTERP_KERNEL::Exception is
428   thrown). After this step this method will
429   merge (by concerving the order in input) and will simplify the
430   merged mesh. After this operation, the groups will be constituted by
431   assigning the groups names with the conresponding names of
432   instance. That's why all meshes have to have a not empty name and
433   different each other. The method to use in this case is
434   MEDLoader::WriteUMeshesPartition.
435
436 For these 2 described methods the semantic of \b writeFromScratch when
437 \b false is the same, that is to say : no writing
438 (INTERP_KERNEL::Exception thrown) will be done if the
439 file already exists and contains already a mesh with name 'meshName'
440 for MEDLoader::WriteUMeshesPartition method and the name of the first
441 of the vector of unstructured meshes passed as first parameter of
442 MEDLoader::WriteUMeshes.
443
444 \subsection MEDLoaderWriteField Writing one time step of a field in a MED file with MEDLoader
445
446 To write \b one \b time \b step of a field from scratch with MEDLoader is to
447 use MEDLoader::WriteField method. The behviour of this method depends
448 on the value of the \b writeFromScratch paramter :
449
450 - When \b writeFromScratch equals to \b true, this method performs two things, it
451 writes the underlying mesh and write the specified time step on it.
452
453 - When \b writeFromScatch equals to \b false, this method looks that
454   the underlying mesh exists (by looking the content of \c field->getMesh()->getName() ) in file. If not, the behaviour is the
455   same that previous case with \b writeFromScratch parameter set to
456   \b true. If the mesh already exists, MEDLoader reads the field and
457   tries to apply field on it. This operation could be rather time
458   consuming because a read operation is performed and a reorder
459   operation too. If the file already contains the same field at the
460   same time step (iteration and order ids) the corresponding time step
461   will be replaced by the field passed in parameter.
462
463 \subsection MEDLoaderWriteFields Writing several time steps of a field in a MED file with MEDLoader
464
465 To write a serie of time steps in a "file3.med" file lying on the same
466 unstructured mesh the typical code
467 to write is the following :
468
469 \snippet MEDLoaderExamplesTest.py PySnippetMeshAdvAPI1_3
470
471 In the previous code, it is important to note that the values of pair
472 (iteration,order) should be different between two calls to avoid that
473 a call to MEDLoader::WriteFieldUsingAlreadyWrittenMesh overwrites a
474 previous call.
475 An another important thing is the fact that \c f->getMesh() does not be
476 modified.
477 This method of writing presents the big advantage to be fast, because
478 no check neither read is performed by this method. That's why contrary
479 to other MEDLoader::Write* method the parameter of \b writeFromScratch
480 is not needed here.
481
482 */
483
484 /*!
485 \page MEDLoaderAdvancedAPIPage Advanced MEDLoader API.
486
487 [TOC]
488
489 This method is much closer to MED file organization than \ref
490 MEDLoaderBasicAPI "basic MEDLoader API". All MED file
491 concepts are exposed to the user. As a consequence, this advanced
492 API is lead to change with MED file data model enhancement.
493
494 In reading mode, the user can scan entirely and directly the content of its MED file as it is organized in its MED file.
495 Inversely, in writing mode, the user can describe its data in the same
496 way that MED file does.
497
498 \section AdvMEDLoaderBasics Some of basics of advanced API
499
500 - Like basic %MEDLoader API there is a notion of \c meshDimRelToMax.
501 Each time This parameter appears in API, it will have the semantic
502 explain here.
503 The value of the parameter \c meshDimRelToMax is at most in {0,-1,-2,-3}. This relative value specifies a level
504 relative to value returned by  ParaMEDMEM::MEDFileMesh::getMeshDimension().
505
506 A mesh containing MED_TETRA4, MED_TRI3, MED_QUAD4 and MED_POINT1 has a meshDimension
507 equal to 3. For \c meshDimRelToMax equal to 0 the user will
508 deal with cells whose type has a dimension equal to 3+0, that is to
509 say here MED_TETRA4. For \c meshDimRelToMax equal to -1 the user will
510 deal with cells witch dimension equal to 3-1 that is to say MED_TRI3
511 and MED_QUAD4.
512
513 An important method is ParaMEDMEM::MEDFileUMesh::getNonEmptyLevels() method. It returns all
514 non empty levels available. In the previous example, this method will
515 return {0,-1,-3}. -2 does not appear because no cells with dimension
516 equal to 1 (3-2) appear in MED file mesh (no MED_SEG2 not MED_SEG3).
517
518 - Besides notion of \c meshDimRelToMax there is notion of \c meshDimRelToMaxExt.
519 \c meshDimRelToMaxExt is simply an extension of \c meshDimRelToMax for
520 nodes.
521
522 The parameter of \c meshDimRelToMaxExt appears in
523 \ref ParaMEDMEM::MEDFileUMesh "umesh advanced API" of %MEDLoader with the following semantics.
524
525 Some of MED file concepts are available both for cells and
526 nodes, (for example families, groups, numbering ) that's why for a simpler API this
527 concept has been introduced. \c meshDimRelToMaxExt parameter can take a value in at
528 most {1,0,-1,-2,-3}.
529 1 stands for node and 0,-1,-2,-3 has exactly the
530 same semantic than those described in \c meshDimRelToMax decribed
531 before.
532
533 - A parameter that also often appears in advanced %MEDLoader API is \c renum.
534 This parameter by default in advanced %MEDLoader API is set to \c
535 true.
536 This parameter indicates if the user intend to take into account
537 of the renumbering array of cells of the current MED file mesh.
538 If no renumbering array is defined, this parameter is ignored by
539 %MEDLoader.
540
541 If such renumbering exists and the \c renum parameter is
542 set to \c true, then the renumbering is taken into account. This is
543 exactly the behaviour of \ref MEDLoader::ReadUMeshFromFile "basic MEDLoader API".
544 If the user expects to ignore this renumbering even in case of
545 presence of renumbering array, false should be passed to \c renum
546 parameter. \b The \b parameter \b renum \b should \b be \b set \b with
547 \b cauton \b for \b users \b concerned \b by \b cells \b orders.
548
549 - A laster important parameter is the \c mode during writing. The
550   available values for the parameter \c mode are :
551   - 2 : for a write from scratch. If file already exists, file will be
552   erased and replace by the content of the instance on which \c write
553   method has been calles.
554   - 1 : If the file does not exists equivalent to 2. If file already
555   exists, the write is done on APPEND mode. That is to say that no
556   data loss will occur. But in case that an element with same ids than
557   current instance already exists, the content is not written and an
558   exception is thrown.
559   - 0 : If the file does not exists equivalent to 2. If file already
560   exists write without any question. If an element with same ids
561   existed previously the content is overwritten by the content of the
562   current instance, that can lead to a file corruption.
563
564 \section AdvMEDLoaderAPIMeshesRW Dealing with Meshes with advanced API.
565
566 Contrary to the basic %MEDLoader API, here after reading process, the user
567 has to deal with a new instance of class that fits the MED file model.
568 To access to a MEDCoupling mesh the user should request this class
569 instance.
570
571 \subsection AdvMEDLoaderAPIMeshReading Reading a mesh.
572
573 The class that incarnates Read/Write mesh in MED file is ParaMEDMEM::MEDFileUMesh.
574
575 First of all, like basic %MEDLoader API, only MEDfile files whose version >= 2.2 are able
576 to be read with advanced API.
577
578 To read a mesh having the name \c meshName in file \c fileName the
579 following simple code has to be written :
580
581 \code
582
583 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName,meshName);
584
585 \endcode
586
587 If the user do not know the name of the mesh inside MED file
588 'fileName' the following code should be written :
589
590 \code
591
592 MEDFileUMesh *myMedMesh=MEDFileUMesh::New(fileName);
593
594 \endcode
595
596 In this case the first mesh (in MED file sense) found in \c fileName
597 file will be loaded.
598
599 Now the user can ask for mesh dimension of of \c myMedMesh instance by
600 calling \c myMedMesh->getMeshDimension(). This method returns the
601 highest level of present cell in MED file mesh \c myMedMesh.
602 This returned integer is computed and \b not those contained in MED file
603 that can be invalid.
604
605 \n
606
607 - Retrieving a mesh at a specified relative level \c meshDimRelToMax=mdrm : simply call
608   - \c myMedMesh->getMeshAtLevel(mdrm)
609   - or \c myMedMesh->getLevel0Mesh() or \c
610   myMedMesh->getLevelM1Mesh(), or \c myMedMesh->getLevelM2Mesh()
611   depending on the value of mdrm
612
613
614 - Retrieving a family at a specified level :
615   - Either an array of node/cell id
616     - \c getFamilyArr method or \c getFamiliesArr
617   - Or on \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" form by calling
618     - \c getFamily method or \c getFamilies
619
620 - Retrieving a group at a specified level :
621   - Either an array of node/cell id
622     - \c getGroupArr method or \c getGroupsArr
623   - Or on \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" form by calling
624     - \c getGroup method or \c getGroups
625
626 - Retrieving family field array :
627 Method \c getFamilyFieldAtLevel retrieves for a specified extended level the
628 family id of each cell or node.
629
630 - Retrieving renumbering array :
631 Method \c getNumberFieldAtLevel returns, if it exists for a specified extended level, the
632 family id of each cell or node. If it does not exist an exception will
633 be thrown.
634
635 An important point is that families and groups are \b not sorted in
636 MED file. No sort is stored in MED file explicitely for Groups and
637 Families. Advanced %MEDLoader API, uses the same order than underlying
638 mesh at specified level.
639
640 \subsection AdvMEDLoaderAPIMeshReadingSampl Sample of reading a mesh.
641
642 Here a typical use of \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" instance.
643
644 \code
645
646 const char fileName[]=...;
647 const char meshName[]=...;
648 MEDFileUMesh *medmesh=MEDFileUMesh::New(fileName,meshName);
649 std::vector<int> nel=medmesh->getNonEmptyLevels();
650 if(nel.size()<1)
651   throw INTERP_KERNEL::Exception("The test is not good for my file ! Expecting a multi level mesh to play with !");
652 MEDCouplingUMesh *m0=medmesh->getMeshAtLevel(nel[1],false);
653 MEDCouplingUMesh *g1=medmesh->getGroup(nel[1],"mesh2",false);
654 DataArrayInt *dag1=medmesh->getGroupArr(nel[1],"mesh2",false);
655 MEDCouplingUMesh *g1bis=m0->buildPartOfMySelf(dag1->getConstPointer(),dag1->getConstPointer()+dag1->getNbOfElems());
656 g1bis->setName(dag1->getName());
657 if(!g1->isEqual(g1bis,1e-12))
658   throw INTERP_KERNEL::Exception("hmmmm :g1 and g1bis should be equal...");
659 //
660 dag1->decrRef();
661 g1->decrRef();
662 m0->decrRef();
663 medmesh->decrRef();
664
665 \endcode
666
667 \subsection AdvMEDLoaderAPIMeshWriting Writing a mesh.
668
669 The use is very symetric to reading part. It is possible to either
670 build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
671 scratch, or to work with an existing instance coming from a loading
672 from a file.
673
674 One important point is that coordinates of a mesh are shared by all
675 cells whatever their level. That's why the
676 \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble" instance
677 should be shared by all \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh" used in input parameter of
678 set* methods. If the user intend to build a \ref ParaMEDMEM::MEDFileUMesh "MEDFileUMesh" instance from
679 scratch, a call to \c setCoords should be done first.
680
681
682 Generally speaking traduce get* methods with set* methods have corresponding write semantic.
683
684 Some differences still exist :
685
686 - \c setMeshAtLevel, \c setMeshAtLevelOld simply call \c setMeshAtLevelGen with repectively \c newOrOld parameter
687 set to true and false. These method specifies if a renumbering computation is needed or not. \c setMeshAtLevelOld is faster
688 than \c setMeshAtLevel because no renumbering computation is done. If the user is not warranty about the order of its meshes to enter
689 it is better to use \c setMeshAtLevel method.
690
691 - Groups definition : Groups constitution is time consuming because of the stored mode chosen by MED file to store them. Groups definition
692 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
693 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
694 set to the desired group name. If not an exception will be thrown, because MED file does not support groups with no name.
695
696 \subsection AdvMEDLoaderAPIMeshWritingSampl Sample of writing a mesh.
697
698 \code
699
700 MEDCouplingUMesh *m=...; //m is a mesh with meshDim=2 spaceDim=2
701 MEDCouplingUMesh *m1=...; //m1 is a mesh with meshDim=1 spaceDim=2 same coords than m
702 MEDCouplingUMesh *m2=...; //m2 is a mesh with meshDim=0 spaceDim=2 same coords than m
703 MEDFileUMesh *mm=MEDFileUMesh::New();
704 mm->setName("mm");//name needed to be non empty
705 mm->setDescription("Description mm");
706 mm->setCoords(m1->getCoords());
707 mm->setMeshAtLevel(-1,m1,false);
708 mm->setMeshAtLevel(0,m,false);
709 mm->setMeshAtLevel(-2,m2,false);
710 DataArrayInt *g1=DataArrayInt::New();
711 g1->alloc(2,1);
712 g1->setName("G1");
713 const int val1[2]={1,3};
714 std::copy(val1,val1+2,g1->getPointer());
715 DataArrayInt *g2=DataArrayInt::New();
716 g2->alloc(3,1);
717 g2->setName("G2");
718 const int val2[3]={1,2,3};
719 std::copy(val2,val2+3,g2->getPointer());
720 //
721 std::vector<const DataArrayInt *> grps(2);
722 grps[0]=g1; grps[1]=g2;
723 mm->setGroupsAtLevel(0,grps,false);
724 //
725 g2->decrRef();
726 g1->decrRef();
727 //
728 mm->write(2);
729
730
731 \endcode
732
733 \section AdvMEDLoaderAPIFieldRW Dealing with Fields with advanced API.
734
735 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".
736
737 Here the list of classes in %MEDLoader advanced API top down sorted :
738
739 - Level 0 : ParaMEDMEM::MEDFileFields
740 - Level -1 : ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA
741 - Level -2 : ParaMEDMEM::MEDFileField1TSWithoutSDA
742 - Level -3 : ParaMEDMEM::MEDFileFieldPerMesh (present only for backward compatibility MED file 2.2)
743 - Level -4 : ParaMEDMEM::MEDFileFieldPerMeshPerType
744 - Level -5 : ParaMEDMEM::MEDFileFieldPerMeshPerTypePerDisc
745
746
747 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 
748 in level -2 (ParaMEDMEM::MEDFileField1TSWithoutSDA)  in which each leaves (level -5) of MED file field
749 point to using a range [\a start, \a end).
750
751 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
752 (ParaMEDMEM::MEDFileField1TS and ParaMEDMEM::MEDFileFieldMultiTS) in advanced API are the result of a subclass of a data class
753 (respectively ParaMEDMEM::MEDFileField1TSWithoutSDA, ParaMEDMEM::MEDFileFieldMultiTSWithoutSDA) and a instance of ParaMEDMEM::MEDFileFieldGlobsReal representing the shared data arrays (SDA)
754 at a specified scope inside the MED file.
755
756 \subsection AdvMEDLoaderAPIFieldR Reading a field
757
758 \subsubsection AdvMEDLoaderAPIFieldRC Reading a field defined on all entity
759
760 Fields defined on all entity are the most used and common fields in MED file world.
761
762 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.
763
764 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
765 by \a iteration and \a order.
766
767 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_1
768
769 To read it there are 3 main approaches :
770
771 - Use ParaMEDMEM::MEDFileField1TS class :
772
773 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_3
774
775 - Use ParaMEDMEM::MEDFileFieldMultiTS class :
776
777 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_4
778
779 - Use iteration ParaMEDMEM::MEDFileFieldMultiTS class :
780
781 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldOnAllEntity1_5
782
783 \subsubsection AdvMEDLoaderAPIFieldRP Reading a partial field
784
785 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
786 by \a iteration and \a order.
787
788 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_1
789
790 Fields defined partially on a meshes can been read using 2 main approaches :
791
792 - 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...
793 \n In this mode the link with the whole mesh is not useful for the user
794
795 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_3
796
797 - 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.
798
799 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_4
800
801 \ref medcoupling "MEDCoupling" allows to make bridges between the approaches. For example \a pfl \ref ParaMEDMEM::DataArrayInt "DataArrayInt instance" retrieved directly
802 from the file in the second approach can be retrived starting from first approach.
803
804 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 :
805
806 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_5
807
808 Inversely, it is possible to rebuild field obtained in first apprach starting from second approach :
809
810 \snippet MEDLoaderExamplesTest.py PySnippetReadFieldPartial1_6
811
812 \subsection AdvMEDLoaderAPIFieldW Writing a field
813
814 \subsubsection AdvMEDLoaderAPIFieldWC Writing a field defined on all entity
815
816 Fields defined on all entity are the most used and common fields in MED file world.
817
818 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.
819
820 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
821 by \a iteration and \a order.
822
823 \snippet MEDLoaderExamplesTest.py PySnippetWriteFieldOnAllEntity1_2
824
825 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.
826 The mode of write is 0 to simply add to the file the field specific part.
827
828 \subsubsection AdvMEDLoaderAPIFieldWP Writing a partial field
829
830 \snippet MEDLoaderExamplesTest.py PySnippetWriteFieldPartial1_2
831
832 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.
833
834
835 */
836