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