1 // Copyright (C) 2007-2023 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, or (at your option) any later version.
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 (EDF R&D)
21 #include "MEDCouplingBasicsTest.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingMappedExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingMemArray.txx"
28 #include "MEDCouplingMultiFields.hxx"
31 void CppExample_MEDCouplingFieldDouble_WriteVTK()
33 using namespace MEDCoupling;
34 //! [CppSnippet_MEDCouplingFieldDouble_WriteVTK_1]
36 const double coords[3] = {0.,2.,4.};
37 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
38 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
39 MCAuto<MEDCouplingCMesh> mesh1 = MEDCouplingCMesh::New();
40 mesh1->setCoords(coordsArr,coordsArr); // mesh becomes a 2D one
42 // 3 fields (lying on the same mesh!)
43 MCAuto<MEDCouplingFieldDouble> field1 =
44 mesh1->getMeasureField( true );
45 MCAuto<MEDCouplingFieldDouble> field2 =
46 mesh1->buildOrthogonalField();
47 MCAuto<MEDCouplingFieldDouble> field3 =
48 mesh1->fillFromAnalytic( ON_CELLS, 1, "x");
49 field2->setName( "Normal" ); // name is necessary!
50 field3->setName( "Barycenter" ); // name is necessary!
53 const char fileName[] = "testExample_MEDCouplingFieldDouble_WriteVTK.vtk";
54 std::vector<const MEDCouplingFieldDouble *> fs( 3 ); // field series
58 MEDCouplingFieldDouble::WriteVTK( fileName, fs );
59 //! [CppSnippet_MEDCouplingFieldDouble_WriteVTK_1]
63 void CppExample_MEDCouplingFieldDouble_MaxFields()
65 using namespace MEDCoupling;
66 //! [CppSnippet_MEDCouplingFieldDouble_MaxFields_1]
67 const double vals1[4] = {0.,2., 4.,6.}; // for field 1
68 const double vals2[4] = {2.,0., 6.,4.}; // for field 2
69 const double valsMax[4] = {2.,2., 6.,6.}; // expected max field
70 const double valsMin[4] = {0.,0., 4.,4.}; // expected min field
72 MCAuto<DataArrayDouble> valsArr1 = DataArrayDouble::New();
73 valsArr1->useExternalArrayWithRWAccess( vals1, 2,2 ); // 2 tuples per 2 components
74 MCAuto<MEDCouplingFieldDouble> field1 = MEDCouplingFieldDouble::New( ON_NODES );
75 field1->setArray( valsArr1 );
77 MCAuto<DataArrayDouble> valsArr2 = DataArrayDouble::New();
78 valsArr2->useExternalArrayWithRWAccess( vals2, 2,2 ); // 2 tuples per 2 components
79 MCAuto<MEDCouplingFieldDouble> field2 = MEDCouplingFieldDouble::New( ON_NODES );
80 field2->setArray( valsArr2 );
82 MCAuto<MEDCouplingFieldDouble> fieldMax = MEDCouplingFieldDouble::MaxFields( field1, field2 );
83 CPPUNIT_ASSERT( std::equal( valsMax, valsMax+4, fieldMax->getArray()->getConstPointer() )); // fieldMax == valsMax
85 MCAuto<MEDCouplingFieldDouble> fieldMin = MEDCouplingFieldDouble::MinFields( field1, field2 );
86 CPPUNIT_ASSERT( std::equal( valsMin, valsMin+4, fieldMin->getArray()->getConstPointer() )); // fieldMin == valsMin
87 //! [CppSnippet_MEDCouplingFieldDouble_MaxFields_1]
90 void CppExample_MEDCouplingFieldDouble_MergeFields()
92 using namespace MEDCoupling;
93 //! [CppSnippet_MEDCouplingFieldDouble_MergeFields_1]
95 const double coords[3] = {0.,2.,4.};
96 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
97 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
98 MCAuto<MEDCouplingCMesh> mesh1 = MEDCouplingCMesh::New();
99 mesh1->setCoords(coordsArr); // mesh becomes a 1D
101 MCAuto<MEDCouplingFieldDouble> field1 =
102 mesh1->fillFromAnalytic( ON_CELLS, 1, "x");
105 MCAuto<MEDCouplingFieldDouble> field2 =
106 field1->cloneWithMesh( true );
107 double vec[1] = { 5. };
108 (const_cast<MEDCoupling::MEDCouplingMesh *>(field2->getMesh()))->translate(vec); // translate mesh2
109 field2->applyFunc("x + 5"); // "translate" field2
111 // concatenate field1 and field2
112 MCAuto<MEDCouplingFieldDouble> field3 =
113 MEDCouplingFieldDouble::MergeFields( field1, field2 );
114 std::vector<const MEDCouplingFieldDouble *> fields( 2 );
117 MCAuto<MEDCouplingFieldDouble> field4 =
118 MEDCouplingFieldDouble::MergeFields( fields );
119 //! [CppSnippet_MEDCouplingFieldDouble_MergeFields_1]
122 void CppExample_MEDCouplingFieldDouble_substractInPlaceDM()
124 using namespace MEDCoupling;
125 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_1]
126 const double coords1[4] = {0.,1.,2.,3.};
127 const double coords2[4] = {2.,1.,0.,3.}; // #0 <==> #2
129 MCAuto<MEDCouplingUMesh> mesh1 = MEDCouplingUMesh::New();
130 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
131 coordsArr->useExternalArrayWithRWAccess( coords1, 4, 1 );
132 mesh1->setCoords(coordsArr);
133 mesh1->setMeshDimension(0);
134 mesh1->allocateCells(0);
135 mesh1->finishInsertingCells();
137 MCAuto<MEDCouplingUMesh> mesh2 =
138 (MEDCouplingUMesh*) mesh1->deepCopy();
139 mesh2->getCoords()->useExternalArrayWithRWAccess( coords2, 4, 1 );
140 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_1]
141 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_2]
142 MCAuto<MEDCouplingFieldDouble> field1 =
143 mesh1->fillFromAnalytic( MEDCoupling::ON_NODES,1,"x"); // field1 values == coords1
144 MCAuto<MEDCouplingFieldDouble> field2 =
145 mesh2->fillFromAnalytic( MEDCoupling::ON_NODES,1,"x"); // field2 values == coords2
146 const int levOfCheck = 10; // nodes can be permuted
147 field1->substractInPlaceDM( field2, levOfCheck, 1e-13, 0 ); // values #0 and #2 must swap
148 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_2]
149 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_3]
150 field2->applyFunc( 1, 0.0 ); // all field2 values == 0.0
151 CPPUNIT_ASSERT( field1->isEqual( field2, 1e-13, 1e-13 )); // field1 == field2 == 0.0
152 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_3]
155 void CppExample_MEDCouplingFieldDouble_changeUnderlyingMesh()
157 using namespace MEDCoupling;
158 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_1]
159 const double coords1[4] = {0.,1.,2.,3.};
160 const double coords2[4] = {2.,1.,0.,3.}; // #0 <==> #2
162 MCAuto<MEDCouplingUMesh> mesh1 = MEDCouplingUMesh::New();
163 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
164 coordsArr->useExternalArrayWithRWAccess( coords1, 4, 1 );
165 mesh1->setCoords(coordsArr);
166 mesh1->setMeshDimension(0);
167 mesh1->allocateCells(0);
168 mesh1->finishInsertingCells();
170 MCAuto<MEDCouplingUMesh> mesh2 =
171 (MEDCouplingUMesh*) mesh1->deepCopy();
172 mesh2->getCoords()->useExternalArrayWithRWAccess( coords2, 4, 1 );
173 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_1]
174 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_2]
175 MCAuto<MEDCouplingFieldDouble> field =
176 mesh1->fillFromAnalytic( MEDCoupling::ON_NODES,1,"x"); // field values == coords1
177 const int levOfCheck = 10; // nodes can be permuted
178 field->changeUnderlyingMesh( mesh2, levOfCheck, 1e-13, 0 ); // values #0 and #2 must swap
179 CPPUNIT_ASSERT( std::equal( coords2, coords2+4, field->getArray()->getConstPointer() ));
180 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_2]
183 void CppExample_MEDCouplingFieldDouble_applyFunc_same_nb_comp()
185 using namespace MEDCoupling;
186 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_1]
187 const double v[4] = {1.,2., 3.,4.};
188 MCAuto<DataArrayDouble> array = DataArrayDouble::New();
189 array->useExternalArrayWithRWAccess( v, 2, 2 ); // 2 tuples per 2 components
190 MCAuto<MEDCouplingFieldDouble> field =
191 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
192 field->setArray( array );
193 const char func[] = "IVec * v + JVec * w*w + 10";
194 field->applyFunc( 2, func );
195 CPPUNIT_ASSERT( field->getNumberOfComponents() == 2 ); // 2 components remains
196 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_1]
197 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_2]
198 const double* v2 = field->getArray()->getConstPointer();
199 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[0], 10 + v[0], 13 ); // "10 + IVec * v"
200 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[1], 10 + v[1]*v[1], 13 ); // "10 + JVec * v*v"
201 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[2], 10 + v[2], 13 ); // "10 + IVec * v"
202 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[3], 10 + v[3]*v[3], 13 ); // "10 + JVec * v*v"
203 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_2]
206 void CppExample_MEDCouplingFieldDouble_applyFunc3()
208 using namespace MEDCoupling;
209 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_1]
210 // create a 2D vector field
211 const double values[4] = {1.,1., 2.,1.};
212 MCAuto<DataArrayDouble> array = DataArrayDouble::New();
213 array->useExternalArrayWithRWAccess( values, 2, 2 ); // 2 tuples per 2 components
214 MCAuto<MEDCouplingFieldDouble> field =
215 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
216 field->setArray( array );
217 // transform the field to a 3D vector field
218 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
219 const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y components
220 std::vector<std::string> varNamesVec( varNames, varNames+2 );
221 field->applyFuncNamedCompo( 3, varNamesVec, func ); // require 3 components
222 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components as required
223 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_1]
224 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_2]
225 double vec1[3]; // vector #1
226 field->getArray()->getTuple( 1, vec1 );
227 const double a = values[2], b = values[3]; // initial components of the vector #1
228 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[0], 10 + b, 13 ); // "10 + IVec * b"
229 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[1], 10 + a, 13 ); // "10 + JVec * a"
230 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[2], 10 + sqrt(a*a+b*b), 13 ); // "10 + KVec * sqrt( a*a + b*b )"
231 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_2]
234 void CppExample_MEDCouplingFieldDouble_applyFunc2()
236 using namespace MEDCoupling;
237 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_1]
238 // create a 2D vector field
239 const double values[4] = {1.,1., 2.,1.};
240 MCAuto<DataArrayDouble> array = DataArrayDouble::New();
241 array->useExternalArrayWithRWAccess( values, 2, 2 ); // 2 tuples per 2 components
242 array->setInfoOnComponent(0,"a"); // name used to refer to X component within a function
243 array->setInfoOnComponent(1,"b"); // name used to refer to Y component within a function
244 MCAuto<MEDCouplingFieldDouble> field =
245 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
246 field->setArray( array );
247 // transform the field to a 3D vector field
248 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
249 field->applyFuncCompo( 3, func ); // require 3 components
250 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components as required
251 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_1]
252 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_2]
253 double vec1[3]; // vector #1
254 field->getArray()->getTuple( 1, vec1 );
255 const double a = values[2], b = values[3]; // initial components of the vector #1
256 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[0], 10 + b, 13 ); // "10 + IVec * b"
257 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[1], 10 + a, 13 ); // "10 + JVec * a"
258 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[2], 10 + sqrt(a*a+b*b), 13 ); // "10 + KVec * sqrt( a*a + b*b )"
259 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_2]
262 void CppExample_MEDCouplingFieldDouble_applyFunc()
264 using namespace MEDCoupling;
265 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_1]
266 // create a 2D vector field
267 const double values[4] = {1.,1., 2.,1.};
268 MCAuto<DataArrayDouble> array = DataArrayDouble::New();
269 array->useExternalArrayWithRWAccess( values, 2, 2 ); // 2 tuples per 2 components
270 MCAuto<MEDCouplingFieldDouble> field =
271 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
272 field->setArray( array );
273 // transform the field to a 3D vector field
274 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
275 field->applyFunc( 3, func ); // require 3 components
276 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components as required
277 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_1]
278 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_2]
279 double vec1[3]; // vector #1
280 field->getArray()->getTuple( 1, vec1 );
281 const double a = values[2], b = values[3]; // initial components of the vector #1
282 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[0], 10 + b, 13 ); // "10 + IVec * b"
283 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[1], 10 + a, 13 ); // "10 + JVec * a"
284 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[2], 10 + sqrt(a*a+b*b), 13 ); // "10 + KVec * sqrt( a*a + b*b )"
285 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_2]
288 void CppExample_MEDCouplingFieldDouble_applyFunc_val()
290 using namespace MEDCoupling;
291 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_1]
293 const double coords[4] = {0.,2.,4.};
294 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
295 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
296 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
297 mesh->setCoords(coordsArr,coordsArr); // mesh becomes a 2D structured mesh
299 MCAuto<MEDCouplingFieldDouble> field =
300 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
301 field->setMesh( mesh );
302 field->fillFromAnalytic(2,"IVec * x + JVec * y"); // 2 components
303 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_1]
304 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_2]
305 const double newValue = 7.;
306 field->applyFunc( 3, newValue ); // # 3 components are required
307 CPPUNIT_ASSERT( field->getIJ(1,0) == newValue ); // a value is as expected
308 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 );
309 CPPUNIT_ASSERT( field->getNumberOfTuples() == mesh->getNumberOfCells() );
310 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_2]
313 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic3()
315 using namespace MEDCoupling;
316 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_1]
317 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
318 MCAuto<DataArrayDouble> x = DataArrayDouble::New();
319 x->useExternalArrayWithRWAccess( coords, 3, 1 );
320 MCAuto<DataArrayDouble> y = DataArrayDouble::New();
321 y->useExternalArrayWithRWAccess( coords, 2, 1 );
322 MCAuto<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
323 mesh->setCoords(x,y);
324 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_1]
325 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_2]
326 MCAuto<MEDCouplingFieldDouble> field =
327 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
328 field->setMesh( mesh );
329 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
330 const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y coord components
331 std::vector<std::string> varNamesVec( varNames, varNames+2 );
332 field->fillFromAnalyticNamedCompo( 3, varNamesVec, func );
333 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_2]
334 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_3]
335 double val1[3]; // a value (vector) of the cell #1
336 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
337 field->getArray()->getTuple( 1, val1 );
339 MCAuto<DataArrayDouble> bc =
340 mesh->computeCellCenterOfMass(); // func is applied to barycenters of cells
341 double bc1[2]; // coordinates of the second point
342 bc->getTuple( 1, bc1 );
344 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
345 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
346 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
347 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
348 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_3]
351 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic2()
353 using namespace MEDCoupling;
354 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_1]
355 const double coords[4] = {0.,2.,4.};
356 MCAuto<DataArrayDouble> x = DataArrayDouble::New();
357 x->useExternalArrayWithRWAccess( coords, 3, 1 );
358 MCAuto<DataArrayDouble> y = DataArrayDouble::New();
359 y->useExternalArrayWithRWAccess( coords, 2, 1 );
360 x->setInfoOnComponent(0,"a"); // name used to refer to X coordinate within a function
361 y->setInfoOnComponent(0,"b"); // name used to refer to Y coordinate within a function
362 MCAuto<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
363 mesh->setCoords(x,y);
364 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_1]
365 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_2]
366 MCAuto<MEDCouplingFieldDouble> field =
367 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
368 field->setMesh( mesh );
369 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
370 field->fillFromAnalytic( 3, func );
371 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_2]
372 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_3]
373 double val1[3]; // a value (vector) of the cell #1
374 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
375 field->getArray()->getTuple( 1, val1 );
377 MCAuto<DataArrayDouble> bc =
378 mesh->computeCellCenterOfMass(); // func is applied to barycenters of cells
379 double bc1[2]; // coordinates of the second point
380 bc->getTuple( 1, bc1 );
382 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
383 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
384 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
385 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
386 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_3]
389 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic()
391 using namespace MEDCoupling;
392 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_1]
393 const double coords[3] = {0.,2.,4};
394 MCAuto<DataArrayDouble> x = DataArrayDouble::New();
395 x->useExternalArrayWithRWAccess( coords, 3, 1 );
396 MCAuto<DataArrayDouble> y = DataArrayDouble::New();
397 y->useExternalArrayWithRWAccess( coords, 2, 1 );
398 MCAuto<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
399 mesh->setCoords(x,y);
400 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_1]
401 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_2]
402 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
403 MCAuto<MEDCouplingFieldDouble> field =
404 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
405 field->setMesh( mesh );
406 field->fillFromAnalytic( 3, func );
407 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_2]
408 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_3]
409 double val1[3]; // a value (vector) of the cell #1
410 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
411 field->getArray()->getTuple( 1, val1 );
413 MCAuto<DataArrayDouble> bc =
414 mesh->computeCellCenterOfMass(); // func is applied to barycenters of cells
415 double bc1[2]; // coordinates of the second point
416 bc->getTuple( 1, bc1 );
418 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
419 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
420 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
421 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
422 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_3]
425 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_0]
426 bool getNewValue(const double *pos, double *res)
430 res[2] = sqrt( pos[0]*pos[0] + pos[1]*pos[1] );
433 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_0]
435 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic_c_func()
437 using namespace MEDCoupling;
438 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_1]
440 const double coords[4] = {0.,2.,4.};
441 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
442 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
443 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
444 mesh->setCoords(coordsArr,coordsArr); // mesh becomes a 2D structured mesh
446 MCAuto<MEDCouplingFieldDouble> field =
447 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
448 field->setMesh( mesh );
449 field->fillFromAnalytic( 3, &getNewValue ); // 3 components are required
450 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 );
451 CPPUNIT_ASSERT( field->getNumberOfTuples() == mesh->getNumberOfCells() );
452 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_1]
455 void CppExample_MEDCouplingFieldDouble_applyFunc_c_func()
457 using namespace MEDCoupling;
458 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_1]
460 const double coords[4] = {0.,2.,4.};
461 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
462 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
463 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
464 mesh->setCoords(coordsArr,coordsArr); // mesh becomes a 2D structured mesh
466 MCAuto<MEDCouplingFieldDouble> field =
467 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS );
468 field->setMesh( mesh );
469 MCAuto<DataArrayDouble> bc = mesh->computeCellCenterOfMass();
470 field->setArray( bc ); // 2 components here as the mesh is 2D
471 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_1]
472 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_2]
473 field->applyFunc( 3, &getNewValue ); // 3 components are required
474 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 );
475 CPPUNIT_ASSERT( field->getNumberOfTuples() == mesh->getNumberOfCells() );
476 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_2]
479 void CppExample_MEDCouplingFieldDouble_getValueOn_time()
481 using namespace MEDCoupling;
482 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_1]
483 const double coords[4] = {0.,2.,4.};
484 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
485 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
486 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
487 mesh->setCoords(coordsArr,coordsArr);
488 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_1]
489 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_2]
490 MCAuto<MEDCouplingFieldDouble> field =
491 MEDCouplingFieldDouble::New( MEDCoupling::ON_CELLS, MEDCoupling::LINEAR_TIME );
492 field->setMesh( mesh );
493 field->fillFromAnalytic( 1,"10"); // all values == 10.
494 MCAuto<DataArrayDouble> array2 =
495 DataArrayDouble::Add( field->getArray(), field->getArray() ); // == 2 * field->getArray()
496 field->setEndArray( array2 ); // all values == 20.
497 const double time1 = 1.1, time2 = 22.;
498 field->setStartTime( time1, 0, 0 );
499 field->setEndTime ( time2, 0, 0 );
500 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_2]
501 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_3]
502 const double pos[2] = { 1., 1. }; // we are in 2D space
503 double value[1]; // the field is scalar <-> 1 component
504 field->getValueOn( pos, 0.5*( time1 + time2 ), value );
505 CPPUNIT_ASSERT( fabs( value[0] - 0.5*( 10. + 20. )) < 1e-13 );
506 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_3]
509 void CppExample_MEDCouplingFieldDouble_getValueOnMulti()
511 using namespace MEDCoupling;
512 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_1]
513 const double coords[4] = {0.,2.,4.};
514 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
515 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
516 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
517 mesh->setCoords(coordsArr,coordsArr);
518 MCAuto<MEDCouplingFieldDouble> field =
519 mesh->fillFromAnalytic( MEDCoupling::ON_CELLS,1,"x+y");
520 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_1]
521 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_2]
522 // field values are located at cell barycenters
523 MCAuto<DataArrayDouble> bc = mesh->computeCellCenterOfMass();
524 MCAuto<DataArrayDouble> valArray =
525 field->getValueOnMulti( bc->getConstPointer(), bc->getNumberOfTuples() );
526 CPPUNIT_ASSERT( valArray->isEqual( * field->getArray(), 1e-13 ));
527 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_2]
530 void CppExample_MEDCouplingFieldDouble_getValueOn()
532 using namespace MEDCoupling;
533 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_1]
534 const double coords[4] = {0.,2.,4.};
535 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
536 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
537 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
538 mesh->setCoords(coordsArr,coordsArr);
539 MCAuto<MEDCouplingFieldDouble> field =
540 mesh->fillFromAnalytic( MEDCoupling::ON_CELLS,1,"x+y");
541 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_1]
542 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_2]
543 // field values are located at cell barycenters
544 MCAuto<DataArrayDouble> bc = mesh->computeCellCenterOfMass();
545 std::vector<double> vals( field->getNumberOfTuples() ); // array to collect values returned by getValueOn()
546 double cellBC[2]; // we are in 2D space
547 for ( int i = 0; i < bc->getNumberOfTuples(); ++i )
549 bc->getTuple( i, cellBC );
550 field->getValueOn( cellBC, & vals[i] );
552 CPPUNIT_ASSERT( std::equal( vals.begin(), vals.end(), field->getArray()->getConstPointer() ));
553 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_2]
556 void CppExample_MEDCouplingFieldDouble_getValueOnPos()
558 using namespace MEDCoupling;
559 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_1]
560 const double coords[4] = {0.,2.,4.};
561 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
562 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
563 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
564 mesh->setCoords(coordsArr,coordsArr);
565 MCAuto<MEDCouplingFieldDouble> field =
566 mesh->fillFromAnalytic( MEDCoupling::ON_CELLS,1,"x+y");
567 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_1]
568 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_2]
569 double val11[1]; // 1 == field->getNumberOfComponents()
570 field->getValueOnPos( 1,1,-1, val11 );
571 // field values are located at cell barycenters
572 MCAuto<DataArrayDouble> bc = mesh->computeCellCenterOfMass();
573 CPPUNIT_ASSERT( val11[0] == bc->getIJ(3,0) + bc->getIJ(3,1) );
574 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_2]
577 void CppExample_MEDCouplingFieldDouble_renumberNodes()
579 using namespace MEDCoupling;
580 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_1]
581 const double coords[4] = {0.,2.,4.};
582 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
583 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
584 MCAuto<MEDCouplingCMesh> cmesh = MEDCouplingCMesh::New();
585 cmesh->setCoords(coordsArr,coordsArr);
586 MCAuto<MEDCouplingUMesh> mesh = cmesh->buildUnstructured();
587 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_1]
588 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_2]
589 MCAuto<MEDCouplingFieldDouble> field =
590 mesh->fillFromAnalytic( MEDCoupling::ON_NODES,2,"IVec*x+JVec*y");
591 const DataArrayDouble* values = field->getArray();
592 const DataArrayDouble* nodeCoords = mesh->getCoords();
593 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *nodeCoords, 1e-13 ));
594 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_2]
595 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_3]
596 const mcIdType renumber[9] = { 8, 7, 6, 5, 4, 3, 2, 1, 0 };
597 field->renumberNodes(renumber,false);
598 const MEDCouplingMesh* mesh2 = field->getMesh(); // field now refers to another mesh
599 values = field->getArray();
600 nodeCoords = (static_cast<const MEDCouplingUMesh*>(mesh2))->getCoords();
601 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *nodeCoords, 1e-13 ));
602 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_3]
605 void CppExample_MEDCouplingFieldDouble_renumberCells()
607 using namespace MEDCoupling;
608 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_1]
609 const double coords[4] = {0.,2.,4.};
610 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
611 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
612 MCAuto<MEDCouplingCMesh> cmesh = MEDCouplingCMesh::New();
613 cmesh->setCoords(coordsArr,coordsArr);
614 MCAuto<MEDCouplingUMesh> mesh = cmesh->buildUnstructured();
615 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_1]
616 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_2]
617 MCAuto<MEDCouplingFieldDouble> field =
618 mesh->fillFromAnalytic( MEDCoupling::ON_CELLS,2,"IVec*x+JVec*y");
619 const DataArrayDouble* values = field->getArray();
620 MCAuto<DataArrayDouble> bc = mesh->computeCellCenterOfMass();
621 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *bc, 1e-13 ));
622 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_2]
623 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_3]
624 const mcIdType renumber[4] = { 3, 2, 1, 0 };
625 field->renumberCells(renumber,false);
626 const MEDCouplingMesh* mesh2 = field->getMesh(); // field now refers to another mesh
627 values = field->getArray();
628 bc = mesh2->computeCellCenterOfMass();
629 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *bc, 1e-13 ));
630 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_3]
633 void CppExample_MEDCouplingFieldDouble_buildNewTimeReprFromThis()
635 using namespace MEDCoupling;
636 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_1]
637 const double coords[4] = {0.,2.,4.};
638 MCAuto<DataArrayDouble> coordsArr = DataArrayDouble::New();
639 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
640 MCAuto<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
641 mesh->setCoords(coordsArr,coordsArr);
642 MCAuto<MEDCouplingFieldDouble> field1 =
643 mesh->fillFromAnalytic( MEDCoupling::ON_NODES,1,"x+y");
644 CPPUNIT_ASSERT( field1->getTimeDiscretization() == MEDCoupling::ONE_TIME );
645 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_1]
646 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_2]
647 MCAuto<MEDCouplingFieldDouble> field2 =
648 field1->buildNewTimeReprFromThis( MEDCoupling::NO_TIME, false );
649 CPPUNIT_ASSERT( field2->getTimeDiscretization() == MEDCoupling::NO_TIME );
650 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_2]
653 void CppExample_MEDCouplingMesh_fillFromAnalytic3()
655 using namespace MEDCoupling;
656 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1]
657 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
658 MCAuto<DataArrayDouble> x = DataArrayDouble::New();
659 x->useExternalArrayWithRWAccess( coords, 3, 1 );
660 MCAuto<DataArrayDouble> y = DataArrayDouble::New();
661 y->useExternalArrayWithRWAccess( coords, 2, 1 );
662 MCAuto<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
663 mesh->setCoords(x,y);
664 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1]
665 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2]
666 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
667 const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y coord components
668 std::vector<std::string> varNamesVec( varNames, varNames+2 );
669 MCAuto<MEDCouplingFieldDouble> field =
670 mesh->fillFromAnalyticNamedCompo( MEDCoupling::ON_CELLS, 3, varNamesVec, func );
671 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2]
672 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3]
673 double val1[3]; // a value (vector) of the cell #1
674 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
675 field->getArray()->getTuple( 1, val1 );
677 MCAuto<DataArrayDouble> bc =
678 mesh->computeCellCenterOfMass(); // func is applied to barycenters of cells
679 double bc1[2]; // coordinates of the second point
680 bc->getTuple( 1, bc1 );
682 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
683 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
684 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
685 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
686 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3]
689 void CppExample_MEDCouplingMesh_fillFromAnalytic2()
691 using namespace MEDCoupling;
692 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1]
693 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
694 MCAuto<DataArrayDouble> x = DataArrayDouble::New();
695 x->useExternalArrayWithRWAccess( coords, 3, 1 );
696 MCAuto<DataArrayDouble> y = DataArrayDouble::New();
697 y->useExternalArrayWithRWAccess( coords, 2, 1 );
698 x->setInfoOnComponent(0,"a"); // name used to refer to X coordinate within a function
699 y->setInfoOnComponent(0,"b"); // name used to refer to Y coordinate within a function
700 MCAuto<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
701 mesh->setCoords(x,y);
702 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1]
703 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2]
704 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
705 MCAuto<MEDCouplingFieldDouble> field =
706 mesh->fillFromAnalyticCompo( MEDCoupling::ON_CELLS, 3, func );
707 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2]
708 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3]
709 double val1[3]; // a value (vector) of the cell #1
710 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
711 field->getArray()->getTuple( 1, val1 );
713 MCAuto<DataArrayDouble> bc =
714 mesh->computeCellCenterOfMass(); // func is applied to barycenters of cells
715 double bc1[2]; // coordinates of the second point
716 bc->getTuple( 1, bc1 );
718 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
719 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
720 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
721 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
722 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3]
725 void CppExample_MEDCouplingMesh_fillFromAnalytic()
727 using namespace MEDCoupling;
728 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1]
729 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
730 MCAuto<DataArrayDouble> x = DataArrayDouble::New();
731 x->useExternalArrayWithRWAccess( coords, 3, 1 );
732 MCAuto<DataArrayDouble> y = DataArrayDouble::New();
733 y->useExternalArrayWithRWAccess( coords, 2, 1 );
734 MCAuto<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
735 mesh->setCoords(x,y);
736 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1]
737 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2]
738 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
739 MCAuto<MEDCouplingFieldDouble> field =
740 mesh->fillFromAnalytic( MEDCoupling::ON_CELLS, 3, func );
741 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2]
742 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3]
743 double val1[3]; // a value (vector) of the cell #1
744 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
745 field->getArray()->getTuple( 1, val1 );
747 MCAuto<DataArrayDouble> bc =
748 mesh->computeCellCenterOfMass(); // func is applied to barycenters of cells
749 double bc1[2]; // coordinates of the second point
750 bc->getTuple( 1, bc1 );
752 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
753 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
754 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
755 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
756 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3]
759 void CppExample_MEDCouplingCMesh_getCoordsAt()
761 using namespace MEDCoupling;
762 //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1]
763 const double coords[3] = {1.,2.,4.};
764 MCAuto<DataArrayDouble> x = DataArrayDouble::New();
765 x->useExternalArrayWithRWAccess( coords, 3, 1 );
766 MCAuto<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
767 mesh->setCoordsAt(0,x);
768 const DataArrayDouble* x2=mesh->getCoordsAt(0);
769 CPPUNIT_ASSERT( x2->isEqual( *x, 1e-13 ));
770 //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1]
773 void CppExample_MEDCouplingUMesh_areCellsIncludedIn()
775 using namespace MEDCoupling;
776 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
777 MCAuto<MEDCouplingUMesh> mesh1=MEDCouplingUMesh::New();
778 mesh1->setMeshDimension(2);
779 mesh1->allocateCells(5);
780 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
781 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // #0
782 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // #1
783 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // #2
784 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // #3
785 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // #4
786 mesh1->finishInsertingCells();
787 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
788 coordsArr->alloc(9,2);
789 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 };
790 std::copy(coords,coords+18,coordsArr->getPointer());
791 mesh1->setCoords(coordsArr);
792 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
793 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
794 const mcIdType cells2[3] = { 4,2,0 }; // even cells selected
795 MCAuto<MEDCouplingUMesh> mesh2 =
796 (MEDCouplingUMesh*) mesh1->buildPartOfMySelf( cells2, cells2+3, true );
797 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
798 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
799 int compType = 0; // the strongest policy
800 DataArrayIdType *corr2to1, *corr1to2;
801 // a larger mesh1 includes a smaller mesh2
802 CPPUNIT_ASSERT( mesh1->areCellsIncludedIn( mesh2, compType, corr2to1 ));
803 CPPUNIT_ASSERT( std::equal( cells2, cells2+3, corr2to1->getConstPointer() ));
804 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
805 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
806 // the smaller mesh2 does NOT include the larger mesh1
807 CPPUNIT_ASSERT( ! mesh2->areCellsIncludedIn( mesh1, compType, corr1to2 ));
808 const mcIdType corr1to2Expected[5] = {2, 3, 1, 4, 0};
809 CPPUNIT_ASSERT(std::equal( corr1to2Expected, corr1to2Expected+5, corr1to2->getConstPointer() ));
810 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
815 void CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells()
817 using namespace MEDCoupling;
818 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
819 // 2D coordinates of 5 base nodes
820 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 };
821 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
822 coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 );
823 // coordinates of 5 top nodes
824 MCAuto<DataArrayDouble> coordsArr2 = coordsArr->deepCopy();
825 // 3D coordinates of base + top nodes
826 coordsArr = coordsArr-> changeNbOfComponents( 3, 0 );
827 coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 );
828 coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 );
830 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
831 mesh->setCoords(coordsArr);
832 mesh->setMeshDimension(3);
833 mesh->allocateCells(2);
834 // connectivity of reversed HEXA8 and PENTA6
835 const mcIdType conn[8+6]={0,1,4,3, 5,6,9,8, 1,2,4, 6,7,9};
836 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8, 8,conn+0);
837 mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+8);
838 mesh->finishInsertingCells();
839 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
840 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
841 MCAuto<DataArrayIdType> fixedCells =
842 mesh->findAndCorrectBadOriented3DExtrudedCells();
843 CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 2 ); // 2 cells fixed
844 fixedCells = mesh->findAndCorrectBadOriented3DExtrudedCells();
845 CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 0 ); // no bad cells
846 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
849 void CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented()
851 using namespace MEDCoupling;
852 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
853 // 2D coordinates of 5 base nodes
854 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 };
855 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
856 coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 );
857 // coordinates of 5 top nodes
858 MCAuto<DataArrayDouble> coordsArr2 = coordsArr->deepCopy();
859 // 3D coordinates of base + top nodes
860 coordsArr = coordsArr-> changeNbOfComponents( 3, 0 );
861 coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 );
862 coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 );
864 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
865 mesh->setCoords(coordsArr);
866 mesh->setMeshDimension(3);
867 mesh->allocateCells(2);
868 // connectivity of a HEXA8 + a reversed PENTA6
869 const mcIdType conn[8+6]={0,3,4,1, 5,8,9,6, 1,2,4, 6,7,9};
870 mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,8,conn); // "extruded" polyhedron
871 mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,6,conn+8);
872 mesh->finishInsertingCells();
873 // fix connectivity of NORM_POLYHED's
874 mesh->convertExtrudedPolyhedra();
875 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
876 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
877 std::vector<mcIdType> badCellIds;
878 mesh->arePolyhedronsNotCorrectlyOriented( badCellIds );
879 CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one polyhedron is KO
880 // fix invalid rolyherdons
881 mesh->orientCorrectlyPolyhedrons();
882 // re-check orientation
883 badCellIds.clear(); // as badCellIds is not cleared by arePolyhedronsNotCorrectlyOriented()
884 mesh->arePolyhedronsNotCorrectlyOriented( badCellIds );
885 CPPUNIT_ASSERT( badCellIds.size() == 0 ); // connectivity is OK
886 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
889 void CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented()
891 using namespace MEDCoupling;
892 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
893 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
894 mesh->setMeshDimension(2);
895 mesh->allocateCells(5);
896 const mcIdType conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4};
897 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
898 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
899 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
900 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
901 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
902 mesh->finishInsertingCells();
903 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
904 coordsArr->alloc(9,2);
905 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 };
906 std::copy(coords,coords+18,coordsArr->getPointer());
907 mesh->setCoords(coordsArr);
908 mesh->changeSpaceDimension(3);
909 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
910 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
911 const double vec[3] = {0.,0.,-1.};
912 std::vector<mcIdType> badCellIds;
913 mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds );
914 CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one cell is reversed
916 mesh->orientCorrectly2DCells( vec, false );
917 // re-check orientation
918 badCellIds.clear(); // as badCellIds is not cleared by are2DCellsNotCorrectlyOriented()
919 mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds );
920 CPPUNIT_ASSERT( badCellIds.size() == 0 ); // the orientation is OK
921 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
922 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_3]
923 mesh->orientCorrectly2DCells();
924 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_3]
925 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_4]
926 const mcIdType refCells[] = { 0,2 };
927 const mcIdType objCells[] = { 1,3 };
928 MCAuto<MEDCouplingUMesh> refGroup = mesh->buildPartOfMySelf( refCells, refCells + 2 );
929 MCAuto<MEDCouplingUMesh> objGroup = mesh->buildPartOfMySelf( objCells, objCells + 2 );
930 objGroup->orientCorrectly2DCells( refGroup );
931 mesh->setPartOfMySelf( objCells, objCells + 2, *objGroup );
932 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_4]
935 void CppExample_MEDCouplingUMesh_getCellsContainingPoints()
937 using namespace MEDCoupling;
938 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
939 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
940 mesh->setMeshDimension(2);
941 mesh->allocateCells(5);
942 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
943 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
944 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
945 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
946 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
947 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
948 mesh->finishInsertingCells();
949 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
950 coordsArr->alloc(9,2);
951 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 };
952 std::copy(coords,coords+18,coordsArr->getPointer());
953 mesh->setCoords(coordsArr);
954 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
955 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
956 const double pos[3*2] = { 10., 10, // point out of the mesh
957 0.3, 0.3, // point located somewhere inside the mesh
958 coords[2], coords[3]}; // point at the node #1
959 const double eps = 1e-4; // ball radius
960 MCAuto<DataArrayIdType> cells, cellsIndex;
961 mesh->getCellsContainingPoints( pos, 3, eps, cells, cellsIndex );
962 const mcIdType cellsExpected[3]={4, 0, 1};
963 const mcIdType cellsIndexExpected[4]={0, 0, 1, 3};
964 CPPUNIT_ASSERT(std::equal( cellsExpected, cellsExpected+3, cells->begin()));
965 CPPUNIT_ASSERT(std::equal( cellsIndexExpected, cellsIndexExpected+4, cellsIndex->begin()));
966 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
969 void CppExample_MEDCouplingUMesh_getCellsContainingPoint()
971 using namespace MEDCoupling;
972 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
973 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
974 mesh->setMeshDimension(2);
975 mesh->allocateCells(5);
976 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
977 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
978 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
979 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
980 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
981 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
982 mesh->finishInsertingCells();
983 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
984 coordsArr->alloc(9,2);
985 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 };
986 std::copy(coords,coords+18,coordsArr->getPointer());
987 mesh->setCoords(coordsArr);
988 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
989 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
990 const double* coords4 = coords + 4*2; // coordinates of the node #4
991 const double eps = 1e-4; // ball radius
992 const double pos[2] = { coords4[0] + eps, coords4[1] - eps }; // ball center
993 std::vector<mcIdType> cellIds;
994 mesh->getCellsContainingPoint( pos, eps, cellIds );
995 CPPUNIT_ASSERT ( ToIdType(cellIds.size()) == mesh->getNumberOfCells() );
996 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
999 void CppExample_MEDCouplingUMesh_buildPartOrthogonalField()
1001 using namespace MEDCoupling;
1002 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
1003 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1004 mesh->setMeshDimension(2);
1005 mesh->allocateCells(5);
1006 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1007 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1008 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1009 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1010 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1011 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1012 mesh->finishInsertingCells();
1013 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1014 coordsArr->alloc(9,2);
1015 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 };
1016 std::copy(coords,coords+18,coordsArr->getPointer());
1017 mesh->setCoords(coordsArr);
1018 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
1019 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
1020 const mcIdType part[4] = {1,2,3,4}; // cell #0 is omitted
1021 MCAuto<MEDCouplingFieldDouble> vecField=
1022 mesh->buildPartOrthogonalField( part, part+4 );
1023 CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfTuples() == 4 );
1024 CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfComponents() == 3 );
1025 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
1028 void CppExample_MEDCouplingUMesh_getPartMeasureField()
1030 using namespace MEDCoupling;
1031 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1]
1032 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1033 mesh->setMeshDimension(2);
1034 mesh->allocateCells(5);
1035 const mcIdType conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4};
1036 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1037 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1038 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1039 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1040 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1041 mesh->finishInsertingCells();
1042 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1043 coordsArr->alloc(9,2);
1044 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 };
1045 std::copy(coords,coords+18,coordsArr->getPointer());
1046 mesh->setCoords(coordsArr);
1047 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1]
1048 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2]
1049 const bool isAbs = true;
1050 const mcIdType part[4] = {1,2,3,4}; // cell #0 is omitted
1051 MCAuto<DataArrayDouble> areaArr=
1052 mesh->getPartMeasureField( isAbs, part, part+4 );
1053 CPPUNIT_ASSERT( areaArr->getIJ(0,0) > 0 ); // orientation ignored
1054 areaArr=mesh->getPartMeasureField( !isAbs, part, part+4 );
1055 CPPUNIT_ASSERT( areaArr->getIJ(0,0) < 0 ); // orientation considered
1056 CPPUNIT_ASSERT ( areaArr->getNumberOfTuples() == 4 );
1057 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2]
1058 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3]
1059 const mcIdType cellIds[4] = {1,2,3,4}; // cell #0 is omitted
1060 MCAuto<DataArrayDouble> baryCenters=
1061 mesh->getPartBarycenterAndOwner( cellIds, cellIds+4 );
1062 CPPUNIT_ASSERT( baryCenters->getNumberOfTuples() == 4 );
1063 CPPUNIT_ASSERT( (int)baryCenters->getNumberOfComponents() == mesh->getSpaceDimension() );
1064 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3]
1067 void CppExample_MEDCouplingUMesh_getCellsInBoundingBox()
1069 using namespace MEDCoupling;
1070 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
1071 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1072 mesh->setMeshDimension(2);
1073 mesh->allocateCells(1);
1074 const double coords[3*2]={0.,0., 0.,1., 1.,1};
1075 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1076 coordsArr->useExternalArrayWithRWAccess(coords, 3,2);
1077 mesh->setCoords(coordsArr);
1078 mesh->allocateCells(1);
1079 const mcIdType conn[3]={0,1,2};
1080 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn);
1081 mesh->finishInsertingCells();
1082 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
1083 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
1084 const double bbox[] = {1., 1., 1.001,1.001}; // xMin, xMax, yMin, yMax
1085 MCAuto<DataArrayIdType> cellIdsArr =
1086 mesh->getCellsInBoundingBox( bbox, 0.0 );
1087 CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 0 );
1088 cellIdsArr = mesh->getCellsInBoundingBox( bbox, 0.1 );
1089 CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 1 );
1090 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
1093 void CppExample_MEDCouplingUMesh_renumberNodesInConn()
1095 using namespace MEDCoupling;
1096 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1]
1097 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1098 mesh->setMeshDimension(2);
1099 mesh->allocateCells(1);
1100 const mcIdType conn[4]={4,3,2,1};
1101 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1102 mesh->finishInsertingCells();
1103 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1]
1104 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2]
1105 const mcIdType old2newIds[] = {-1,3,2,1,0};
1106 mesh->renumberNodesInConn( old2newIds );
1107 const mcIdType nodes0Expected[] = {0,1,2,3};
1108 std::vector<mcIdType> nodes0;
1109 mesh->getNodeIdsOfCell( 0, nodes0 );
1110 CPPUNIT_ASSERT(std::equal( nodes0Expected, nodes0Expected+4, &nodes0[0] ));
1111 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2]
1114 void CppExample_MEDCouplingUMesh_renumberNodes()
1116 using namespace MEDCoupling;
1117 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1]
1118 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1119 mesh->setMeshDimension(2);
1120 const double coords[4*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.3};
1121 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1122 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1123 mesh->setCoords(coordsArr);
1124 mesh->allocateCells(0);
1125 mesh->finishInsertingCells();
1126 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1]
1127 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2]
1128 const mcIdType newIds[] = { 2,1,0,-1 };
1129 mesh->renumberNodes(newIds, 3);
1130 coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array
1131 const double coordsExpected[3*2]={0.7,-0.3, 0.2,-0.3, -0.3,-0.3};
1132 MCAuto<DataArrayDouble> coordsExpectedArr=DataArrayDouble::New();
1133 coordsExpectedArr->useExternalArrayWithRWAccess(coordsExpected, 3,2);
1134 CPPUNIT_ASSERT( coordsExpectedArr->isEqual( *coordsArr, 1e-13 ));
1135 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2]
1136 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3]
1137 coordsArr->useExternalArrayWithRWAccess(coords, 4,2); // restore old nodes
1138 const mcIdType newIds2[] = { 2,1,0,2 };
1139 mesh->renumberNodesCenter(newIds2, 3);
1140 coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array
1141 const double coordsExpected2[3*2]={0.7,-0.3, 0.2,-0.3, -0.3, 0.0};
1142 MCAuto<DataArrayDouble> coordsExpectedArr2=DataArrayDouble::New();
1143 coordsExpectedArr2->useExternalArrayWithRWAccess(coordsExpected2, 3,2);
1144 CPPUNIT_ASSERT( coordsExpectedArr2->isEqual( *coordsArr, 1e-13 ));
1145 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3]
1148 void CppExample_MEDCouplingUMesh_findBoundaryNodes()
1150 using namespace MEDCoupling;
1151 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1]
1152 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1153 mesh->setMeshDimension(2);
1154 mesh->allocateCells(5);
1155 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1156 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1157 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1158 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1159 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1160 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1161 mesh->finishInsertingCells();
1162 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1163 coordsArr->alloc(9,2);
1164 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 };
1165 std::copy(coords,coords+18,coordsArr->getPointer());
1166 mesh->setCoords(coordsArr);
1167 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1]
1168 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2]
1169 MCAuto<DataArrayIdType> nodeIdsArr=mesh->findBoundaryNodes();
1170 CPPUNIT_ASSERT( nodeIdsArr->getNumberOfTuples() == mesh->getNumberOfNodes() - 1 );
1171 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2]
1174 void CppExample_MEDCouplingUMesh_buildBoundaryMesh()
1176 using namespace MEDCoupling;
1177 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
1178 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1179 mesh->setMeshDimension(2);
1180 mesh->allocateCells(5);
1181 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1182 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1183 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1184 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1185 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1186 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1187 mesh->finishInsertingCells();
1188 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1189 coordsArr->alloc(9,2);
1190 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 };
1191 std::copy(coords,coords+18,coordsArr->getPointer());
1192 mesh->setCoords(coordsArr);
1193 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
1194 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
1195 MCAuto<MEDCouplingPointSet> mesh1=mesh->buildBoundaryMesh(true);
1196 MCAuto<MEDCouplingPointSet> mesh2=mesh->buildBoundaryMesh(false);
1197 CPPUNIT_ASSERT( coordsArr->isEqual( *mesh1->getCoords(), 1e-13 )); // same nodes
1198 CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // different nodes
1199 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
1202 void CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode()
1204 using namespace MEDCoupling;
1205 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
1206 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1207 mesh->setMeshDimension(2);
1208 mesh->allocateCells(5);
1209 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1210 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1211 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1212 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1213 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1214 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1215 mesh->finishInsertingCells();
1216 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1217 coordsArr->alloc(9,2);
1218 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 };
1219 std::copy(coords,coords+18,coordsArr->getPointer());
1220 mesh->setCoords(coordsArr);
1221 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
1222 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
1223 std::vector<mcIdType> nodes;
1224 mesh->getNodeIdsOfCell( 0, nodes );
1225 const bool allNodes = true;
1226 MCAuto<MEDCouplingUMesh> mesh1 =
1227 (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),allNodes);
1228 CPPUNIT_ASSERT( mesh1->getNumberOfCells() == 4 ); // 4 segments bounding QUAD4 #0 only
1229 MCAuto<MEDCouplingUMesh> mesh2 =
1230 (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),!allNodes);
1231 CPPUNIT_ASSERT( mesh2->getNumberOfCells() == 9 ); // more segments added
1232 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
1235 void CppExample_MEDCouplingUMesh_buildPartOfMySelfNode()
1237 using namespace MEDCoupling;
1238 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
1239 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1240 mesh->setMeshDimension(2);
1241 mesh->allocateCells(5);
1242 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1243 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1244 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1245 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1246 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1247 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1248 mesh->finishInsertingCells();
1249 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1250 coordsArr->alloc(9,2);
1251 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 };
1252 std::copy(coords,coords+18,coordsArr->getPointer());
1253 mesh->setCoords(coordsArr);
1254 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
1255 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
1256 std::vector<mcIdType> nodes;
1257 mesh->getNodeIdsOfCell( 0, nodes );
1258 const bool allNodes = true;
1259 MCAuto<MEDCouplingUMesh> mesh1 =
1260 (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(), allNodes);
1261 MCAuto<MEDCouplingUMesh> mesh2 =
1262 (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(),!allNodes);
1263 CPPUNIT_ASSERT_EQUAL( mesh1->getNumberOfCells(), ToIdType( 1 ));
1264 CPPUNIT_ASSERT_EQUAL( mesh2->getNumberOfCells(), mesh->getNumberOfCells() );
1265 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
1268 void CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes()
1270 using namespace MEDCoupling;
1271 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
1272 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1273 mesh->setMeshDimension(2);
1274 mesh->allocateCells(5);
1275 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1276 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1277 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1278 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1279 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1280 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1281 mesh->finishInsertingCells();
1282 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1283 coordsArr->alloc(9,2);
1284 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 };
1285 std::copy(coords,coords+18,coordsArr->getPointer());
1286 mesh->setCoords(coordsArr);
1287 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
1288 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
1289 std::vector<mcIdType> nodes;
1290 mesh->getNodeIdsOfCell( 0, nodes );
1291 const bool allNodes = true;
1292 DataArrayIdType* cellIdsArr1 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(), allNodes);
1293 DataArrayIdType* cellIdsArr2 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(),!allNodes);
1294 CPPUNIT_ASSERT_EQUAL( cellIdsArr1->getNumberOfTuples(), ToIdType( 1 ));
1295 CPPUNIT_ASSERT_EQUAL( cellIdsArr2->getNumberOfTuples(), mesh->getNumberOfCells() );
1296 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
1297 cellIdsArr1->decrRef();
1298 cellIdsArr2->decrRef();
1301 void CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds()
1303 using namespace MEDCoupling;
1304 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
1305 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1306 mesh->setMeshDimension(2);
1307 mesh->allocateCells(5);
1308 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1309 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1310 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1311 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1312 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1313 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1314 mesh->finishInsertingCells();
1315 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1316 coordsArr->alloc(9,2);
1317 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 };
1318 std::copy(coords,coords+18,coordsArr->getPointer());
1319 mesh->setCoords(coordsArr);
1320 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
1321 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
1322 const mcIdType cellIds[2]={1,2};
1323 std::vector<mcIdType> nodes;
1324 mesh->getNodeIdsOfCell( cellIds[0], nodes );
1325 mesh->getNodeIdsOfCell( cellIds[1], nodes );
1326 DataArrayIdType* cellIdsArr = mesh->getCellIdsFullyIncludedInNodeIds( &nodes[0], &nodes[0]+nodes.size());
1327 CPPUNIT_ASSERT(std::equal( cellIds, cellIds+2, cellIdsArr->getPointer() ));
1328 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
1329 cellIdsArr->decrRef();
1332 void CppExample_MEDCouplingUMesh_buildPartOfMySelf()
1334 using namespace MEDCoupling;
1335 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
1336 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1337 mesh->setMeshDimension(2);
1338 mesh->allocateCells(5);
1339 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1340 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1341 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1342 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1343 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1344 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1345 mesh->finishInsertingCells();
1346 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1347 coordsArr->alloc(9,2);
1348 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 };
1349 std::copy(coords,coords+18,coordsArr->getPointer());
1350 mesh->setCoords(coordsArr);
1351 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
1352 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
1353 const mcIdType cellIds[2]={1,2};
1354 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
1355 MEDCouplingUMesh* mesh3=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,false);
1356 CPPUNIT_ASSERT( coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // same nodes
1357 CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh3->getCoords(), 1e-13 )); // different nodes
1358 for ( mcIdType i = 0; i < 2; ++i )
1360 std::vector<mcIdType> nodes1, nodes2;
1361 mesh ->getNodeIdsOfCell(cellIds[i], nodes1);
1362 mesh2->getNodeIdsOfCell(i, nodes2);
1363 CPPUNIT_ASSERT( nodes1 == nodes2 ); // cell #cellIds[i] was copied
1365 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
1370 void CppExample_MEDCouplingUMesh_mergeNodes()
1372 using namespace MEDCoupling;
1373 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1]
1374 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1375 mesh->setMeshDimension(2);
1376 mesh->allocateCells(5);
1377 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2};
1378 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1379 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1380 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1381 mesh->finishInsertingCells();
1382 const double coords[6*2]={0.3,-0.301, // #0
1384 0.3,-0.302, // #2 ~~ #0
1386 1.1,0.0, // #4 == #3
1387 0.3,-0.303}; // #5 ~~ #0
1388 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1389 coordsArr->alloc(6,2);
1390 std::copy(coords,coords+6*2,coordsArr->getPointer());
1391 mesh->setCoords(coordsArr);
1392 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1]
1393 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2]
1394 bool areNodesMerged; mcIdType newNbOfNodes;
1395 MCAuto<DataArrayIdType> arr=
1396 mesh->mergeNodes(0.004,areNodesMerged,newNbOfNodes);
1397 const mcIdType idsExpected[6] = {0, 1, 0, 2, 2, 0};
1398 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+6,arr->getPointer()));
1399 CPPUNIT_ASSERT( areNodesMerged );
1400 CPPUNIT_ASSERT_EQUAL( ToIdType( 3 ), newNbOfNodes );
1401 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2]
1402 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3]
1403 const double* baryCoords2 = coords + 2*2; // initial coordinates of node #2
1404 coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array
1405 CPPUNIT_ASSERT( fabs( baryCoords2[1] - coordsArr->getIJ(0,1)) > 1e-4 ); // Y of node #0 differs from that of baryCoords2
1406 // restore coordinates
1407 coordsArr->alloc(6,2);
1408 std::copy(coords,coords+6*2,coordsArr->getPointer());
1409 mesh->setCoords(coordsArr);
1410 // call mergeNodesCenter()
1411 arr = mesh->mergeNodesCenter(0.004,areNodesMerged,newNbOfNodes);
1412 coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array
1413 CPPUNIT_ASSERT_DOUBLES_EQUAL( baryCoords2[1], coordsArr->getIJ(0,1), 13 ); // Y of node #0 equals to that of baryCoords2
1414 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3]
1417 void CppExample_MEDCouplingUMesh_zipConnectivityTraducer()
1419 using namespace MEDCoupling;
1420 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
1421 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1422 mesh->setMeshDimension(2);
1423 mesh->allocateCells(5);
1424 const mcIdType conn[11]={0,3,4,1, 1,4,2, 4,1,0,3};
1425 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 0
1426 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1427 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 2 == 1
1428 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 3 == 0
1429 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+7); // 4 ~~ 0
1430 mesh->finishInsertingCells();
1431 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1432 coordsArr->alloc(9,2);
1433 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 };
1434 std::copy(coords,coords+18,coordsArr->getPointer());
1435 mesh->setCoords(coordsArr);
1436 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
1437 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
1438 const mcIdType oldNbCells = mesh->getNumberOfCells();
1439 DataArrayIdType *arr = mesh->zipConnectivityTraducer(0);
1440 CPPUNIT_ASSERT_EQUAL( oldNbCells-2, mesh->getNumberOfCells() );
1441 const mcIdType idsExpected[5] = {0, 1, 1, 0, 2};
1442 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+5,arr->getPointer()));
1443 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
1447 void CppExample_MEDCouplingUMesh_zipCoordsTraducer()
1449 using namespace MEDCoupling;
1450 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
1451 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1452 mesh->setMeshDimension(2);
1453 mesh->allocateCells(5);
1454 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1455 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1456 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1457 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1458 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1459 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1460 mesh->finishInsertingCells();
1461 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1462 coordsArr->alloc(9,2);
1463 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 };
1464 std::copy(coords,coords+18,coordsArr->getPointer());
1465 mesh->setCoords(coordsArr);
1466 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
1467 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
1468 const mcIdType cellIds[2]={1,2};
1469 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
1470 DataArrayIdType *arr=mesh2->zipCoordsTraducer();
1471 CPPUNIT_ASSERT_EQUAL( ToIdType(4), mesh2->getNumberOfNodes() ); // nb of nodes decreased
1472 CPPUNIT_ASSERT_EQUAL( mesh->getNumberOfNodes(), arr->getNumberOfTuples() );
1473 const mcIdType idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1}; // -1 for unused nodes
1474 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer()));
1475 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
1480 void CppExample_MEDCouplingUMesh_getNodeIdsInUse()
1482 using namespace MEDCoupling;
1483 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
1484 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1485 mesh->setMeshDimension(2);
1486 mesh->allocateCells(5);
1487 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1488 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1489 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1490 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1491 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1492 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1493 mesh->finishInsertingCells();
1494 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1495 coordsArr->alloc(9,2);
1496 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 };
1497 std::copy(coords,coords+18,coordsArr->getPointer());
1498 mesh->setCoords(coordsArr);
1499 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
1500 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
1501 const mcIdType cellIds[2]={1,2};
1502 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
1503 mcIdType newNbOfNodes = 0;
1504 DataArrayIdType *arr=mesh2->getNodeIdsInUse( newNbOfNodes );
1505 const mcIdType idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1};
1506 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer()));
1507 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
1508 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
1509 DataArrayIdType *arr2=arr->invertArrayO2N2N2O(newNbOfNodes);
1510 const mcIdType idsExpected2[4] = {1,2,4,5};
1511 CPPUNIT_ASSERT(std::equal(idsExpected2,idsExpected2+4,arr2->getPointer()));
1512 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
1518 void CppExample_MEDCouplingUMesh_convertToPolyTypes()
1520 using namespace MEDCoupling;
1521 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1]
1522 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1523 mesh->setMeshDimension(2);
1524 mesh->allocateCells(5);
1525 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1526 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1527 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1528 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1529 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1530 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1531 mesh->finishInsertingCells();
1532 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1533 coordsArr->alloc(9,2);
1534 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 };
1535 std::copy(coords,coords+18,coordsArr->getPointer());
1536 mesh->setCoords(coordsArr);
1537 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1]
1538 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2]
1539 const mcIdType cells[2]={1,3};
1540 mesh->convertToPolyTypes(cells, cells+2);
1541 CPPUNIT_ASSERT( mesh->getTypeOfCell(0) == INTERP_KERNEL::NORM_QUAD4 );
1542 CPPUNIT_ASSERT( mesh->getTypeOfCell(1) == INTERP_KERNEL::NORM_POLYGON );
1543 CPPUNIT_ASSERT( mesh->getTypeOfCell(2) == INTERP_KERNEL::NORM_TRI3 );
1544 CPPUNIT_ASSERT( mesh->getTypeOfCell(3) == INTERP_KERNEL::NORM_POLYGON );
1545 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2]
1548 void CppExample_MEDCouplingUMesh_buildDescendingConnectivity2()
1550 using namespace MEDCoupling;
1551 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
1552 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1553 mesh->setMeshDimension(2);
1554 mesh->allocateCells(5);
1555 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1556 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1557 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1558 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1559 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1560 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1561 mesh->finishInsertingCells();
1562 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1563 coordsArr->alloc(9,2);
1564 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 };
1565 std::copy(coords,coords+18,coordsArr->getPointer());
1566 mesh->setCoords(coordsArr);
1567 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
1568 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
1569 DataArrayIdType *desc =DataArrayIdType::New();
1570 DataArrayIdType *descIndx =DataArrayIdType::New();
1571 DataArrayIdType *revDesc =DataArrayIdType::New();
1572 DataArrayIdType *revDescIndx=DataArrayIdType::New();
1573 MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx);
1574 const mcIdType descExpected[] = {1,2,3,4,-3,5,6,7,8,-5,9,10,-2,11,12,13,-7,-10};
1575 const mcIdType descIndxExpected[] = {0,4,7,10,14,18};
1576 const mcIdType revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
1577 const mcIdType revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18};
1578 CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer()));
1579 CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer()));
1580 CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer()));
1581 CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer()));
1582 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
1583 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
1584 const mcIdType cell2ConnExpect[] = {4,1};
1585 std::vector<mcIdType> cell2Conn;
1586 mesh2->getNodeIdsOfCell( 3-1, cell2Conn ); // cell #3 in FORTRAN mode
1587 CPPUNIT_ASSERT(std::equal(cell2ConnExpect,cell2ConnExpect+2,&cell2Conn[0]));
1588 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
1590 descIndx->decrRef();
1592 revDescIndx->decrRef();
1596 void CppExample_MEDCouplingUMesh_buildDescendingConnectivity()
1598 using namespace MEDCoupling;
1599 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
1600 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1601 mesh->setMeshDimension(2);
1602 mesh->allocateCells(5);
1603 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1604 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1605 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1606 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1607 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1608 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1609 mesh->finishInsertingCells();
1610 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1611 coordsArr->alloc(9,2);
1612 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 };
1613 std::copy(coords,coords+18,coordsArr->getPointer());
1614 mesh->setCoords(coordsArr);
1615 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
1616 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
1617 DataArrayIdType *desc =DataArrayIdType::New();
1618 DataArrayIdType *descIndx =DataArrayIdType::New();
1619 DataArrayIdType *revDesc =DataArrayIdType::New();
1620 DataArrayIdType *revDescIndx=DataArrayIdType::New();
1621 MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
1622 const mcIdType descExpected[] = {0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
1623 const mcIdType descIndxExpected[] = {0,4,7,10,14,18};
1624 const mcIdType revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
1625 const mcIdType revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18};
1626 CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer()));
1627 CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer()));
1628 CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer()));
1629 CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer()));
1630 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
1632 descIndx->decrRef();
1634 revDescIndx->decrRef();
1638 void CppExample_MEDCouplingUMesh_getReverseNodalConnectivity()
1640 using namespace MEDCoupling;
1641 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1642 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1643 mesh->setMeshDimension(2);
1644 mesh->allocateCells(5);
1645 const mcIdType conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1646 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1647 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1648 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1649 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1650 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1651 mesh->finishInsertingCells();
1652 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1653 coordsArr->alloc(9,2);
1654 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 };
1655 std::copy(coords,coords+18,coordsArr->getPointer());
1656 mesh->setCoords(coordsArr);
1657 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1658 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1659 DataArrayIdType *revNodal=DataArrayIdType::New();
1660 DataArrayIdType *revNodalIndx=DataArrayIdType::New();
1661 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
1662 const mcIdType revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
1663 const mcIdType revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
1664 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
1665 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
1666 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1667 revNodal->decrRef();
1668 revNodalIndx->decrRef();
1671 void CppExample_MEDCouplingUMesh_checkDeepEquivalWith()
1673 using namespace MEDCoupling;
1674 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1676 MEDCouplingUMesh *mesh1=MEDCouplingUMesh::New();
1677 const double coords[4*2]={0.0,0.0, // #0
1682 mesh1->setMeshDimension(2);
1683 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1684 coordsArr->useExternalArrayWithRWAccess( coords, 4, 2 );
1685 mesh1->setCoords(coordsArr);
1686 mesh1->allocateCells(2);
1687 const mcIdType conn[6]={0,1,2, 1,2,3};
1688 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0
1689 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1
1690 mesh1->finishInsertingCells();
1693 MEDCouplingUMesh *mesh2=MEDCouplingUMesh::New();
1694 const double coords2[4*2]={0.0,1.0, // #0 = #3
1697 1.0,1.001}; // #3 ~ #2
1699 mesh2->setMeshDimension(2);
1700 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1701 coordsArr->useExternalArrayWithRWAccess( coords2, 4, 2 );
1702 mesh2->setCoords(coordsArr);
1703 mesh2->allocateCells(2);
1704 const mcIdType conn[6]={2,3,0, 3,1,2};
1705 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0 = #1
1706 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1 ~ #0
1707 mesh2->finishInsertingCells();
1709 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1710 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1711 int cellCompPol = 1; // "permuted same orientation" - policy of medium severity
1712 DataArrayIdType *nOld2New, *cOld2New;
1713 mesh1->checkDeepEquivalWith( mesh2, cellCompPol, 0.002, cOld2New, nOld2New );
1714 const mcIdType nOld2NewExpected[4] = { 3, 0, 1, 2 };
1715 const mcIdType cOld2NewExpected[2] = { 1, 0 };
1716 CPPUNIT_ASSERT(std::equal(nOld2NewExpected,nOld2NewExpected+4,nOld2New->getConstPointer()));
1717 CPPUNIT_ASSERT(std::equal(cOld2NewExpected,cOld2NewExpected+2,cOld2New->getConstPointer()));
1718 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1719 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1720 cOld2New->decrRef(); // else memory leaks
1721 CPPUNIT_ASSERT_THROW ( mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0.002, cOld2New ), INTERP_KERNEL::Exception );
1722 mesh2->setCoords( mesh1->getCoords() ); // make meshes share the same coordinates array
1723 mesh2->allocateCells(2);
1724 const mcIdType conn[6]={1,2,3, 1,0,2};
1725 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+0); // #0 = #1
1726 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3); // #1 ~ #0
1727 mesh2->finishInsertingCells();
1728 cellCompPol = 2; // the weakest policy
1729 mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0, cOld2New );
1730 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1731 nOld2New->decrRef();
1732 cOld2New->decrRef();
1737 void CppExample_MEDCouplingPointSet_scale()
1739 using namespace MEDCoupling;
1740 //! [CppSnippet_MEDCouplingPointSet_scale_1]
1741 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
1742 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1743 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1744 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1745 mesh->setCoords(coordsArr);
1746 DataArrayDouble *initCoords = coordsArr->deepCopy();
1747 //! [CppSnippet_MEDCouplingPointSet_scale_1]
1748 //! [CppSnippet_MEDCouplingPointSet_scale_2]
1749 const double center[2] = {0.,0.};
1750 const double factor = 2.;
1751 mesh->scale( center, factor );
1752 //! [CppSnippet_MEDCouplingPointSet_scale_2]
1753 //! [CppSnippet_MEDCouplingPointSet_scale_3]
1754 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1755 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 ));
1756 CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 ));
1758 initCoords->decrRef();
1759 //! [CppSnippet_MEDCouplingPointSet_scale_3]
1762 void CppExample_MEDCouplingPointSet_translate()
1764 using namespace MEDCoupling;
1765 //! [CppSnippet_MEDCouplingPointSet_translate_1]
1766 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
1767 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1768 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1769 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1770 mesh->setCoords(coordsArr);
1771 DataArrayDouble *initCoords = coordsArr->deepCopy();
1772 //! [CppSnippet_MEDCouplingPointSet_translate_1]
1773 //! [CppSnippet_MEDCouplingPointSet_translate_2]
1774 double vector[2] = {1.,1.};
1775 mesh->translate( vector );
1776 //! [CppSnippet_MEDCouplingPointSet_translate_2]
1777 //! [CppSnippet_MEDCouplingPointSet_translate_3]
1778 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1779 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 ));
1780 CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 ));
1782 initCoords->decrRef();
1783 //! [CppSnippet_MEDCouplingPointSet_translate_3]
1786 void CppExample_MEDCouplingPointSet_rotate()
1788 using namespace MEDCoupling;
1789 //! [CppSnippet_MEDCouplingPointSet_rotate_1]
1790 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
1791 double coordsOrig[4*2];
1792 std::copy(coords,coords+sizeof(coords)/sizeof(double),coordsOrig);//keep tracks of initial values
1793 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1794 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1795 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1796 mesh->setCoords(coordsArr);
1797 //! [CppSnippet_MEDCouplingPointSet_rotate_1]
1798 //! [CppSnippet_MEDCouplingPointSet_rotate_2]
1799 double center[3] = {0.,0.,0.}; // it suits for 2D as well
1800 double vector[3] = {0.,0.,1.}; // it is not used in 2D
1801 mesh->rotate( center, vector, -M_PI/2); // warning here C++ 'coords' array (defined above) has been modified !
1802 //! [CppSnippet_MEDCouplingPointSet_rotate_2]
1803 //! [CppSnippet_MEDCouplingPointSet_rotate_3]
1804 mesh->changeSpaceDimension(3);
1805 mesh->rotate( center, vector, +M_PI/2);
1806 //! [CppSnippet_MEDCouplingPointSet_rotate_3]
1807 //! [CppSnippet_MEDCouplingPointSet_rotate_4]
1808 mesh->changeSpaceDimension(2);
1809 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1810 coordsArr->useExternalArrayWithRWAccess(coordsOrig, 4,2);
1811 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *coordsArr, 1e-13 ));
1812 //! [CppSnippet_MEDCouplingPointSet_rotate_4]
1815 void CppExample_MEDCouplingPointSet_getBoundingBox()
1817 using namespace MEDCoupling;
1818 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1]
1819 double cc[2*3]={0.0, 0.1, 0.2, // 3D coordinates of 2 nodes
1821 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1822 coordsArr->useExternalArrayWithRWAccess(cc, 2,3);
1823 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1824 mesh->setCoords(coordsArr);
1825 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1]
1826 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2]
1828 mesh->getBoundingBox( (double*) bbox );
1830 // check the returned coordinates of extremum points of the bounding box
1831 for ( mcIdType i = 0; i < 2; ++i ) // point id
1832 for ( mcIdType j = 0; j < 3; ++j ) // component
1833 CPPUNIT_ASSERT_DOUBLES_EQUAL( cc[ i*3 + j ], bbox[j][i], 1e-13);
1834 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2]
1837 void CppExample_MEDCouplingPointSet_getNodeIdsNearPoint()
1839 using namespace MEDCoupling;
1840 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1841 // 2D coordinates of 5 nodes
1842 double coords[5*2]={0.3,-0.30001, // #0
1847 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1848 coordsArr->useExternalArrayWithRWAccess(coords, 5,2);
1849 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1850 mesh->setCoords(coordsArr);
1851 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1852 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1853 double point [2]={0.3, -0.3}; // point close to nodes #0, #2 and #4
1854 DataArrayIdType *ids = mesh->getNodeIdsNearPoint(point, 1e-2);
1857 const mcIdType expectedIDs[3] = {0,2,4};
1858 DataArrayIdType * okIDs = ids->findIdsEqualList ( expectedIDs, expectedIDs+3 );
1859 CPPUNIT_ASSERT_EQUAL(ToIdType(3), okIDs->getNumberOfTuples());
1864 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1866 void CppExample_MEDCouplingPointSet_getNodeIdsNearPoints()
1868 using namespace MEDCoupling;
1869 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1870 // 2D coordinates of 7 nodes
1871 double coords[7*2]={0.3,-0.301, // #0
1878 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1879 coordsArr->useExternalArrayWithRWAccess(coords, 7,2);
1880 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1881 mesh->setCoords(coordsArr);
1882 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1883 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1884 const mcIdType nbOfPoints = 3;
1885 double points [nbOfPoints*2]={0.2,-0.30001, // ~ node #1
1887 1.1, 0.002}; // ~ nodes #3, #4 and #5
1888 DataArrayIdType *ids, *idsIndex;
1889 mesh->getNodeIdsNearPoints(points, nbOfPoints, 1e-1,ids,idsIndex);
1891 // check found ids (i.e. contents of 'ids' array)
1892 const mcIdType expectedIDs[4] = {1, 3, 4, 5};
1893 DataArrayIdType * okIDs = ids->findIdsEqualList ( expectedIDs, expectedIDs+4 );
1894 CPPUNIT_ASSERT_EQUAL(ToIdType(4), okIDs->getNumberOfTuples());
1898 idsIndex->decrRef();
1900 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1903 void CppExample_MEDCouplingPointSet_findCommonNodes()
1905 using namespace MEDCoupling;
1906 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1]
1907 double coords[6*2]={0.3,-0.301, // 0
1913 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1914 coordsArr->useExternalArrayWithRWAccess(coords, 6,2);
1915 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1916 mesh->setCoords(coordsArr);
1917 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1]
1918 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2]
1919 DataArrayIdType *com, *comI;
1920 mesh->findCommonNodes(1e-13,-1,com,comI);
1921 CPPUNIT_ASSERT_EQUAL(ToIdType(2),com->getNumberOfTuples());
1922 com->decrRef(); comI->decrRef();
1923 mesh->findCommonNodes(0.004,-1,com,comI);
1924 CPPUNIT_ASSERT_EQUAL(ToIdType(5), com->getNumberOfTuples());
1925 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2]
1926 com->decrRef(); comI->decrRef();
1929 void CppExample_MEDCouplingPointSet_getCoordinatesOfNode()
1931 using namespace MEDCoupling;
1932 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1933 double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3};
1934 MCAuto<DataArrayDouble> coordsArr=DataArrayDouble::New();
1935 coordsArr->useExternalArrayWithRWAccess(coords, 3,2);
1936 MCAuto<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1937 mesh->setCoords(coordsArr);
1938 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1939 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1940 std::vector<double> coords2;
1941 mesh->getCoordinatesOfNode(1,coords2);
1942 CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[2],coords2[0],1e-13);
1943 CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[3],coords2[1],1e-13);
1944 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1947 void CppExample_DataArrayInt_buildPermutationArr()
1949 using namespace MEDCoupling;
1950 //! [CppSnippet_DataArrayInt_buildPermutationArr_1]
1951 DataArrayInt *a=DataArrayInt::New();
1952 const mcIdType vala[5]={4,5,6,7,8};
1954 std::copy(vala,vala+5,a->getPointer());
1955 DataArrayInt *b=DataArrayInt::New();
1956 const mcIdType valb[5]={5,4,8,6,7};
1958 std::copy(valb,valb+5,b->getPointer());
1959 DataArrayIdType *c=a->buildPermutationArr(*b);
1960 //! [CppSnippet_DataArrayInt_buildPermutationArr_1]
1961 const mcIdType expect1[5]={1,0,4,2,3};
1962 CPPUNIT_ASSERT_EQUAL(ToIdType(5),c->getNumberOfTuples());
1963 CPPUNIT_ASSERT_EQUAL(1,(int)c->getNumberOfComponents());
1964 CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
1965 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
1971 void CppExample_DataArrayInt_invertArrayO2N2N2O()
1973 using namespace MEDCoupling;
1974 //! [CppSnippet_DataArrayInt_invertArrayO2N2N2O_1]
1975 const mcIdType arr1[6]={2,0,4,1,5,3};
1976 DataArrayInt *da=DataArrayInt::New();
1978 std::copy(arr1,arr1+6,da->getPointer());
1979 DataArrayIdType *da2=da->invertArrayO2N2N2O(6);
1980 const mcIdType expected1[6]={1,3,0,5,2,4};
1981 for(mcIdType i=0;i<6;i++)
1982 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
1983 //! [CppSnippet_DataArrayInt_invertArrayO2N2N2O_1]
1988 void CppExample_DataArrayInt_invertArrayN2O2O2N()
1990 using namespace MEDCoupling;
1991 //! [CppSnippet_DataArrayInt_invertArrayN2O2O2N_1]
1992 const mcIdType arr1[6]={2,0,4,1,5,3};
1993 DataArrayInt *da=DataArrayInt::New();
1995 std::copy(arr1,arr1+6,da->getPointer());
1996 DataArrayIdType *da2=da->invertArrayN2O2O2N(6);
1997 const mcIdType expected1[6]={1,3,0,5,2,4};
1998 for(mcIdType i=0;i<6;i++)
1999 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
2000 //! [CppSnippet_DataArrayInt_invertArrayN2O2O2N_1]
2005 void CppExample_DataArrayDouble_getIdsInRange()
2007 using namespace MEDCoupling;
2008 //! [CppSnippet_DataArrayDouble_getIdsInRange_1]
2009 DataArrayDouble *da=DataArrayDouble::New();
2013 DataArrayIdType* da2 = da->findIdsInRange( 2.5, 6 );
2014 //! [CppSnippet_DataArrayDouble_getIdsInRange_1]
2019 void CppExample_DataArrayDouble_findCommonTuples()
2021 using namespace MEDCoupling;
2022 //! [CppSnippet_DataArrayDouble_findCommonTuples1]
2023 DataArrayDouble *da=DataArrayDouble::New();
2025 const double array2[12]={2.3,2.3, // 0
2032 std::copy(array2,array2+12,da->getPointer());
2033 //! [CppSnippet_DataArrayDouble_findCommonTuples1]
2034 //! [CppSnippet_DataArrayDouble_findCommonTuples2]
2035 DataArrayIdType *c=0,*cI=0;
2036 da->findCommonTuples(1.01e-1,-1,c,cI);
2038 const mcIdType expected3[5]={0,3,4,1,2};
2039 const mcIdType expected4[3]={0,3,5};
2040 CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer()));
2041 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer()));
2045 //! [CppSnippet_DataArrayDouble_findCommonTuples2]
2048 void CppExample_DataArrayDouble_Meld1()
2050 using namespace MEDCoupling;
2051 //! [CppSnippet_DataArrayDouble_Meld1_1]
2052 const mcIdType sameNbTuples = 7;
2054 DataArrayDouble *da1=DataArrayDouble::New();
2055 da1->alloc(sameNbTuples,2);
2056 da1->fillWithValue(7.);
2057 da1->setInfoOnComponent(0,"c0da1");
2058 da1->setInfoOnComponent(1,"c1da1");
2060 DataArrayDouble *da2=DataArrayDouble::New();
2061 da2->alloc(sameNbTuples,1);
2063 da2->setInfoOnComponent(0,"c0da2");
2066 //! [CppSnippet_DataArrayDouble_Meld1_1]
2067 //! [CppSnippet_DataArrayDouble_Meld1_2]
2070 //! [CppSnippet_DataArrayDouble_Meld1_2]
2073 void CppExample_DataArrayInt_Meld1()
2075 using namespace MEDCoupling;
2076 //! [CppSnippet_DataArrayInt_Meld1_1]
2077 const mcIdType sameNbTuples = 7;
2079 DataArrayInt *da1=DataArrayInt::New();
2080 da1->alloc(sameNbTuples,2);
2081 da1->fillWithValue(7);
2082 da1->setInfoOnComponent(0,"c0da1");
2083 da1->setInfoOnComponent(1,"c1da1");
2085 DataArrayInt *da2=DataArrayInt::New();
2086 da2->alloc(sameNbTuples,1);
2088 da2->setInfoOnComponent(0,"c0da2");
2091 //! [CppSnippet_DataArrayInt_Meld1_1]
2092 //! [CppSnippet_DataArrayInt_Meld1_2]
2095 //! [CppSnippet_DataArrayInt_Meld1_2]
2098 void CppExampleFieldDoubleBuildSubPart1()
2100 //! [CppSnippetFieldDoubleBuildSubPart1_1]
2101 MEDCoupling::MEDCouplingUMesh *mesh1=MEDCoupling::MEDCouplingBasicsTest::build2DTargetMesh_1();
2102 MEDCoupling::MEDCouplingFieldDouble *f1=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_CELLS,MEDCoupling::ONE_TIME);
2103 f1->setTime(2.3,5,6);
2105 MEDCoupling::DataArrayDouble *array=MEDCoupling::DataArrayDouble::New();
2106 array->alloc(mesh1->getNumberOfCells(),2);
2107 const double arr1[10]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.};
2108 std::copy(arr1,arr1+10,array->getPointer());
2109 f1->setArray(array);
2111 //! [CppSnippetFieldDoubleBuildSubPart1_1]
2112 //! [CppSnippetFieldDoubleBuildSubPart1_2]
2113 const mcIdType part1[3]={2,1,4};
2114 MEDCoupling::MEDCouplingFieldDouble *f2=f1->buildSubPart(part1,part1+3);
2115 //! [CppSnippetFieldDoubleBuildSubPart1_2]
2117 CPPUNIT_ASSERT_EQUAL(ToIdType(3),f2->getMesh()->getNumberOfCells());
2118 CPPUNIT_ASSERT_EQUAL(ToIdType(6),f2->getMesh()->getNumberOfNodes());
2119 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
2120 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
2121 MEDCoupling::MEDCouplingUMesh *m2C=dynamic_cast<MEDCoupling::MEDCouplingUMesh *>(const_cast<MEDCoupling::MEDCouplingMesh *>(f2->getMesh()));
2122 CPPUNIT_ASSERT_EQUAL(ToIdType(13),m2C->getNodalConnectivityArrayLen());
2123 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};
2124 for(mcIdType i=0;i<12;i++)
2125 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
2126 const double expected3[13]={3,2,3,1,3,0,2,1,4,4,5,3,2};
2127 CPPUNIT_ASSERT(std::equal(expected3,expected3+13,m2C->getNodalConnectivity()->getConstPointer()));
2128 const double expected4[4]={0,4,8,13};
2129 CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
2132 //! [CppSnippetFieldDoubleBuildSubPart1_3]
2133 f1=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_NODES,MEDCoupling::ONE_TIME);
2134 f1->setTime(2.3,5,6);
2136 array=MEDCoupling::DataArrayDouble::New();
2137 array->alloc(mesh1->getNumberOfNodes(),2);
2138 const double arr2[18]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
2139 std::copy(arr2,arr2+18,array->getPointer());
2140 f1->setArray(array);
2142 //! [CppSnippetFieldDoubleBuildSubPart1_3]
2143 //! [CppSnippetFieldDoubleBuildSubPart1_4]
2144 const mcIdType part2[2]={1,2};
2145 f2=f1->buildSubPart(part2,part2+2);
2146 //! [CppSnippetFieldDoubleBuildSubPart1_4]
2148 //idem previous because nodes of cell#4 are not fully present in part3
2149 const mcIdType part3[2]={1,2};
2150 MEDCoupling::DataArrayIdType *arrr=MEDCoupling::DataArrayIdType::New();
2152 std::copy(part3,part3+2,arrr->getPointer());
2153 f2=f1->buildSubPart(arrr);
2157 const mcIdType part4[3]={1,2,4};
2158 f2=f1->buildSubPart(part4,part4+3);
2166 void CppSnippetUMeshStdBuild1()
2168 //! [CppSnippetUMeshStdBuild1_1]
2169 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.,
2170 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. };
2171 mcIdType nodalConnPerCell[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
2172 //! [CppSnippetUMeshStdBuild1_1]
2173 //! [CppSnippetUMeshStdBuild1_2]
2174 MEDCoupling::MEDCouplingUMesh *mesh=MEDCoupling::MEDCouplingUMesh::New("My2DMesh",2);
2175 //! [CppSnippetUMeshStdBuild1_2]
2176 //! [CppSnippetUMeshStdBuild1_3]
2177 mesh->allocateCells(5);//You can put more than 5 if you want but not less.
2178 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell);
2179 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,nodalConnPerCell+4);
2180 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,nodalConnPerCell+7);
2181 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell+10);
2182 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell+14);
2183 mesh->finishInsertingCells();
2184 //! [CppSnippetUMeshStdBuild1_3]
2185 //! [CppSnippetUMeshStdBuild1_4]
2186 MEDCoupling::DataArrayDouble *coordsArr=MEDCoupling::DataArrayDouble::New();
2187 coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
2188 std::copy(coords,coords+27,coordsArr->getPointer());
2189 mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
2190 coordsArr->decrRef();
2191 //! [CppSnippetUMeshStdBuild1_4]
2192 mesh->checkConsistencyLight();
2193 //! [CppSnippetUMeshStdBuild1_5]
2195 //! [CppSnippetUMeshStdBuild1_5]
2198 void CppSnippetCMeshStdBuild1()
2200 //! [CppSnippetCMeshStdBuild1_1]
2201 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2202 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2203 MEDCoupling::DataArrayDouble *arrX=MEDCoupling::DataArrayDouble::New();
2205 std::copy(XCoords,XCoords+9,arrX->getPointer());
2206 arrX->setInfoOnComponent(0,"X [m]");
2207 MEDCoupling::DataArrayDouble *arrY=MEDCoupling::DataArrayDouble::New();
2209 std::copy(YCoords,YCoords+7,arrY->getPointer());
2210 arrY->setInfoOnComponent(0,"Y [m]");
2211 //! [CppSnippetCMeshStdBuild1_1]
2212 //! [CppSnippetCMeshStdBuild1_2]
2213 MEDCoupling::MEDCouplingCMesh *mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh");
2214 mesh->setCoords(arrX,arrY);
2217 //! [CppSnippetCMeshStdBuild1_2]
2218 //! [CppSnippetCMeshStdBuild1_3]
2219 CPPUNIT_ASSERT_EQUAL(ToIdType(8*6),mesh->getNumberOfCells());
2220 CPPUNIT_ASSERT_EQUAL(ToIdType(9*7),mesh->getNumberOfNodes());
2221 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
2222 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
2223 //! [CppSnippetCMeshStdBuild1_3]
2225 mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh");
2226 arrX=MEDCoupling::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2227 arrY=MEDCoupling::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2228 //! [CppSnippetCMeshStdBuild1_2bis]
2229 mesh->setCoordsAt(0,arrX);
2231 mesh->setCoordsAt(1,arrY);
2233 //! [CppSnippetCMeshStdBuild1_2bis]
2234 CPPUNIT_ASSERT_EQUAL(ToIdType(8*6),mesh->getNumberOfCells());
2235 CPPUNIT_ASSERT_EQUAL(ToIdType(9*7),mesh->getNumberOfNodes());
2236 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
2237 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
2238 //! [CppSnippetCMeshStdBuild1_4]
2240 //! [CppSnippetCMeshStdBuild1_4]
2243 void CppSnippetUMeshAdvBuild1()
2245 //! [CppSnippetUMeshAdvBuild1_1]
2246 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.,
2247 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. };
2248 mcIdType 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};
2249 mcIdType nodalConnPerCellIndex[6]={0,5,9,13,18,23};
2250 //! [CppSnippetUMeshAdvBuild1_1]
2251 //! [CppSnippetUMeshAdvBuild1_2]
2252 MEDCoupling::MEDCouplingUMesh *mesh=MEDCoupling::MEDCouplingUMesh::New("My2DMesh",2);
2253 //! [CppSnippetUMeshAdvBuild1_2]
2254 //! [CppSnippetUMeshAdvBuild1_3]
2255 MEDCoupling::DataArrayIdType *nodalConn=MEDCoupling::DataArrayIdType::New();
2256 nodalConn->alloc(23,1);
2257 std::copy(nodalConnPerCell,nodalConnPerCell+23,nodalConn->getPointer());
2258 MEDCoupling::DataArrayIdType *nodalConnI=MEDCoupling::DataArrayIdType::New();
2259 nodalConnI->alloc(6,1);
2260 std::copy(nodalConnPerCellIndex,nodalConnPerCellIndex+6,nodalConnI->getPointer());
2261 mesh->setConnectivity(nodalConn,nodalConnI,true);
2262 nodalConn->decrRef();// nodalConn DataArrayIdType instance is owned by mesh after call to setConnectivity method. No more need here -> decrRef()
2263 nodalConnI->decrRef();// nodalConnI DataArrayIdType instance is owned by mesh after call to setConnectivity method. No more need here -> decrRef()
2264 //! [CppSnippetUMeshAdvBuild1_3]
2265 //! [CppSnippetUMeshAdvBuild1_4]
2266 MEDCoupling::DataArrayDouble *coordsArr=MEDCoupling::DataArrayDouble::New();
2267 coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
2268 std::copy(coords,coords+27,coordsArr->getPointer());
2269 mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
2270 coordsArr->decrRef();
2271 //! [CppSnippetUMeshAdvBuild1_4]
2272 mesh->checkConsistencyLight();
2273 //! [CppSnippetUMeshAdvBuild1_5]
2275 //! [CppSnippetUMeshAdvBuild1_5]
2278 void CppSnippetDataArrayBuild1()
2280 //! [CppSnippetDataArrayBuild1_0]
2281 const mcIdType nbOfNodes=12;
2282 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.};
2284 MEDCoupling::DataArrayDouble *coordsArr=0;
2286 //! [CppSnippetDataArrayBuild1_0]
2288 //! [CppSnippetDataArrayBuild1_1]
2289 coordsArr=MEDCoupling::DataArrayDouble::New();
2290 coordsArr->useArray(coords,false,MEDCoupling::DeallocType::CPP_DEALLOC,nbOfNodes,3);
2291 //now use coordsArr as you need
2293 //coordsArr is no more useful here : release it
2294 coordsArr->decrRef();
2295 //! [CppSnippetDataArrayBuild1_1]
2296 //! [CppSnippetDataArrayBuild1_2]
2297 coordsArr=MEDCoupling::DataArrayDouble::New();
2298 tmp=new double[3*nbOfNodes];
2299 std::copy(coords,coords+3*nbOfNodes,tmp);
2300 coordsArr->useArray(tmp,true,MEDCoupling::DeallocType::CPP_DEALLOC,nbOfNodes,3);
2301 //now use coordsArr as you need
2303 //coordsArr is no more useful, release it
2304 coordsArr->decrRef();
2305 //! [CppSnippetDataArrayBuild1_2]
2306 //! [CppSnippetDataArrayBuild1_3]
2307 coordsArr=MEDCoupling::DataArrayDouble::New();
2308 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
2309 std::copy(coords,coords+3*nbOfNodes,tmp);
2310 coordsArr->useArray(tmp,true,MEDCoupling::DeallocType::C_DEALLOC,nbOfNodes,3);
2311 //now use coordsArr as you need
2313 //coordsArr is no more useful here : release it
2314 coordsArr->decrRef();
2315 //! [CppSnippetDataArrayBuild1_3]
2316 //! [CppSnippetDataArrayBuild1_4]
2317 coordsArr=MEDCoupling::DataArrayDouble::New();
2318 coordsArr->alloc(nbOfNodes,3);
2319 tmp=coordsArr->getPointer();
2320 std::copy(coords,coords+3*nbOfNodes,tmp);
2321 coordsArr->declareAsNew();//you have modified data pointed by internal pointer notify object
2322 //now use coordsArr as you need
2324 //coordsArr is no more useful here : release it
2325 coordsArr->decrRef();
2326 //! [CppSnippetDataArrayBuild1_4]
2327 coordsArr=MEDCoupling::DataArrayDouble::New();
2328 coordsArr->alloc(nbOfNodes,3);
2329 tmp=coordsArr->getPointer();
2330 std::copy(coords,coords+3*nbOfNodes,tmp);
2331 MEDCoupling::DataArrayDouble *coordsArrCpy=0;
2332 //! [CppSnippetDataArrayBuild1_5]
2333 coordsArrCpy=coordsArr->deepCopy();
2334 //! [CppSnippetDataArrayBuild1_5]
2335 //! [CppSnippetDataArrayBuild1_6]
2336 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2337 coordsArrCpy->setIJ(0,0,1000.);
2338 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
2339 //! [CppSnippetDataArrayBuild1_6]
2340 //! [CppSnippetDataArrayBuild1_7]
2341 coordsArrCpy->decrRef();
2342 //! [CppSnippetDataArrayBuild1_7]
2343 //! [CppSnippetDataArrayBuild1_5bis]
2344 coordsArrCpy=coordsArr->performCopyOrIncrRef(true);
2345 //! [CppSnippetDataArrayBuild1_5bis]
2346 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2347 coordsArrCpy->setIJ(0,0,1000.);
2348 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
2349 coordsArrCpy->decrRef();
2350 //! [CppSnippetDataArrayBuild1_8]
2351 coordsArrCpy=coordsArr->performCopyOrIncrRef(false);
2352 //! [CppSnippetDataArrayBuild1_8]
2353 //! [CppSnippetDataArrayBuild1_9]
2354 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2355 coordsArrCpy->setIJ(0,0,1000.);
2356 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArr and coordsArrCpy have been modified simultaneously
2357 //! [CppSnippetDataArrayBuild1_9]
2358 //! [CppSnippetDataArrayBuild1_10]
2359 coordsArrCpy->decrRef();
2360 //! [CppSnippetDataArrayBuild1_10]
2361 //! [CppSnippetDataArrayBuild1_11]
2362 coordsArrCpy=MEDCoupling::DataArrayDouble::New();
2363 //! [CppSnippetDataArrayBuild1_11]
2364 //! [CppSnippetDataArrayBuild1_12]
2365 coordsArrCpy->deepCopyFrom(*coordsArr);
2366 //! [CppSnippetDataArrayBuild1_12]
2367 //! [CppSnippetDataArrayBuild1_13]
2368 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2369 coordsArrCpy->setIJ(0,0,2000.);
2370 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
2371 //! [CppSnippetDataArrayBuild1_13]
2372 //! [CppSnippetDataArrayBuild1_14]
2373 coordsArrCpy->decrRef();
2374 //! [CppSnippetDataArrayBuild1_14]
2375 coordsArr->decrRef();
2376 //! [CppSnippetDataArrayBuild1_14]
2379 void CppSnippetFieldDoubleBuild1()
2381 double XCoords[9]={-0.3,0.07,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2382 double YCoords[7]={0.07,0.1,0.37,0.45,0.47,0.49,1.007};
2383 MEDCoupling::DataArrayDouble *arrX=MEDCoupling::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2384 MEDCoupling::DataArrayDouble *arrY=MEDCoupling::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2385 MEDCoupling::MEDCouplingCMesh *mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh");
2386 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2387 //! [CppSnippetFieldDoubleBuild1_1]
2388 MEDCoupling::MEDCouplingFieldDouble* fieldOnCells=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_CELLS,MEDCoupling::NO_TIME);
2389 fieldOnCells->setName("MyTensorFieldOnCellNoTime");
2390 fieldOnCells->setMesh(mesh);
2391 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnCells
2392 MEDCoupling::DataArrayDouble *array=MEDCoupling::DataArrayDouble::New();
2393 array->alloc(fieldOnCells->getMesh()->getNumberOfCells(),9);//Implicitly fieldOnCells will be a 9 components field.
2394 array->fillWithValue(7.);
2395 fieldOnCells->setArray(array);
2397 // fieldOnCells is now usable
2399 // fieldOnCells is no more useful here : release it
2400 fieldOnCells->decrRef();
2401 //! [CppSnippetFieldDoubleBuild1_1]
2402 arrX=MEDCoupling::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2403 arrY=MEDCoupling::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2404 mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh");
2405 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2406 //! [CppSnippetFieldDoubleBuild1_2]
2407 MEDCoupling::MEDCouplingFieldDouble *f1=mesh->fillFromAnalytic(MEDCoupling::ON_CELLS,1,"x*x+y*y*3+2.*x");//f1 is scalar
2408 MEDCoupling::MEDCouplingFieldDouble *f2=mesh->fillFromAnalytic(MEDCoupling::ON_CELLS,1,"cos(x+y/x)");//f2 is scalar too
2409 MEDCoupling::MEDCouplingFieldDouble *f2bis=mesh->fillFromAnalytic(MEDCoupling::ON_CELLS,2,"x*x*IVec+3*y*JVec");//f2bis is a vectors field
2410 MEDCoupling::MEDCouplingFieldDouble *f3=(*f1)+(*f2);//f3 scalar
2411 MEDCoupling::MEDCouplingFieldDouble *f4=(*f3)/(*f2);//f4 scalar
2412 f2bis->applyFunc(1,"sqrt(x*x+y*y)");//f2bis becomes scalar
2413 MEDCoupling::MEDCouplingFieldDouble *f5=(*f2bis)*(*f4);//f5 scalar
2414 const double pos1[2]={0.48,0.38};
2416 f4->getValueOn(pos1,&res);//f4 is scalar so the returned value is of size 1.
2418 //! [CppSnippetFieldDoubleBuild1_2]
2420 //! [CppSnippetFieldDoubleBuild1_3]
2421 // f1, f2, f2bis, f3, f4, f5 are no more useful here : release them
2428 //! [CppSnippetFieldDoubleBuild1_3]
2431 void CppSnippetFieldDoubleBuild2()
2433 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2434 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2435 MEDCoupling::DataArrayDouble *arrX=MEDCoupling::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2436 MEDCoupling::DataArrayDouble *arrY=MEDCoupling::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2437 MEDCoupling::MEDCouplingCMesh *mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh");
2438 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2439 //! [CppSnippetFieldDoubleBuild2_1]
2440 MEDCoupling::MEDCouplingFieldDouble* fieldOnNodes=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_NODES,MEDCoupling::NO_TIME);
2441 fieldOnNodes->setName("MyScalarFieldOnNodeNoTime");
2442 fieldOnNodes->setMesh(mesh);
2443 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnNodes
2444 MEDCoupling::DataArrayDouble *array=MEDCoupling::DataArrayDouble::New();
2445 array->alloc(fieldOnNodes->getMesh()->getNumberOfNodes(),1);//Implicitly fieldOnNodes will be a 1 component field.
2446 array->fillWithValue(8.);
2447 fieldOnNodes->setArray(array);
2449 // fieldOnNodes is now usable
2451 // fieldOnNodes is no more useful here : release it
2452 fieldOnNodes->decrRef();
2453 //! [CppSnippetFieldDoubleBuild2_1]
2456 void CppSnippetFieldDoubleBuild3()
2458 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2459 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2460 MEDCoupling::DataArrayDouble *arrX=MEDCoupling::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2461 MEDCoupling::DataArrayDouble *arrY=MEDCoupling::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2462 MEDCoupling::MEDCouplingCMesh *mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh");
2463 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2464 //! [CppSnippetFieldDoubleBuild3_1]
2465 MEDCoupling::MEDCouplingFieldDouble* fieldOnCells=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_CELLS,MEDCoupling::ONE_TIME);
2466 fieldOnCells->setName("MyTensorFieldOnCellNoTime");
2467 fieldOnCells->setTimeUnit("ms"); // Time unit is ms.
2468 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
2469 fieldOnCells->setMesh(mesh);
2470 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnCells
2471 MEDCoupling::DataArrayDouble *array=MEDCoupling::DataArrayDouble::New();
2472 array->alloc(fieldOnCells->getMesh()->getNumberOfCells(),2);//Implicitly fieldOnCells will be a 2 components field.
2473 array->fillWithValue(7.);
2474 fieldOnCells->setArray(array);
2476 // fieldOnCells is now usable
2478 // fieldOnCells is no more useful here : release it
2479 fieldOnCells->decrRef();
2480 //! [CppSnippetFieldDoubleBuild3_1]
2483 void CppSnippetFieldDoubleBuild4()
2485 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2486 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2487 MEDCoupling::DataArrayDouble *arrX=MEDCoupling::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2488 MEDCoupling::DataArrayDouble *arrY=MEDCoupling::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2489 MEDCoupling::MEDCouplingCMesh *mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh");
2490 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2491 //! [CppSnippetFieldDoubleBuild4_1]
2492 MEDCoupling::MEDCouplingFieldDouble* fieldOnNodes=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_NODES,MEDCoupling::CONST_ON_TIME_INTERVAL);
2493 fieldOnNodes->setName("MyVecFieldOnNodeWithConstTime");
2494 fieldOnNodes->setTimeUnit("ms"); // Time unit is ms.
2495 fieldOnNodes->setStartTime(4.22,2,-1);
2496 fieldOnNodes->setEndTime(6.44,4,-1); // fieldOnNodes is defined in interval [4.22 ms,6.44 ms]
2497 fieldOnNodes->setMesh(mesh);
2498 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnNodes
2499 MEDCoupling::DataArrayDouble *array=MEDCoupling::DataArrayDouble::New();
2500 array->alloc(fieldOnNodes->getMesh()->getNumberOfNodes(),3);//Implicitly fieldOnNodes will be a 3 components field.
2501 array->fillWithValue(8.);
2502 fieldOnNodes->setArray(array);
2504 // fieldOnNodes is now usable
2506 // fieldOnNodes is no more useful here : release it
2507 fieldOnNodes->decrRef();
2508 //! [CppSnippetFieldDoubleBuild4_1]
2511 int main(int argc, char *argv[])
2513 CppExample_MEDCouplingFieldDouble_WriteVTK();
2514 CppExample_MEDCouplingFieldDouble_MaxFields();
2515 CppExample_MEDCouplingFieldDouble_MergeFields();
2516 CppExample_MEDCouplingFieldDouble_substractInPlaceDM();
2517 CppExample_MEDCouplingFieldDouble_changeUnderlyingMesh();
2518 CppExample_MEDCouplingFieldDouble_applyFunc_same_nb_comp();
2519 CppExample_MEDCouplingFieldDouble_applyFunc3();
2520 CppExample_MEDCouplingFieldDouble_applyFunc2();
2521 CppExample_MEDCouplingFieldDouble_applyFunc();
2522 CppExample_MEDCouplingFieldDouble_applyFunc_val();
2523 CppExample_MEDCouplingFieldDouble_fillFromAnalytic3();
2524 CppExample_MEDCouplingFieldDouble_fillFromAnalytic2();
2525 CppExample_MEDCouplingFieldDouble_fillFromAnalytic();
2526 CppExample_MEDCouplingFieldDouble_fillFromAnalytic_c_func();
2527 CppExample_MEDCouplingFieldDouble_applyFunc_c_func();
2528 CppExample_MEDCouplingFieldDouble_getValueOn_time();
2529 CppExample_MEDCouplingFieldDouble_getValueOnMulti();
2530 CppExample_MEDCouplingFieldDouble_getValueOn();
2531 CppExample_MEDCouplingFieldDouble_getValueOnPos();
2532 CppExample_MEDCouplingFieldDouble_renumberNodes();
2533 CppExample_MEDCouplingFieldDouble_renumberCells();
2534 CppExample_MEDCouplingFieldDouble_buildNewTimeReprFromThis();
2535 CppExample_MEDCouplingMesh_fillFromAnalytic3();
2536 CppExample_MEDCouplingMesh_fillFromAnalytic2();
2537 CppExample_MEDCouplingMesh_fillFromAnalytic();
2538 CppExample_MEDCouplingCMesh_getCoordsAt();
2539 CppExample_MEDCouplingUMesh_areCellsIncludedIn();
2540 CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells();
2541 CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented();
2542 CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented();
2543 CppExample_MEDCouplingUMesh_getCellsContainingPoints();
2544 CppExample_MEDCouplingUMesh_getCellsContainingPoint();
2545 CppExample_MEDCouplingUMesh_buildPartOrthogonalField();
2546 CppExample_MEDCouplingUMesh_getPartMeasureField();
2547 CppExample_MEDCouplingUMesh_getCellsInBoundingBox();
2548 CppExample_MEDCouplingUMesh_renumberNodesInConn();
2549 CppExample_MEDCouplingUMesh_renumberNodes();
2550 CppExample_MEDCouplingUMesh_findBoundaryNodes();
2551 CppExample_MEDCouplingUMesh_buildBoundaryMesh();
2552 CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode();
2553 CppExample_MEDCouplingUMesh_buildPartOfMySelfNode();
2554 CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes();
2555 CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds();
2556 CppExample_MEDCouplingUMesh_buildPartOfMySelf();
2557 CppExample_MEDCouplingUMesh_mergeNodes();
2558 CppExample_MEDCouplingUMesh_zipConnectivityTraducer();
2559 CppExample_MEDCouplingUMesh_zipCoordsTraducer();
2560 CppExample_MEDCouplingUMesh_getNodeIdsInUse();
2561 CppExample_MEDCouplingUMesh_convertToPolyTypes();
2562 CppExample_MEDCouplingUMesh_buildDescendingConnectivity2();
2563 CppExample_MEDCouplingUMesh_buildDescendingConnectivity();
2564 CppExample_MEDCouplingUMesh_getReverseNodalConnectivity();
2565 CppExample_MEDCouplingUMesh_checkDeepEquivalWith();
2566 CppExample_MEDCouplingPointSet_scale();
2567 CppExample_MEDCouplingPointSet_translate();
2568 CppExample_MEDCouplingPointSet_rotate();
2569 CppExample_MEDCouplingPointSet_getBoundingBox();
2570 CppExample_MEDCouplingPointSet_getNodeIdsNearPoint();
2571 CppExample_MEDCouplingPointSet_getNodeIdsNearPoints();
2572 CppExample_MEDCouplingPointSet_findCommonNodes();
2573 CppExample_MEDCouplingPointSet_getCoordinatesOfNode();
2574 CppExample_DataArrayInt_buildPermutationArr();
2575 CppExample_DataArrayInt_invertArrayO2N2N2O();
2576 CppExample_DataArrayInt_invertArrayN2O2O2N();
2577 CppExample_DataArrayDouble_getIdsInRange();
2578 CppExample_DataArrayDouble_findCommonTuples();
2579 CppExample_DataArrayDouble_Meld1();
2580 CppExampleFieldDoubleBuildSubPart1();
2581 CppSnippetUMeshStdBuild1();
2582 CppSnippetUMeshAdvBuild1();
2583 CppSnippetDataArrayBuild1();
2584 CppSnippetCMeshStdBuild1();
2585 CppSnippetFieldDoubleBuild1();
2586 CppSnippetFieldDoubleBuild2();
2587 CppSnippetFieldDoubleBuild3();
2588 CppSnippetFieldDoubleBuild4();