Salome HOME
bf96a4e501864acc7fe6170ac4383a2d8bb8fe81
[modules/med.git] / doc / user / doxygen / doxfiles / examples / medcouplingexamplesarrays.doxy
1
2 \section ExamplesArrays Arrays
3
4 \subsection ExamplesArraysCreate Create
5
6 \anchor BEGIN_PYTHON_ONLY
7 \subsubsection MEDCouplingArraySteps0 Building an array from scratch in Python
8 \anchor MEDCouplingArraySteps0Double
9 <h3>Building a double array from scratch in Python</h3>
10
11 Let's consider a list of floats \c dataDouble.
12
13 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_0
14
15 The easiest way to build the \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble instance" called \c arrayDouble simply call :
16
17 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_1bis
18
19 An another way is to do that :
20
21 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_1
22
23 \anchor MEDCouplingArraySteps0Int
24 <h3>Building an int array from scratch in Python</h3>
25
26 Let's consider a list of ints \c dataInt.
27
28 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_2
29
30 The easiest way to build the \ref ParaMEDMEM::DataArrayInt "DataArrayInt instance" called \c arrayInt simply call :
31
32 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_3bis
33
34 An another way is to do that :
35
36 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_3
37 \anchor END_PYTHON_ONLY
38
39
40 \anchor BEGIN_CPP_ONLY
41 \subsubsection MEDCouplingArraySteps1 Building an array from scratch in C++
42
43 In this example we will create arrays with 12 tuples constituted each
44 of 3 components. These arrays will be created using different ways.\n
45
46 The following code is only based using \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble"
47 but the use of \ref ParaMEDMEM::DataArrayInt "DataArrayInt" is strictly equivalent.
48
49 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_0
50
51 \anchor MEDCouplingArraySteps1NCNO
52 <h3>Building an array from scratch in C++, no copy no ownership</h3>
53
54 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_1
55
56 \anchor MEDCouplingArraySteps1NCWCPPO
57 <h3>Building an array from scratch in C++, no copy with C++ ownership</h3>
58
59 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_2
60
61 \anchor MEDCouplingArraySteps1NCWCO
62 <h3>Building an array from scratch in C++, no copy with C ownership</h3>
63
64 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_3
65
66 \anchor MEDCouplingArraySteps1WC
67 <h3>Building an array from scratch in C++, with copy</h3>
68
69 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_4
70 \anchor END_CPP_ONLY
71
72 \anchor BEGIN_CPP_ONLY
73 \subsubsection cpp_mcdataarray_copy Copy DataArrays
74
75 \anchor cpp_mcdataarray_deepcopy
76 <h3>Deep copy</h3>
77
78 To perform a deep copy of a DataArray instance simply invoke :
79
80 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_5
81
82 or :
83
84 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_5bis
85
86 \c coordsArrCpy is the deep copy of \c coordsArr so they are independent and their *raw data* has been deeply copied.
87
88 So it leads to the following behaviour :
89 \anchor MEDCouplingArrayBasicsCopyDeepTestEqual
90
91 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_6
92
93 As \c coordsArrCpy is a copy object it needs to be deallocated in C++ like \c coordsArr.
94
95 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_7
96
97 \anchor cpp_mcdataarray_shallowcopy
98 <h3>Shallow copy</h3>
99
100 To perform a shallow copy of a DataArray instance simply invoke :
101
102 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_8
103
104 \c coordsArrCpy is the shallow copy of \c coordsArr so they share the same *raw data*. In reality they are the same object.
105 So it leads to the following behaviour to compare with the deep copy :
106
107 \anchor MEDCouplingArrayBasicsCopyShallowTestEqual
108
109 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_9
110
111 So here the content of \c coordsArr and \c coordsArrCpy are linked, contrary to the deep copy case.
112
113 As \c coordsArrCpy is a copy object, in C++, it needs to be deallocated.
114
115 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_10
116
117 \anchor MEDCouplingArrayBasicsCopyDeepAssign
118 <h3>Assignation by deep copy of DataArray</h3>
119
120 We start by building a instance of ParaMEDMEM::DataArrayDouble allocated or not. Here, instance is not allocated, only built empty.
121
122 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_11
123
124 Then, \c coordsArrCpy is assigned with the content of \c coordsArr.
125
126 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_12
127
128 Then \c coordsArrCpy is a deep copy of \c coordsArr except that the instance of ParaMEDMEM::DataArrayDouble is those specified.
129 But the behaviour is the same than those seen for \ref MEDCouplingArrayBasicsCopyDeepTestEqual "deep copy".
130
131 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_13
132
133 As always, in C++, \c coordsArrCpy is an object whose life cycle is fully independent from \c coordsArr so decrement is needed.
134
135 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_14
136
137 \anchor END_CPP_ONLY
138
139
140 \subsubsection cpp_mcdataarrayint_buildpermutationarr Building a permutation array
141
142 Here we create two arrays containing same values but in different order and then we use
143 \ref ParaMEDMEM::DataArrayInt::buildPermutationArr "DataArrayInt::buildPermutationArr()" to get
144 an array showing in what places the values of \b b array are located in \b a array.
145 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_buildPermutationArr_1
146 The result array \b c contains [1,0,4,2,3].
147
148
149 \subsection ExamplesArraysModify Modify
150
151 \subsubsection cpp_mcdataarrayint_invertarray Inverting renumbering maps
152
153 \anchor cpp_mcdataarrayint_invertarrayo2n2n2o
154 <h3> invertArrayO2N2N2O() </h3>
155
156 In this example we create a DataArrayInt containing a renumbering map in
157 "Old to New" mode, convert it into the renumbering map in "New to Old" mode and check the
158 result.
159 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_invertArrayO2N2N2O_1
160
161 \anchor cpp_mcdataarrayint_invertarrayn2o2o2n
162 <br><h3> invertArrayN2O2O2N() </h3>
163
164 In this example we create a DataArrayInt containing a renumbering map in
165 "New to Old" mode, convert it into the renumbering map in "Old to New" mode and check the
166 result.
167 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_invertArrayN2O2O2N_1
168
169
170 \subsubsection py_mcdataarraydouble_setpartofvalues Set part of values of DataArrayDouble
171
172 \anchor py_mcdataarraydouble_setselectedcomponents
173 <h3> setSelectedComponents() </h3>
174 First, we create a 'source' array.
175 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents1
176 Now we create a larger zero array and assign the array \b da into it.
177 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents2
178 As result contents of the array \b dv are as follows.
179 <pre>
180 Info of components : "a2"   "a1"   "v3"   "v4"
181     Tuple #0 : 2 1 0 0
182     Tuple #1 : 4 3 0 0
183     Tuple #2 : 6 5 0 0
184     Tuple #3 : 0 0 0 0
185 </pre>
186 The same result can be achieved other way (except that component info
187 is not copied):
188 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents3
189
190 \anchor py_mcdataarraydouble_setpartofvalues1
191 <br><h3> setPartOfValues1() </h3>
192 We create two arrays:
193 - a "large" (4x4) zero array \b da to assign to and
194 - a smaller (2x2) array \b dv filled with values [7.,8.,9.,10].
195
196 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_1
197 Now we copy \b dv to the middle of \b da.
198 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_2
199 As result contents of the array \b da are as follows.
200 <pre>
201     Info of components :"v1"   "v2"   "v3"   "v4"
202     Tuple #0 : 0 0 0 0
203     Tuple #1 : 0 7 8 0
204     Tuple #2 : 0 9 10 0
205     Tuple #3 : 0 0 0 0
206 </pre>
207
208 Here we re-fill \b da with zeros and copy \b dv into a component of \b da.
209
210 Note that the last parameter \b strictCompoCompare should be \c False
211 in this case, else \ref ParaMEDMEM::DataArrayDouble::setPartOfValues1()
212 throws an exception because \b da has 2 components but only one target
213 component is specified.
214 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_3
215 <pre>
216     Tuple #0 : 0 7 0 0
217     Tuple #1 : 0 8 0 0
218     Tuple #2 : 0 9 0 0
219     Tuple #3 : 0 10 0 0
220 </pre>
221 Below more two variants of location of target values are shown.
222 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_4
223 <pre>
224     Tuple #0 : 0 0 0 0
225     Tuple #1 : 7 8 9 10
226     Tuple #2 : 0 0 0 0
227     Tuple #3 : 0 0 0 0
228 </pre>
229
230 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_5
231 <pre>
232     Tuple #0 : 0 7 0 8
233     Tuple #1 : 0 0 0 0
234     Tuple #2 : 0 9 0 10
235     Tuple #3 : 0 0 0 0
236 </pre>
237 The same result can be achieved other way:
238 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_6
239
240
241 \anchor py_mcdataarraydouble_setpartofvaluessimple1
242 <br><h3> setPartOfValuesSimple1() </h3>
243 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
244 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_1
245 Now we assign \b dv to the middle of \b da.
246 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_2
247 As result contents of the array \b da are as follows.
248 <pre>
249     Tuple #0 : 0 0 0 0
250     Tuple #1 : 0 7 7 0
251     Tuple #2 : 0 7 7 0
252     Tuple #3 : 0 0 0 0
253 </pre>
254
255 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
256 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_3
257 <pre>
258     Tuple #0 : 0 7 0 0
259     Tuple #1 : 0 7 0 0
260     Tuple #2 : 0 7 0 0
261     Tuple #3 : 0 7 0 0
262 </pre>
263 Below more two variants of location of target values are shown.
264 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_4
265 <pre>
266     Tuple #0 : 0 0 0 0
267     Tuple #1 : 7 7 7 7
268     Tuple #2 : 0 0 0 0
269     Tuple #3 : 0 0 0 0
270 </pre>
271
272 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_5
273 <pre>
274     Tuple #0 : 0 7 0 7
275     Tuple #1 : 0 0 0 0
276     Tuple #2 : 0 7 0 7
277     Tuple #3 : 0 0 0 0
278 </pre>
279 The same result can be achieved other way:
280 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_6
281
282
283 \anchor py_mcdataarraydouble_setpartofvaluessimple2
284 <br><h3> setPartOfValuesSimple2() </h3>
285 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
286 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_1
287 Now we assign \b dv to the middle of \b da.
288 We explicitly specify tuples and component to assign to by a list [1,2].
289 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_2
290 As result contents of the array \b da are as follows.
291 <pre>
292     Tuple #0 : 0 0 0 0
293     Tuple #1 : 0 7 7 0
294     Tuple #2 : 0 7 7 0
295     Tuple #3 : 0 0 0 0
296 </pre>
297
298 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
299 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_3
300 <pre>
301     Tuple #0 : 0 7 0 0
302     Tuple #1 : 0 7 0 0
303     Tuple #2 : 0 7 0 0
304     Tuple #3 : 0 7 0 0
305 </pre>
306 Below more two variants of location of target values are shown.
307 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_4
308 <pre>
309     Tuple #0 : 0 0 0 0
310     Tuple #1 : 7 7 7 7
311     Tuple #2 : 0 0 0 0
312     Tuple #3 : 0 0 0 0
313 </pre>
314
315 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_5
316 <pre>
317     Tuple #0 : 0 7 0 7
318     Tuple #1 : 0 0 0 0
319     Tuple #2 : 0 7 0 7
320     Tuple #3 : 0 0 0 0
321 </pre>
322 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValuesSimple2() can't
323 be explicitly called in Python.
324
325
326 \anchor py_mcdataarraydouble_setpartofvaluessimple3
327 <br><h3> setPartOfValuesSimple3() </h3>
328 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
329 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_1
330 Now we assign \b dv to the middle of \b da.
331 We explicitly specify tuples to assign to by a list [1,2]. And we specify
332 components to assign to using slicing: 1:3.
333 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_2
334 As result contents of the array \b da are as follows.
335 <pre>
336     Tuple #0 : 0 0 0 0
337     Tuple #1 : 0 7 7 0
338     Tuple #2 : 0 7 7 0
339     Tuple #3 : 0 0 0 0
340 </pre>
341
342 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
343 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_3
344 <pre>
345     Tuple #0 : 0 7 0 0
346     Tuple #1 : 0 7 0 0
347     Tuple #2 : 0 7 0 0
348     Tuple #3 : 0 7 0 0
349 </pre>
350 Below more two variants of location of target values are shown.
351 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_4
352 <pre>
353     Tuple #0 : 0 0 0 0
354     Tuple #1 : 7 7 7 7
355     Tuple #2 : 0 0 0 0
356     Tuple #3 : 0 0 0 0
357 </pre>
358
359 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_5
360 <pre>
361     Tuple #0 : 0 7 0 7
362     Tuple #1 : 0 0 0 0
363     Tuple #2 : 0 7 0 7
364     Tuple #3 : 0 0 0 0
365 </pre>
366 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValuesSimple3() can't
367 be explicitly called in Python.
368
369
370 \anchor py_mcdataarraydouble_setpartofvalues2
371 <br><h3> setPartOfValues2() </h3>
372 We create two arrays:
373 - a "large" (4x7) zero array \b da to assign to,
374 - a smaller (3x2) array \b dv filled with values [7.,8.,9.,10.,11.,12.].
375
376 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_1
377 Now we assign the two components of \b dv to the components of \b da
378 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
379   indices [0,1,2]. This is the first mode of usage.
380 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_2
381 As result contents of the array \b da are as follows.
382 <pre>
383     Tuple #0 : 0  7  0  8  0  0  0
384     Tuple #1 : 0  9  0 10  0  0  0
385     Tuple #2 : 0 11  0 12  0  0  0
386     Tuple #3 : 0  0  0  0  0  0  0
387 </pre>
388 Every value of \b dv has been assigned to its own location within \b da.
389
390 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
391 And we assign \b dv to the tuples of \b da with indices [0,2,3] .
392 This is the second mode of usage.
393 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_3
394 The contents of \b dv have been assigned to each of specified tuples of \b da.
395 Every value of \b dv is repeated in the 3 specified tuples within \b da.
396 <pre>
397     Tuple #0 : 7  0  8  9 10 11 12
398     Tuple #1 : 0  0  0  0  0  0  0
399     Tuple #2 : 7  0  8  9 10 11 12
400     Tuple #3 : 7  0  8  9 10 11 12
401 </pre>
402 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValues2() can't
403 be explicitly called in Python.
404
405
406 \anchor py_mcdataarraydouble_setpartofvalues3
407 <br><h3> setPartOfValues3() </h3>
408 We create two arrays:
409 - a "large" (4x7) zero array \b da to assign to,
410 - a smaller (3x2) array \b dv filled with values [7.,8.,9.,10.,11.,12.].
411
412 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_1
413 Now we assign the two components of \b dv to the components of \b da
414 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
415 indices [0,1,2] which are specified using slicing: "0:3".
416 This is the first mode of usage.
417 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_2
418 As result contents of the array \b da are as follows.
419 <pre>
420     Tuple #0 : 0  7  0  8  0  0  0
421     Tuple #1 : 0  9  0 10  0  0  0
422     Tuple #2 : 0 11  0 12  0  0  0
423     Tuple #3 : 0  0  0  0  0  0  0
424 </pre>
425 Every value of \b dv has been assigned to its own location within \b da.
426
427 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
428 And we assign \b dv to the tuples of \b da with indices [0,2] using \a
429 slice notation "0:4:2". This is the second mode of usage.
430 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_3
431 The contents of \b dv have been assigned to each of specified tuples of \b da.
432 Every value of \b dv is repeated in the 3 specified tuples within \b da.
433 <pre>
434     Tuple #0 : 7  0  8  9 10 11 12
435     Tuple #1 : 0  0  0  0  0  0  0
436     Tuple #2 : 7  0  8  9 10 11 12
437     Tuple #3 : 0  0  0  0  0  0  0
438 </pre>
439 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValues3() can't
440 be explicitly called in Python.
441
442
443 \subsubsection py_mcdataarrayint_setpartofvalues Set part of values of DataArrayInt
444
445 \anchor py_mcdataarrayint_setselectedcomponents
446 <h3> setSelectedComponents() </h3>
447 First, we create a 'source' array.
448 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents1
449 Now we create a larger zero array and assign the array \b da to it.
450 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents2
451 As result contents of the array \b dv are as follows.
452 <pre>
453 Info of components : "a2"   "a1"   "v3"   "v4"
454     Tuple #0 : 2 1 0 0
455     Tuple #1 : 4 3 0 0
456     Tuple #2 : 6 5 0 0
457     Tuple #3 : 0 0 0 0
458 </pre>
459 The same result can be achieved other way (except that component info
460 is not copied):
461 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents3
462
463 \anchor py_mcdataarrayint_setpartofvalues1
464 <br><h3> setPartOfValues1() </h3>
465 We create two arrays:
466 - a "large" (4x4) zero array \b da to assign to, and
467 - a smaller (2x2) array \b dv filled with values [7,8,9,10].
468
469 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_1
470 Now we copy \b dv to the middle of \b da.
471 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_2
472 As result contents of the array \b da are as follows.
473 <pre>
474     Info of components :"v1"   "v2"   "v3"   "v4"
475     Tuple #0 : 0 0 0 0
476     Tuple #1 : 0 7 8 0
477     Tuple #2 : 0 9 10 0
478     Tuple #3 : 0 0 0 0
479 </pre>
480
481 Here we re-fill \b da with zeros and copy \b dv into a component of \b da.
482
483 Note that the last parameter \b strictCompoCompare should be \c False
484 in this case, else \ref ParaMEDMEM::DataArrayInt::setPartOfValues1()
485 throws an exception because \b da has 2 components but only one target
486 component is specified.
487 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_3
488 <pre>
489     Tuple #0 : 0 7 0 0
490     Tuple #1 : 0 8 0 0
491     Tuple #2 : 0 9 0 0
492     Tuple #3 : 0 10 0 0
493 </pre>
494 Below more two variants of location of target values are shown.
495 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_4
496 <pre>
497     Tuple #0 : 0 0 0 0
498     Tuple #1 : 7 8 9 10
499     Tuple #2 : 0 0 0 0
500     Tuple #3 : 0 0 0 0
501 </pre>
502
503 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_5
504 <pre>
505     Tuple #0 : 0 7 0 8
506     Tuple #1 : 0 0 0 0
507     Tuple #2 : 0 9 0 10
508     Tuple #3 : 0 0 0 0
509 </pre>
510 The same result can be achieved other way:
511 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_6
512
513
514
515 \anchor py_mcdataarrayint_setpartofvaluessimple1
516 <br><h3> setPartOfValuesSimple1() </h3>
517 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
518 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_1
519 Now we assign \b dv to the middle of \b da.
520 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_2
521 As result contents of the array \b da are as follows.
522 <pre>
523     Tuple #0 : 0 0 0 0
524     Tuple #1 : 0 7 7 0
525     Tuple #2 : 0 7 7 0
526     Tuple #3 : 0 0 0 0
527 </pre>
528
529 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
530 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_3
531 <pre>
532     Tuple #0 : 0 7 0 0
533     Tuple #1 : 0 7 0 0
534     Tuple #2 : 0 7 0 0
535     Tuple #3 : 0 7 0 0
536 </pre>
537 Below more two variants of location of target values are shown.
538 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_4
539 <pre>
540     Tuple #0 : 0 0 0 0
541     Tuple #1 : 7 7 7 7
542     Tuple #2 : 0 0 0 0
543     Tuple #3 : 0 0 0 0
544 </pre>
545
546 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_5
547 <pre>
548     Tuple #0 : 0 7 0 7
549     Tuple #1 : 0 0 0 0
550     Tuple #2 : 0 7 0 7
551     Tuple #3 : 0 0 0 0
552 </pre>
553 The same result can be achieved other way:
554 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_6
555
556
557 \anchor py_mcdataarrayint_setpartofvaluessimple2
558 <br><h3> setPartOfValuesSimple2() </h3>
559 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
560 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_1
561 Now we assign \b dv to the middle of \b da.
562 We explicitly specify tuples and component to assign to by a list [1,2].
563 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_2
564 As result contents of the array \b da are as follows.
565 <pre>
566     Tuple #0 : 0 0 0 0
567     Tuple #1 : 0 7 7 0
568     Tuple #2 : 0 7 7 0
569     Tuple #3 : 0 0 0 0
570 </pre>
571
572 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
573 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_3
574 <pre>
575     Tuple #0 : 0 7 0 0
576     Tuple #1 : 0 7 0 0
577     Tuple #2 : 0 7 0 0
578     Tuple #3 : 0 7 0 0
579 </pre>
580 Below more two variants of location of target values are shown.
581 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_4
582 <pre>
583     Tuple #0 : 0 0 0 0
584     Tuple #1 : 7 7 7 7
585     Tuple #2 : 0 0 0 0
586     Tuple #3 : 0 0 0 0
587 </pre>
588
589 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_5
590 <pre>
591     Tuple #0 : 0 7 0 7
592     Tuple #1 : 0 0 0 0
593     Tuple #2 : 0 7 0 7
594     Tuple #3 : 0 0 0 0
595 </pre>
596 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValuesSimple2() can't
597 be explicitly called in Python.
598
599
600 \anchor py_mcdataarrayint_setpartofvaluessimple3
601 <br><h3> setPartOfValuesSimple3() </h3>
602 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
603 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_1
604 Now we assign \b dv to the middle of \b da.
605 We explicitly specify tuples to assign to by a list [1,2]. And we specify
606 components to assign to using slicing: 1:3.
607 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_2
608 As result contents of the array \b da are as follows.
609 <pre>
610     Tuple #0 : 0 0 0 0
611     Tuple #1 : 0 7 7 0
612     Tuple #2 : 0 7 7 0
613     Tuple #3 : 0 0 0 0
614 </pre>
615
616 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
617 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_3
618 <pre>
619     Tuple #0 : 0 7 0 0
620     Tuple #1 : 0 7 0 0
621     Tuple #2 : 0 7 0 0
622     Tuple #3 : 0 7 0 0
623 </pre>
624 Below more two variants of location of target values are shown.
625 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_4
626 <pre>
627     Tuple #0 : 0 0 0 0
628     Tuple #1 : 7 7 7 7
629     Tuple #2 : 0 0 0 0
630     Tuple #3 : 0 0 0 0
631 </pre>
632
633 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_5
634 <pre>
635     Tuple #0 : 0 7 0 7
636     Tuple #1 : 0 0 0 0
637     Tuple #2 : 0 7 0 7
638     Tuple #3 : 0 0 0 0
639 </pre>
640 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValuesSimple3() can't
641 be explicitly called in Python.
642
643
644 \anchor py_mcdataarrayint_setpartofvalues2
645 <br><h3> setPartOfValues2() </h3>
646 We create two arrays:
647 - a "large" (4x7) zero array \b da to assign to,
648 - a smaller (3x2) array \b dv filled with values [7,8,9,10,11,12].
649
650 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_1
651 Now we assign the two components of \b dv to the components of \b da
652 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
653   indices [0,1,2]. This is the first mode of usage.
654 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_2
655 As result contents of the array \b da are as follows.
656 <pre>
657     Tuple #0 : 0  7  0  8  0  0  0
658     Tuple #1 : 0  9  0 10  0  0  0
659     Tuple #2 : 0 11  0 12  0  0  0
660     Tuple #3 : 0  0  0  0  0  0  0
661 </pre>
662 Every value of \b dv has been assigned to its own location within \b da.
663
664 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
665 And we assign \b dv to the tuples of \b da with indices [0,2,3] .
666 This is the second mode of usage.
667 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_3
668 The contents of \b dv have been assigned to each of specified tuples of \b da.
669 Every value of \b dv is repeated in the 3 specified tuples within \b da.
670 <pre>
671     Tuple #0 : 7  0  8  9 10 11 12
672     Tuple #1 : 0  0  0  0  0  0  0
673     Tuple #2 : 7  0  8  9 10 11 12
674     Tuple #3 : 7  0  8  9 10 11 12
675 </pre>
676 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValues2() can't
677 be explicitly called in Python.
678
679
680 \anchor py_mcdataarrayint_setpartofvalues3
681 <br><h3> setPartOfValues3() </h3>
682 We create two arrays:
683 - a "large" (4x7) zero array \b da to assign to,
684 - a smaller (3x2) array \b dv filled with values [7,8,9,10,11,12].
685
686 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_1
687 Now we assign the two components of \b dv to the components of \b da
688 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
689 indices [0,1,2] which are specified using slicing: "0:3".
690 This is the first mode of usage.
691 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_2
692 As result contents of the array \b da are as follows.
693 <pre>
694     Tuple #0 : 0  7  0  8  0  0  0
695     Tuple #1 : 0  9  0 10  0  0  0
696     Tuple #2 : 0 11  0 12  0  0  0
697     Tuple #3 : 0  0  0  0  0  0  0
698 </pre>
699 Every value of \b dv has been assigned to its own location within \b da.
700
701 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
702 And we assign \b dv to the tuples of \b da with indices [0,2] using \a
703 slice notation "0:4:2". This is the second mode of usage.
704 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_3
705 The contents of \b dv have been assigned to each of specified tuples of \b da.
706 Every value of \b dv is repeated in the 3 specified tuples within \b da.
707 <pre>
708     Tuple #0 : 7  0  8  9 10 11 12
709     Tuple #1 : 0  0  0  0  0  0  0
710     Tuple #2 : 7  0  8  9 10 11 12
711     Tuple #3 : 0  0  0  0  0  0  0
712 </pre>
713 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValues3() can't
714 be explicitly called in Python.
715
716
717 \subsubsection py_mcdataarraydouble_getdifferentvalues Excluding coincident tuples from DataArrayDouble
718
719 The code below creates an array of real values and than an array of
720   unique values, not closer one to another than 0.2, is retrieved from it.
721 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_getDifferentValues1
722
723
724 \subsubsection cpp_mcdataarraydouble_meldwith Concatenating DataArrayDouble's by appending components
725
726 In this example we create two data arrays including \b same number of
727 tuples and then we concatenate them using \ref
728 ParaMEDMEM::DataArrayDouble::meldWith "meldWith()".
729 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_Meld1_1
730 Now the array \b da1 includes 7 tuples (as before) of 3 components
731 each. Its components are: "c0da1","c1da1","c0da2".
732
733
734 \subsubsection cpp_mcdataarrayint_meldwith Concatenating DataArrayInt's by appending components
735
736 In this example we create two data arrays including \b same number of
737 tuples and then we concatenate them using \ref
738 ParaMEDMEM::DataArrayInt::meldWith "meldWith()".
739 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_Meld1_1
740 Now the array \b da1 includes 7 tuples (as before) of 3 components
741 each. Its components are: "c0da1","c1da1","c0da2".
742
743
744 \subsection ExamplesArraysAccess Access
745
746 \subsubsection cpp_mcdataarrayint_getTuple Getting a tuple of DataArrayInt
747
748 In this simple example we create an array of integers arranged into 3
749 tuples per 2 components, and finally print the second tuple.
750 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_getTuple_1
751 The output is
752 <pre> [9, 10] </pre>
753 Note that we can traverse all tuples in the array by simply iterating
754 over it as the code below does.
755 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_getTuple_2
756 Its output follows.
757 <pre>
758 (7, 8)
759 (9, 10)
760 (11, 12)
761 </pre>
762
763
764 \subsubsection cpp_mcdataarraydouble_getidsinrange Finding values in range in  DataArrayDouble
765
766 In this example we create an array \b da containing same values as ones returned by
767 \c range( \c 10 ). Then we get an array of indices of values of \b da being in
768 range [ 2.5, 6 ].
769 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_getIdsInRange_1
770 As result contents of the array \b da2 are as follows.
771 <pre>
772     Tuple #0 : 3
773     Tuple #1 : 4
774     Tuple #2 : 5
775     Tuple #3 : 6
776 </pre>
777
778
779 \subsubsection cpp_mcdataarraydouble_findcommontuples Finding coincident tuples in DataArrayDouble
780
781 Let's create an array of 6 tuples and 2 components that can be
782   considered as coordinates of 6 points in 2D space.
783 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_findCommonTuples1
784 Now we find points that are not far each from other than 1e-1.
785 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_findCommonTuples2
786 As we can realize from the above code, a hardcoded array \b expected3 is equal
787   to the raw data of a DataArrayInt \b c and a hardcoded array \b expected4 is equal
788   to the raw data of the DataArrayInt \b cI.
789
790 The array \b c contains indices of 5 coincident points. The array \b
791   cI shows us boundaries of (cI->getNumberOfTuples()-1) = 2 groups of coincident points:
792 - The first group starts at index 0 and includes (3 - 0) = 3 points: 0,3,4.
793 - The second group starts at index 3 and includes (5 - 3) = 2 points: 1,2.
794
795
796 \subsubsection py_mcdataarraydouble_KeepSelectedComponents Creation of a sub-part of the DataArrayDouble by selecting components
797
798 \snippet MEDCouplingExamplesTest.py SnippeDataArrayDoubleKeepSelectedComponents1_1
799 We created an array \b a1 containing 5 tuples of 4 components each (20
800 values). Now we are going to create an array \b a2 containing some
801 components of \b a1.
802 \snippet MEDCouplingExamplesTest.py SnippeDataArrayDoubleKeepSelectedComponents1_2
803 Now each tuple of \b a2 includes components named "b","c","b","c","a","a". Thus
804 the result array \b a2 includes 30 elements (5 tuples per 6 components).
805
806
807 \subsubsection py_mcdataarrayint_keepselectedcomponents Creation of a sub-part of the DataArrayInt by selecting components
808
809 \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_1
810 We created an array \b a1 containing 5 tuples of 4 components each (20
811 values). Now we are going to create an array \b a2 containing some
812 components of \b a1.
813 \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_2
814 Now each tuple of \b a2 includes components named "b","c","b","c","a","a". Thus
815 the result array \b a2 includes 30 elements (5 tuples per 6 components).
816
817 Note that
818 \ref ParaMEDMEM::DataArrayInt::keepSelectedComponents() "DataArrayInt::keepSelectedComponents()"
819 is called, providing the same result, by the following python code:
820 \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_3