Salome HOME
Correction of bug EDF10723 for 0D mesh.
[modules/med.git] / doc / doxygen / doxfiles / examples / medcouplingexamplesmeshes.doxy
1
2 \section ExamplesMeshes Meshes
3
4 \subsection ExamplesMeshesCreate Create
5
6 \subsubsection medcouplingcppexamplesUmeshStdBuild1 Standard build of an unstructured mesh from scratch
7
8 Firstly retrieve basic data in full interlace mode for coordinates, and nodal connectivity cell per cell.
9 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_1
10
11 Then create ParaMEDMEM::MEDCouplingUMesh instance giving its mesh dimension (2 here) and a name.
12
13 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_2
14
15 Gives an upper bound of the number of cells to be inserted into the unstructured mesh.
16 \n Then enter nodal connectivity of all cells, cell per cell using ParaMEDMEM::MEDCouplingUMesh::insertNextCell method.
17 \n When the nodal connectivity cell per cell has been finished, call ParaMEDMEM::MEDCouplingUMesh::finishInsertingCells method in order to restore \b mesh instance.
18
19 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_3
20
21 At this level the connectivity part of the mesh \b mesh as been defined. Now let's set the coordinates using array \b coords defined above.
22
23 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_4
24
25 At this level mesh is usable. When this mesh is no more needed simply call decrRef to decrement its reference counter.
26
27 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_5
28
29
30 \subsubsection medcouplingcppexamplesUmeshAdvBuild1 Advanced build of an unstructured mesh from scratch
31
32 Firstly retrieve basic data in full interlace mode for coordinates, and nodal connectivity cell per cell, cell type \b included (3 for INTERP_KERNEL::NORM_TRI3 and 4 for INTERP_KERNEL::QUAD4).
33 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_1
34
35 Then create ParaMEDMEM::MEDCouplingUMesh instance giving its mesh dimension (2 here) and a name.
36
37 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_2
38
39 Then enter nodal connectivity at once.
40
41 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_3
42
43 At this level the connectivity part of the mesh \b mesh as been defined. Now let's set the coordinates using array \b coords defined above.
44
45 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_4
46
47 At this level mesh is usable. When this mesh is no more needed simply call decrRef() to decrement its reference counter.
48
49 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_5
50
51
52 \subsubsection medcouplingcppexamplesCmeshStdBuild1 Standard build of an cartesian mesh from scratch
53
54 We are going to build a 2D cartesian mesh, constituted from 9 nodes along X axis, and 7 nodes along Y axis.
55
56 Firstly retrieve for each direction the discretization and build a \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble instance" on the corresponding direction.
57
58 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_1
59
60 Then create ParaMEDMEM::MEDCouplingCMesh instance giving the 2 instances of \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble" obtained above.
61
62 There are 2 techniques to get it.
63
64 Either :
65
66 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_2
67
68 Or :
69
70 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_2bis
71
72 \c mesh is now available for use :
73
74 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_3
75
76 When this mesh is no more needed simply call decrRef to decrement its reference counter.
77
78 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_4
79
80
81 \subsubsection cpp_mcumesh_buildBoundaryMesh Getting a bounding mesh
82
83 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
84 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1
85 Now we use
86 \ref ParaMEDMEM::MEDCouplingUMesh::buildBoundaryMesh "buildBoundaryMesh()" to get a mesh
87 of lower dimension bounding \b mesh.
88 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2
89 Depending on the value of a parameter,
90 \ref ParaMEDMEM::MEDCouplingUMesh::buildBoundaryMesh "buildBoundaryMesh()"
91 creates the mesh sharing the node coordinates array with \b mesh or not.
92
93
94 \subsubsection cpp_mcumesh_buildFacePartOfMySelfNode Retrieving a lower dimension mesh based on given nodes
95
96 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
97 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1
98 In the following code we retrieve nodes of the cell #0 an then we call
99 \ref ParaMEDMEM::MEDCouplingUMesh::buildFacePartOfMySelfNode "buildFacePartOfMySelfNode()"
100 twice with these nodes and with varying last parameter \b allNodes as input.
101 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2
102 <br>If the last parameter is \c true
103 \ref ParaMEDMEM::MEDCouplingUMesh::buildFacePartOfMySelfNode "buildFacePartOfMySelfNode()" looks
104 for segements whose all nodes are given to it, hence it finds segments bounding the cell #0 only.
105 <br>If the last parameter is \c false
106 \ref ParaMEDMEM::MEDCouplingUMesh::buildFacePartOfMySelfNode "buildFacePartOfMySelfNode()" looks
107 for any segment whose nodes are given to it, hence it adds more segments to \b mesh2.
108
109
110 \subsubsection cpp_mcumesh_buildPartOfMySelfNode Copying cells selected by nodes
111
112 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
113 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1
114 In the following code we retrieve nodes of the cell #0 an then we call
115 \ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelfNode "buildPartOfMySelfNode()"
116 twice with these nodes and with varying last parameter \b allNodes as input.
117 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2
118 <br>If the last parameter is \c true
119 \ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelfNode "buildPartOfMySelfNode()" looks
120 for cells whose all nodes are given to it, hence it finds the cell #0 only.
121 <br>If the last parameter is \c false
122 \ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelfNode "buildPartOfMySelfNode()" looks
123 for any cell whose nodes are given to it, hence it finds all cells of \b mesh because all
124 cells share the node #4.
125
126
127 \subsubsection cpp_mcumesh_buildPartOfMySelf Getting a part of mesh
128
129 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
130 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1
131 Now we use
132 \ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelf "buildPartOfMySelf()" to get a mesh
133 containing only two cells of \b mesh.
134 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2
135
136
137 \subsection ExamplesMeshesModify Modify
138
139 \subsubsection cpp_mcumesh_findAndCorrectBadOriented3DExtrudedCells Fixing orientation of "extruded" volumes
140
141 First, we create a mesh with 2 incorrectly oriented "extruded" volumes.
142 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1
143 Now we check that
144 \ref ParaMEDMEM::MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells "findAndCorrectBadOriented3DExtrudedCells()"
145 finds and fixes the reversed cells.
146 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2
147
148
149 \subsubsection cpp_mcumesh_arePolyhedronsNotCorrectlyOriented Fixing orientation of polyhedra
150
151 First, we create a mesh with 2 polyhedra, one of which is incorrectly oriented. We create
152 two "extruded" polyhedra and then convert them to correctly defined polyhedra.
153 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1
154 Now we check that
155 \ref ParaMEDMEM::MEDCouplingUMesh::arePolyhedronsNotCorrectlyOriented "arePolyhedronsNotCorrectlyOriented()"
156 finds one reversed cell. After that we fix it using
157 \ref ParaMEDMEM::MEDCouplingUMesh::orientCorrectlyPolyhedrons "orientCorrectlyPolyhedrons()" and
158 re-check the orientation of polyhedra.
159 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2
160
161
162 \subsubsection cpp_mcumesh_are2DCellsNotCorrectlyOriented Fixing orientation of faces
163
164 First, we create a 2D mesh in 3D space with 3 QUAD4 and 2 TRI3 cells. Orientation of the cell #1 is
165 reversed comparing with others.
166 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1
167 Now we check that
168 \ref ParaMEDMEM::MEDCouplingUMesh::are2DCellsNotCorrectlyOriented "are2DCellsNotCorrectlyOriented()"
169 finds one reversed face. After that we fix the incorrectly oriented cell using
170 \ref ParaMEDMEM::MEDCouplingUMesh::orientCorrectly2DCells "orientCorrectly2DCells()" and
171 re-check the orientation of cells.
172 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2
173
174
175 \subsubsection cpp_mcumesh_renumberNodesInConn Renumbering nodes in the connectivity array
176
177 First, we create a 2D mesh with 1 QUAD4 cell and with undefined coordinates of nodes.
178 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1
179 Now we use
180 \ref ParaMEDMEM::MEDCouplingUMesh::renumberNodesInConn "renumberNodesInConn()"
181 to get the following nodal connectivity of a sole cell: 0,1,2,3.
182 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2
183 \b old2newIds array defines how node ids are changed:
184 - new id of node #0 is -1,
185 - new id of node #1 is 3,
186 - new id of node #2 is 4,
187 - new id of node #3 is 1,
188 - new id of node #4 is 0.
189
190
191 \subsubsection cpp_mcumesh_renumberNodes Renumbering nodes
192
193 First, we create a 2D mesh with 4 nodes and no cells.
194 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodes_1
195 Next, we use
196 \ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes "renumberNodes()"
197 to permute nodes so that
198 - old node #0 becomes #2,
199 - old node #1 remains #1,
200 - old node #2 becomes #0,
201 - old node #3 is removed.
202
203 Number of nodes becomes 3.
204 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodes_2
205
206 Next we compare behavior of
207 \ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes "renumberNodes()" and that of
208 \ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes2 "renumberNodes2()" which, in contrast to
209 \ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes "renumberNodes()",
210 moves merged nodes to their barycenter.<br>
211 We set #2 as new id of old node #3 and expect that
212 \ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes2 "renumberNodes2()" moves old nodes #0
213 and #3 to their barycenter (-0.3,0.0) which becomes position of node #2.<br>
214 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodes_3
215
216
217 \subsubsection cpp_mcumesh_mergeNodes Merging equal nodes
218
219 First, we create a 2D mesh with 1 QUAD4 and 2 TRI3 cells. The cells are based on 6 nodes
220 of which 2 nodes fully coincide (#3 and #4) and 3 nodes are equal with precision 0.003.
221 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_mergeNodes_1
222 Now we merge node duplicates using
223 \ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()" and check values it returns.
224 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_mergeNodes_2
225 Contents of \b arr shows ids of old nodes after the merging. The nodes considered equal
226 one to the other have the same id in \b arr.
227
228 Next we compare behavior of
229 \ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()" and that of
230 \ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes2 "mergeNodes2()" which, in contrast to
231 \ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()",
232 moves merged nodes to their barycenter.<br> We expect that
233 \ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes2 "mergeNodes2()" moves old nodes #0, #2
234 and #5 to their barycenter equal to position of node #2.<br>
235 First we check that
236 \ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()" does not move nodes
237 coincident with the node #2 to the position of node #2, and then we check that
238 \ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes2()" does move.
239 (We check only the second (Y) component of node coordinates since the first component of
240 these nodes is exactly same.)
241 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_mergeNodes_3
242
243
244 \subsubsection cpp_mcumesh_zipConnectivityTraducer Removing cell duplicates
245
246 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells, so that
247 - the cell #2 has the same nodal connectivity as the cell #1 does,
248 - the cell #3 has the same nodal connectivity as the cell #0 does,
249 - the cell #4 is based on the same nodes as the cell #0 but nodes order is different.
250
251 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1
252 Now we use
253 \ref ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer "zipConnectivityTraducer()"
254 to remove duplicate cells. Then we check that two cells, having exactly same nodal
255 connectivity with other cells, have been removed.
256 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2
257 Contents of \b arr shows ids of cells after duplicates removal. If a value (cell id)
258 equals to its index in \b arr, this means that the cell is not a duplicate of any cell
259 with lower id. Else, the value gives a cell id to which this cell is equal. <br>
260 Thus, the cells #0 and #1 have no preceding equal cell since \b arr[i] == i.<br>
261 The cell #2 equals to the cell #1 (== \b arr[2] ).<br>
262 The cell #3 equals to the cell #0 (== \b arr[3] ).<br>
263 The cell #4 has no equal cell. This is because the cell comparison technique specified
264 when we called
265 \ref ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer "zipConnectivityTraducer()"
266 was 0 ("exact"), if we had used the technique 2 ("nodal"), \b arr[4] would be 0.
267
268
269 \subsubsection cpp_mcumesh_zipCoordsTraducer Removing unused nodes
270
271 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
272 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1
273 Now we create \b mesh2 including all nodes but only two cells of \b mesh, and we use \ref
274 ParaMEDMEM::MEDCouplingUMesh::zipCoordsTraducer "zipCoordsTraducer()" to remove unused
275 nodes from \b mesh2.
276 \ref ParaMEDMEM::MEDCouplingUMesh::zipCoordsTraducer "zipCoordsTraducer()" returns an array
277 with -1 for unused nodes and new ids for used ones.
278 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2
279
280
281 \subsubsection cpp_mcumesh_getNodeIdsInUse Retrieving unused nodes
282
283 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
284 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1
285 Now we create \b mesh2 including all nodes but only two cells of \b mesh, and we use \ref
286 ParaMEDMEM::MEDCouplingUMesh::getNodeIdsInUse "getNodeIdsInUse()" to get nodes of \b mesh2
287 used in its two cells.
288 \ref ParaMEDMEM::MEDCouplingUMesh::getNodeIdsInUse "getNodeIdsInUse()" returns an array
289 with -1 for unused nodes and new ids for used ones.
290 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2
291 Now we use \b newNbOfNodes returned by
292 \ref ParaMEDMEM::MEDCouplingUMesh::getNodeIdsInUse "getNodeIdsInUse()" to convert \b arr
293 to "New to Old" mode.
294 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3
295
296
297 \subsubsection cpp_mcumesh_convertToPolyTypes Conversion of cells to "poly" types
298
299 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
300 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1
301 Now we convert cells #1 and #3 to type POLYGON and check the result
302 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2
303
304
305 \subsubsection cpp_mcpointset_scale Scaling the mesh
306
307 First, we create a 2D mesh with 4 nodes and no cells.
308 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_scale_1
309 Then we scale it by a factor of 2 with a center (0.,0.).
310 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_scale_2
311 Finally we check that all node coordinates have changed by more than 0.9.
312 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_scale_3
313
314
315 \subsubsection cpp_mcpointset_translate Translating the mesh
316
317 First, we create a 2D mesh with 4 nodes and no cells.
318 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_translate_1
319 Then we translate it by a vector (1.,1.).
320 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_translate_2
321 Finally we check that all node coordinates have changed by more than 0.9.
322 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_translate_3
323
324
325 \subsubsection cpp_mcpointset_rotate Rotating the mesh
326
327 First, we create a 2D mesh with 4 nodes and no cells.
328 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_1
329 Then we rotate it around a point (0.,0.) by 90 degrees clockwise.
330 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_2
331 Next, we make a 3D mesh from the 2D one and rotate it around the Z axis by 90 degrees
332 counter-clockwise.
333 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_3
334 Finally we transform the mesh back to 2D space and check that all nodes get back to the
335 initial location.
336 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_4
337
338
339 \subsection ExamplesMeshesAccess Access
340
341 \subsubsection cpp_mccmesh_getCoordsAt Getting node coordinates along an axis
342
343 We create an 1D Cartesian mesh and retrieves node coordinates using
344 \ref ParaMEDMEM::MEDCouplingCMesh::getCoordsAt "getCoordsAt()".
345 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingCMesh_getCoordsAt_1
346
347
348 \subsubsection cpp_mcpointset_getcoordinatesofnode Getting coordinates of a node
349
350 The following code creates a 2D \ref ParaMEDMEM::MEDCouplingUMesh
351 "MEDCouplingUMesh" with 3 nodes and no cells.
352 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1
353 Here we get coordinates of the second node and check its two coordinates.
354 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2
355
356
357 \subsubsection cpp_mcumesh_areCellsIncludedIn Cells correspondence in two meshes
358
359 First, we create a 2D \b mesh1 with 3 QUAD4 and 2 TRI3 cells.
360 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1
361 Then we create a \b mesh2 which includes cells #4, #2 and #0 of \b mesh1. The two meshes
362 share the same node coordinates array.
363 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2
364 Now we ascertain that
365 - \ref ParaMEDMEM::MEDCouplingUMesh::areCellsIncludedIn "areCellsIncludedIn()"
366 detects that all cells of \b mesh2 are present in \b mesh1,
367 -  the correspondence array \b corr2to1, which gives cell ids of \b mesh2 within
368 \b mesh1, is equal to the array \b cells2 which selected cells from \b mesh1 for creation
369 of \b mesh2.
370
371 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3
372 Now we apply
373 \ref ParaMEDMEM::MEDCouplingUMesh::areCellsIncludedIn "areCellsIncludedIn()"
374 in a reverse direction and ascertain that it returns \c false.
375 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4
376 The contents of the correspondence
377 array \b corr1to2 [2, 3, 1, 4, 0] means the following.
378 - The cell #0 of \b mesh1 is equal to the cell #2 (== \b corr1to2[ 0 ]) of \b mesh2.
379 - The cell #1 of \b mesh1 is missing from \b mesh2 (as \b corr1to2[ 1 ] >= \b mesh2->getNumberOfCells()).
380 - The cell #2 of \b mesh1 is equal to the cell #1 (== \b corr1to2[ 2 ]) of \b mesh2.
381 - The cell #3 of \b mesh1 is missing from \b mesh2 (as \b corr1to2[ 3 ] >= \b mesh2->getNumberOfCells()).
382 - The cell #4 of \b mesh1 is equal to the cell #0 (== \b corr1to2[ 4 ]) of \b mesh2.
383
384
385 \subsubsection cpp_mcumesh_checkDeepEquivalWith Deep comparison of meshes
386
387 First, we create two 2D meshes with two triangles, so that
388 - their nodes are almost same but permuted,
389 - the first triangle is based exactly on the same nodes (taking the permutation into account),
390 - an order of nodes in the second triangle is changed.
391
392 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1
393 Then we check that
394 - \ref ParaMEDMEM::MEDCouplingUMesh::checkDeepEquivalWith "checkDeepEquivalWith()"
395 considers the meshes equal (i.e. it does not throw any exception) if it is called with a cell
396 comparison policy \b cellCompPol == 1
397 -  mapping from \b mesh1 to \b mesh2 for both nodes and cells is as expected.
398
399 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2
400 Next we ascertain that
401 \ref ParaMEDMEM::MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith "checkDeepEquivalOnSameNodesWith()"
402 consider \b mesh1 and \b mesh2 different as they do not share the same nodal connectivity
403 array. <br>
404 After that we make the meshes share the node coordinates array and insert new
405 triangles based on the same nodes but in different order. This is to ascertain that
406 \ref ParaMEDMEM::MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith "checkDeepEquivalOnSameNodesWith()"
407 called with the weakest cell comparison policy considers the meshes equal.
408 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3
409
410
411 \subsubsection cpp_mcumesh_getPartBarycenterAndOwner Getting barycenters of cells
412
413 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
414 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_1
415 Now we use
416 \ref ParaMEDMEM::MEDCouplingUMesh::getPartBarycenterAndOwner "getPartBarycenterAndOwner()" to get
417 barycenters of all but the first cell.
418 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_3
419 The returned array contains 4 tuples per 2 components.
420
421
422 \subsubsection cpp_mcumesh_getCellsContainingPoints Finding cells containing a point (multi-point case)
423
424 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
425 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1
426 Then we use
427 \ref ParaMEDMEM::MEDCouplingUMesh::getCellsContainingPoints "getCellsContainingPoints()" to
428 get cells in contact with tree points. Two of them are in contact with some cells and one is not.
429 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2
430 The contents of the result arrays \b cells ([4, 0, 1]) and \b cellsIndex ([0, 0, 1, 3])
431 mean the following.
432 - Point #0 is in contact with none (== \b cellsIndx[1] - \b cellsIndx[0]) cell.
433 - Point #1 is in contact with 1 (== \b cellsIndx[2] - \b cellsIndx[1]) cell whose id is #4
434   (== \b cells[ \b cellsIndx[ 1 ]]).
435 - Point #2 is in contact with 2 (== \b cellsIndx[3] - \b cellsIndx[2]) cells whose ids are #0
436   (== \b cells[ \b cellsIndx[ 2 ]]) and #1 (== \b cells[ \b cellsIndx[ 2 ] + 1 ]).
437
438
439 \subsubsection cpp_mcumesh_getCellsContainingPoint Finding cells containing a point
440
441 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
442 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1
443 Then we use
444 \ref ParaMEDMEM::MEDCouplingUMesh::getCellsContainingPoint "getCellsContainingPoint()" to
445 get cells in contact with a small ball (point with precision) located near the node #4 and
446 shifted from this node by its radius \b eps.
447 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2
448 Since the node #4 is shared by all cells, size of the vector \b cellIds must be equal to
449 the number of cells in \b mesh.
450
451
452 \subsubsection cpp_mcumesh_buildPartOrthogonalField Getting normals of cells
453
454 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. Orientation of the cell #1 is
455 reversed.
456 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1
457 Now we use
458 \ref ParaMEDMEM::MEDCouplingUMesh::buildPartOrthogonalField "buildPartOrthogonalField()" to get
459 normal vectors to the cells.
460 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2
461
462
463 \subsubsection cpp_mcumesh_getPartMeasureField Getting volumes of cells
464
465 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. Orientation of the cell #1 is
466 reversed.
467 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_1
468 Now we use
469 \ref ParaMEDMEM::MEDCouplingUMesh::getPartMeasureField "getPartMeasureField()" to get
470 volumes of all but the first cell. If we call
471 \ref ParaMEDMEM::MEDCouplingUMesh::getPartMeasureField "getPartMeasureField()" with \b
472 isAbs == \c true, the area of the cell #1 is returned positive, else, negative that
473 reflects its inverse orientation.
474 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_2
475
476
477 \subsubsection cpp_mcumesh_getCellsInBoundingBox Getting cells using the bounding box
478
479 First, we create a 2D mesh with 1 TRI3 cell. Bounding box of this cell is [0.,0., 1.,1].
480 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1
481 Now we check how
482 \ref ParaMEDMEM::MEDCouplingUMesh::getCellsInBoundingBox "getCellsInBoundingBox()"
483 searches for cells using the bounding box. We use a bounding box touching the bounding box
484 of the sole cell at one point (1.,1.).
485 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2
486 If \ref ParaMEDMEM::MEDCouplingUMesh::getCellsInBoundingBox "getCellsInBoundingBox()" is
487 called with parameter \b eps == 0.0, the cell is not found because the two bounding boxes
488 (one of the cell and the one passed as parameter) do not overlap. <br>
489 If \ref ParaMEDMEM::MEDCouplingUMesh::getCellsInBoundingBox "getCellsInBoundingBox()" is
490 called with parameter \b eps == 0.1, the cell is found because \b eps is used to increase
491 the bounding box of the cell and thus the two bounding boxes intersect each other. <br>
492
493
494 \subsubsection cpp_mcumesh_findBoundaryNodes Getting boundary nodes
495
496 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
497 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1
498 Now we use
499 \ref ParaMEDMEM::MEDCouplingUMesh::findBoundaryNodes "findBoundaryNodes()" to get ids
500 of boundary nodes.
501 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2
502 \ref ParaMEDMEM::MEDCouplingUMesh::findBoundaryNodes "findBoundaryNodes()" returns all
503 node ids except the node #4 which is in the middle of \b mesh.
504
505
506 \subsubsection cpp_mcumesh_getCellIdsLyingOnNodes Getting cells by nodes
507
508 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
509 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1
510 In the following code we retrieve nodes of the cell #0 an then we call
511 \ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes "getCellIdsLyingOnNodes()"
512 twice with these nodes and with varying last parameter \b allNodes as input.
513 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2
514 <br>If the last parameter is \c true
515 \ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes "getCellIdsLyingOnNodes()" looks
516 for cells whose all nodes are given to it, hence it finds the cell #0 only.
517 <br>If the last parameter is \c false
518 \ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes "getCellIdsLyingOnNodes()" looks
519 for any cell whose nodes are given to it, hence it finds all cells of \b mesh because all
520 cells share the node #4.
521
522
523 \subsubsection cpp_mcumesh_getCellIdsFullyIncludedInNodeIds Getting cells by nodes
524
525 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
526 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1
527 In the following code we retrieve nodes of two cells an then we use
528 \ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsFullyIncludedInNodeIds
529 "getCellIdsFullyIncludedInNodeIds()" to find these cells by their nodes.
530 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2
531
532
533 \subsubsection cpp_mcumesh_buildDescendingConnectivity2 Retrieving the descending connectivity with orientation
534
535 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
536 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1
537 Now we get and check the descending connectivity.
538 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2
539 Here we get connectivity of the cell #2 (#3 in FORTRAN mode) of \b mesh2 to see how
540 mutual orientation of cells in \b mesh and \b mesh2 is defined.
541 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3
542 The contents of the result arrays \b desc and \b descIndx mean the following.
543 - The cell #0 of \b mesh (QUAD4) is bound by 4 (== \b descIndx[1] - \b descIndx[0])
544   segments (SEG2) of \b mesh2 whose ids in FORTRAN mode are
545   - #1 (== \b desc[ \b descIndx[ 0 ]]),
546   - #2 (== \b desc[ \b descIndx[ 0 ] + 1 ]),
547   - #3 (== \b desc[ \b descIndx[ 0 ] + 2 ]) and
548   - #4 (== \b desc[ \b descIndx[ 0 ] + 3 ]).
549   <br>Ids are positive since order of nodes in the corresponding cells of \b mesh and \b mesh2
550   are same. For example nodes of SEG2 #3 are [4,1] and nodes of QUAD4 #0 are [0,3,\b 4,\b 1].
551 - The cell #1 of \b mesh (TRI3) is bound by 3 (== \b descIndx[2] - \b descIndx[1]) segements of
552   \b mesh2 whose ids in FORTRAN mode are:
553   - #-3 (== \b desc[ \b descIndx[ 1 ]]),
554   - #5 (== \b desc[ \b descIndx[ 1 ] + 1 ]) and
555   - #6 (== \b desc[ \b descIndx[ 1 ] + 2 ]).
556   <br>The id -3 means that order of nodes in SEG2 #3 ([4,1]) is different from the order of
557   these nodes in TRI3 #1: [\b 1,\b 4,2].
558 - etc.
559
560 The contents of the result arrays \b revDesc and \b revDescIndx mean the following.
561 - The cell #0 of \b mesh2 (SEG2) bounds 1 (== \b revDescIndx[1] - \b revDescIndx[0]) cell of \b
562   mesh whose id is:
563   - # 0 (== \b revDesc[ \b revDescIndx[ 0 ]]).
564 - The cell #1 of \b mesh2 bounds 2 (== \b revDescIndx[2] - \b revDescIndx[1]) cells of \b
565   mesh whose ids are:
566   - # 0 (== \b revDesc[ \b revDescIndx[ 1 ]]) and
567   - # 1 (== \b revDesc[ \b revDescIndx[ 1 ] + 1 ]).
568 - etc.
569
570
571 \subsubsection cpp_mcumesh_buildDescendingConnectivity Retrieving the descending connectivity
572
573 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
574 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1
575 Now we get and check the descending connectivity.
576 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2
577 The contents of the result arrays \b desc and \b descIndx mean the following.
578 - The cell #0 of \b mesh (QUAD4) is bound by 4 (== \b descIndx[1] - \b descIndx[0])
579   segments (SEG2) of \b mesh2 whose ids are
580   - #0 (== \b desc[ \b descIndx[ 0 ]]),
581   - #1 (== \b desc[ \b descIndx[ 0 ] + 1 ]),
582   - #2 (== \b desc[ \b descIndx[ 0 ] + 2 ]) and
583   - #3 (== \b desc[ \b descIndx[ 0 ] + 3 ]).
584 - The cell #1 of \b mesh (TRI3) is bound by 3 (== \b descIndx[2] - \b descIndx[1]) segements of
585   \b mesh2 whose ids are:
586   - #2 (== \b desc[ \b descIndx[ 1 ]]),
587   - #4 (== \b desc[ \b descIndx[ 1 ] + 1 ]) and
588   - #5 (== \b desc[ \b descIndx[ 1 ] + 2 ]).
589 - etc.
590
591 The contents of the result arrays \b revDesc and \b revDescIndx mean the following.
592 - The cell #0 of \b mesh2 (SEG2) bounds 1 (== \b revDescIndx[1] - \b revDescIndx[0]) cell of \b
593   mesh whose id is:
594   - # 0 (== \b revDesc[ \b revDescIndx[ 0 ]]).
595 - The cell #1 of \b mesh2 bounds 2 (== \b revDescIndx[2] - \b revDescIndx[1]) cells of \b
596   mesh whose ids are:
597   - # 0 (== \b revDesc[ \b revDescIndx[ 1 ]]) and
598   - # 1 (== \b revDesc[ \b revDescIndx[ 1 ] + 1 ]).
599 - etc.
600
601
602 \subsubsection cpp_mcumesh_getReverseNodalConnectivity Getting the reverse nodal connectivity
603
604 First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells.
605 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1
606 Now we get and check its reverse nodal connectivity.
607 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2
608 The contents of the result arrays mean the following.
609 - Node #0 is shared by 1 (== \b revNodalIndx[1] - \b revNodalIndx[0]) cell whose id is #0
610   (== \b revNodal[ \b revNodalIndx[ 0 ]]).
611 - Node #1 is shared by 2 (== \b revNodalIndx[2] - \b revNodalIndx[1]) cells whose ids are #0
612   (== \b revNodal[ \b revNodalIndx[ 1 ]]) and #1 (== \b revNodal[ \b revNodalIndx[ 1 ] + 1 ]).
613 - etc.
614
615
616 \subsubsection cpp_mcpointset_getBoundingBox Getting a minimum box bounding nodes
617
618 First, we create a 3D mesh with 2 nodes, so that the first one has minimal coordinates and
619 the second one has maximal coordinates.
620 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getBoundingBox_1
621 Now we get a bounding box enclosing these nodes. This bounding box should contain
622 coordinates of our two nodes (but in "no interlace" mode), as the nodes coincide with
623 points returned by the bounding box.
624 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getBoundingBox_2
625
626
627 \subsubsection cpp_mcpointset_getnodeidsnearpoint Getting nodes close to a point
628
629 The following code creates a 2D \ref ParaMEDMEM::MEDCouplingUMesh
630 "MEDCouplingUMesh" with 5 nodes and no cells.
631 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1
632 Now we define an array of coordinates of a point close to nodes #0, #2 and #4.
633
634 Thus we expect that
635 \ref ParaMEDMEM::MEDCouplingPointSet::getNodeIdsNearPoint "getNodeIdsNearPoint()" that
636 we are going to use,
637 if called with \b eps = 0.003, would return ids of nodes #0, #2 and #4.
638 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2
639
640
641 \subsubsection cpp_mcpointset_getnodeidsnearpoints Getting nodes close to some points
642
643 The following code creates a 2D \ref ParaMEDMEM::MEDCouplingUMesh
644 "MEDCouplingUMesh" with 7 nodes and no cells.
645 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1
646 Now we define an array of coordinates of 3 points near which we want to find nodes of the mesh.
647 - Point #0 is at distance 0.001 from the node #1.
648 - Point #1 is rather far from all nodes.
649 - Point #2 is close to nodes #3, #4 and #5.
650
651 Thus we expect that
652 \ref ParaMEDMEM::MEDCouplingPointSet::getNodeIdsNearPoints "getNodeIdsNearPoints()" that
653 we are going to use,
654 if called with \b eps = 0.003, would return ids of close nodes #1, #3, #4 and #5.
655 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2
656 \b idsIndex returns [0, 1, 1, 4] which means that:
657 - Point #0 is close to 1 (== \b idsIndex[1] - \b idsIndex[0]) node whose id is
658 \b ids[ \b idsIndex[ 0 ]].
659 - Point #1 is close to 0 (== \b idsIndex[2] - \b idsIndex[1]) nodes.
660 - Point #2 is close to 3 (== \b idsIndex[3] - \b idsIndex[2]) nodes whose ids are
661 \b ids[ \b idsIndex[ 2 ]], \b ids[ \b idsIndex[ 2 ] + 1 ] and \b ids[ \b idsIndex[ 2 ] + 2 ].
662
663
664 \subsubsection cpp_mcpointset_findcommonnodes Finding coincident nodes
665
666 First, we create a mesh with 6 nodes, of which two nodes (#3 and #4) are fully coincident
667 and 3 nodes (#0, #2 and #5) have distance less than 0.004 between them.
668 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_findCommonNodes_1
669 Then, we use \ref ParaMEDMEM::MEDCouplingPointSet::findCommonNodes() "findCommonNodes()" to find
670 coincident nodes, and check that (1) calling
671 \ref ParaMEDMEM::MEDCouplingPointSet::findCommonNodes() "findCommonNodes()" with \b prec
672 == 1e-13 finds the two fully coincident nodes only and (2)
673 \ref ParaMEDMEM::MEDCouplingPointSet::findCommonNodes() "findCommonNodes"(0.004) finds 5
674 equal nodes.
675 \snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_findCommonNodes_2