1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingBasicsTest.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingMultiFields.hxx"
30 void CppExample_MEDCouplingPointSet_fillFromAnalytic3()
32 using namespace ParaMEDMEM;
33 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1]
34 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
35 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
36 x->useExternalArrayWithRWAccess( coords, 3, 1 );
37 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
38 y->useExternalArrayWithRWAccess( coords, 2, 1 );
39 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
41 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1]
42 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2]
43 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
44 const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y coord components
45 std::vector<std::string> varNamesVec( varNames, varNames+2 );
46 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
47 mesh->fillFromAnalytic3( ParaMEDMEM::ON_CELLS, 3, varNamesVec, func );
48 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2]
49 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3]
50 double vals1[3]; // values of the cell #1
51 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
52 field->getArray()->getTuple( 1, vals1 );
54 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
55 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
56 double bc1[2]; // coordinates of the second point
57 bc->getTuple( 1, bc1 );
59 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
60 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
61 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
62 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
63 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3]
66 void CppExample_MEDCouplingPointSet_fillFromAnalytic2()
68 using namespace ParaMEDMEM;
69 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1]
70 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
71 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
72 x->useExternalArrayWithRWAccess( coords, 3, 1 );
73 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
74 y->useExternalArrayWithRWAccess( coords, 2, 1 );
75 x->setInfoOnComponent(0,"a"); // name used to refer to X coordinate within a function
76 y->setInfoOnComponent(0,"b"); // name used to refer to Y coordinate within a function
77 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
79 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1]
80 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2]
81 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
82 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
83 mesh->fillFromAnalytic2( ParaMEDMEM::ON_CELLS, 3, func );
84 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2]
85 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3]
86 double vals1[3]; // values of the cell #1
87 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
88 field->getArray()->getTuple( 1, vals1 );
90 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
91 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
92 double bc1[2]; // coordinates of the second point
93 bc->getTuple( 1, bc1 );
95 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
96 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
97 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
98 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
99 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3]
102 void CppExample_MEDCouplingPointSet_fillFromAnalytic()
104 using namespace ParaMEDMEM;
105 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1]
106 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
107 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
108 x->useExternalArrayWithRWAccess( coords, 3, 1 );
109 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
110 y->useExternalArrayWithRWAccess( coords, 2, 1 );
111 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
112 mesh->setCoords(x,y);
113 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1]
114 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2]
115 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
116 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
117 mesh->fillFromAnalytic( ParaMEDMEM::ON_CELLS, 3, func );
118 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2]
119 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3]
120 double vals1[3]; // values of the cell #1
121 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
122 field->getArray()->getTuple( 1, vals1 );
124 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
125 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
126 double bc1[2]; // coordinates of the second point
127 bc->getTuple( 1, bc1 );
129 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
130 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
131 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
132 CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
133 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3]
136 void CppExample_MEDCouplingPointSet_getCoordsAt()
138 using namespace ParaMEDMEM;
139 //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1]
140 const double coords[3] = {1.,2.,4.};
141 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
142 x->useExternalArrayWithRWAccess( coords, 3, 1 );
143 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
144 mesh->setCoordsAt(0,x);
145 const DataArrayDouble* x2=mesh->getCoordsAt(0);
146 CPPUNIT_ASSERT( x2->isEqual( *x, 1e-13 ));
147 //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1]
150 void CppExample_MEDCouplingUMesh_areCellsIncludedIn()
152 using namespace ParaMEDMEM;
153 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
154 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1=MEDCouplingUMesh::New();
155 mesh1->setMeshDimension(2);
156 mesh1->allocateCells(5);
157 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
158 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // #0
159 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // #1
160 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // #2
161 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // #3
162 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // #4
163 mesh1->finishInsertingCells();
164 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
165 coordsArr->alloc(9,2);
166 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
167 std::copy(coords,coords+18,coordsArr->getPointer());
168 mesh1->setCoords(coordsArr);
169 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
170 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
171 const int cells2[3] = { 4,2,0 }; // even cells selected
172 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
173 (MEDCouplingUMesh*) mesh1->buildPartOfMySelf( cells2, cells2+3, true );
174 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
175 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
176 int compType = 0; // the strongest policy
177 DataArrayInt *corr2to1, *corr1to2;
178 // a larger mesh1 includes a smaller mesh2
179 CPPUNIT_ASSERT( mesh1->areCellsIncludedIn( mesh2, compType, corr2to1 ));
180 CPPUNIT_ASSERT( std::equal( cells2, cells2+3, corr2to1->getConstPointer() ));
181 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
182 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
183 // the smaller mesh2 does NOT include the larger mesh1
184 CPPUNIT_ASSERT( ! mesh2->areCellsIncludedIn( mesh1, compType, corr1to2 ));
185 const int corr1to2Expected[5] = {2, 3, 1, 4, 0};
186 CPPUNIT_ASSERT(std::equal( corr1to2Expected, corr1to2Expected+5, corr1to2->getConstPointer() ));
187 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
192 void CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells()
194 using namespace ParaMEDMEM;
195 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
196 // 2D coordinates of 5 base nodes
197 const double coords[5*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2 };
198 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
199 coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 );
200 // coordinates of 5 top nodes
201 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr2 = coordsArr->deepCpy();
202 // 3D coordinates of base + top nodes
203 coordsArr = coordsArr-> changeNbOfComponents( 3, 0 );
204 coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 );
205 coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 );
207 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
208 mesh->setCoords(coordsArr);
209 mesh->setMeshDimension(3);
210 mesh->allocateCells(2);
211 // connectivity of reversed HEXA8 and PENTA6
212 const int conn[8+6]={0,1,4,3, 5,6,9,8, 1,2,4, 6,7,9};
213 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8, 8,conn+0);
214 mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+8);
215 mesh->finishInsertingCells();
216 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
217 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
218 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fixedCells =
219 mesh->findAndCorrectBadOriented3DExtrudedCells();
220 CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 2 ); // 2 cells fixed
221 fixedCells = mesh->findAndCorrectBadOriented3DExtrudedCells();
222 CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 0 ); // no bad cells
223 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
226 void CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented()
228 using namespace ParaMEDMEM;
229 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
230 // 2D coordinates of 5 base nodes
231 const double coords[5*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2 };
232 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
233 coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 );
234 // coordinates of 5 top nodes
235 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr2 = coordsArr->deepCpy();
236 // 3D coordinates of base + top nodes
237 coordsArr = coordsArr-> changeNbOfComponents( 3, 0 );
238 coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 );
239 coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 );
241 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
242 mesh->setCoords(coordsArr);
243 mesh->setMeshDimension(3);
244 mesh->allocateCells(2);
245 // connectivity of a HEXA8 + a reversed PENTA6
246 const int conn[8+6]={0,3,4,1, 5,8,9,6, 1,2,4, 6,7,9};
247 mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,8,conn); // "extruded" polyhedron
248 mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,6,conn+8);
249 mesh->finishInsertingCells();
250 // fix connectivity of NORM_POLYHED's
251 mesh->convertExtrudedPolyhedra();
252 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
253 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
254 std::vector<int> badCellIds;
255 mesh->arePolyhedronsNotCorrectlyOriented( badCellIds );
256 CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one polyhedron is KO
257 // fix invalid rolyherdons
258 mesh->orientCorrectlyPolyhedrons();
259 // re-check orientation
260 badCellIds.clear(); // as badCellIds is not cleared by arePolyhedronsNotCorrectlyOriented()
261 mesh->arePolyhedronsNotCorrectlyOriented( badCellIds );
262 CPPUNIT_ASSERT( badCellIds.size() == 0 ); // connectivity is OK
263 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
266 void CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented()
268 using namespace ParaMEDMEM;
269 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
270 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
271 mesh->setMeshDimension(2);
272 mesh->allocateCells(5);
273 const int conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4};
274 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
275 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
276 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
277 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
278 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
279 mesh->finishInsertingCells();
280 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
281 coordsArr->alloc(9,2);
282 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
283 std::copy(coords,coords+18,coordsArr->getPointer());
284 mesh->setCoords(coordsArr);
285 mesh->changeSpaceDimension(3);
286 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
287 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
288 const double vec[3] = {0.,0.,-1.};
289 std::vector<int> badCellIds;
290 mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds );
291 CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one cell is reversed
293 mesh->orientCorrectly2DCells( vec, false );
294 // re-check orientation
295 badCellIds.clear(); // as badCellIds is not cleared by are2DCellsNotCorrectlyOriented()
296 mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds );
297 CPPUNIT_ASSERT( badCellIds.size() == 0 ); // the orientation is OK
298 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
301 void CppExample_MEDCouplingUMesh_getCellsContainingPoints()
303 using namespace ParaMEDMEM;
304 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
305 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
306 mesh->setMeshDimension(2);
307 mesh->allocateCells(5);
308 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
309 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
310 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
311 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
312 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
313 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
314 mesh->finishInsertingCells();
315 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
316 coordsArr->alloc(9,2);
317 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
318 std::copy(coords,coords+18,coordsArr->getPointer());
319 mesh->setCoords(coordsArr);
320 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
321 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
322 const double pos[3*2] = { 10., 10, // point out of the mesh
323 0.3, 0.3, // point located somewhere inside the mesh
324 coords[2], coords[3]}; // point at the node #1
325 const double eps = 1e-4; // ball radius
326 std::vector<int> cells, cellsIndex;
327 mesh->getCellsContainingPoints( pos, 3, eps, cells, cellsIndex );
328 const int cellsExpected[3]={4, 0, 1};
329 const int cellsIndexExpected[4]={0, 0, 1, 3};
330 CPPUNIT_ASSERT(std::equal( cellsExpected, cellsExpected+3, &cells[0]));
331 CPPUNIT_ASSERT(std::equal( cellsIndexExpected, cellsIndexExpected+4, &cellsIndex[0]));
332 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
335 void CppExample_MEDCouplingUMesh_getCellsContainingPoint()
337 using namespace ParaMEDMEM;
338 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
339 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
340 mesh->setMeshDimension(2);
341 mesh->allocateCells(5);
342 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
343 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
344 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
345 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
346 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
347 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
348 mesh->finishInsertingCells();
349 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
350 coordsArr->alloc(9,2);
351 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
352 std::copy(coords,coords+18,coordsArr->getPointer());
353 mesh->setCoords(coordsArr);
354 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
355 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
356 const double* coords4 = coords + 4*2; // coordinates of the node #4
357 const double eps = 1e-4; // ball radius
358 const double pos[2] = { coords4[0] + eps, coords4[1] - eps }; // ball center
359 std::vector<int> cellIds;
360 mesh->getCellsContainingPoint( pos, eps, cellIds );
361 CPPUNIT_ASSERT ( (int)cellIds.size() == mesh->getNumberOfCells() );
362 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
365 void CppExample_MEDCouplingUMesh_buildPartOrthogonalField()
367 using namespace ParaMEDMEM;
368 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
369 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
370 mesh->setMeshDimension(2);
371 mesh->allocateCells(5);
372 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
373 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
374 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
375 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
376 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
377 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
378 mesh->finishInsertingCells();
379 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
380 coordsArr->alloc(9,2);
381 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
382 std::copy(coords,coords+18,coordsArr->getPointer());
383 mesh->setCoords(coordsArr);
384 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
385 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
386 const int part[4] = {1,2,3,4}; // cell #0 is omitted
387 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vecField=
388 mesh->buildPartOrthogonalField( part, part+4 );
389 CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfTuples() == 4 );
390 CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfComponents() == 3 );
391 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
394 void CppExample_MEDCouplingUMesh_getPartMeasureField()
396 using namespace ParaMEDMEM;
397 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1]
398 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
399 mesh->setMeshDimension(2);
400 mesh->allocateCells(5);
401 const int conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4};
402 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
403 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
404 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
405 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
406 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
407 mesh->finishInsertingCells();
408 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
409 coordsArr->alloc(9,2);
410 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
411 std::copy(coords,coords+18,coordsArr->getPointer());
412 mesh->setCoords(coordsArr);
413 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1]
414 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2]
415 const bool isAbs = true;
416 const int part[4] = {1,2,3,4}; // cell #0 is omitted
417 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> areaArr=
418 mesh->getPartMeasureField( isAbs, part, part+4 );
419 CPPUNIT_ASSERT( areaArr->getIJ(0,0) > 0 ); // orientation ignored
420 areaArr=mesh->getPartMeasureField( !isAbs, part, part+4 );
421 CPPUNIT_ASSERT( areaArr->getIJ(0,0) < 0 ); // orientation considered
422 CPPUNIT_ASSERT ( areaArr->getNumberOfTuples() == 4 );
423 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2]
424 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3]
425 const int cellIds[4] = {1,2,3,4}; // cell #0 is omitted
426 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> baryCenters=
427 mesh->getPartBarycenterAndOwner( cellIds, cellIds+4 );
428 CPPUNIT_ASSERT( baryCenters->getNumberOfTuples() == 4 );
429 CPPUNIT_ASSERT( baryCenters->getNumberOfComponents() == mesh->getSpaceDimension() );
430 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3]
433 void CppExample_MEDCouplingUMesh_getCellsInBoundingBox()
435 using namespace ParaMEDMEM;
436 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
437 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
438 mesh->setMeshDimension(2);
439 mesh->allocateCells(1);
440 const double coords[3*2]={0.,0., 0.,1., 1.,1};
441 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
442 coordsArr->useExternalArrayWithRWAccess(coords, 3,2);
443 mesh->setCoords(coordsArr);
444 mesh->allocateCells(1);
445 const int conn[3]={0,1,2};
446 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn);
447 mesh->finishInsertingCells();
448 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
449 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
450 const double bbox[] = {1., 1., 1.001,1.001}; // xMin, xMax, yMin, yMax
451 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsArr =
452 mesh->getCellsInBoundingBox( bbox, 0.0 );
453 CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 0 );
454 cellIdsArr = mesh->getCellsInBoundingBox( bbox, 0.1 );
455 CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 1 );
456 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
459 void CppExample_MEDCouplingUMesh_renumberNodesInConn()
461 using namespace ParaMEDMEM;
462 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1]
463 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
464 mesh->setMeshDimension(2);
465 mesh->allocateCells(1);
466 const int conn[4]={4,3,2,1};
467 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
468 mesh->finishInsertingCells();
469 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1]
470 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2]
471 const int old2newIds[] = {-1,3,2,1,0};
472 mesh->renumberNodesInConn( old2newIds );
473 const int nodes0Expected[] = {0,1,2,3};
474 std::vector<int> nodes0;
475 mesh->getNodeIdsOfCell( 0, nodes0 );
476 CPPUNIT_ASSERT(std::equal( nodes0Expected, nodes0Expected+4, &nodes0[0] ));
477 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2]
480 void CppExample_MEDCouplingUMesh_renumberNodes()
482 using namespace ParaMEDMEM;
483 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1]
484 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
485 mesh->setMeshDimension(2);
486 const double coords[4*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.3};
487 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
488 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
489 mesh->setCoords(coordsArr);
490 mesh->allocateCells(0);
491 mesh->finishInsertingCells();
492 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1]
493 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2]
494 const int newIds[] = { 2,1,0,-1 };
495 mesh->renumberNodes(newIds, 3);
496 coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array
497 const double coordsExpected[3*2]={0.7,-0.3, 0.2,-0.3, -0.3,-0.3};
498 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsExpectedArr=DataArrayDouble::New();
499 coordsExpectedArr->useExternalArrayWithRWAccess(coordsExpected, 3,2);
500 CPPUNIT_ASSERT( coordsExpectedArr->isEqual( *coordsArr, 1e-13 ));
501 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2]
502 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3]
503 coordsArr->useExternalArrayWithRWAccess(coords, 4,2); // restore old nodes
504 const int newIds2[] = { 2,1,0,2 };
505 mesh->renumberNodes2(newIds2, 3);
506 coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array
507 const double coordsExpected2[3*2]={0.7,-0.3, 0.2,-0.3, -0.3, 0.0};
508 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsExpectedArr2=DataArrayDouble::New();
509 coordsExpectedArr2->useExternalArrayWithRWAccess(coordsExpected2, 3,2);
510 CPPUNIT_ASSERT( coordsExpectedArr2->isEqual( *coordsArr, 1e-13 ));
511 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3]
514 void CppExample_MEDCouplingUMesh_findBoundaryNodes()
516 using namespace ParaMEDMEM;
517 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1]
518 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
519 mesh->setMeshDimension(2);
520 mesh->allocateCells(5);
521 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
522 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
523 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
524 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
525 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
526 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
527 mesh->finishInsertingCells();
528 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
529 coordsArr->alloc(9,2);
530 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
531 std::copy(coords,coords+18,coordsArr->getPointer());
532 mesh->setCoords(coordsArr);
533 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1]
534 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2]
535 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeIdsArr=mesh->findBoundaryNodes();
536 CPPUNIT_ASSERT( nodeIdsArr->getNumberOfTuples() == mesh->getNumberOfNodes() - 1 );
537 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2]
540 void CppExample_MEDCouplingUMesh_buildBoundaryMesh()
542 using namespace ParaMEDMEM;
543 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
544 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
545 mesh->setMeshDimension(2);
546 mesh->allocateCells(5);
547 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
548 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
549 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
550 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
551 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
552 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
553 mesh->finishInsertingCells();
554 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
555 coordsArr->alloc(9,2);
556 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
557 std::copy(coords,coords+18,coordsArr->getPointer());
558 mesh->setCoords(coordsArr);
559 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
560 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
561 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> mesh1=mesh->buildBoundaryMesh(true);
562 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> mesh2=mesh->buildBoundaryMesh(false);
563 CPPUNIT_ASSERT( coordsArr->isEqual( *mesh1->getCoords(), 1e-13 )); // same nodes
564 CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // different nodes
565 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
568 void CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode()
570 using namespace ParaMEDMEM;
571 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
572 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
573 mesh->setMeshDimension(2);
574 mesh->allocateCells(5);
575 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
576 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
577 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
578 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
579 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
580 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
581 mesh->finishInsertingCells();
582 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
583 coordsArr->alloc(9,2);
584 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
585 std::copy(coords,coords+18,coordsArr->getPointer());
586 mesh->setCoords(coordsArr);
587 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
588 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
589 std::vector<int> nodes;
590 mesh->getNodeIdsOfCell( 0, nodes );
591 const bool allNodes = true;
592 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1 =
593 (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),allNodes);
594 CPPUNIT_ASSERT( mesh1->getNumberOfCells() == 4 ); // 4 segments bounding QUAD4 #0 only
595 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
596 (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),!allNodes);
597 CPPUNIT_ASSERT( mesh2->getNumberOfCells() == 9 ); // more segments added
598 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
601 void CppExample_MEDCouplingUMesh_buildPartOfMySelfNode()
603 using namespace ParaMEDMEM;
604 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
605 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
606 mesh->setMeshDimension(2);
607 mesh->allocateCells(5);
608 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
609 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
610 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
611 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
612 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
613 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
614 mesh->finishInsertingCells();
615 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
616 coordsArr->alloc(9,2);
617 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
618 std::copy(coords,coords+18,coordsArr->getPointer());
619 mesh->setCoords(coordsArr);
620 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
621 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
622 std::vector<int> nodes;
623 mesh->getNodeIdsOfCell( 0, nodes );
624 const bool allNodes = true;
625 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1 =
626 (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(), allNodes);
627 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
628 (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(),!allNodes);
629 CPPUNIT_ASSERT_EQUAL( mesh1->getNumberOfCells(), 1 );
630 CPPUNIT_ASSERT_EQUAL( mesh2->getNumberOfCells(), mesh->getNumberOfCells() );
631 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
634 void CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes()
636 using namespace ParaMEDMEM;
637 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
638 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
639 mesh->setMeshDimension(2);
640 mesh->allocateCells(5);
641 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
642 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
643 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
644 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
645 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
646 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
647 mesh->finishInsertingCells();
648 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
649 coordsArr->alloc(9,2);
650 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
651 std::copy(coords,coords+18,coordsArr->getPointer());
652 mesh->setCoords(coordsArr);
653 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
654 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
655 std::vector<int> nodes;
656 mesh->getNodeIdsOfCell( 0, nodes );
657 const bool allNodes = true;
658 DataArrayInt* cellIdsArr1 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(), allNodes);
659 DataArrayInt* cellIdsArr2 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(),!allNodes);
660 CPPUNIT_ASSERT_EQUAL( cellIdsArr1->getNumberOfTuples(), 1 );
661 CPPUNIT_ASSERT_EQUAL( cellIdsArr2->getNumberOfTuples(), mesh->getNumberOfCells() );
662 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
663 cellIdsArr1->decrRef();
664 cellIdsArr2->decrRef();
667 void CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds()
669 using namespace ParaMEDMEM;
670 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
671 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
672 mesh->setMeshDimension(2);
673 mesh->allocateCells(5);
674 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
675 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
676 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
677 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
678 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
679 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
680 mesh->finishInsertingCells();
681 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
682 coordsArr->alloc(9,2);
683 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
684 std::copy(coords,coords+18,coordsArr->getPointer());
685 mesh->setCoords(coordsArr);
686 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
687 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
688 const int cellIds[2]={1,2};
689 std::vector<int> nodes;
690 mesh->getNodeIdsOfCell( cellIds[0], nodes );
691 mesh->getNodeIdsOfCell( cellIds[1], nodes );
692 DataArrayInt* cellIdsArr = mesh->getCellIdsFullyIncludedInNodeIds( &nodes[0], &nodes[0]+nodes.size());
693 CPPUNIT_ASSERT(std::equal( cellIds, cellIds+2, cellIdsArr->getPointer() ));
694 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
695 cellIdsArr->decrRef();
698 void CppExample_MEDCouplingUMesh_buildPartOfMySelf()
700 using namespace ParaMEDMEM;
701 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
702 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
703 mesh->setMeshDimension(2);
704 mesh->allocateCells(5);
705 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
706 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
707 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
708 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
709 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
710 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
711 mesh->finishInsertingCells();
712 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
713 coordsArr->alloc(9,2);
714 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
715 std::copy(coords,coords+18,coordsArr->getPointer());
716 mesh->setCoords(coordsArr);
717 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
718 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
719 const int cellIds[2]={1,2};
720 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
721 MEDCouplingUMesh* mesh3=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,false);
722 CPPUNIT_ASSERT( coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // same nodes
723 CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh3->getCoords(), 1e-13 )); // different nodes
724 for ( int i = 0; i < 2; ++i )
726 std::vector<int> nodes1, nodes2;
727 mesh ->getNodeIdsOfCell(cellIds[i], nodes1);
728 mesh2->getNodeIdsOfCell(i, nodes2);
729 CPPUNIT_ASSERT( nodes1 == nodes2 ); // cell #cellIds[i] was copied
731 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
736 void CppExample_MEDCouplingUMesh_mergeNodes()
738 using namespace ParaMEDMEM;
739 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1]
740 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
741 mesh->setMeshDimension(2);
742 mesh->allocateCells(5);
743 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2};
744 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
745 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
746 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
747 mesh->finishInsertingCells();
748 const double coords[6*2]={0.3,-0.301, // #0
750 0.3,-0.302, // #2 ~~ #0
753 0.3,-0.303}; // #5 ~~ #0
754 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
755 coordsArr->alloc(6,2);
756 std::copy(coords,coords+6*2,coordsArr->getPointer());
757 mesh->setCoords(coordsArr);
758 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1]
759 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2]
760 bool areNodesMerged; int newNbOfNodes;
761 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=
762 mesh->mergeNodes(0.004,areNodesMerged,newNbOfNodes);
763 const int idsExpected[6] = {0, 1, 0, 2, 2, 0};
764 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+6,arr->getPointer()));
765 CPPUNIT_ASSERT( areNodesMerged );
766 CPPUNIT_ASSERT_EQUAL( 3, newNbOfNodes );
767 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2]
768 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3]
769 const double* baryCoords2 = coords + 2*2; // initial coordinates of node #2
770 coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array
771 CPPUNIT_ASSERT( fabs( baryCoords2[1] - coordsArr->getIJ(0,1)) > 1e-4 ); // Y of node #0 differs from that of baryCoords2
772 // restore coordinates
773 coordsArr->alloc(6,2);
774 std::copy(coords,coords+6*2,coordsArr->getPointer());
775 mesh->setCoords(coordsArr);
776 // call mergeNodes2()
777 arr = mesh->mergeNodes2(0.004,areNodesMerged,newNbOfNodes);
778 coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array
779 CPPUNIT_ASSERT_DOUBLES_EQUAL( baryCoords2[1], coordsArr->getIJ(0,1), 13 ); // Y of node #0 equals to that of baryCoords2
780 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3]
783 void CppExample_MEDCouplingUMesh_zipConnectivityTraducer()
785 using namespace ParaMEDMEM;
786 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
787 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
788 mesh->setMeshDimension(2);
789 mesh->allocateCells(5);
790 const int conn[11]={0,3,4,1, 1,4,2, 4,1,0,3};
791 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 0
792 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
793 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 2 == 1
794 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 3 == 0
795 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+7); // 4 ~~ 0
796 mesh->finishInsertingCells();
797 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
798 coordsArr->alloc(9,2);
799 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
800 std::copy(coords,coords+18,coordsArr->getPointer());
801 mesh->setCoords(coordsArr);
802 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
803 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
804 const int oldNbCells = mesh->getNumberOfCells();
805 DataArrayInt *arr = mesh->zipConnectivityTraducer(0);
806 CPPUNIT_ASSERT_EQUAL( oldNbCells-2, mesh->getNumberOfCells() );
807 const int idsExpected[5] = {0, 1, 1, 0, 2};
808 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+5,arr->getPointer()));
809 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
813 void CppExample_MEDCouplingUMesh_zipCoordsTraducer()
815 using namespace ParaMEDMEM;
816 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
817 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
818 mesh->setMeshDimension(2);
819 mesh->allocateCells(5);
820 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
821 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
822 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
823 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
824 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
825 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
826 mesh->finishInsertingCells();
827 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
828 coordsArr->alloc(9,2);
829 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
830 std::copy(coords,coords+18,coordsArr->getPointer());
831 mesh->setCoords(coordsArr);
832 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
833 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
834 const int cellIds[2]={1,2};
835 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
836 DataArrayInt *arr=mesh2->zipCoordsTraducer();
837 CPPUNIT_ASSERT_EQUAL( 4, mesh2->getNumberOfNodes() ); // nb of nodes decreased
838 CPPUNIT_ASSERT_EQUAL( mesh->getNumberOfNodes(), arr->getNumberOfTuples() );
839 const int idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1}; // -1 for unused nodes
840 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer()));
841 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
846 void CppExample_MEDCouplingUMesh_getNodeIdsInUse()
848 using namespace ParaMEDMEM;
849 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
850 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
851 mesh->setMeshDimension(2);
852 mesh->allocateCells(5);
853 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
854 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
855 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
856 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
857 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
858 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
859 mesh->finishInsertingCells();
860 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
861 coordsArr->alloc(9,2);
862 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
863 std::copy(coords,coords+18,coordsArr->getPointer());
864 mesh->setCoords(coordsArr);
865 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
866 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
867 const int cellIds[2]={1,2};
868 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
869 int newNbOfNodes = 0;
870 DataArrayInt *arr=mesh2->getNodeIdsInUse( newNbOfNodes );
871 const int idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1};
872 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer()));
873 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
874 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
875 DataArrayInt *arr2=arr->invertArrayO2N2N2O(newNbOfNodes);
876 const int idsExpected2[4] = {1,2,4,5};
877 CPPUNIT_ASSERT(std::equal(idsExpected2,idsExpected2+4,arr2->getPointer()));
878 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
884 void CppExample_MEDCouplingUMesh_convertToPolyTypes()
886 using namespace ParaMEDMEM;
887 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1]
888 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
889 mesh->setMeshDimension(2);
890 mesh->allocateCells(5);
891 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
892 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
893 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
894 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
895 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
896 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
897 mesh->finishInsertingCells();
898 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
899 coordsArr->alloc(9,2);
900 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
901 std::copy(coords,coords+18,coordsArr->getPointer());
902 mesh->setCoords(coordsArr);
903 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1]
904 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2]
905 const int cells[2]={1,3};
906 mesh->convertToPolyTypes(cells, cells+2);
907 CPPUNIT_ASSERT( mesh->getTypeOfCell(0) == INTERP_KERNEL::NORM_QUAD4 );
908 CPPUNIT_ASSERT( mesh->getTypeOfCell(1) == INTERP_KERNEL::NORM_POLYGON );
909 CPPUNIT_ASSERT( mesh->getTypeOfCell(2) == INTERP_KERNEL::NORM_TRI3 );
910 CPPUNIT_ASSERT( mesh->getTypeOfCell(3) == INTERP_KERNEL::NORM_POLYGON );
911 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2]
914 void CppExample_MEDCouplingUMesh_buildDescendingConnectivity2()
916 using namespace ParaMEDMEM;
917 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
918 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
919 mesh->setMeshDimension(2);
920 mesh->allocateCells(5);
921 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
922 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
923 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
924 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
925 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
926 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
927 mesh->finishInsertingCells();
928 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
929 coordsArr->alloc(9,2);
930 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
931 std::copy(coords,coords+18,coordsArr->getPointer());
932 mesh->setCoords(coordsArr);
933 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
934 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
935 DataArrayInt *desc =DataArrayInt::New();
936 DataArrayInt *descIndx =DataArrayInt::New();
937 DataArrayInt *revDesc =DataArrayInt::New();
938 DataArrayInt *revDescIndx=DataArrayInt::New();
939 MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx);
940 const int descExpected[] = {1,2,3,4,-3,5,6,7,8,-5,9,10,-2,11,12,13,-7,-10};
941 const int descIndxExpected[] = {0,4,7,10,14,18};
942 const int revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
943 const int revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18};
944 CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer()));
945 CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer()));
946 CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer()));
947 CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer()));
948 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
949 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
950 const int cell2ConnExpect[] = {4,1};
951 std::vector<int> cell2Conn;
952 mesh2->getNodeIdsOfCell( 3-1, cell2Conn ); // cell #3 in FORTRAN mode
953 CPPUNIT_ASSERT(std::equal(cell2ConnExpect,cell2ConnExpect+2,&cell2Conn[0]));
954 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
958 revDescIndx->decrRef();
962 void CppExample_MEDCouplingUMesh_buildDescendingConnectivity()
964 using namespace ParaMEDMEM;
965 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
966 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
967 mesh->setMeshDimension(2);
968 mesh->allocateCells(5);
969 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
970 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
971 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
972 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
973 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
974 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
975 mesh->finishInsertingCells();
976 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
977 coordsArr->alloc(9,2);
978 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
979 std::copy(coords,coords+18,coordsArr->getPointer());
980 mesh->setCoords(coordsArr);
981 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
982 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
983 DataArrayInt *desc =DataArrayInt::New();
984 DataArrayInt *descIndx =DataArrayInt::New();
985 DataArrayInt *revDesc =DataArrayInt::New();
986 DataArrayInt *revDescIndx=DataArrayInt::New();
987 MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
988 const int descExpected[] = {0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
989 const int descIndxExpected[] = {0,4,7,10,14,18};
990 const int revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
991 const int revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18};
992 CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer()));
993 CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer()));
994 CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer()));
995 CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer()));
996 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
1000 revDescIndx->decrRef();
1004 void CppExample_MEDCouplingUMesh_getReverseNodalConnectivity()
1006 using namespace ParaMEDMEM;
1007 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1008 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1009 mesh->setMeshDimension(2);
1010 mesh->allocateCells(5);
1011 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1012 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1013 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1014 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1015 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1016 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1017 mesh->finishInsertingCells();
1018 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1019 coordsArr->alloc(9,2);
1020 const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
1021 std::copy(coords,coords+18,coordsArr->getPointer());
1022 mesh->setCoords(coordsArr);
1023 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1024 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1025 DataArrayInt *revNodal=DataArrayInt::New();
1026 DataArrayInt *revNodalIndx=DataArrayInt::New();
1027 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
1028 const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
1029 const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
1030 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
1031 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
1032 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1033 revNodal->decrRef();
1034 revNodalIndx->decrRef();
1037 void CppExample_MEDCouplingUMesh_checkDeepEquivalWith()
1039 using namespace ParaMEDMEM;
1040 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1042 MEDCouplingUMesh *mesh1=MEDCouplingUMesh::New();
1043 const double coords[4*2]={0.0,0.0, // #0
1048 mesh1->setMeshDimension(2);
1049 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1050 coordsArr->useExternalArrayWithRWAccess( coords, 4, 2 );
1051 mesh1->setCoords(coordsArr);
1052 mesh1->allocateCells(2);
1053 const int conn[6]={0,1,2, 1,2,3};
1054 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0
1055 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1
1056 mesh1->finishInsertingCells();
1059 MEDCouplingUMesh *mesh2=MEDCouplingUMesh::New();
1060 const double coords2[4*2]={0.0,1.0, // #0 = #3
1063 1.0,1.001}; // #3 ~ #2
1065 mesh2->setMeshDimension(2);
1066 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1067 coordsArr->useExternalArrayWithRWAccess( coords2, 4, 2 );
1068 mesh2->setCoords(coordsArr);
1069 mesh2->allocateCells(2);
1070 const int conn[6]={2,3,0, 3,1,2};
1071 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0 = #1
1072 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1 ~ #0
1073 mesh2->finishInsertingCells();
1075 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1076 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1077 int cellCompPol = 1; // "permuted same orientation" - policy of medium severity
1078 DataArrayInt *nOld2New, *cOld2New;
1079 mesh1->checkDeepEquivalWith( mesh2, cellCompPol, 0.002, cOld2New, nOld2New );
1080 const int nOld2NewExpected[4] = { 3, 0, 1, 2 };
1081 const int cOld2NewExpected[2] = { 1, 0 };
1082 CPPUNIT_ASSERT(std::equal(nOld2NewExpected,nOld2NewExpected+4,nOld2New->getConstPointer()));
1083 CPPUNIT_ASSERT(std::equal(cOld2NewExpected,cOld2NewExpected+2,cOld2New->getConstPointer()));
1084 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1085 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1086 cOld2New->decrRef(); // else memory leaks
1087 CPPUNIT_ASSERT_THROW ( mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0.002, cOld2New ), INTERP_KERNEL::Exception );
1088 mesh2->setCoords( mesh1->getCoords() ); // make meshes share the same coordinates array
1089 mesh2->allocateCells(2);
1090 const int conn[6]={1,2,3, 1,0,2};
1091 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+0); // #0 = #1
1092 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3); // #1 ~ #0
1093 mesh2->finishInsertingCells();
1094 cellCompPol = 2; // the weakest policy
1095 mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0, cOld2New );
1096 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1097 nOld2New->decrRef();
1098 cOld2New->decrRef();
1103 void CppExample_MEDCouplingPointSet_scale()
1105 using namespace ParaMEDMEM;
1106 //! [CppSnippet_MEDCouplingPointSet_scale_1]
1107 double coords[4*2]={0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0}; // 2D coordinates of 4 nodes
1108 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1109 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1110 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1111 mesh->setCoords(coordsArr);
1112 DataArrayDouble *initCoords = coordsArr->deepCpy();
1113 //! [CppSnippet_MEDCouplingPointSet_scale_1]
1114 //! [CppSnippet_MEDCouplingPointSet_scale_2]
1115 const double center[2] = {0.,0.};
1116 const double factor = 2.;
1117 mesh->scale( center, factor );
1118 //! [CppSnippet_MEDCouplingPointSet_scale_2]
1119 //! [CppSnippet_MEDCouplingPointSet_scale_3]
1120 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1121 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 ));
1122 CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 ));
1124 initCoords->decrRef();
1125 //! [CppSnippet_MEDCouplingPointSet_scale_3]
1128 void CppExample_MEDCouplingPointSet_translate()
1130 using namespace ParaMEDMEM;
1131 //! [CppSnippet_MEDCouplingPointSet_translate_1]
1132 double coords[4*2]={0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0}; // 2D coordinates of 4 nodes
1133 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1134 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1135 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1136 mesh->setCoords(coordsArr);
1137 DataArrayDouble *initCoords = coordsArr->deepCpy();
1138 //! [CppSnippet_MEDCouplingPointSet_translate_1]
1139 //! [CppSnippet_MEDCouplingPointSet_translate_2]
1140 double vector[2] = {1.,1.};
1141 mesh->translate( vector );
1142 //! [CppSnippet_MEDCouplingPointSet_translate_2]
1143 //! [CppSnippet_MEDCouplingPointSet_translate_3]
1144 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1145 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 ));
1146 CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 ));
1148 initCoords->decrRef();
1149 //! [CppSnippet_MEDCouplingPointSet_translate_3]
1152 void CppExample_MEDCouplingPointSet_rotate()
1154 using namespace ParaMEDMEM;
1155 //! [CppSnippet_MEDCouplingPointSet_rotate_1]
1156 double coords[4*2]={0.0,0.0, 0.1,0.0, 0.1,0.1, 0.0,0.1}; // 2D coordinates of 4 nodes
1157 double coordsOrig[4*2];
1158 std::copy(coords,coords+sizeof(coords)/sizeof(double),coordsOrig);//keep tracks of initial values
1159 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1160 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1161 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1162 mesh->setCoords(coordsArr);
1163 //! [CppSnippet_MEDCouplingPointSet_rotate_1]
1164 //! [CppSnippet_MEDCouplingPointSet_rotate_2]
1165 double center[3] = {0.,0.,0.}; // it suits for 2D as well
1166 double vector[3] = {0.,0.,1.}; // it is not used in 2D
1167 mesh->rotate( center, vector, -M_PI/2); // warning here C++ 'coords' array (defined above) has been modified !
1168 //! [CppSnippet_MEDCouplingPointSet_rotate_2]
1169 //! [CppSnippet_MEDCouplingPointSet_rotate_3]
1170 mesh->changeSpaceDimension(3);
1171 mesh->rotate( center, vector, +M_PI/2);
1172 //! [CppSnippet_MEDCouplingPointSet_rotate_3]
1173 //! [CppSnippet_MEDCouplingPointSet_rotate_4]
1174 mesh->changeSpaceDimension(2);
1175 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1176 coordsArr->useExternalArrayWithRWAccess(coordsOrig, 4,2);
1177 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *coordsArr, 1e-13 ));
1178 //! [CppSnippet_MEDCouplingPointSet_rotate_4]
1181 void CppExample_MEDCouplingPointSet_getBoundingBox()
1183 using namespace ParaMEDMEM;
1184 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1]
1185 double cc[2*3]={0.0, 0.1, 0.2, // 3D coordinates of 2 nodes
1187 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1188 coordsArr->useExternalArrayWithRWAccess(cc, 2,3);
1189 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1190 mesh->setCoords(coordsArr);
1191 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1]
1192 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2]
1194 mesh->getBoundingBox( (double*) bbox );
1196 // check the returned coordinates of extremum points of the bounding box
1197 for ( int i = 0; i < 2; ++i ) // point id
1198 for ( int j = 0; j < 3; ++j ) // component
1199 CPPUNIT_ASSERT_DOUBLES_EQUAL( cc[ i*3 + j ], bbox[j][i], 1e-13);
1200 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2]
1203 void CppExample_MEDCouplingPointSet_getNodeIdsNearPoint()
1205 using namespace ParaMEDMEM;
1206 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1207 // 2D coordinates of 5 nodes
1208 double coords[5*2]={0.3,-0.30001, // #0
1213 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1214 coordsArr->useExternalArrayWithRWAccess(coords, 5,2);
1215 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1216 mesh->setCoords(coordsArr);
1217 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1218 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1219 double point [2]={0.3, -0.3}; // point close to nodes #0, #2 and #4
1220 DataArrayInt *ids = mesh->getNodeIdsNearPoint(point, 1e-2);
1223 const int expectedIDs[3] = {0,2,4};
1224 DataArrayInt * okIDs = ids->getIdsEqualList ( expectedIDs, expectedIDs+3 );
1225 CPPUNIT_ASSERT_EQUAL(3, okIDs->getNumberOfTuples());
1230 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1232 void CppExample_MEDCouplingPointSet_getNodeIdsNearPoints()
1234 using namespace ParaMEDMEM;
1235 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1236 // 2D coordinates of 7 nodes
1237 double coords[7*2]={0.3,-0.301, // #0
1244 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1245 coordsArr->useExternalArrayWithRWAccess(coords, 7,2);
1246 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1247 mesh->setCoords(coordsArr);
1248 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1249 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1250 const int nbOfPoints = 3;
1251 double points [nbOfPoints*2]={0.2,-0.30001, // ~ node #1
1253 1.1, 0.002}; // ~ nodes #3, #4 and #5
1254 DataArrayInt *ids, *idsIndex;
1255 mesh->getNodeIdsNearPoints(points, nbOfPoints, 1e-1,ids,idsIndex);
1257 // check found ids (i.e. contents of 'ids' array)
1258 const int expectedIDs[4] = {1, 3, 4, 5};
1259 DataArrayInt * okIDs = ids->getIdsEqualList ( expectedIDs, expectedIDs+4 );
1260 CPPUNIT_ASSERT_EQUAL(4, okIDs->getNumberOfTuples());
1264 idsIndex->decrRef();
1266 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1269 void CppExample_MEDCouplingPointSet_findCommonNodes()
1271 using namespace ParaMEDMEM;
1272 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1]
1273 double coords[6*2]={0.3,-0.301, // 0
1279 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1280 coordsArr->useExternalArrayWithRWAccess(coords, 6,2);
1281 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1282 mesh->setCoords(coordsArr);
1283 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1]
1284 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2]
1285 DataArrayInt *com, *comI;
1286 mesh->findCommonNodes(1e-13,-1,com,comI);
1287 CPPUNIT_ASSERT_EQUAL(2, com->getNumberOfTuples());
1288 com->decrRef(); comI->decrRef();
1289 mesh->findCommonNodes(0.004,-1,com,comI);
1290 CPPUNIT_ASSERT_EQUAL(5, com->getNumberOfTuples());
1291 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2]
1292 com->decrRef(); comI->decrRef();
1295 void CppExample_MEDCouplingPointSet_getCoordinatesOfNode()
1297 using namespace ParaMEDMEM;
1298 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1299 double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3};
1300 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1301 coordsArr->useExternalArrayWithRWAccess(coords, 3,2);
1302 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1303 mesh->setCoords(coordsArr);
1304 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1305 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1306 std::vector<double> coords2;
1307 mesh->getCoordinatesOfNode(1,coords2);
1308 CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[2],coords2[0],1e-13);
1309 CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[3],coords2[1],1e-13);
1310 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1313 void CppExample_DataArrayInt_buildPermutationArr()
1315 using namespace ParaMEDMEM;
1316 //! [CppSnippet_DataArrayInt_buildPermutationArr_1]
1317 DataArrayInt *a=DataArrayInt::New();
1318 const int vala[5]={4,5,6,7,8};
1320 std::copy(vala,vala+5,a->getPointer());
1321 DataArrayInt *b=DataArrayInt::New();
1322 const int valb[5]={5,4,8,6,7};
1324 std::copy(valb,valb+5,b->getPointer());
1325 DataArrayInt *c=a->buildPermutationArr(*b);
1326 //! [CppSnippet_DataArrayInt_buildPermutationArr_1]
1327 const int expect1[5]={1,0,4,2,3};
1328 CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
1329 CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
1330 CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
1331 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
1337 void CppExample_DataArrayInt_invertArrayO2N2N2O()
1339 using namespace ParaMEDMEM;
1340 //! [CppSnippet_DataArrayInt_invertArrayO2N2N2O_1]
1341 const int arr1[6]={2,0,4,1,5,3};
1342 DataArrayInt *da=DataArrayInt::New();
1344 std::copy(arr1,arr1+6,da->getPointer());
1345 DataArrayInt *da2=da->invertArrayO2N2N2O(6);
1346 const int expected1[6]={1,3,0,5,2,4};
1347 for(int i=0;i<6;i++)
1348 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
1349 //! [CppSnippet_DataArrayInt_invertArrayO2N2N2O_1]
1354 void CppExample_DataArrayInt_invertArrayN2O2O2N()
1356 using namespace ParaMEDMEM;
1357 //! [CppSnippet_DataArrayInt_invertArrayN2O2O2N_1]
1358 const int arr1[6]={2,0,4,1,5,3};
1359 DataArrayInt *da=DataArrayInt::New();
1361 std::copy(arr1,arr1+6,da->getPointer());
1362 DataArrayInt *da2=da->invertArrayN2O2O2N(6);
1363 const int expected1[6]={1,3,0,5,2,4};
1364 for(int i=0;i<6;i++)
1365 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
1366 //! [CppSnippet_DataArrayInt_invertArrayN2O2O2N_1]
1371 void CppExample_DataArrayDouble_getIdsInRange()
1373 using namespace ParaMEDMEM;
1374 //! [CppSnippet_DataArrayDouble_getIdsInRange_1]
1375 DataArrayDouble *da=DataArrayDouble::New();
1379 DataArrayInt* da2 = da->getIdsInRange( 2.5, 6 );
1380 //! [CppSnippet_DataArrayDouble_getIdsInRange_1]
1385 void CppExample_DataArrayDouble_findCommonTuples()
1387 using namespace ParaMEDMEM;
1388 //! [CppSnippet_DataArrayDouble_findCommonTuples1]
1389 DataArrayDouble *da=DataArrayDouble::New();
1391 const double array2[12]={2.3,2.3, // 0
1398 std::copy(array2,array2+12,da->getPointer());
1399 //! [CppSnippet_DataArrayDouble_findCommonTuples1]
1400 //! [CppSnippet_DataArrayDouble_findCommonTuples2]
1401 DataArrayInt *c=0,*cI=0;
1402 da->findCommonTuples(1.01e-1,-1,c,cI);
1404 const int expected3[5]={0,3,4,1,2};
1405 const int expected4[3]={0,3,5};
1406 CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer()));
1407 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer()));
1411 //! [CppSnippet_DataArrayDouble_findCommonTuples2]
1414 void CppExample_DataArrayDouble_Meld1()
1416 using namespace ParaMEDMEM;
1417 //! [CppSnippet_DataArrayDouble_Meld1_1]
1418 const int sameNbTuples = 7;
1420 DataArrayDouble *da1=DataArrayDouble::New();
1421 da1->alloc(sameNbTuples,2);
1422 da1->fillWithValue(7.);
1423 da1->setInfoOnComponent(0,"c0da1");
1424 da1->setInfoOnComponent(1,"c1da1");
1426 DataArrayDouble *da2=DataArrayDouble::New();
1427 da2->alloc(sameNbTuples,1);
1429 da2->setInfoOnComponent(0,"c0da2");
1432 //! [CppSnippet_DataArrayDouble_Meld1_1]
1433 //! [CppSnippet_DataArrayDouble_Meld1_2]
1436 //! [CppSnippet_DataArrayDouble_Meld1_2]
1439 void CppExample_DataArrayInt_Meld1()
1441 using namespace ParaMEDMEM;
1442 //! [CppSnippet_DataArrayInt_Meld1_1]
1443 const int sameNbTuples = 7;
1445 DataArrayInt *da1=DataArrayInt::New();
1446 da1->alloc(sameNbTuples,2);
1447 da1->fillWithValue(7);
1448 da1->setInfoOnComponent(0,"c0da1");
1449 da1->setInfoOnComponent(1,"c1da1");
1451 DataArrayInt *da2=DataArrayInt::New();
1452 da2->alloc(sameNbTuples,1);
1454 da2->setInfoOnComponent(0,"c0da2");
1457 //! [CppSnippet_DataArrayInt_Meld1_1]
1458 //! [CppSnippet_DataArrayInt_Meld1_2]
1461 //! [CppSnippet_DataArrayInt_Meld1_2]
1464 void CppExampleFieldDoubleBuildSubPart1()
1466 //! [CppSnippetFieldDoubleBuildSubPart1_1]
1467 ParaMEDMEM::MEDCouplingUMesh *mesh1=ParaMEDMEM::MEDCouplingBasicsTest::build2DTargetMesh_1();
1468 ParaMEDMEM::MEDCouplingFieldDouble *f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
1469 f1->setTime(2.3,5,6);
1471 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
1472 array->alloc(mesh1->getNumberOfCells(),2);
1473 const double arr1[10]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.};
1474 std::copy(arr1,arr1+10,array->getPointer());
1475 f1->setArray(array);
1477 //! [CppSnippetFieldDoubleBuildSubPart1_1]
1478 //! [CppSnippetFieldDoubleBuildSubPart1_2]
1479 const int part1[3]={2,1,4};
1480 ParaMEDMEM::MEDCouplingFieldDouble *f2=f1->buildSubPart(part1,part1+3);
1481 //! [CppSnippetFieldDoubleBuildSubPart1_2]
1483 CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
1484 CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
1485 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1486 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1487 ParaMEDMEM::MEDCouplingUMesh *m2C=dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(const_cast<ParaMEDMEM::MEDCouplingMesh *>(f2->getMesh()));
1488 CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
1489 const double expected2[12]={0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7};
1490 for(int i=0;i<12;i++)
1491 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1492 const double expected3[13]={3,2,3,1,3,0,2,1,4,4,5,3,2};
1493 CPPUNIT_ASSERT(std::equal(expected3,expected3+13,m2C->getNodalConnectivity()->getConstPointer()));
1494 const double expected4[4]={0,4,8,13};
1495 CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
1498 //! [CppSnippetFieldDoubleBuildSubPart1_3]
1499 f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::ONE_TIME);
1500 f1->setTime(2.3,5,6);
1502 array=ParaMEDMEM::DataArrayDouble::New();
1503 array->alloc(mesh1->getNumberOfNodes(),2);
1504 const double arr2[18]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
1505 std::copy(arr2,arr2+18,array->getPointer());
1506 f1->setArray(array);
1508 //! [CppSnippetFieldDoubleBuildSubPart1_3]
1509 //! [CppSnippetFieldDoubleBuildSubPart1_4]
1510 const int part2[2]={1,2};
1511 f2=f1->buildSubPart(part2,part2+2);
1512 //! [CppSnippetFieldDoubleBuildSubPart1_4]
1514 //idem previous because nodes of cell#4 are not fully present in part3
1515 const int part3[2]={1,2};
1516 ParaMEDMEM::DataArrayInt *arrr=ParaMEDMEM::DataArrayInt::New();
1518 std::copy(part3,part3+2,arrr->getPointer());
1519 f2=f1->buildSubPart(arrr);
1523 const int part4[3]={1,2,4};
1524 f2=f1->buildSubPart(part4,part4+3);
1532 void CppSnippetUMeshStdBuild1()
1534 //! [CppSnippetUMeshStdBuild1_1]
1535 double coords[27]={-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0.,
1536 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. };
1537 int nodalConnPerCell[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1538 //! [CppSnippetUMeshStdBuild1_1]
1539 //! [CppSnippetUMeshStdBuild1_2]
1540 ParaMEDMEM::MEDCouplingUMesh *mesh=ParaMEDMEM::MEDCouplingUMesh::New("My2DMesh",2);
1541 //! [CppSnippetUMeshStdBuild1_2]
1542 //! [CppSnippetUMeshStdBuild1_3]
1543 mesh->allocateCells(5);//You can put more than 5 if you want but not less.
1544 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell);
1545 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,nodalConnPerCell+4);
1546 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,nodalConnPerCell+7);
1547 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell+10);
1548 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell+14);
1549 mesh->finishInsertingCells();
1550 //! [CppSnippetUMeshStdBuild1_3]
1551 //! [CppSnippetUMeshStdBuild1_4]
1552 ParaMEDMEM::DataArrayDouble *coordsArr=ParaMEDMEM::DataArrayDouble::New();
1553 coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
1554 std::copy(coords,coords+27,coordsArr->getPointer());
1555 mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
1556 coordsArr->decrRef();
1557 //! [CppSnippetUMeshStdBuild1_4]
1558 mesh->checkCoherency();
1559 //! [CppSnippetUMeshStdBuild1_5]
1561 //! [CppSnippetUMeshStdBuild1_5]
1564 void CppSnippetCMeshStdBuild1()
1566 //! [CppSnippetCMeshStdBuild1_1]
1567 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
1568 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
1569 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New();
1571 std::copy(XCoords,XCoords+9,arrX->getPointer());
1572 arrX->setInfoOnComponent(0,"X [m]");
1573 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New();
1575 std::copy(YCoords,YCoords+7,arrY->getPointer());
1576 arrY->setInfoOnComponent(0,"Y [m]");
1577 //! [CppSnippetCMeshStdBuild1_1]
1578 //! [CppSnippetCMeshStdBuild1_2]
1579 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
1580 mesh->setCoords(arrX,arrY);
1583 //! [CppSnippetCMeshStdBuild1_2]
1584 //! [CppSnippetCMeshStdBuild1_3]
1585 CPPUNIT_ASSERT_EQUAL(8*6,mesh->getNumberOfCells());
1586 CPPUNIT_ASSERT_EQUAL(9*7,mesh->getNumberOfNodes());
1587 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
1588 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1589 //! [CppSnippetCMeshStdBuild1_3]
1591 mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
1592 arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
1593 arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
1594 //! [CppSnippetCMeshStdBuild1_2bis]
1595 mesh->setCoordsAt(0,arrX);
1597 mesh->setCoordsAt(1,arrY);
1599 //! [CppSnippetCMeshStdBuild1_2bis]
1600 CPPUNIT_ASSERT_EQUAL(8*6,mesh->getNumberOfCells());
1601 CPPUNIT_ASSERT_EQUAL(9*7,mesh->getNumberOfNodes());
1602 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
1603 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
1604 //! [CppSnippetCMeshStdBuild1_4]
1606 //! [CppSnippetCMeshStdBuild1_4]
1609 void CppSnippetUMeshAdvBuild1()
1611 //! [CppSnippetUMeshAdvBuild1_1]
1612 double coords[27]={-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0.,
1613 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. };
1614 int nodalConnPerCell[23]={4,0,3,4,1, 3,1,4,2, 3,4,5,2, 4,6,7,4,3, 4,7,8,5,4};
1615 int nodalConnPerCellIndex[6]={0,5,9,13,18,23};
1616 //! [CppSnippetUMeshAdvBuild1_1]
1617 //! [CppSnippetUMeshAdvBuild1_2]
1618 ParaMEDMEM::MEDCouplingUMesh *mesh=ParaMEDMEM::MEDCouplingUMesh::New("My2DMesh",2);
1619 //! [CppSnippetUMeshAdvBuild1_2]
1620 //! [CppSnippetUMeshAdvBuild1_3]
1621 ParaMEDMEM::DataArrayInt *nodalConn=ParaMEDMEM::DataArrayInt::New();
1622 nodalConn->alloc(23,1);
1623 std::copy(nodalConnPerCell,nodalConnPerCell+23,nodalConn->getPointer());
1624 ParaMEDMEM::DataArrayInt *nodalConnI=ParaMEDMEM::DataArrayInt::New();
1625 nodalConnI->alloc(6,1);
1626 std::copy(nodalConnPerCellIndex,nodalConnPerCellIndex+6,nodalConnI->getPointer());
1627 mesh->setConnectivity(nodalConn,nodalConnI,true);
1628 nodalConn->decrRef();// nodalConn DataArrayInt instance is owned by mesh after call to setConnectivity method. No more need here -> decrRef()
1629 nodalConnI->decrRef();// nodalConnI DataArrayInt instance is owned by mesh after call to setConnectivity method. No more need here -> decrRef()
1630 //! [CppSnippetUMeshAdvBuild1_3]
1631 //! [CppSnippetUMeshAdvBuild1_4]
1632 ParaMEDMEM::DataArrayDouble *coordsArr=ParaMEDMEM::DataArrayDouble::New();
1633 coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
1634 std::copy(coords,coords+27,coordsArr->getPointer());
1635 mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
1636 coordsArr->decrRef();
1637 //! [CppSnippetUMeshAdvBuild1_4]
1638 mesh->checkCoherency();
1639 //! [CppSnippetUMeshAdvBuild1_5]
1641 //! [CppSnippetUMeshAdvBuild1_5]
1644 void CppSnippetDataArrayBuild1()
1646 //! [CppSnippetDataArrayBuild1_0]
1647 const int nbOfNodes=12;
1648 double coords[3*nbOfNodes]={2.,3.,4.,3.,4.,5.,4.,5.,6.,5.,6.,7.,6.,7.,8.,7.,8.,9.,8.,9.,10.,9.,10.,11.,10.,11.,12.,11.,12.,13.,12.,13.,14.,13.,14.,15.};
1650 ParaMEDMEM::DataArrayDouble *coordsArr=0;
1652 //! [CppSnippetDataArrayBuild1_0]
1654 //! [CppSnippetDataArrayBuild1_1]
1655 coordsArr=ParaMEDMEM::DataArrayDouble::New();
1656 coordsArr->useArray(coords,false,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3);
1657 //now use coordsArr as you need
1659 //coordsArr is no more useful here : release it
1660 coordsArr->decrRef();
1661 //! [CppSnippetDataArrayBuild1_1]
1662 //! [CppSnippetDataArrayBuild1_2]
1663 coordsArr=ParaMEDMEM::DataArrayDouble::New();
1664 tmp=new double[3*nbOfNodes];
1665 std::copy(coords,coords+3*nbOfNodes,tmp);
1666 coordsArr->useArray(tmp,true,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3);
1667 //now use coordsArr as you need
1669 //coordsArr is no more useful, release it
1670 coordsArr->decrRef();
1671 //! [CppSnippetDataArrayBuild1_2]
1672 //! [CppSnippetDataArrayBuild1_3]
1673 coordsArr=ParaMEDMEM::DataArrayDouble::New();
1674 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
1675 std::copy(coords,coords+3*nbOfNodes,tmp);
1676 coordsArr->useArray(tmp,true,ParaMEDMEM::C_DEALLOC,nbOfNodes,3);
1677 //now use coordsArr as you need
1679 //coordsArr is no more useful here : release it
1680 coordsArr->decrRef();
1681 //! [CppSnippetDataArrayBuild1_3]
1682 //! [CppSnippetDataArrayBuild1_4]
1683 coordsArr=ParaMEDMEM::DataArrayDouble::New();
1684 coordsArr->alloc(nbOfNodes,3);
1685 tmp=coordsArr->getPointer();
1686 std::copy(coords,coords+3*nbOfNodes,tmp);
1687 coordsArr->declareAsNew();//you have modified data pointed by internal pointer notify object
1688 //now use coordsArr as you need
1690 //coordsArr is no more useful here : release it
1691 coordsArr->decrRef();
1692 //! [CppSnippetDataArrayBuild1_4]
1693 coordsArr=ParaMEDMEM::DataArrayDouble::New();
1694 coordsArr->alloc(nbOfNodes,3);
1695 tmp=coordsArr->getPointer();
1696 std::copy(coords,coords+3*nbOfNodes,tmp);
1697 ParaMEDMEM::DataArrayDouble *coordsArrCpy=0;
1698 //! [CppSnippetDataArrayBuild1_5]
1699 coordsArrCpy=coordsArr->deepCpy();
1700 //! [CppSnippetDataArrayBuild1_5]
1701 //! [CppSnippetDataArrayBuild1_6]
1702 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
1703 coordsArrCpy->setIJ(0,0,1000.);
1704 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
1705 //! [CppSnippetDataArrayBuild1_6]
1706 //! [CppSnippetDataArrayBuild1_7]
1707 coordsArrCpy->decrRef();
1708 //! [CppSnippetDataArrayBuild1_7]
1709 //! [CppSnippetDataArrayBuild1_5bis]
1710 coordsArrCpy=coordsArr->performCpy(true);
1711 //! [CppSnippetDataArrayBuild1_5bis]
1712 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
1713 coordsArrCpy->setIJ(0,0,1000.);
1714 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
1715 coordsArrCpy->decrRef();
1716 //! [CppSnippetDataArrayBuild1_8]
1717 coordsArrCpy=coordsArr->performCpy(false);
1718 //! [CppSnippetDataArrayBuild1_8]
1719 //! [CppSnippetDataArrayBuild1_9]
1720 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
1721 coordsArrCpy->setIJ(0,0,1000.);
1722 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArr and coordsArrCpy have been modified simultaneously
1723 //! [CppSnippetDataArrayBuild1_9]
1724 //! [CppSnippetDataArrayBuild1_10]
1725 coordsArrCpy->decrRef();
1726 //! [CppSnippetDataArrayBuild1_10]
1727 //! [CppSnippetDataArrayBuild1_11]
1728 coordsArrCpy=ParaMEDMEM::DataArrayDouble::New();
1729 //! [CppSnippetDataArrayBuild1_11]
1730 //! [CppSnippetDataArrayBuild1_12]
1731 coordsArrCpy->cpyFrom(*coordsArr);
1732 //! [CppSnippetDataArrayBuild1_12]
1733 //! [CppSnippetDataArrayBuild1_13]
1734 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
1735 coordsArrCpy->setIJ(0,0,2000.);
1736 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
1737 //! [CppSnippetDataArrayBuild1_13]
1738 //! [CppSnippetDataArrayBuild1_14]
1739 coordsArrCpy->decrRef();
1740 //! [CppSnippetDataArrayBuild1_14]
1741 coordsArr->decrRef();
1742 //! [CppSnippetDataArrayBuild1_14]
1745 void CppSnippetFieldDoubleBuild1()
1747 double XCoords[9]={-0.3,0.07,0.1,0.3,0.45,0.47,0.49,1.,1.22};
1748 double YCoords[7]={0.07,0.1,0.37,0.45,0.47,0.49,1.007};
1749 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
1750 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
1751 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
1752 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
1753 //! [CppSnippetFieldDoubleBuild1_1]
1754 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::NO_TIME);
1755 fieldOnCells->setName("MyTensorFieldOnCellNoTime");
1756 fieldOnCells->setMesh(mesh);
1757 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnCells
1758 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
1759 array->alloc(fieldOnCells->getMesh()->getNumberOfCells(),9);//Implicitely fieldOnCells will be a 9 components field.
1760 array->fillWithValue(7.);
1761 fieldOnCells->setArray(array);
1763 // fieldOnCells is now usable
1765 // fieldOnCells is no more useful here : release it
1766 fieldOnCells->decrRef();
1767 //! [CppSnippetFieldDoubleBuild1_1]
1768 arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
1769 arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
1770 mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
1771 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
1772 //! [CppSnippetFieldDoubleBuild1_2]
1773 ParaMEDMEM::MEDCouplingFieldDouble *f1=mesh->fillFromAnalytic(ParaMEDMEM::ON_CELLS,1,"x*x+y*y*3+2.*x");//f1 is scalar
1774 ParaMEDMEM::MEDCouplingFieldDouble *f2=mesh->fillFromAnalytic(ParaMEDMEM::ON_CELLS,1,"cos(x+y/x)");//f2 is scalar too
1775 ParaMEDMEM::MEDCouplingFieldDouble *f2bis=mesh->fillFromAnalytic(ParaMEDMEM::ON_CELLS,2,"x*x*IVec+3*y*JVec");//f2bis is a vectors field
1776 ParaMEDMEM::MEDCouplingFieldDouble *f3=(*f1)+(*f2);//f3 scalar
1777 ParaMEDMEM::MEDCouplingFieldDouble *f4=(*f3)/(*f2);//f4 scalar
1778 f2bis->applyFunc(1,"sqrt(x*x+y*y)");//f2bis becomes scalar
1779 ParaMEDMEM::MEDCouplingFieldDouble *f5=(*f2bis)*(*f4);//f5 scalar
1780 const double pos1[2]={0.48,0.38};
1782 f4->getValueOn(pos1,&res);//f4 is scalar so the returned value is of size 1.
1784 //! [CppSnippetFieldDoubleBuild1_2]
1786 //! [CppSnippetFieldDoubleBuild1_3]
1787 // f1, f2, f2bis, f3, f4, f5 are no more useful here : release them
1794 //! [CppSnippetFieldDoubleBuild1_3]
1797 void CppSnippetFieldDoubleBuild2()
1799 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
1800 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
1801 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
1802 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
1803 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
1804 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
1805 //! [CppSnippetFieldDoubleBuild2_1]
1806 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnNodes=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::NO_TIME);
1807 fieldOnNodes->setName("MyScalarFieldOnNodeNoTime");
1808 fieldOnNodes->setMesh(mesh);
1809 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnNodes
1810 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
1811 array->alloc(fieldOnNodes->getMesh()->getNumberOfNodes(),1);//Implicitely fieldOnNodes will be a 1 component field.
1812 array->fillWithValue(8.);
1813 fieldOnNodes->setArray(array);
1815 // fieldOnNodes is now usable
1817 // fieldOnNodes is no more useful here : release it
1818 fieldOnNodes->decrRef();
1819 //! [CppSnippetFieldDoubleBuild2_1]
1822 void CppSnippetFieldDoubleBuild3()
1824 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
1825 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
1826 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
1827 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
1828 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
1829 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
1830 //! [CppSnippetFieldDoubleBuild3_1]
1831 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
1832 fieldOnCells->setName("MyTensorFieldOnCellNoTime");
1833 fieldOnCells->setTimeUnit("ms"); // Time unit is ms.
1834 fieldOnCells->setTime(4.22,2,-1); // Time attached is 4.22 ms, iteration id is 2 and order id (or sub iteration id) is -1
1835 fieldOnCells->setMesh(mesh);
1836 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnCells
1837 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
1838 array->alloc(fieldOnCells->getMesh()->getNumberOfCells(),2);//Implicitely fieldOnCells will be a 2 components field.
1839 array->fillWithValue(7.);
1840 fieldOnCells->setArray(array);
1842 // fieldOnCells is now usable
1844 // fieldOnCells is no more useful here : release it
1845 fieldOnCells->decrRef();
1846 //! [CppSnippetFieldDoubleBuild3_1]
1849 void CppSnippetFieldDoubleBuild4()
1851 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
1852 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
1853 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
1854 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
1855 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
1856 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
1857 //! [CppSnippetFieldDoubleBuild4_1]
1858 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnNodes=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::CONST_ON_TIME_INTERVAL);
1859 fieldOnNodes->setName("MyVecFieldOnNodeWithConstTime");
1860 fieldOnNodes->setTimeUnit("ms"); // Time unit is ms.
1861 fieldOnNodes->setStartTime(4.22,2,-1);
1862 fieldOnNodes->setEndTime(6.44,4,-1); // fieldOnNodes is defined in interval [4.22 ms,6.44 ms]
1863 fieldOnNodes->setMesh(mesh);
1864 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnNodes
1865 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
1866 array->alloc(fieldOnNodes->getMesh()->getNumberOfNodes(),3);//Implicitely fieldOnNodes will be a 3 components field.
1867 array->fillWithValue(8.);
1868 fieldOnNodes->setArray(array);
1870 // fieldOnNodes is now usable
1872 // fieldOnNodes is no more useful here : release it
1873 fieldOnNodes->decrRef();
1874 //! [CppSnippetFieldDoubleBuild4_1]
1877 int main(int argc, char *argv[])
1879 CppExample_MEDCouplingPointSet_getCoordsAt();
1880 CppExample_MEDCouplingUMesh_areCellsIncludedIn();
1881 CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells();
1882 CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented();
1883 CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented();
1884 CppExample_MEDCouplingUMesh_getCellsContainingPoints();
1885 CppExample_MEDCouplingUMesh_getCellsContainingPoint();
1886 CppExample_MEDCouplingUMesh_buildPartOrthogonalField();
1887 CppExample_MEDCouplingUMesh_getPartMeasureField();
1888 CppExample_MEDCouplingUMesh_getCellsInBoundingBox();
1889 CppExample_MEDCouplingUMesh_renumberNodesInConn();
1890 CppExample_MEDCouplingUMesh_renumberNodes();
1891 CppExample_MEDCouplingUMesh_findBoundaryNodes();
1892 CppExample_MEDCouplingUMesh_buildBoundaryMesh();
1893 CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode();
1894 CppExample_MEDCouplingUMesh_buildPartOfMySelfNode();
1895 CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes();
1896 CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds();
1897 CppExample_MEDCouplingUMesh_buildPartOfMySelf();
1898 CppExample_MEDCouplingUMesh_mergeNodes();
1899 CppExample_MEDCouplingUMesh_zipConnectivityTraducer();
1900 CppExample_MEDCouplingUMesh_zipCoordsTraducer();
1901 CppExample_MEDCouplingUMesh_getNodeIdsInUse();
1902 CppExample_MEDCouplingUMesh_convertToPolyTypes();
1903 CppExample_MEDCouplingUMesh_buildDescendingConnectivity2();
1904 CppExample_MEDCouplingUMesh_buildDescendingConnectivity();
1905 CppExample_MEDCouplingUMesh_getReverseNodalConnectivity();
1906 CppExample_MEDCouplingUMesh_checkDeepEquivalWith();
1907 CppExample_MEDCouplingPointSet_scale();
1908 CppExample_MEDCouplingPointSet_translate();
1909 CppExample_MEDCouplingPointSet_rotate();
1910 CppExample_MEDCouplingPointSet_getBoundingBox();
1911 CppExample_MEDCouplingPointSet_getNodeIdsNearPoint();
1912 CppExample_MEDCouplingPointSet_getNodeIdsNearPoints();
1913 CppExample_MEDCouplingPointSet_findCommonNodes();
1914 CppExample_MEDCouplingPointSet_getCoordinatesOfNode();
1915 CppExample_DataArrayInt_buildPermutationArr();
1916 CppExample_DataArrayInt_invertArrayO2N2N2O();
1917 CppExample_DataArrayInt_invertArrayN2O2O2N();
1918 CppExample_DataArrayDouble_getIdsInRange();
1919 CppExample_DataArrayDouble_findCommonTuples();
1920 CppExample_DataArrayDouble_Meld1();
1921 CppExampleFieldDoubleBuildSubPart1();
1922 CppSnippetUMeshStdBuild1();
1923 CppSnippetUMeshAdvBuild1();
1924 CppSnippetDataArrayBuild1();
1925 CppSnippetCMeshStdBuild1();
1926 CppSnippetFieldDoubleBuild1();
1927 CppSnippetFieldDoubleBuild2();
1928 CppSnippetFieldDoubleBuild3();
1929 CppSnippetFieldDoubleBuild4();