2 \page medcouplingcppexamples <br><h1> MEDCoupling C++ examples </h1>
4 \anchor cpp_mcfielddouble_subpart1
5 <br><h2>Creation of a sub part of a field</h2>
6 <br><h3>Creation of a sub part of a field on cells</h3>
7 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_1
8 The field on cells \b f1 lies on a mesh containg 5 cells and 9 nodes.
9 So this field \b f1 contains 5 tuples of 2 components each (10 values).
10 Now let's create a subfield on cells \b f2 from \b f1.
11 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_2
13 \b f1 is a field on cells, \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" method performs an extraction on cells too.
15 So the array \b part1 lists ids on cells.
17 - cell #0 of \b f2 is the same cell of cell #2 of \b f1
18 - cell #1 of \b f2 is the same cell of cell #1 of \b f1
19 - cell #2 of \b f2 is the same cell of cell #4 of \b f1
21 So \b f2 contains 3 tuples with 2 components.
23 The underlying mesh of \b f2 contains a newly created mesh with 3 cells (not as \b mesh1 in \b f1) and 9 nodes (as \b mesh1 in \b f1).
24 \n For fields on cells the number of tuples of the returned field is always equal to the number of ids given in input (here \b part1).
25 \nOnly fields on cells have this particular behaviour.
27 <br><h3>Creation of a sub part of a field on nodes</h3>
28 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_3
29 The field on nodes \b f1 lies on a mesh containg 5 cells and 9 nodes.
30 So this field \b f1 contains 9 tuples of 2 components each (18 values).
31 Now let's create a subfield on nodes \b f2 from \b f1.
32 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_4
34 \b f1 is a field on nodes, but \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" method performs an extraction on \b cells.
36 After the call of \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" on node field \b f1, \b f1 will be reduced on a
37 submesh of \b mesh1 containing cells whoses ids are in \b part2. So here the number of cells of \b f2 is 2 and the number of nodes is 4.
38 \nSo contrary to fields on cells, it is normal for fields on nodes that number of tuples of the returned field of \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart"
39 method does not match the size of the input array (here \b part2).
44 \page medcouplingcppexamplesUmeshStdBuild1 <br><h1> Example of standard build of an unstructured mesh from scratch in C++ </h1>
46 Firstly retrieve basic data in full interlace mode for coordinates, and nodal connectivity cell per cell.
47 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_1
49 Then create ParaMEDMEM::MEDCouplingUMesh instance giving its meshdimension (2 here) and a name.
51 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_2
53 Gives an upper bound of the number of cells to be inserted into the unstructured mesh.
54 \n Then enter nodal connectivity of all cells, cell per cell using ParaMEDMEM::MEDCouplingUMesh::insertNextCell method.
55 \n When the nodal connectivity cell per cell has been finished, call ParaMEDMEM::MEDCouplingUMesh::finishInsertingCells method in order to restore \b mesh instance.
57 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_3
59 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.
61 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_4
63 At this level mesh is usable. When this mesh is no more needed simply call decrRef to decrement its reference counter.
65 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshStdBuild1_5
70 \page medcouplingcppexamplesUmeshAdvBuild1 <br><h1> Example of advanced build of an unstructured mesh from scratch in C++ </h1>
72 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).
73 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_1
75 Then create ParaMEDMEM::MEDCouplingUMesh instance giving its meshdimension (2 here) and a name.
77 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_2
79 Then enter nodal connectivity at once.
81 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_3
83 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.
85 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_4
87 At this level mesh is usable. When this mesh is no more needed simply call decrRef to decrement its reference counter.
89 \snippet MEDCouplingExamplesTest.cxx CppSnippetUMeshAdvBuild1_5
94 \page medcouplingcppexamplesCmeshStdBuild1 <br><h1> Example of standard build of an cartesian mesh from scratch in C++ </h1>
96 We are going to build a 2D cartesian mesh, constituted from 9 nodes along X axis, and 7 nodes along Y axis.
98 Firstly retrieve for each direction the discretization and build a \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble instance" on the corresponding direction.
100 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_1
102 Then create ParaMEDMEM::MEDCouplingCMesh instance giving the 2 instances of \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble" obtained above.
104 There are 2 technics to get it.
108 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_2
112 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_2bis
114 \c mesh is now available for use :
116 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_3
118 When this mesh is no more needed simply call decrRef to decrement its reference counter.
120 \snippet MEDCouplingExamplesTest.cxx CppSnippetCMeshStdBuild1_4
125 \page medcouplingcppexamplesFieldDoubleBuild1 <br><h1> Examples in C++ of standard build of a tensor field on cells with no time attached </h1>
127 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuild1_1
132 \page medcouplingcppexamplesFieldDoubleBuild2 <br><h1> Examples in C++ of standard build of a scalar field on nodes with no time attached </h1>
134 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuild2_1
139 \page medcouplingcppexamplesFieldDoubleBuild3 <br><h1> Examples in C++ of standard build of a vector field on cells with with one time attached and no time interval </h1>
141 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuild3_1
146 \page medcouplingcppexamplesFieldDoubleBuild4 <br><h1> Examples in C++ of standard build of a vector field on nodes defined on a time interval with a constant value during this interval </h1>
148 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuild4_1
153 \page medcouplingcppexamplesFieldDoubleBuild5 <br><h1> Examples in C++ of operation that can be carried out on fields on cells </h1>
155 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuild1_2
157 The decrementation of ref counter should be carried out in CPlusPlus only ...
159 \snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuild1_3