1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingBasicsTest.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingMultiFields.hxx"
30 void CppExample_MEDCouplingFieldDouble_WriteVTK()
32 using namespace ParaMEDMEM;
33 //! [CppSnippet_MEDCouplingFieldDouble_WriteVTK_1]
35 const double coords[3] = {0.,2.,4.};
36 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
37 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
38 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh1 = MEDCouplingCMesh::New();
39 mesh1->setCoords(coordsArr,coordsArr); // mesh becomes a 2D one
41 // 3 fields (lying on the same mesh!)
42 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field1 =
43 mesh1->getMeasureField( true );
44 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2 =
45 mesh1->buildOrthogonalField();
46 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field3 =
47 mesh1->fillFromAnalytic( ON_CELLS, 1, "x");
48 field2->setName( "Normal" ); // name is necessary!
49 field3->setName( "Barycenter" ); // name is necessary!
52 const char fileName[] = "testExample_MEDCouplingFieldDouble_WriteVTK.vtk";
53 std::vector<const MEDCouplingFieldDouble *> fs( 3 ); // field series
57 MEDCouplingFieldDouble::WriteVTK( fileName, fs );
58 //! [CppSnippet_MEDCouplingFieldDouble_WriteVTK_1]
62 void CppExample_MEDCouplingFieldDouble_MaxFields()
64 using namespace ParaMEDMEM;
65 //! [CppSnippet_MEDCouplingFieldDouble_MaxFields_1]
66 const double vals1[4] = {0.,2., 4.,6.}; // for field 1
67 const double vals2[4] = {2.,0., 6.,4.}; // for field 2
68 const double valsMax[4] = {2.,2., 6.,6.}; // expected max field
69 const double valsMin[4] = {0.,0., 4.,4.}; // expected min field
71 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> valsArr1 = DataArrayDouble::New();
72 valsArr1->useExternalArrayWithRWAccess( vals1, 2,2 ); // 2 tuples per 2 components
73 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field1 = MEDCouplingFieldDouble::New( ON_NODES );
74 field1->setArray( valsArr1 );
76 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> valsArr2 = DataArrayDouble::New();
77 valsArr2->useExternalArrayWithRWAccess( vals2, 2,2 ); // 2 tuples per 2 components
78 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2 = MEDCouplingFieldDouble::New( ON_NODES );
79 field2->setArray( valsArr2 );
81 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> fieldMax = MEDCouplingFieldDouble::MaxFields( field1, field2 );
82 CPPUNIT_ASSERT( std::equal( valsMax, valsMax+4, fieldMax->getArray()->getConstPointer() )); // fieldMax == valsMax
84 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> fieldMin = MEDCouplingFieldDouble::MinFields( field1, field2 );
85 CPPUNIT_ASSERT( std::equal( valsMin, valsMin+4, fieldMin->getArray()->getConstPointer() )); // fieldMin == valsMin
86 //! [CppSnippet_MEDCouplingFieldDouble_MaxFields_1]
89 void CppExample_MEDCouplingFieldDouble_MergeFields()
91 using namespace ParaMEDMEM;
92 //! [CppSnippet_MEDCouplingFieldDouble_MergeFields_1]
94 const double coords[3] = {0.,2.,4.};
95 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
96 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
97 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh1 = MEDCouplingCMesh::New();
98 mesh1->setCoords(coordsArr); // mesh becomes a 1D
100 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field1 =
101 mesh1->fillFromAnalytic( ON_CELLS, 1, "x");
104 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2 =
105 field1->cloneWithMesh( true );
106 double vec[1] = { 5. };
107 (const_cast<ParaMEDMEM::MEDCouplingMesh *>(field2->getMesh()))->translate(vec); // translate mesh2
108 field2->applyFunc("x + 5"); // "translate" field2
110 // concatenate field1 and field2
111 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field3 =
112 MEDCouplingFieldDouble::MergeFields( field1, field2 );
113 std::vector<const MEDCouplingFieldDouble *> fields( 2 );
116 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field4 =
117 MEDCouplingFieldDouble::MergeFields( fields );
118 //! [CppSnippet_MEDCouplingFieldDouble_MergeFields_1]
121 void CppExample_MEDCouplingFieldDouble_substractInPlaceDM()
123 using namespace ParaMEDMEM;
124 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_1]
125 const double coords1[4] = {0.,1.,2.,3.};
126 const double coords2[4] = {2.,1.,0.,3.}; // #0 <==> #2
128 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1 = MEDCouplingUMesh::New();
129 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
130 coordsArr->useExternalArrayWithRWAccess( coords1, 4, 1 );
131 mesh1->setCoords(coordsArr);
132 mesh1->setMeshDimension(0);
133 mesh1->allocateCells(0);
134 mesh1->finishInsertingCells();
136 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
137 (MEDCouplingUMesh*) mesh1->deepCpy();
138 mesh2->getCoords()->useExternalArrayWithRWAccess( coords2, 4, 1 );
139 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_1]
140 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_2]
141 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field1 =
142 mesh1->fillFromAnalytic( ParaMEDMEM::ON_NODES,1,"x"); // field1 values == coords1
143 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2 =
144 mesh2->fillFromAnalytic( ParaMEDMEM::ON_NODES,1,"x"); // field2 values == coords2
145 const double levOfCheck = 10; // nodes can be permuted
146 field1->substractInPlaceDM( field2, levOfCheck, 1e-13, 0 ); // values #0 and #2 must swap
147 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_2]
148 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_3]
149 field2->applyFunc( 1, 0.0 ); // all field2 values == 0.0
150 CPPUNIT_ASSERT( field1->isEqual( field2, 1e-13, 1e-13 )); // field1 == field2 == 0.0
151 //! [CppSnippet_MEDCouplingFieldDouble_substractInPlaceDM_3]
154 void CppExample_MEDCouplingFieldDouble_changeUnderlyingMesh()
156 using namespace ParaMEDMEM;
157 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_1]
158 const double coords1[4] = {0.,1.,2.,3.};
159 const double coords2[4] = {2.,1.,0.,3.}; // #0 <==> #2
161 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1 = MEDCouplingUMesh::New();
162 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
163 coordsArr->useExternalArrayWithRWAccess( coords1, 4, 1 );
164 mesh1->setCoords(coordsArr);
165 mesh1->setMeshDimension(0);
166 mesh1->allocateCells(0);
167 mesh1->finishInsertingCells();
169 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
170 (MEDCouplingUMesh*) mesh1->deepCpy();
171 mesh2->getCoords()->useExternalArrayWithRWAccess( coords2, 4, 1 );
172 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_1]
173 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_2]
174 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
175 mesh1->fillFromAnalytic( ParaMEDMEM::ON_NODES,1,"x"); // field values == coords1
176 const double levOfCheck = 10; // nodes can be permuted
177 field->changeUnderlyingMesh( mesh2, levOfCheck, 1e-13, 0 ); // values #0 and #2 must swap
178 CPPUNIT_ASSERT( std::equal( coords2, coords2+4, field->getArray()->getConstPointer() ));
179 //! [CppSnippet_MEDCouplingFieldDouble_changeUnderlyingMesh_2]
182 void CppExample_MEDCouplingFieldDouble_applyFunc_same_nb_comp()
184 using namespace ParaMEDMEM;
185 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_1]
186 const double v[4] = {1.,2., 3.,4.};
187 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> array = DataArrayDouble::New();
188 array->useExternalArrayWithRWAccess( v, 2, 2 ); // 2 tuples per 2 components
189 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
190 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
191 field->setArray( array );
192 const char func[] = "IVec * v + JVec * v*v + 10";
193 field->applyFunc( func );
194 CPPUNIT_ASSERT( field->getNumberOfComponents() == 2 ); // 2 components remains
195 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_1]
196 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_2]
197 const double* v2 = field->getArray()->getConstPointer();
198 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[0], 10 + v[0], 13 ); // "10 + IVec * v"
199 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[1], 10 + v[1]*v[1], 13 ); // "10 + JVec * v*v"
200 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[2], 10 + v[2], 13 ); // "10 + IVec * v"
201 CPPUNIT_ASSERT_DOUBLES_EQUAL( v2[3], 10 + v[3]*v[3], 13 ); // "10 + JVec * v*v"
202 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_same_nb_comp_2]
205 void CppExample_MEDCouplingFieldDouble_applyFunc3()
207 using namespace ParaMEDMEM;
208 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_1]
209 // create a 2D vector field
210 const double values[4] = {1.,1., 2.,1.};
211 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> array = DataArrayDouble::New();
212 array->useExternalArrayWithRWAccess( values, 2, 2 ); // 2 tuples per 2 components
213 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
214 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
215 field->setArray( array );
216 // transform the field to a 3D vector field
217 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
218 const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y components
219 std::vector<std::string> varNamesVec( varNames, varNames+2 );
220 field->applyFunc3( 3, varNamesVec, func ); // require 3 components
221 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components as required
222 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_1]
223 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_2]
224 double vec1[3]; // vector #1
225 field->getArray()->getTuple( 1, vec1 );
226 const double a = values[2], b = values[3]; // initial components of the vector #1
227 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[0], 10 + b, 13 ); // "10 + IVec * b"
228 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[1], 10 + a, 13 ); // "10 + JVec * a"
229 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[2], 10 + sqrt(a*a+b*b), 13 ); // "10 + KVec * sqrt( a*a + b*b )"
230 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc3_2]
233 void CppExample_MEDCouplingFieldDouble_applyFunc2()
235 using namespace ParaMEDMEM;
236 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_1]
237 // create a 2D vector field
238 const double values[4] = {1.,1., 2.,1.};
239 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> array = DataArrayDouble::New();
240 array->useExternalArrayWithRWAccess( values, 2, 2 ); // 2 tuples per 2 components
241 array->setInfoOnComponent(0,"a"); // name used to refer to X component within a function
242 array->setInfoOnComponent(1,"b"); // name used to refer to Y component within a function
243 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
244 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
245 field->setArray( array );
246 // transform the field to a 3D vector field
247 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
248 field->applyFunc2( 3, func ); // require 3 components
249 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components as required
250 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_1]
251 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_2]
252 double vec1[3]; // vector #1
253 field->getArray()->getTuple( 1, vec1 );
254 const double a = values[2], b = values[3]; // initial components of the vector #1
255 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[0], 10 + b, 13 ); // "10 + IVec * b"
256 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[1], 10 + a, 13 ); // "10 + JVec * a"
257 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[2], 10 + sqrt(a*a+b*b), 13 ); // "10 + KVec * sqrt( a*a + b*b )"
258 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc2_2]
261 void CppExample_MEDCouplingFieldDouble_applyFunc()
263 using namespace ParaMEDMEM;
264 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_1]
265 // create a 2D vector field
266 const double values[4] = {1.,1., 2.,1.};
267 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> array = DataArrayDouble::New();
268 array->useExternalArrayWithRWAccess( values, 2, 2 ); // 2 tuples per 2 components
269 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
270 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
271 field->setArray( array );
272 // transform the field to a 3D vector field
273 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
274 field->applyFunc( 3, func ); // require 3 components
275 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components as required
276 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_1]
277 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_2]
278 double vec1[3]; // vector #1
279 field->getArray()->getTuple( 1, vec1 );
280 const double a = values[2], b = values[3]; // initial components of the vector #1
281 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[0], 10 + b, 13 ); // "10 + IVec * b"
282 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[1], 10 + a, 13 ); // "10 + JVec * a"
283 CPPUNIT_ASSERT_DOUBLES_EQUAL( vec1[2], 10 + sqrt(a*a+b*b), 13 ); // "10 + KVec * sqrt( a*a + b*b )"
284 //! [CppSnippet_MEDCouplingFieldDouble_applyFunc_2]
287 void CppExample_MEDCouplingFieldDouble_applyFunc_val()
289 using namespace ParaMEDMEM;
290 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_1]
292 const double coords[4] = {0.,2.,4.};
293 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
294 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
295 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
296 mesh->setCoords(coordsArr,coordsArr); // mesh becomes a 2D structured mesh
298 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
299 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
300 field->setMesh( mesh );
301 field->fillFromAnalytic(2,"IVec * x + JVec * y"); // 2 components
302 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_1]
303 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_2]
304 const double newValue = 7.;
305 field->applyFunc( 3, newValue ); // # 3 components are required
306 CPPUNIT_ASSERT( field->getIJ(1,0) == newValue ); // a value is as expected
307 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 );
308 CPPUNIT_ASSERT( field->getNumberOfTuples() == mesh->getNumberOfCells() );
309 //! [Snippet_MEDCouplingFieldDouble_applyFunc_val_2]
312 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic3()
314 using namespace ParaMEDMEM;
315 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_1]
316 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
317 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
318 x->useExternalArrayWithRWAccess( coords, 3, 1 );
319 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
320 y->useExternalArrayWithRWAccess( coords, 2, 1 );
321 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
322 mesh->setCoords(x,y);
323 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_1]
324 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_2]
325 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
326 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
327 field->setMesh( mesh );
328 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
329 const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y coord components
330 std::vector<std::string> varNamesVec( varNames, varNames+2 );
331 field->fillFromAnalytic3( 3, varNamesVec, func );
332 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_2]
333 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_3]
334 double val1[3]; // a value (vector) of the cell #1
335 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
336 field->getArray()->getTuple( 1, val1 );
338 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
339 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
340 double bc1[2]; // coordinates of the second point
341 bc->getTuple( 1, bc1 );
343 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
344 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
345 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
346 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
347 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic3_3]
350 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic2()
352 using namespace ParaMEDMEM;
353 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_1]
354 const double coords[4] = {0.,2.,4.};
355 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
356 x->useExternalArrayWithRWAccess( coords, 3, 1 );
357 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
358 y->useExternalArrayWithRWAccess( coords, 2, 1 );
359 x->setInfoOnComponent(0,"a"); // name used to refer to X coordinate within a function
360 y->setInfoOnComponent(0,"b"); // name used to refer to Y coordinate within a function
361 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
362 mesh->setCoords(x,y);
363 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_1]
364 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_2]
365 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
366 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
367 field->setMesh( mesh );
368 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
369 field->fillFromAnalytic( 3, func );
370 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_2]
371 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_3]
372 double val1[3]; // a value (vector) of the cell #1
373 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
374 field->getArray()->getTuple( 1, val1 );
376 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
377 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
378 double bc1[2]; // coordinates of the second point
379 bc->getTuple( 1, bc1 );
381 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
382 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
383 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
384 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
385 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic2_3]
388 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic()
390 using namespace ParaMEDMEM;
391 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_1]
392 const double coords[3] = {0.,2.,4};
393 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
394 x->useExternalArrayWithRWAccess( coords, 3, 1 );
395 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
396 y->useExternalArrayWithRWAccess( coords, 2, 1 );
397 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
398 mesh->setCoords(x,y);
399 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_1]
400 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_2]
401 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
402 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
403 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
404 field->setMesh( mesh );
405 field->fillFromAnalytic( 3, func );
406 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_2]
407 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_3]
408 double val1[3]; // a value (vector) of the cell #1
409 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
410 field->getArray()->getTuple( 1, val1 );
412 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
413 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
414 double bc1[2]; // coordinates of the second point
415 bc->getTuple( 1, bc1 );
417 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
418 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
419 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
420 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
421 //! [CppSnippet_MEDCouplingFieldDouble_fillFromAnalytic_3]
424 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_0]
425 bool getNewValue(const double *pos, double *res)
429 res[2] = sqrt( pos[0]*pos[0] + pos[1]*pos[1] );
432 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_0]
434 void CppExample_MEDCouplingFieldDouble_fillFromAnalytic_c_func()
436 using namespace ParaMEDMEM;
437 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_1]
439 const double coords[4] = {0.,2.,4.};
440 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
441 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
442 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
443 mesh->setCoords(coordsArr,coordsArr); // mesh becomes a 2D structured mesh
445 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
446 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
447 field->setMesh( mesh );
448 field->fillFromAnalytic( 3, &getNewValue ); // 3 components are required
449 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 );
450 CPPUNIT_ASSERT( field->getNumberOfTuples() == mesh->getNumberOfCells() );
451 //! [Snippet_MEDCouplingFieldDouble_fillFromAnalytic_c_func_1]
454 void CppExample_MEDCouplingFieldDouble_applyFunc_c_func()
456 using namespace ParaMEDMEM;
457 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_1]
459 const double coords[4] = {0.,2.,4.};
460 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
461 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
462 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
463 mesh->setCoords(coordsArr,coordsArr); // mesh becomes a 2D structured mesh
465 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
466 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS );
467 field->setMesh( mesh );
468 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc = mesh->getBarycenterAndOwner();
469 field->setArray( bc ); // 2 components here as the mesh is 2D
470 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_1]
471 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_2]
472 field->applyFunc( 3, &getNewValue ); // 3 components are required
473 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 );
474 CPPUNIT_ASSERT( field->getNumberOfTuples() == mesh->getNumberOfCells() );
475 //! [Snippet_MEDCouplingFieldDouble_applyFunc_c_func_2]
478 void CppExample_MEDCouplingFieldDouble_getValueOn_time()
480 using namespace ParaMEDMEM;
481 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_1]
482 const double coords[4] = {0.,2.,4.};
483 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
484 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
485 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
486 mesh->setCoords(coordsArr,coordsArr);
487 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_1]
488 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_2]
489 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
490 MEDCouplingFieldDouble::New( ParaMEDMEM::ON_CELLS, ParaMEDMEM::LINEAR_TIME );
491 field->setMesh( mesh );
492 field->fillFromAnalytic( 1,"10"); // all values == 10.
493 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> array2 =
494 DataArrayDouble::Add( field->getArray(), field->getArray() ); // == 2 * field->getArray()
495 field->setEndArray( array2 ); // all values == 20.
496 const double time1 = 1.1, time2 = 22.;
497 field->setStartTime( time1, 0, 0 );
498 field->setEndTime ( time2, 0, 0 );
499 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_2]
500 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_3]
501 const double pos[2] = { 1., 1. }; // we are in 2D space
502 double value[1]; // the field is scalar <-> 1 component
503 field->getValueOn( pos, 0.5*( time1 + time2 ), value );
504 CPPUNIT_ASSERT( fabs( value[0] - 0.5*( 10. + 20. )) < 1e-13 );
505 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_time_3]
508 void CppExample_MEDCouplingFieldDouble_getValueOnMulti()
510 using namespace ParaMEDMEM;
511 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_1]
512 const double coords[4] = {0.,2.,4.};
513 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
514 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
515 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
516 mesh->setCoords(coordsArr,coordsArr);
517 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
518 mesh->fillFromAnalytic( ParaMEDMEM::ON_CELLS,1,"x+y");
519 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_1]
520 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_2]
521 // field values are located at cell barycenters
522 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc = mesh->getBarycenterAndOwner();
523 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> valArray =
524 field->getValueOnMulti( bc->getConstPointer(), bc->getNumberOfTuples() );
525 CPPUNIT_ASSERT( valArray->isEqual( * field->getArray(), 1e-13 ));
526 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnMulti_2]
529 void CppExample_MEDCouplingFieldDouble_getValueOn()
531 using namespace ParaMEDMEM;
532 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_1]
533 const double coords[4] = {0.,2.,4.};
534 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
535 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
536 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
537 mesh->setCoords(coordsArr,coordsArr);
538 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
539 mesh->fillFromAnalytic( ParaMEDMEM::ON_CELLS,1,"x+y");
540 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_1]
541 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_2]
542 // field values are located at cell barycenters
543 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc = mesh->getBarycenterAndOwner();
544 std::vector<double> vals( field->getNumberOfTuples() ); // array to collect values returned by getValueOn()
545 double cellBC[2]; // we are in 2D space
546 for ( int i = 0; i < bc->getNumberOfTuples(); ++i )
548 bc->getTuple( i, cellBC );
549 field->getValueOn( cellBC, & vals[i] );
551 CPPUNIT_ASSERT( std::equal( vals.begin(), vals.end(), field->getArray()->getConstPointer() ));
552 //! [CppSnippet_MEDCouplingFieldDouble_getValueOn_2]
555 void CppExample_MEDCouplingFieldDouble_getValueOnPos()
557 using namespace ParaMEDMEM;
558 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_1]
559 const double coords[4] = {0.,2.,4.};
560 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
561 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
562 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
563 mesh->setCoords(coordsArr,coordsArr);
564 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
565 mesh->fillFromAnalytic( ParaMEDMEM::ON_CELLS,1,"x+y");
566 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_1]
567 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_2]
568 double val11[1]; // 1 == field->getNumberOfComponents()
569 field->getValueOnPos( 1,1,-1, val11 );
570 // field values are located at cell barycenters
571 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc = mesh->getBarycenterAndOwner();
572 CPPUNIT_ASSERT( val11[0] == bc->getIJ(3,0) + bc->getIJ(3,1) );
573 //! [CppSnippet_MEDCouplingFieldDouble_getValueOnPos_2]
576 void CppExample_MEDCouplingFieldDouble_renumberNodes()
578 using namespace ParaMEDMEM;
579 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_1]
580 const double coords[4] = {0.,2.,4.};
581 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
582 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
583 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> cmesh = MEDCouplingCMesh::New();
584 cmesh->setCoords(coordsArr,coordsArr);
585 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh = cmesh->buildUnstructured();
586 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_1]
587 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_2]
588 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
589 mesh->fillFromAnalytic( ParaMEDMEM::ON_NODES,2,"IVec*x+JVec*y");
590 const DataArrayDouble* values = field->getArray();
591 const DataArrayDouble* nodeCoords = mesh->getCoords();
592 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *nodeCoords, 1e-13 ));
593 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_2]
594 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_3]
595 const int renumber[9] = { 8, 7, 6, 5, 4, 3, 2, 1, 0 };
596 field->renumberNodes(renumber,false);
597 const MEDCouplingMesh* mesh2 = field->getMesh(); // field now refers to another mesh
598 values = field->getArray();
599 nodeCoords = (static_cast<const MEDCouplingUMesh*>(mesh2))->getCoords();
600 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *nodeCoords, 1e-13 ));
601 //! [CppSnippet_MEDCouplingFieldDouble_renumberNodes_3]
604 void CppExample_MEDCouplingFieldDouble_renumberCells()
606 using namespace ParaMEDMEM;
607 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_1]
608 const double coords[4] = {0.,2.,4.};
609 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
610 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
611 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> cmesh = MEDCouplingCMesh::New();
612 cmesh->setCoords(coordsArr,coordsArr);
613 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh = cmesh->buildUnstructured();
614 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_1]
615 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_2]
616 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
617 mesh->fillFromAnalytic( ParaMEDMEM::ON_CELLS,2,"IVec*x+JVec*y");
618 const DataArrayDouble* values = field->getArray();
619 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc = mesh->getBarycenterAndOwner();
620 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *bc, 1e-13 ));
621 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_2]
622 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_3]
623 const int renumber[4] = { 3, 2, 1, 0 };
624 field->renumberCells(renumber,false);
625 const MEDCouplingMesh* mesh2 = field->getMesh(); // field now refers to another mesh
626 values = field->getArray();
627 bc = mesh2->getBarycenterAndOwner();
628 CPPUNIT_ASSERT( values->isEqualWithoutConsideringStr( *bc, 1e-13 ));
629 //! [CppSnippet_MEDCouplingFieldDouble_renumberCells_3]
632 void CppExample_MEDCouplingFieldDouble_buildNewTimeReprFromThis()
634 using namespace ParaMEDMEM;
635 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_1]
636 const double coords[4] = {0.,2.,4.};
637 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr = DataArrayDouble::New();
638 coordsArr->useExternalArrayWithRWAccess( coords, 3, 1 );
639 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh = MEDCouplingCMesh::New();
640 mesh->setCoords(coordsArr,coordsArr);
641 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field1 =
642 mesh->fillFromAnalytic( ParaMEDMEM::ON_NODES,1,"x+y");
643 CPPUNIT_ASSERT( field1->getTimeDiscretization() == ParaMEDMEM::ONE_TIME );
644 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_1]
645 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_2]
646 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2 =
647 field1->buildNewTimeReprFromThis( ParaMEDMEM::NO_TIME, false );
648 CPPUNIT_ASSERT( field2->getTimeDiscretization() == ParaMEDMEM::NO_TIME );
649 //! [CppSnippet_MEDCouplingFieldDouble_buildNewTimeReprFromThis_2]
652 void CppExample_MEDCouplingMesh_fillFromAnalytic3()
654 using namespace ParaMEDMEM;
655 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1]
656 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
657 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
658 x->useExternalArrayWithRWAccess( coords, 3, 1 );
659 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
660 y->useExternalArrayWithRWAccess( coords, 2, 1 );
661 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
662 mesh->setCoords(x,y);
663 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1]
664 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2]
665 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
666 const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y coord components
667 std::vector<std::string> varNamesVec( varNames, varNames+2 );
668 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
669 mesh->fillFromAnalytic3( ParaMEDMEM::ON_CELLS, 3, varNamesVec, func );
670 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2]
671 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3]
672 double val1[3]; // a value (vector) of the cell #1
673 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
674 field->getArray()->getTuple( 1, val1 );
676 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
677 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
678 double bc1[2]; // coordinates of the second point
679 bc->getTuple( 1, bc1 );
681 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
682 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
683 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
684 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
685 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3]
688 void CppExample_MEDCouplingMesh_fillFromAnalytic2()
690 using namespace ParaMEDMEM;
691 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1]
692 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
693 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
694 x->useExternalArrayWithRWAccess( coords, 3, 1 );
695 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
696 y->useExternalArrayWithRWAccess( coords, 2, 1 );
697 x->setInfoOnComponent(0,"a"); // name used to refer to X coordinate within a function
698 y->setInfoOnComponent(0,"b"); // name used to refer to Y coordinate within a function
699 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
700 mesh->setCoords(x,y);
701 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1]
702 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2]
703 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
704 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
705 mesh->fillFromAnalytic2( ParaMEDMEM::ON_CELLS, 3, func );
706 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2]
707 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3]
708 double val1[3]; // a value (vector) of the cell #1
709 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
710 field->getArray()->getTuple( 1, val1 );
712 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
713 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
714 double bc1[2]; // coordinates of the second point
715 bc->getTuple( 1, bc1 );
717 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
718 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
719 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
720 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
721 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3]
724 void CppExample_MEDCouplingMesh_fillFromAnalytic()
726 using namespace ParaMEDMEM;
727 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1]
728 const double coords[4] = {0.,2.,4.,6.}; // 6. is not used
729 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
730 x->useExternalArrayWithRWAccess( coords, 3, 1 );
731 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> y = DataArrayDouble::New();
732 y->useExternalArrayWithRWAccess( coords, 2, 1 );
733 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
734 mesh->setCoords(x,y);
735 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1]
736 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2]
737 const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10";
738 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field =
739 mesh->fillFromAnalytic( ParaMEDMEM::ON_CELLS, 3, func );
740 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2]
741 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3]
742 double val1[3]; // a value (vector) of the cell #1
743 CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field
744 field->getArray()->getTuple( 1, val1 );
746 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bc =
747 mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells
748 double bc1[2]; // coordinates of the second point
749 bc->getTuple( 1, bc1 );
751 double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )"
752 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[0], 10 + bc1[1], 13 ); // "10 + IVec * b"
753 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[1], 10 + bc1[0], 13 ); // "10 + JVec * a"
754 CPPUNIT_ASSERT_DOUBLES_EQUAL( val1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )"
755 //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3]
758 void CppExample_MEDCouplingCMesh_getCoordsAt()
760 using namespace ParaMEDMEM;
761 //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1]
762 const double coords[3] = {1.,2.,4.};
763 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> x = DataArrayDouble::New();
764 x->useExternalArrayWithRWAccess( coords, 3, 1 );
765 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New();
766 mesh->setCoordsAt(0,x);
767 const DataArrayDouble* x2=mesh->getCoordsAt(0);
768 CPPUNIT_ASSERT( x2->isEqual( *x, 1e-13 ));
769 //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1]
772 void CppExample_MEDCouplingUMesh_areCellsIncludedIn()
774 using namespace ParaMEDMEM;
775 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
776 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1=MEDCouplingUMesh::New();
777 mesh1->setMeshDimension(2);
778 mesh1->allocateCells(5);
779 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
780 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // #0
781 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // #1
782 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // #2
783 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // #3
784 mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // #4
785 mesh1->finishInsertingCells();
786 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
787 coordsArr->alloc(9,2);
788 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 };
789 std::copy(coords,coords+18,coordsArr->getPointer());
790 mesh1->setCoords(coordsArr);
791 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1]
792 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
793 const int cells2[3] = { 4,2,0 }; // even cells selected
794 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
795 (MEDCouplingUMesh*) mesh1->buildPartOfMySelf( cells2, cells2+3, true );
796 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2]
797 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
798 int compType = 0; // the strongest policy
799 DataArrayInt *corr2to1, *corr1to2;
800 // a larger mesh1 includes a smaller mesh2
801 CPPUNIT_ASSERT( mesh1->areCellsIncludedIn( mesh2, compType, corr2to1 ));
802 CPPUNIT_ASSERT( std::equal( cells2, cells2+3, corr2to1->getConstPointer() ));
803 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3]
804 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
805 // the smaller mesh2 does NOT include the larger mesh1
806 CPPUNIT_ASSERT( ! mesh2->areCellsIncludedIn( mesh1, compType, corr1to2 ));
807 const int corr1to2Expected[5] = {2, 3, 1, 4, 0};
808 CPPUNIT_ASSERT(std::equal( corr1to2Expected, corr1to2Expected+5, corr1to2->getConstPointer() ));
809 //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4]
814 void CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells()
816 using namespace ParaMEDMEM;
817 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
818 // 2D coordinates of 5 base nodes
819 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 };
820 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
821 coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 );
822 // coordinates of 5 top nodes
823 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr2 = coordsArr->deepCpy();
824 // 3D coordinates of base + top nodes
825 coordsArr = coordsArr-> changeNbOfComponents( 3, 0 );
826 coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 );
827 coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 );
829 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
830 mesh->setCoords(coordsArr);
831 mesh->setMeshDimension(3);
832 mesh->allocateCells(2);
833 // connectivity of reversed HEXA8 and PENTA6
834 const int conn[8+6]={0,1,4,3, 5,6,9,8, 1,2,4, 6,7,9};
835 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8, 8,conn+0);
836 mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+8);
837 mesh->finishInsertingCells();
838 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1]
839 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
840 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fixedCells =
841 mesh->findAndCorrectBadOriented3DExtrudedCells();
842 CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 2 ); // 2 cells fixed
843 fixedCells = mesh->findAndCorrectBadOriented3DExtrudedCells();
844 CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 0 ); // no bad cells
845 //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2]
848 void CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented()
850 using namespace ParaMEDMEM;
851 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
852 // 2D coordinates of 5 base nodes
853 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 };
854 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
855 coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 );
856 // coordinates of 5 top nodes
857 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr2 = coordsArr->deepCpy();
858 // 3D coordinates of base + top nodes
859 coordsArr = coordsArr-> changeNbOfComponents( 3, 0 );
860 coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 );
861 coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 );
863 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
864 mesh->setCoords(coordsArr);
865 mesh->setMeshDimension(3);
866 mesh->allocateCells(2);
867 // connectivity of a HEXA8 + a reversed PENTA6
868 const int conn[8+6]={0,3,4,1, 5,8,9,6, 1,2,4, 6,7,9};
869 mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,8,conn); // "extruded" polyhedron
870 mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,6,conn+8);
871 mesh->finishInsertingCells();
872 // fix connectivity of NORM_POLYHED's
873 mesh->convertExtrudedPolyhedra();
874 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1]
875 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
876 std::vector<int> badCellIds;
877 mesh->arePolyhedronsNotCorrectlyOriented( badCellIds );
878 CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one polyhedron is KO
879 // fix invalid rolyherdons
880 mesh->orientCorrectlyPolyhedrons();
881 // re-check orientation
882 badCellIds.clear(); // as badCellIds is not cleared by arePolyhedronsNotCorrectlyOriented()
883 mesh->arePolyhedronsNotCorrectlyOriented( badCellIds );
884 CPPUNIT_ASSERT( badCellIds.size() == 0 ); // connectivity is OK
885 //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2]
888 void CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented()
890 using namespace ParaMEDMEM;
891 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
892 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
893 mesh->setMeshDimension(2);
894 mesh->allocateCells(5);
895 const int conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4};
896 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
897 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
898 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
899 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
900 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
901 mesh->finishInsertingCells();
902 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
903 coordsArr->alloc(9,2);
904 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 };
905 std::copy(coords,coords+18,coordsArr->getPointer());
906 mesh->setCoords(coordsArr);
907 mesh->changeSpaceDimension(3);
908 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1]
909 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
910 const double vec[3] = {0.,0.,-1.};
911 std::vector<int> badCellIds;
912 mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds );
913 CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one cell is reversed
915 mesh->orientCorrectly2DCells( vec, false );
916 // re-check orientation
917 badCellIds.clear(); // as badCellIds is not cleared by are2DCellsNotCorrectlyOriented()
918 mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds );
919 CPPUNIT_ASSERT( badCellIds.size() == 0 ); // the orientation is OK
920 //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2]
923 void CppExample_MEDCouplingUMesh_getCellsContainingPoints()
925 using namespace ParaMEDMEM;
926 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
927 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
928 mesh->setMeshDimension(2);
929 mesh->allocateCells(5);
930 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
931 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
932 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
933 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
934 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
935 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
936 mesh->finishInsertingCells();
937 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
938 coordsArr->alloc(9,2);
939 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 };
940 std::copy(coords,coords+18,coordsArr->getPointer());
941 mesh->setCoords(coordsArr);
942 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1]
943 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
944 const double pos[3*2] = { 10., 10, // point out of the mesh
945 0.3, 0.3, // point located somewhere inside the mesh
946 coords[2], coords[3]}; // point at the node #1
947 const double eps = 1e-4; // ball radius
948 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cells, cellsIndex;
949 mesh->getCellsContainingPoints( pos, 3, eps, cells, cellsIndex );
950 const int cellsExpected[3]={4, 0, 1};
951 const int cellsIndexExpected[4]={0, 0, 1, 3};
952 CPPUNIT_ASSERT(std::equal( cellsExpected, cellsExpected+3, cells->begin()));
953 CPPUNIT_ASSERT(std::equal( cellsIndexExpected, cellsIndexExpected+4, cellsIndex->begin()));
954 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2]
957 void CppExample_MEDCouplingUMesh_getCellsContainingPoint()
959 using namespace ParaMEDMEM;
960 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
961 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
962 mesh->setMeshDimension(2);
963 mesh->allocateCells(5);
964 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
965 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
966 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
967 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
968 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
969 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
970 mesh->finishInsertingCells();
971 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
972 coordsArr->alloc(9,2);
973 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 };
974 std::copy(coords,coords+18,coordsArr->getPointer());
975 mesh->setCoords(coordsArr);
976 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1]
977 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
978 const double* coords4 = coords + 4*2; // coordinates of the node #4
979 const double eps = 1e-4; // ball radius
980 const double pos[2] = { coords4[0] + eps, coords4[1] - eps }; // ball center
981 std::vector<int> cellIds;
982 mesh->getCellsContainingPoint( pos, eps, cellIds );
983 CPPUNIT_ASSERT ( (int)cellIds.size() == mesh->getNumberOfCells() );
984 //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2]
987 void CppExample_MEDCouplingUMesh_buildPartOrthogonalField()
989 using namespace ParaMEDMEM;
990 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
991 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
992 mesh->setMeshDimension(2);
993 mesh->allocateCells(5);
994 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
995 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
996 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
997 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
998 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
999 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1000 mesh->finishInsertingCells();
1001 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1002 coordsArr->alloc(9,2);
1003 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 };
1004 std::copy(coords,coords+18,coordsArr->getPointer());
1005 mesh->setCoords(coordsArr);
1006 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1]
1007 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
1008 const int part[4] = {1,2,3,4}; // cell #0 is omitted
1009 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vecField=
1010 mesh->buildPartOrthogonalField( part, part+4 );
1011 CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfTuples() == 4 );
1012 CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfComponents() == 3 );
1013 //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2]
1016 void CppExample_MEDCouplingUMesh_getPartMeasureField()
1018 using namespace ParaMEDMEM;
1019 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1]
1020 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1021 mesh->setMeshDimension(2);
1022 mesh->allocateCells(5);
1023 const int conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4};
1024 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1025 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1026 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1027 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1028 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1029 mesh->finishInsertingCells();
1030 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1031 coordsArr->alloc(9,2);
1032 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 };
1033 std::copy(coords,coords+18,coordsArr->getPointer());
1034 mesh->setCoords(coordsArr);
1035 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1]
1036 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2]
1037 const bool isAbs = true;
1038 const int part[4] = {1,2,3,4}; // cell #0 is omitted
1039 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> areaArr=
1040 mesh->getPartMeasureField( isAbs, part, part+4 );
1041 CPPUNIT_ASSERT( areaArr->getIJ(0,0) > 0 ); // orientation ignored
1042 areaArr=mesh->getPartMeasureField( !isAbs, part, part+4 );
1043 CPPUNIT_ASSERT( areaArr->getIJ(0,0) < 0 ); // orientation considered
1044 CPPUNIT_ASSERT ( areaArr->getNumberOfTuples() == 4 );
1045 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2]
1046 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3]
1047 const int cellIds[4] = {1,2,3,4}; // cell #0 is omitted
1048 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> baryCenters=
1049 mesh->getPartBarycenterAndOwner( cellIds, cellIds+4 );
1050 CPPUNIT_ASSERT( baryCenters->getNumberOfTuples() == 4 );
1051 CPPUNIT_ASSERT( baryCenters->getNumberOfComponents() == mesh->getSpaceDimension() );
1052 //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3]
1055 void CppExample_MEDCouplingUMesh_getCellsInBoundingBox()
1057 using namespace ParaMEDMEM;
1058 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
1059 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1060 mesh->setMeshDimension(2);
1061 mesh->allocateCells(1);
1062 const double coords[3*2]={0.,0., 0.,1., 1.,1};
1063 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1064 coordsArr->useExternalArrayWithRWAccess(coords, 3,2);
1065 mesh->setCoords(coordsArr);
1066 mesh->allocateCells(1);
1067 const int conn[3]={0,1,2};
1068 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn);
1069 mesh->finishInsertingCells();
1070 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1]
1071 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
1072 const double bbox[] = {1., 1., 1.001,1.001}; // xMin, xMax, yMin, yMax
1073 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsArr =
1074 mesh->getCellsInBoundingBox( bbox, 0.0 );
1075 CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 0 );
1076 cellIdsArr = mesh->getCellsInBoundingBox( bbox, 0.1 );
1077 CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 1 );
1078 //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2]
1081 void CppExample_MEDCouplingUMesh_renumberNodesInConn()
1083 using namespace ParaMEDMEM;
1084 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1]
1085 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1086 mesh->setMeshDimension(2);
1087 mesh->allocateCells(1);
1088 const int conn[4]={4,3,2,1};
1089 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1090 mesh->finishInsertingCells();
1091 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1]
1092 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2]
1093 const int old2newIds[] = {-1,3,2,1,0};
1094 mesh->renumberNodesInConn( old2newIds );
1095 const int nodes0Expected[] = {0,1,2,3};
1096 std::vector<int> nodes0;
1097 mesh->getNodeIdsOfCell( 0, nodes0 );
1098 CPPUNIT_ASSERT(std::equal( nodes0Expected, nodes0Expected+4, &nodes0[0] ));
1099 //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2]
1102 void CppExample_MEDCouplingUMesh_renumberNodes()
1104 using namespace ParaMEDMEM;
1105 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1]
1106 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1107 mesh->setMeshDimension(2);
1108 const double coords[4*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.3};
1109 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1110 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1111 mesh->setCoords(coordsArr);
1112 mesh->allocateCells(0);
1113 mesh->finishInsertingCells();
1114 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1]
1115 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2]
1116 const int newIds[] = { 2,1,0,-1 };
1117 mesh->renumberNodes(newIds, 3);
1118 coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array
1119 const double coordsExpected[3*2]={0.7,-0.3, 0.2,-0.3, -0.3,-0.3};
1120 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsExpectedArr=DataArrayDouble::New();
1121 coordsExpectedArr->useExternalArrayWithRWAccess(coordsExpected, 3,2);
1122 CPPUNIT_ASSERT( coordsExpectedArr->isEqual( *coordsArr, 1e-13 ));
1123 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2]
1124 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3]
1125 coordsArr->useExternalArrayWithRWAccess(coords, 4,2); // restore old nodes
1126 const int newIds2[] = { 2,1,0,2 };
1127 mesh->renumberNodes2(newIds2, 3);
1128 coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array
1129 const double coordsExpected2[3*2]={0.7,-0.3, 0.2,-0.3, -0.3, 0.0};
1130 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsExpectedArr2=DataArrayDouble::New();
1131 coordsExpectedArr2->useExternalArrayWithRWAccess(coordsExpected2, 3,2);
1132 CPPUNIT_ASSERT( coordsExpectedArr2->isEqual( *coordsArr, 1e-13 ));
1133 //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3]
1136 void CppExample_MEDCouplingUMesh_findBoundaryNodes()
1138 using namespace ParaMEDMEM;
1139 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1]
1140 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1141 mesh->setMeshDimension(2);
1142 mesh->allocateCells(5);
1143 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1144 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1145 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1146 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1147 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1148 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1149 mesh->finishInsertingCells();
1150 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1151 coordsArr->alloc(9,2);
1152 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 };
1153 std::copy(coords,coords+18,coordsArr->getPointer());
1154 mesh->setCoords(coordsArr);
1155 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1]
1156 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2]
1157 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeIdsArr=mesh->findBoundaryNodes();
1158 CPPUNIT_ASSERT( nodeIdsArr->getNumberOfTuples() == mesh->getNumberOfNodes() - 1 );
1159 //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2]
1162 void CppExample_MEDCouplingUMesh_buildBoundaryMesh()
1164 using namespace ParaMEDMEM;
1165 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
1166 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1167 mesh->setMeshDimension(2);
1168 mesh->allocateCells(5);
1169 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1170 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1171 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1172 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1173 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1174 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1175 mesh->finishInsertingCells();
1176 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1177 coordsArr->alloc(9,2);
1178 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 };
1179 std::copy(coords,coords+18,coordsArr->getPointer());
1180 mesh->setCoords(coordsArr);
1181 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1]
1182 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
1183 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> mesh1=mesh->buildBoundaryMesh(true);
1184 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> mesh2=mesh->buildBoundaryMesh(false);
1185 CPPUNIT_ASSERT( coordsArr->isEqual( *mesh1->getCoords(), 1e-13 )); // same nodes
1186 CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // different nodes
1187 //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2]
1190 void CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode()
1192 using namespace ParaMEDMEM;
1193 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
1194 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1195 mesh->setMeshDimension(2);
1196 mesh->allocateCells(5);
1197 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1198 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1199 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1200 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1201 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1202 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1203 mesh->finishInsertingCells();
1204 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1205 coordsArr->alloc(9,2);
1206 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 };
1207 std::copy(coords,coords+18,coordsArr->getPointer());
1208 mesh->setCoords(coordsArr);
1209 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1]
1210 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
1211 std::vector<int> nodes;
1212 mesh->getNodeIdsOfCell( 0, nodes );
1213 const bool allNodes = true;
1214 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1 =
1215 (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),allNodes);
1216 CPPUNIT_ASSERT( mesh1->getNumberOfCells() == 4 ); // 4 segments bounding QUAD4 #0 only
1217 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
1218 (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),!allNodes);
1219 CPPUNIT_ASSERT( mesh2->getNumberOfCells() == 9 ); // more segments added
1220 //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2]
1223 void CppExample_MEDCouplingUMesh_buildPartOfMySelfNode()
1225 using namespace ParaMEDMEM;
1226 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
1227 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1228 mesh->setMeshDimension(2);
1229 mesh->allocateCells(5);
1230 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1231 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1232 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1233 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1234 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1235 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1236 mesh->finishInsertingCells();
1237 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1238 coordsArr->alloc(9,2);
1239 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 };
1240 std::copy(coords,coords+18,coordsArr->getPointer());
1241 mesh->setCoords(coordsArr);
1242 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1]
1243 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
1244 std::vector<int> nodes;
1245 mesh->getNodeIdsOfCell( 0, nodes );
1246 const bool allNodes = true;
1247 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh1 =
1248 (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(), allNodes);
1249 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2 =
1250 (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(),!allNodes);
1251 CPPUNIT_ASSERT_EQUAL( mesh1->getNumberOfCells(), 1 );
1252 CPPUNIT_ASSERT_EQUAL( mesh2->getNumberOfCells(), mesh->getNumberOfCells() );
1253 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2]
1256 void CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes()
1258 using namespace ParaMEDMEM;
1259 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
1260 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1261 mesh->setMeshDimension(2);
1262 mesh->allocateCells(5);
1263 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1264 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1265 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1266 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1267 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1268 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1269 mesh->finishInsertingCells();
1270 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1271 coordsArr->alloc(9,2);
1272 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 };
1273 std::copy(coords,coords+18,coordsArr->getPointer());
1274 mesh->setCoords(coordsArr);
1275 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1]
1276 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
1277 std::vector<int> nodes;
1278 mesh->getNodeIdsOfCell( 0, nodes );
1279 const bool allNodes = true;
1280 DataArrayInt* cellIdsArr1 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(), allNodes);
1281 DataArrayInt* cellIdsArr2 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(),!allNodes);
1282 CPPUNIT_ASSERT_EQUAL( cellIdsArr1->getNumberOfTuples(), 1 );
1283 CPPUNIT_ASSERT_EQUAL( cellIdsArr2->getNumberOfTuples(), mesh->getNumberOfCells() );
1284 //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2]
1285 cellIdsArr1->decrRef();
1286 cellIdsArr2->decrRef();
1289 void CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds()
1291 using namespace ParaMEDMEM;
1292 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
1293 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1294 mesh->setMeshDimension(2);
1295 mesh->allocateCells(5);
1296 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1297 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1298 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1299 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1300 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1301 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1302 mesh->finishInsertingCells();
1303 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1304 coordsArr->alloc(9,2);
1305 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 };
1306 std::copy(coords,coords+18,coordsArr->getPointer());
1307 mesh->setCoords(coordsArr);
1308 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1]
1309 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
1310 const int cellIds[2]={1,2};
1311 std::vector<int> nodes;
1312 mesh->getNodeIdsOfCell( cellIds[0], nodes );
1313 mesh->getNodeIdsOfCell( cellIds[1], nodes );
1314 DataArrayInt* cellIdsArr = mesh->getCellIdsFullyIncludedInNodeIds( &nodes[0], &nodes[0]+nodes.size());
1315 CPPUNIT_ASSERT(std::equal( cellIds, cellIds+2, cellIdsArr->getPointer() ));
1316 //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2]
1317 cellIdsArr->decrRef();
1320 void CppExample_MEDCouplingUMesh_buildPartOfMySelf()
1322 using namespace ParaMEDMEM;
1323 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
1324 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1325 mesh->setMeshDimension(2);
1326 mesh->allocateCells(5);
1327 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1328 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1329 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1330 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1331 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1332 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1333 mesh->finishInsertingCells();
1334 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1335 coordsArr->alloc(9,2);
1336 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 };
1337 std::copy(coords,coords+18,coordsArr->getPointer());
1338 mesh->setCoords(coordsArr);
1339 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1]
1340 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
1341 const int cellIds[2]={1,2};
1342 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
1343 MEDCouplingUMesh* mesh3=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,false);
1344 CPPUNIT_ASSERT( coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // same nodes
1345 CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh3->getCoords(), 1e-13 )); // different nodes
1346 for ( int i = 0; i < 2; ++i )
1348 std::vector<int> nodes1, nodes2;
1349 mesh ->getNodeIdsOfCell(cellIds[i], nodes1);
1350 mesh2->getNodeIdsOfCell(i, nodes2);
1351 CPPUNIT_ASSERT( nodes1 == nodes2 ); // cell #cellIds[i] was copied
1353 //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2]
1358 void CppExample_MEDCouplingUMesh_mergeNodes()
1360 using namespace ParaMEDMEM;
1361 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1]
1362 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1363 mesh->setMeshDimension(2);
1364 mesh->allocateCells(5);
1365 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2};
1366 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1367 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1368 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1369 mesh->finishInsertingCells();
1370 const double coords[6*2]={0.3,-0.301, // #0
1372 0.3,-0.302, // #2 ~~ #0
1374 1.1,0.0, // #4 == #3
1375 0.3,-0.303}; // #5 ~~ #0
1376 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1377 coordsArr->alloc(6,2);
1378 std::copy(coords,coords+6*2,coordsArr->getPointer());
1379 mesh->setCoords(coordsArr);
1380 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1]
1381 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2]
1382 bool areNodesMerged; int newNbOfNodes;
1383 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=
1384 mesh->mergeNodes(0.004,areNodesMerged,newNbOfNodes);
1385 const int idsExpected[6] = {0, 1, 0, 2, 2, 0};
1386 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+6,arr->getPointer()));
1387 CPPUNIT_ASSERT( areNodesMerged );
1388 CPPUNIT_ASSERT_EQUAL( 3, newNbOfNodes );
1389 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2]
1390 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3]
1391 const double* baryCoords2 = coords + 2*2; // initial coordinates of node #2
1392 coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array
1393 CPPUNIT_ASSERT( fabs( baryCoords2[1] - coordsArr->getIJ(0,1)) > 1e-4 ); // Y of node #0 differs from that of baryCoords2
1394 // restore coordinates
1395 coordsArr->alloc(6,2);
1396 std::copy(coords,coords+6*2,coordsArr->getPointer());
1397 mesh->setCoords(coordsArr);
1398 // call mergeNodes2()
1399 arr = mesh->mergeNodes2(0.004,areNodesMerged,newNbOfNodes);
1400 coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array
1401 CPPUNIT_ASSERT_DOUBLES_EQUAL( baryCoords2[1], coordsArr->getIJ(0,1), 13 ); // Y of node #0 equals to that of baryCoords2
1402 //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3]
1405 void CppExample_MEDCouplingUMesh_zipConnectivityTraducer()
1407 using namespace ParaMEDMEM;
1408 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
1409 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1410 mesh->setMeshDimension(2);
1411 mesh->allocateCells(5);
1412 const int conn[11]={0,3,4,1, 1,4,2, 4,1,0,3};
1413 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 0
1414 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1415 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 2 == 1
1416 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 3 == 0
1417 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+7); // 4 ~~ 0
1418 mesh->finishInsertingCells();
1419 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1420 coordsArr->alloc(9,2);
1421 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 };
1422 std::copy(coords,coords+18,coordsArr->getPointer());
1423 mesh->setCoords(coordsArr);
1424 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1]
1425 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
1426 const int oldNbCells = mesh->getNumberOfCells();
1427 DataArrayInt *arr = mesh->zipConnectivityTraducer(0);
1428 CPPUNIT_ASSERT_EQUAL( oldNbCells-2, mesh->getNumberOfCells() );
1429 const int idsExpected[5] = {0, 1, 1, 0, 2};
1430 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+5,arr->getPointer()));
1431 //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2]
1435 void CppExample_MEDCouplingUMesh_zipCoordsTraducer()
1437 using namespace ParaMEDMEM;
1438 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
1439 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1440 mesh->setMeshDimension(2);
1441 mesh->allocateCells(5);
1442 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1443 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1444 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1445 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1446 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1447 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1448 mesh->finishInsertingCells();
1449 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1450 coordsArr->alloc(9,2);
1451 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 };
1452 std::copy(coords,coords+18,coordsArr->getPointer());
1453 mesh->setCoords(coordsArr);
1454 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1]
1455 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
1456 const int cellIds[2]={1,2};
1457 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
1458 DataArrayInt *arr=mesh2->zipCoordsTraducer();
1459 CPPUNIT_ASSERT_EQUAL( 4, mesh2->getNumberOfNodes() ); // nb of nodes decreased
1460 CPPUNIT_ASSERT_EQUAL( mesh->getNumberOfNodes(), arr->getNumberOfTuples() );
1461 const int idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1}; // -1 for unused nodes
1462 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer()));
1463 //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2]
1468 void CppExample_MEDCouplingUMesh_getNodeIdsInUse()
1470 using namespace ParaMEDMEM;
1471 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
1472 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1473 mesh->setMeshDimension(2);
1474 mesh->allocateCells(5);
1475 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1476 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
1477 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4);
1478 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7);
1479 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
1480 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
1481 mesh->finishInsertingCells();
1482 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1483 coordsArr->alloc(9,2);
1484 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 };
1485 std::copy(coords,coords+18,coordsArr->getPointer());
1486 mesh->setCoords(coordsArr);
1487 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1]
1488 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
1489 const int cellIds[2]={1,2};
1490 MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true);
1491 int newNbOfNodes = 0;
1492 DataArrayInt *arr=mesh2->getNodeIdsInUse( newNbOfNodes );
1493 const int idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1};
1494 CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer()));
1495 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2]
1496 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
1497 DataArrayInt *arr2=arr->invertArrayO2N2N2O(newNbOfNodes);
1498 const int idsExpected2[4] = {1,2,4,5};
1499 CPPUNIT_ASSERT(std::equal(idsExpected2,idsExpected2+4,arr2->getPointer()));
1500 //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3]
1506 void CppExample_MEDCouplingUMesh_convertToPolyTypes()
1508 using namespace ParaMEDMEM;
1509 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1]
1510 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1511 mesh->setMeshDimension(2);
1512 mesh->allocateCells(5);
1513 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1514 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1515 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1516 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1517 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1518 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1519 mesh->finishInsertingCells();
1520 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1521 coordsArr->alloc(9,2);
1522 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 };
1523 std::copy(coords,coords+18,coordsArr->getPointer());
1524 mesh->setCoords(coordsArr);
1525 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1]
1526 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2]
1527 const int cells[2]={1,3};
1528 mesh->convertToPolyTypes(cells, cells+2);
1529 CPPUNIT_ASSERT( mesh->getTypeOfCell(0) == INTERP_KERNEL::NORM_QUAD4 );
1530 CPPUNIT_ASSERT( mesh->getTypeOfCell(1) == INTERP_KERNEL::NORM_POLYGON );
1531 CPPUNIT_ASSERT( mesh->getTypeOfCell(2) == INTERP_KERNEL::NORM_TRI3 );
1532 CPPUNIT_ASSERT( mesh->getTypeOfCell(3) == INTERP_KERNEL::NORM_POLYGON );
1533 //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2]
1536 void CppExample_MEDCouplingUMesh_buildDescendingConnectivity2()
1538 using namespace ParaMEDMEM;
1539 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
1540 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1541 mesh->setMeshDimension(2);
1542 mesh->allocateCells(5);
1543 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1544 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1545 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1546 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1547 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1548 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1549 mesh->finishInsertingCells();
1550 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1551 coordsArr->alloc(9,2);
1552 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 };
1553 std::copy(coords,coords+18,coordsArr->getPointer());
1554 mesh->setCoords(coordsArr);
1555 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1]
1556 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
1557 DataArrayInt *desc =DataArrayInt::New();
1558 DataArrayInt *descIndx =DataArrayInt::New();
1559 DataArrayInt *revDesc =DataArrayInt::New();
1560 DataArrayInt *revDescIndx=DataArrayInt::New();
1561 MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx);
1562 const int descExpected[] = {1,2,3,4,-3,5,6,7,8,-5,9,10,-2,11,12,13,-7,-10};
1563 const int descIndxExpected[] = {0,4,7,10,14,18};
1564 const int revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
1565 const int revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18};
1566 CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer()));
1567 CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer()));
1568 CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer()));
1569 CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer()));
1570 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2]
1571 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
1572 const int cell2ConnExpect[] = {4,1};
1573 std::vector<int> cell2Conn;
1574 mesh2->getNodeIdsOfCell( 3-1, cell2Conn ); // cell #3 in FORTRAN mode
1575 CPPUNIT_ASSERT(std::equal(cell2ConnExpect,cell2ConnExpect+2,&cell2Conn[0]));
1576 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3]
1578 descIndx->decrRef();
1580 revDescIndx->decrRef();
1584 void CppExample_MEDCouplingUMesh_buildDescendingConnectivity()
1586 using namespace ParaMEDMEM;
1587 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
1588 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1589 mesh->setMeshDimension(2);
1590 mesh->allocateCells(5);
1591 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1592 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1593 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1594 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1595 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1596 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1597 mesh->finishInsertingCells();
1598 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1599 coordsArr->alloc(9,2);
1600 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 };
1601 std::copy(coords,coords+18,coordsArr->getPointer());
1602 mesh->setCoords(coordsArr);
1603 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1]
1604 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
1605 DataArrayInt *desc =DataArrayInt::New();
1606 DataArrayInt *descIndx =DataArrayInt::New();
1607 DataArrayInt *revDesc =DataArrayInt::New();
1608 DataArrayInt *revDescIndx=DataArrayInt::New();
1609 MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
1610 const int descExpected[] = {0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
1611 const int descIndxExpected[] = {0,4,7,10,14,18};
1612 const int revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
1613 const int revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18};
1614 CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer()));
1615 CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer()));
1616 CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer()));
1617 CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer()));
1618 //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2]
1620 descIndx->decrRef();
1622 revDescIndx->decrRef();
1626 void CppExample_MEDCouplingUMesh_getReverseNodalConnectivity()
1628 using namespace ParaMEDMEM;
1629 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1630 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1631 mesh->setMeshDimension(2);
1632 mesh->allocateCells(5);
1633 const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
1634 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0
1635 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1
1636 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2
1637 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3
1638 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4
1639 mesh->finishInsertingCells();
1640 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1641 coordsArr->alloc(9,2);
1642 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 };
1643 std::copy(coords,coords+18,coordsArr->getPointer());
1644 mesh->setCoords(coordsArr);
1645 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1]
1646 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1647 DataArrayInt *revNodal=DataArrayInt::New();
1648 DataArrayInt *revNodalIndx=DataArrayInt::New();
1649 mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
1650 const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
1651 const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
1652 CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
1653 CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
1654 //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2]
1655 revNodal->decrRef();
1656 revNodalIndx->decrRef();
1659 void CppExample_MEDCouplingUMesh_checkDeepEquivalWith()
1661 using namespace ParaMEDMEM;
1662 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1664 MEDCouplingUMesh *mesh1=MEDCouplingUMesh::New();
1665 const double coords[4*2]={0.0,0.0, // #0
1670 mesh1->setMeshDimension(2);
1671 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1672 coordsArr->useExternalArrayWithRWAccess( coords, 4, 2 );
1673 mesh1->setCoords(coordsArr);
1674 mesh1->allocateCells(2);
1675 const int conn[6]={0,1,2, 1,2,3};
1676 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0
1677 mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1
1678 mesh1->finishInsertingCells();
1681 MEDCouplingUMesh *mesh2=MEDCouplingUMesh::New();
1682 const double coords2[4*2]={0.0,1.0, // #0 = #3
1685 1.0,1.001}; // #3 ~ #2
1687 mesh2->setMeshDimension(2);
1688 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1689 coordsArr->useExternalArrayWithRWAccess( coords2, 4, 2 );
1690 mesh2->setCoords(coordsArr);
1691 mesh2->allocateCells(2);
1692 const int conn[6]={2,3,0, 3,1,2};
1693 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0 = #1
1694 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1 ~ #0
1695 mesh2->finishInsertingCells();
1697 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1]
1698 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1699 int cellCompPol = 1; // "permuted same orientation" - policy of medium severity
1700 DataArrayInt *nOld2New, *cOld2New;
1701 mesh1->checkDeepEquivalWith( mesh2, cellCompPol, 0.002, cOld2New, nOld2New );
1702 const int nOld2NewExpected[4] = { 3, 0, 1, 2 };
1703 const int cOld2NewExpected[2] = { 1, 0 };
1704 CPPUNIT_ASSERT(std::equal(nOld2NewExpected,nOld2NewExpected+4,nOld2New->getConstPointer()));
1705 CPPUNIT_ASSERT(std::equal(cOld2NewExpected,cOld2NewExpected+2,cOld2New->getConstPointer()));
1706 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2]
1707 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1708 cOld2New->decrRef(); // else memory leaks
1709 CPPUNIT_ASSERT_THROW ( mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0.002, cOld2New ), INTERP_KERNEL::Exception );
1710 mesh2->setCoords( mesh1->getCoords() ); // make meshes share the same coordinates array
1711 mesh2->allocateCells(2);
1712 const int conn[6]={1,2,3, 1,0,2};
1713 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+0); // #0 = #1
1714 mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3); // #1 ~ #0
1715 mesh2->finishInsertingCells();
1716 cellCompPol = 2; // the weakest policy
1717 mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0, cOld2New );
1718 //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3]
1719 nOld2New->decrRef();
1720 cOld2New->decrRef();
1725 void CppExample_MEDCouplingPointSet_scale()
1727 using namespace ParaMEDMEM;
1728 //! [CppSnippet_MEDCouplingPointSet_scale_1]
1729 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
1730 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1731 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1732 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1733 mesh->setCoords(coordsArr);
1734 DataArrayDouble *initCoords = coordsArr->deepCpy();
1735 //! [CppSnippet_MEDCouplingPointSet_scale_1]
1736 //! [CppSnippet_MEDCouplingPointSet_scale_2]
1737 const double center[2] = {0.,0.};
1738 const double factor = 2.;
1739 mesh->scale( center, factor );
1740 //! [CppSnippet_MEDCouplingPointSet_scale_2]
1741 //! [CppSnippet_MEDCouplingPointSet_scale_3]
1742 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1743 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 ));
1744 CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 ));
1746 initCoords->decrRef();
1747 //! [CppSnippet_MEDCouplingPointSet_scale_3]
1750 void CppExample_MEDCouplingPointSet_translate()
1752 using namespace ParaMEDMEM;
1753 //! [CppSnippet_MEDCouplingPointSet_translate_1]
1754 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
1755 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1756 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1757 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1758 mesh->setCoords(coordsArr);
1759 DataArrayDouble *initCoords = coordsArr->deepCpy();
1760 //! [CppSnippet_MEDCouplingPointSet_translate_1]
1761 //! [CppSnippet_MEDCouplingPointSet_translate_2]
1762 double vector[2] = {1.,1.};
1763 mesh->translate( vector );
1764 //! [CppSnippet_MEDCouplingPointSet_translate_2]
1765 //! [CppSnippet_MEDCouplingPointSet_translate_3]
1766 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1767 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 ));
1768 CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 ));
1770 initCoords->decrRef();
1771 //! [CppSnippet_MEDCouplingPointSet_translate_3]
1774 void CppExample_MEDCouplingPointSet_rotate()
1776 using namespace ParaMEDMEM;
1777 //! [CppSnippet_MEDCouplingPointSet_rotate_1]
1778 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
1779 double coordsOrig[4*2];
1780 std::copy(coords,coords+sizeof(coords)/sizeof(double),coordsOrig);//keep tracks of initial values
1781 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1782 coordsArr->useExternalArrayWithRWAccess(coords, 4,2);
1783 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1784 mesh->setCoords(coordsArr);
1785 //! [CppSnippet_MEDCouplingPointSet_rotate_1]
1786 //! [CppSnippet_MEDCouplingPointSet_rotate_2]
1787 double center[3] = {0.,0.,0.}; // it suits for 2D as well
1788 double vector[3] = {0.,0.,1.}; // it is not used in 2D
1789 mesh->rotate( center, vector, -M_PI/2); // warning here C++ 'coords' array (defined above) has been modified !
1790 //! [CppSnippet_MEDCouplingPointSet_rotate_2]
1791 //! [CppSnippet_MEDCouplingPointSet_rotate_3]
1792 mesh->changeSpaceDimension(3);
1793 mesh->rotate( center, vector, +M_PI/2);
1794 //! [CppSnippet_MEDCouplingPointSet_rotate_3]
1795 //! [CppSnippet_MEDCouplingPointSet_rotate_4]
1796 mesh->changeSpaceDimension(2);
1797 const DataArrayDouble * coordsArr2 = mesh->getCoords();
1798 coordsArr->useExternalArrayWithRWAccess(coordsOrig, 4,2);
1799 CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *coordsArr, 1e-13 ));
1800 //! [CppSnippet_MEDCouplingPointSet_rotate_4]
1803 void CppExample_MEDCouplingPointSet_getBoundingBox()
1805 using namespace ParaMEDMEM;
1806 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1]
1807 double cc[2*3]={0.0, 0.1, 0.2, // 3D coordinates of 2 nodes
1809 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1810 coordsArr->useExternalArrayWithRWAccess(cc, 2,3);
1811 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1812 mesh->setCoords(coordsArr);
1813 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1]
1814 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2]
1816 mesh->getBoundingBox( (double*) bbox );
1818 // check the returned coordinates of extremum points of the bounding box
1819 for ( int i = 0; i < 2; ++i ) // point id
1820 for ( int j = 0; j < 3; ++j ) // component
1821 CPPUNIT_ASSERT_DOUBLES_EQUAL( cc[ i*3 + j ], bbox[j][i], 1e-13);
1822 //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2]
1825 void CppExample_MEDCouplingPointSet_getNodeIdsNearPoint()
1827 using namespace ParaMEDMEM;
1828 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1829 // 2D coordinates of 5 nodes
1830 double coords[5*2]={0.3,-0.30001, // #0
1835 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1836 coordsArr->useExternalArrayWithRWAccess(coords, 5,2);
1837 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1838 mesh->setCoords(coordsArr);
1839 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1]
1840 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1841 double point [2]={0.3, -0.3}; // point close to nodes #0, #2 and #4
1842 DataArrayInt *ids = mesh->getNodeIdsNearPoint(point, 1e-2);
1845 const int expectedIDs[3] = {0,2,4};
1846 DataArrayInt * okIDs = ids->getIdsEqualList ( expectedIDs, expectedIDs+3 );
1847 CPPUNIT_ASSERT_EQUAL(3, okIDs->getNumberOfTuples());
1852 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2]
1854 void CppExample_MEDCouplingPointSet_getNodeIdsNearPoints()
1856 using namespace ParaMEDMEM;
1857 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1858 // 2D coordinates of 7 nodes
1859 double coords[7*2]={0.3,-0.301, // #0
1866 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1867 coordsArr->useExternalArrayWithRWAccess(coords, 7,2);
1868 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1869 mesh->setCoords(coordsArr);
1870 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1]
1871 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1872 const int nbOfPoints = 3;
1873 double points [nbOfPoints*2]={0.2,-0.30001, // ~ node #1
1875 1.1, 0.002}; // ~ nodes #3, #4 and #5
1876 DataArrayInt *ids, *idsIndex;
1877 mesh->getNodeIdsNearPoints(points, nbOfPoints, 1e-1,ids,idsIndex);
1879 // check found ids (i.e. contents of 'ids' array)
1880 const int expectedIDs[4] = {1, 3, 4, 5};
1881 DataArrayInt * okIDs = ids->getIdsEqualList ( expectedIDs, expectedIDs+4 );
1882 CPPUNIT_ASSERT_EQUAL(4, okIDs->getNumberOfTuples());
1886 idsIndex->decrRef();
1888 //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2]
1891 void CppExample_MEDCouplingPointSet_findCommonNodes()
1893 using namespace ParaMEDMEM;
1894 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1]
1895 double coords[6*2]={0.3,-0.301, // 0
1901 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1902 coordsArr->useExternalArrayWithRWAccess(coords, 6,2);
1903 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1904 mesh->setCoords(coordsArr);
1905 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1]
1906 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2]
1907 DataArrayInt *com, *comI;
1908 mesh->findCommonNodes(1e-13,-1,com,comI);
1909 CPPUNIT_ASSERT_EQUAL(2, com->getNumberOfTuples());
1910 com->decrRef(); comI->decrRef();
1911 mesh->findCommonNodes(0.004,-1,com,comI);
1912 CPPUNIT_ASSERT_EQUAL(5, com->getNumberOfTuples());
1913 //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2]
1914 com->decrRef(); comI->decrRef();
1917 void CppExample_MEDCouplingPointSet_getCoordinatesOfNode()
1919 using namespace ParaMEDMEM;
1920 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1921 double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3};
1922 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsArr=DataArrayDouble::New();
1923 coordsArr->useExternalArrayWithRWAccess(coords, 3,2);
1924 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MEDCouplingUMesh::New();
1925 mesh->setCoords(coordsArr);
1926 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1]
1927 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1928 std::vector<double> coords2;
1929 mesh->getCoordinatesOfNode(1,coords2);
1930 CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[2],coords2[0],1e-13);
1931 CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[3],coords2[1],1e-13);
1932 //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2]
1935 void CppExample_DataArrayInt_buildPermutationArr()
1937 using namespace ParaMEDMEM;
1938 //! [CppSnippet_DataArrayInt_buildPermutationArr_1]
1939 DataArrayInt *a=DataArrayInt::New();
1940 const int vala[5]={4,5,6,7,8};
1942 std::copy(vala,vala+5,a->getPointer());
1943 DataArrayInt *b=DataArrayInt::New();
1944 const int valb[5]={5,4,8,6,7};
1946 std::copy(valb,valb+5,b->getPointer());
1947 DataArrayInt *c=a->buildPermutationArr(*b);
1948 //! [CppSnippet_DataArrayInt_buildPermutationArr_1]
1949 const int expect1[5]={1,0,4,2,3};
1950 CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
1951 CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
1952 CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
1953 CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
1959 void CppExample_DataArrayInt_invertArrayO2N2N2O()
1961 using namespace ParaMEDMEM;
1962 //! [CppSnippet_DataArrayInt_invertArrayO2N2N2O_1]
1963 const int arr1[6]={2,0,4,1,5,3};
1964 DataArrayInt *da=DataArrayInt::New();
1966 std::copy(arr1,arr1+6,da->getPointer());
1967 DataArrayInt *da2=da->invertArrayO2N2N2O(6);
1968 const int expected1[6]={1,3,0,5,2,4};
1969 for(int i=0;i<6;i++)
1970 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
1971 //! [CppSnippet_DataArrayInt_invertArrayO2N2N2O_1]
1976 void CppExample_DataArrayInt_invertArrayN2O2O2N()
1978 using namespace ParaMEDMEM;
1979 //! [CppSnippet_DataArrayInt_invertArrayN2O2O2N_1]
1980 const int arr1[6]={2,0,4,1,5,3};
1981 DataArrayInt *da=DataArrayInt::New();
1983 std::copy(arr1,arr1+6,da->getPointer());
1984 DataArrayInt *da2=da->invertArrayN2O2O2N(6);
1985 const int expected1[6]={1,3,0,5,2,4};
1986 for(int i=0;i<6;i++)
1987 CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
1988 //! [CppSnippet_DataArrayInt_invertArrayN2O2O2N_1]
1993 void CppExample_DataArrayDouble_getIdsInRange()
1995 using namespace ParaMEDMEM;
1996 //! [CppSnippet_DataArrayDouble_getIdsInRange_1]
1997 DataArrayDouble *da=DataArrayDouble::New();
2001 DataArrayInt* da2 = da->getIdsInRange( 2.5, 6 );
2002 //! [CppSnippet_DataArrayDouble_getIdsInRange_1]
2007 void CppExample_DataArrayDouble_findCommonTuples()
2009 using namespace ParaMEDMEM;
2010 //! [CppSnippet_DataArrayDouble_findCommonTuples1]
2011 DataArrayDouble *da=DataArrayDouble::New();
2013 const double array2[12]={2.3,2.3, // 0
2020 std::copy(array2,array2+12,da->getPointer());
2021 //! [CppSnippet_DataArrayDouble_findCommonTuples1]
2022 //! [CppSnippet_DataArrayDouble_findCommonTuples2]
2023 DataArrayInt *c=0,*cI=0;
2024 da->findCommonTuples(1.01e-1,-1,c,cI);
2026 const int expected3[5]={0,3,4,1,2};
2027 const int expected4[3]={0,3,5};
2028 CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer()));
2029 CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer()));
2033 //! [CppSnippet_DataArrayDouble_findCommonTuples2]
2036 void CppExample_DataArrayDouble_Meld1()
2038 using namespace ParaMEDMEM;
2039 //! [CppSnippet_DataArrayDouble_Meld1_1]
2040 const int sameNbTuples = 7;
2042 DataArrayDouble *da1=DataArrayDouble::New();
2043 da1->alloc(sameNbTuples,2);
2044 da1->fillWithValue(7.);
2045 da1->setInfoOnComponent(0,"c0da1");
2046 da1->setInfoOnComponent(1,"c1da1");
2048 DataArrayDouble *da2=DataArrayDouble::New();
2049 da2->alloc(sameNbTuples,1);
2051 da2->setInfoOnComponent(0,"c0da2");
2054 //! [CppSnippet_DataArrayDouble_Meld1_1]
2055 //! [CppSnippet_DataArrayDouble_Meld1_2]
2058 //! [CppSnippet_DataArrayDouble_Meld1_2]
2061 void CppExample_DataArrayInt_Meld1()
2063 using namespace ParaMEDMEM;
2064 //! [CppSnippet_DataArrayInt_Meld1_1]
2065 const int sameNbTuples = 7;
2067 DataArrayInt *da1=DataArrayInt::New();
2068 da1->alloc(sameNbTuples,2);
2069 da1->fillWithValue(7);
2070 da1->setInfoOnComponent(0,"c0da1");
2071 da1->setInfoOnComponent(1,"c1da1");
2073 DataArrayInt *da2=DataArrayInt::New();
2074 da2->alloc(sameNbTuples,1);
2076 da2->setInfoOnComponent(0,"c0da2");
2079 //! [CppSnippet_DataArrayInt_Meld1_1]
2080 //! [CppSnippet_DataArrayInt_Meld1_2]
2083 //! [CppSnippet_DataArrayInt_Meld1_2]
2086 void CppExampleFieldDoubleBuildSubPart1()
2088 //! [CppSnippetFieldDoubleBuildSubPart1_1]
2089 ParaMEDMEM::MEDCouplingUMesh *mesh1=ParaMEDMEM::MEDCouplingBasicsTest::build2DTargetMesh_1();
2090 ParaMEDMEM::MEDCouplingFieldDouble *f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
2091 f1->setTime(2.3,5,6);
2093 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
2094 array->alloc(mesh1->getNumberOfCells(),2);
2095 const double arr1[10]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.};
2096 std::copy(arr1,arr1+10,array->getPointer());
2097 f1->setArray(array);
2099 //! [CppSnippetFieldDoubleBuildSubPart1_1]
2100 //! [CppSnippetFieldDoubleBuildSubPart1_2]
2101 const int part1[3]={2,1,4};
2102 ParaMEDMEM::MEDCouplingFieldDouble *f2=f1->buildSubPart(part1,part1+3);
2103 //! [CppSnippetFieldDoubleBuildSubPart1_2]
2105 CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
2106 CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
2107 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
2108 CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
2109 ParaMEDMEM::MEDCouplingUMesh *m2C=dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(const_cast<ParaMEDMEM::MEDCouplingMesh *>(f2->getMesh()));
2110 CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
2111 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};
2112 for(int i=0;i<12;i++)
2113 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
2114 const double expected3[13]={3,2,3,1,3,0,2,1,4,4,5,3,2};
2115 CPPUNIT_ASSERT(std::equal(expected3,expected3+13,m2C->getNodalConnectivity()->getConstPointer()));
2116 const double expected4[4]={0,4,8,13};
2117 CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
2120 //! [CppSnippetFieldDoubleBuildSubPart1_3]
2121 f1=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::ONE_TIME);
2122 f1->setTime(2.3,5,6);
2124 array=ParaMEDMEM::DataArrayDouble::New();
2125 array->alloc(mesh1->getNumberOfNodes(),2);
2126 const double arr2[18]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
2127 std::copy(arr2,arr2+18,array->getPointer());
2128 f1->setArray(array);
2130 //! [CppSnippetFieldDoubleBuildSubPart1_3]
2131 //! [CppSnippetFieldDoubleBuildSubPart1_4]
2132 const int part2[2]={1,2};
2133 f2=f1->buildSubPart(part2,part2+2);
2134 //! [CppSnippetFieldDoubleBuildSubPart1_4]
2136 //idem previous because nodes of cell#4 are not fully present in part3
2137 const int part3[2]={1,2};
2138 ParaMEDMEM::DataArrayInt *arrr=ParaMEDMEM::DataArrayInt::New();
2140 std::copy(part3,part3+2,arrr->getPointer());
2141 f2=f1->buildSubPart(arrr);
2145 const int part4[3]={1,2,4};
2146 f2=f1->buildSubPart(part4,part4+3);
2154 void CppSnippetUMeshStdBuild1()
2156 //! [CppSnippetUMeshStdBuild1_1]
2157 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.,
2158 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. };
2159 int nodalConnPerCell[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
2160 //! [CppSnippetUMeshStdBuild1_1]
2161 //! [CppSnippetUMeshStdBuild1_2]
2162 ParaMEDMEM::MEDCouplingUMesh *mesh=ParaMEDMEM::MEDCouplingUMesh::New("My2DMesh",2);
2163 //! [CppSnippetUMeshStdBuild1_2]
2164 //! [CppSnippetUMeshStdBuild1_3]
2165 mesh->allocateCells(5);//You can put more than 5 if you want but not less.
2166 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell);
2167 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,nodalConnPerCell+4);
2168 mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,nodalConnPerCell+7);
2169 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell+10);
2170 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,nodalConnPerCell+14);
2171 mesh->finishInsertingCells();
2172 //! [CppSnippetUMeshStdBuild1_3]
2173 //! [CppSnippetUMeshStdBuild1_4]
2174 ParaMEDMEM::DataArrayDouble *coordsArr=ParaMEDMEM::DataArrayDouble::New();
2175 coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
2176 std::copy(coords,coords+27,coordsArr->getPointer());
2177 mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
2178 coordsArr->decrRef();
2179 //! [CppSnippetUMeshStdBuild1_4]
2180 mesh->checkCoherency();
2181 //! [CppSnippetUMeshStdBuild1_5]
2183 //! [CppSnippetUMeshStdBuild1_5]
2186 void CppSnippetCMeshStdBuild1()
2188 //! [CppSnippetCMeshStdBuild1_1]
2189 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2190 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2191 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New();
2193 std::copy(XCoords,XCoords+9,arrX->getPointer());
2194 arrX->setInfoOnComponent(0,"X [m]");
2195 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New();
2197 std::copy(YCoords,YCoords+7,arrY->getPointer());
2198 arrY->setInfoOnComponent(0,"Y [m]");
2199 //! [CppSnippetCMeshStdBuild1_1]
2200 //! [CppSnippetCMeshStdBuild1_2]
2201 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
2202 mesh->setCoords(arrX,arrY);
2205 //! [CppSnippetCMeshStdBuild1_2]
2206 //! [CppSnippetCMeshStdBuild1_3]
2207 CPPUNIT_ASSERT_EQUAL(8*6,mesh->getNumberOfCells());
2208 CPPUNIT_ASSERT_EQUAL(9*7,mesh->getNumberOfNodes());
2209 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
2210 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
2211 //! [CppSnippetCMeshStdBuild1_3]
2213 mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
2214 arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2215 arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2216 //! [CppSnippetCMeshStdBuild1_2bis]
2217 mesh->setCoordsAt(0,arrX);
2219 mesh->setCoordsAt(1,arrY);
2221 //! [CppSnippetCMeshStdBuild1_2bis]
2222 CPPUNIT_ASSERT_EQUAL(8*6,mesh->getNumberOfCells());
2223 CPPUNIT_ASSERT_EQUAL(9*7,mesh->getNumberOfNodes());
2224 CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
2225 CPPUNIT_ASSERT_EQUAL(2,mesh->getMeshDimension());
2226 //! [CppSnippetCMeshStdBuild1_4]
2228 //! [CppSnippetCMeshStdBuild1_4]
2231 void CppSnippetUMeshAdvBuild1()
2233 //! [CppSnippetUMeshAdvBuild1_1]
2234 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.,
2235 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. };
2236 int nodalConnPerCell[23]={4,0,3,4,1, 3,1,4,2, 3,4,5,2, 4,6,7,4,3, 4,7,8,5,4};
2237 int nodalConnPerCellIndex[6]={0,5,9,13,18,23};
2238 //! [CppSnippetUMeshAdvBuild1_1]
2239 //! [CppSnippetUMeshAdvBuild1_2]
2240 ParaMEDMEM::MEDCouplingUMesh *mesh=ParaMEDMEM::MEDCouplingUMesh::New("My2DMesh",2);
2241 //! [CppSnippetUMeshAdvBuild1_2]
2242 //! [CppSnippetUMeshAdvBuild1_3]
2243 ParaMEDMEM::DataArrayInt *nodalConn=ParaMEDMEM::DataArrayInt::New();
2244 nodalConn->alloc(23,1);
2245 std::copy(nodalConnPerCell,nodalConnPerCell+23,nodalConn->getPointer());
2246 ParaMEDMEM::DataArrayInt *nodalConnI=ParaMEDMEM::DataArrayInt::New();
2247 nodalConnI->alloc(6,1);
2248 std::copy(nodalConnPerCellIndex,nodalConnPerCellIndex+6,nodalConnI->getPointer());
2249 mesh->setConnectivity(nodalConn,nodalConnI,true);
2250 nodalConn->decrRef();// nodalConn DataArrayInt instance is owned by mesh after call to setConnectivity method. No more need here -> decrRef()
2251 nodalConnI->decrRef();// nodalConnI DataArrayInt instance is owned by mesh after call to setConnectivity method. No more need here -> decrRef()
2252 //! [CppSnippetUMeshAdvBuild1_3]
2253 //! [CppSnippetUMeshAdvBuild1_4]
2254 ParaMEDMEM::DataArrayDouble *coordsArr=ParaMEDMEM::DataArrayDouble::New();
2255 coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3.
2256 std::copy(coords,coords+27,coordsArr->getPointer());
2257 mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes.
2258 coordsArr->decrRef();
2259 //! [CppSnippetUMeshAdvBuild1_4]
2260 mesh->checkCoherency();
2261 //! [CppSnippetUMeshAdvBuild1_5]
2263 //! [CppSnippetUMeshAdvBuild1_5]
2266 void CppSnippetDataArrayBuild1()
2268 //! [CppSnippetDataArrayBuild1_0]
2269 const int nbOfNodes=12;
2270 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.};
2272 ParaMEDMEM::DataArrayDouble *coordsArr=0;
2274 //! [CppSnippetDataArrayBuild1_0]
2276 //! [CppSnippetDataArrayBuild1_1]
2277 coordsArr=ParaMEDMEM::DataArrayDouble::New();
2278 coordsArr->useArray(coords,false,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3);
2279 //now use coordsArr as you need
2281 //coordsArr is no more useful here : release it
2282 coordsArr->decrRef();
2283 //! [CppSnippetDataArrayBuild1_1]
2284 //! [CppSnippetDataArrayBuild1_2]
2285 coordsArr=ParaMEDMEM::DataArrayDouble::New();
2286 tmp=new double[3*nbOfNodes];
2287 std::copy(coords,coords+3*nbOfNodes,tmp);
2288 coordsArr->useArray(tmp,true,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3);
2289 //now use coordsArr as you need
2291 //coordsArr is no more useful, release it
2292 coordsArr->decrRef();
2293 //! [CppSnippetDataArrayBuild1_2]
2294 //! [CppSnippetDataArrayBuild1_3]
2295 coordsArr=ParaMEDMEM::DataArrayDouble::New();
2296 tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
2297 std::copy(coords,coords+3*nbOfNodes,tmp);
2298 coordsArr->useArray(tmp,true,ParaMEDMEM::C_DEALLOC,nbOfNodes,3);
2299 //now use coordsArr as you need
2301 //coordsArr is no more useful here : release it
2302 coordsArr->decrRef();
2303 //! [CppSnippetDataArrayBuild1_3]
2304 //! [CppSnippetDataArrayBuild1_4]
2305 coordsArr=ParaMEDMEM::DataArrayDouble::New();
2306 coordsArr->alloc(nbOfNodes,3);
2307 tmp=coordsArr->getPointer();
2308 std::copy(coords,coords+3*nbOfNodes,tmp);
2309 coordsArr->declareAsNew();//you have modified data pointed by internal pointer notify object
2310 //now use coordsArr as you need
2312 //coordsArr is no more useful here : release it
2313 coordsArr->decrRef();
2314 //! [CppSnippetDataArrayBuild1_4]
2315 coordsArr=ParaMEDMEM::DataArrayDouble::New();
2316 coordsArr->alloc(nbOfNodes,3);
2317 tmp=coordsArr->getPointer();
2318 std::copy(coords,coords+3*nbOfNodes,tmp);
2319 ParaMEDMEM::DataArrayDouble *coordsArrCpy=0;
2320 //! [CppSnippetDataArrayBuild1_5]
2321 coordsArrCpy=coordsArr->deepCpy();
2322 //! [CppSnippetDataArrayBuild1_5]
2323 //! [CppSnippetDataArrayBuild1_6]
2324 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2325 coordsArrCpy->setIJ(0,0,1000.);
2326 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
2327 //! [CppSnippetDataArrayBuild1_6]
2328 //! [CppSnippetDataArrayBuild1_7]
2329 coordsArrCpy->decrRef();
2330 //! [CppSnippetDataArrayBuild1_7]
2331 //! [CppSnippetDataArrayBuild1_5bis]
2332 coordsArrCpy=coordsArr->performCpy(true);
2333 //! [CppSnippetDataArrayBuild1_5bis]
2334 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2335 coordsArrCpy->setIJ(0,0,1000.);
2336 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
2337 coordsArrCpy->decrRef();
2338 //! [CppSnippetDataArrayBuild1_8]
2339 coordsArrCpy=coordsArr->performCpy(false);
2340 //! [CppSnippetDataArrayBuild1_8]
2341 //! [CppSnippetDataArrayBuild1_9]
2342 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2343 coordsArrCpy->setIJ(0,0,1000.);
2344 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArr and coordsArrCpy have been modified simultaneously
2345 //! [CppSnippetDataArrayBuild1_9]
2346 //! [CppSnippetDataArrayBuild1_10]
2347 coordsArrCpy->decrRef();
2348 //! [CppSnippetDataArrayBuild1_10]
2349 //! [CppSnippetDataArrayBuild1_11]
2350 coordsArrCpy=ParaMEDMEM::DataArrayDouble::New();
2351 //! [CppSnippetDataArrayBuild1_11]
2352 //! [CppSnippetDataArrayBuild1_12]
2353 coordsArrCpy->cpyFrom(*coordsArr);
2354 //! [CppSnippetDataArrayBuild1_12]
2355 //! [CppSnippetDataArrayBuild1_13]
2356 CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));
2357 coordsArrCpy->setIJ(0,0,2000.);
2358 CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified
2359 //! [CppSnippetDataArrayBuild1_13]
2360 //! [CppSnippetDataArrayBuild1_14]
2361 coordsArrCpy->decrRef();
2362 //! [CppSnippetDataArrayBuild1_14]
2363 coordsArr->decrRef();
2364 //! [CppSnippetDataArrayBuild1_14]
2367 void CppSnippetFieldDoubleBuild1()
2369 double XCoords[9]={-0.3,0.07,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2370 double YCoords[7]={0.07,0.1,0.37,0.45,0.47,0.49,1.007};
2371 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2372 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2373 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
2374 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2375 //! [CppSnippetFieldDoubleBuild1_1]
2376 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::NO_TIME);
2377 fieldOnCells->setName("MyTensorFieldOnCellNoTime");
2378 fieldOnCells->setMesh(mesh);
2379 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnCells
2380 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
2381 array->alloc(fieldOnCells->getMesh()->getNumberOfCells(),9);//Implicitely fieldOnCells will be a 9 components field.
2382 array->fillWithValue(7.);
2383 fieldOnCells->setArray(array);
2385 // fieldOnCells is now usable
2387 // fieldOnCells is no more useful here : release it
2388 fieldOnCells->decrRef();
2389 //! [CppSnippetFieldDoubleBuild1_1]
2390 arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2391 arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2392 mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
2393 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2394 //! [CppSnippetFieldDoubleBuild1_2]
2395 ParaMEDMEM::MEDCouplingFieldDouble *f1=mesh->fillFromAnalytic(ParaMEDMEM::ON_CELLS,1,"x*x+y*y*3+2.*x");//f1 is scalar
2396 ParaMEDMEM::MEDCouplingFieldDouble *f2=mesh->fillFromAnalytic(ParaMEDMEM::ON_CELLS,1,"cos(x+y/x)");//f2 is scalar too
2397 ParaMEDMEM::MEDCouplingFieldDouble *f2bis=mesh->fillFromAnalytic(ParaMEDMEM::ON_CELLS,2,"x*x*IVec+3*y*JVec");//f2bis is a vectors field
2398 ParaMEDMEM::MEDCouplingFieldDouble *f3=(*f1)+(*f2);//f3 scalar
2399 ParaMEDMEM::MEDCouplingFieldDouble *f4=(*f3)/(*f2);//f4 scalar
2400 f2bis->applyFunc(1,"sqrt(x*x+y*y)");//f2bis becomes scalar
2401 ParaMEDMEM::MEDCouplingFieldDouble *f5=(*f2bis)*(*f4);//f5 scalar
2402 const double pos1[2]={0.48,0.38};
2404 f4->getValueOn(pos1,&res);//f4 is scalar so the returned value is of size 1.
2406 //! [CppSnippetFieldDoubleBuild1_2]
2408 //! [CppSnippetFieldDoubleBuild1_3]
2409 // f1, f2, f2bis, f3, f4, f5 are no more useful here : release them
2416 //! [CppSnippetFieldDoubleBuild1_3]
2419 void CppSnippetFieldDoubleBuild2()
2421 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2422 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2423 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2424 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2425 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
2426 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2427 //! [CppSnippetFieldDoubleBuild2_1]
2428 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnNodes=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::NO_TIME);
2429 fieldOnNodes->setName("MyScalarFieldOnNodeNoTime");
2430 fieldOnNodes->setMesh(mesh);
2431 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnNodes
2432 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
2433 array->alloc(fieldOnNodes->getMesh()->getNumberOfNodes(),1);//Implicitely fieldOnNodes will be a 1 component field.
2434 array->fillWithValue(8.);
2435 fieldOnNodes->setArray(array);
2437 // fieldOnNodes is now usable
2439 // fieldOnNodes is no more useful here : release it
2440 fieldOnNodes->decrRef();
2441 //! [CppSnippetFieldDoubleBuild2_1]
2444 void CppSnippetFieldDoubleBuild3()
2446 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2447 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2448 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2449 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2450 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
2451 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2452 //! [CppSnippetFieldDoubleBuild3_1]
2453 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnCells=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
2454 fieldOnCells->setName("MyTensorFieldOnCellNoTime");
2455 fieldOnCells->setTimeUnit("ms"); // Time unit is ms.
2456 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
2457 fieldOnCells->setMesh(mesh);
2458 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnCells
2459 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
2460 array->alloc(fieldOnCells->getMesh()->getNumberOfCells(),2);//Implicitely fieldOnCells will be a 2 components field.
2461 array->fillWithValue(7.);
2462 fieldOnCells->setArray(array);
2464 // fieldOnCells is now usable
2466 // fieldOnCells is no more useful here : release it
2467 fieldOnCells->decrRef();
2468 //! [CppSnippetFieldDoubleBuild3_1]
2471 void CppSnippetFieldDoubleBuild4()
2473 double XCoords[9]={-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22};
2474 double YCoords[7]={0.,0.1,0.37,0.45,0.47,0.49,1.007};
2475 ParaMEDMEM::DataArrayDouble *arrX=ParaMEDMEM::DataArrayDouble::New(); arrX->alloc(9,1); std::copy(XCoords,XCoords+9,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]");
2476 ParaMEDMEM::DataArrayDouble *arrY=ParaMEDMEM::DataArrayDouble::New(); arrY->alloc(7,1); std::copy(YCoords,YCoords+7,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]");
2477 ParaMEDMEM::MEDCouplingCMesh *mesh=ParaMEDMEM::MEDCouplingCMesh::New("My2D_CMesh");
2478 mesh->setCoords(arrX,arrY); arrX->decrRef(); arrY->decrRef();
2479 //! [CppSnippetFieldDoubleBuild4_1]
2480 ParaMEDMEM::MEDCouplingFieldDouble* fieldOnNodes=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::CONST_ON_TIME_INTERVAL);
2481 fieldOnNodes->setName("MyVecFieldOnNodeWithConstTime");
2482 fieldOnNodes->setTimeUnit("ms"); // Time unit is ms.
2483 fieldOnNodes->setStartTime(4.22,2,-1);
2484 fieldOnNodes->setEndTime(6.44,4,-1); // fieldOnNodes is defined in interval [4.22 ms,6.44 ms]
2485 fieldOnNodes->setMesh(mesh);
2486 mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnNodes
2487 ParaMEDMEM::DataArrayDouble *array=ParaMEDMEM::DataArrayDouble::New();
2488 array->alloc(fieldOnNodes->getMesh()->getNumberOfNodes(),3);//Implicitely fieldOnNodes will be a 3 components field.
2489 array->fillWithValue(8.);
2490 fieldOnNodes->setArray(array);
2492 // fieldOnNodes is now usable
2494 // fieldOnNodes is no more useful here : release it
2495 fieldOnNodes->decrRef();
2496 //! [CppSnippetFieldDoubleBuild4_1]
2499 int main(int argc, char *argv[])
2501 CppExample_MEDCouplingFieldDouble_WriteVTK();
2502 CppExample_MEDCouplingFieldDouble_MaxFields();
2503 CppExample_MEDCouplingFieldDouble_MergeFields();
2504 CppExample_MEDCouplingFieldDouble_substractInPlaceDM();
2505 CppExample_MEDCouplingFieldDouble_changeUnderlyingMesh();
2506 CppExample_MEDCouplingFieldDouble_applyFunc_same_nb_comp();
2507 CppExample_MEDCouplingFieldDouble_applyFunc3();
2508 CppExample_MEDCouplingFieldDouble_applyFunc2();
2509 CppExample_MEDCouplingFieldDouble_applyFunc();
2510 CppExample_MEDCouplingFieldDouble_applyFunc_val();
2511 CppExample_MEDCouplingFieldDouble_fillFromAnalytic3();
2512 CppExample_MEDCouplingFieldDouble_fillFromAnalytic2();
2513 CppExample_MEDCouplingFieldDouble_fillFromAnalytic();
2514 CppExample_MEDCouplingFieldDouble_fillFromAnalytic_c_func();
2515 CppExample_MEDCouplingFieldDouble_applyFunc_c_func();
2516 CppExample_MEDCouplingFieldDouble_getValueOn_time();
2517 CppExample_MEDCouplingFieldDouble_getValueOnMulti();
2518 CppExample_MEDCouplingFieldDouble_getValueOn();
2519 CppExample_MEDCouplingFieldDouble_getValueOnPos();
2520 CppExample_MEDCouplingFieldDouble_renumberNodes();
2521 CppExample_MEDCouplingFieldDouble_renumberCells();
2522 CppExample_MEDCouplingFieldDouble_buildNewTimeReprFromThis();
2523 CppExample_MEDCouplingMesh_fillFromAnalytic3();
2524 CppExample_MEDCouplingMesh_fillFromAnalytic2();
2525 CppExample_MEDCouplingMesh_fillFromAnalytic();
2526 CppExample_MEDCouplingCMesh_getCoordsAt();
2527 CppExample_MEDCouplingUMesh_areCellsIncludedIn();
2528 CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells();
2529 CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented();
2530 CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented();
2531 CppExample_MEDCouplingUMesh_getCellsContainingPoints();
2532 CppExample_MEDCouplingUMesh_getCellsContainingPoint();
2533 CppExample_MEDCouplingUMesh_buildPartOrthogonalField();
2534 CppExample_MEDCouplingUMesh_getPartMeasureField();
2535 CppExample_MEDCouplingUMesh_getCellsInBoundingBox();
2536 CppExample_MEDCouplingUMesh_renumberNodesInConn();
2537 CppExample_MEDCouplingUMesh_renumberNodes();
2538 CppExample_MEDCouplingUMesh_findBoundaryNodes();
2539 CppExample_MEDCouplingUMesh_buildBoundaryMesh();
2540 CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode();
2541 CppExample_MEDCouplingUMesh_buildPartOfMySelfNode();
2542 CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes();
2543 CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds();
2544 CppExample_MEDCouplingUMesh_buildPartOfMySelf();
2545 CppExample_MEDCouplingUMesh_mergeNodes();
2546 CppExample_MEDCouplingUMesh_zipConnectivityTraducer();
2547 CppExample_MEDCouplingUMesh_zipCoordsTraducer();
2548 CppExample_MEDCouplingUMesh_getNodeIdsInUse();
2549 CppExample_MEDCouplingUMesh_convertToPolyTypes();
2550 CppExample_MEDCouplingUMesh_buildDescendingConnectivity2();
2551 CppExample_MEDCouplingUMesh_buildDescendingConnectivity();
2552 CppExample_MEDCouplingUMesh_getReverseNodalConnectivity();
2553 CppExample_MEDCouplingUMesh_checkDeepEquivalWith();
2554 CppExample_MEDCouplingPointSet_scale();
2555 CppExample_MEDCouplingPointSet_translate();
2556 CppExample_MEDCouplingPointSet_rotate();
2557 CppExample_MEDCouplingPointSet_getBoundingBox();
2558 CppExample_MEDCouplingPointSet_getNodeIdsNearPoint();
2559 CppExample_MEDCouplingPointSet_getNodeIdsNearPoints();
2560 CppExample_MEDCouplingPointSet_findCommonNodes();
2561 CppExample_MEDCouplingPointSet_getCoordinatesOfNode();
2562 CppExample_DataArrayInt_buildPermutationArr();
2563 CppExample_DataArrayInt_invertArrayO2N2N2O();
2564 CppExample_DataArrayInt_invertArrayN2O2O2N();
2565 CppExample_DataArrayDouble_getIdsInRange();
2566 CppExample_DataArrayDouble_findCommonTuples();
2567 CppExample_DataArrayDouble_Meld1();
2568 CppExampleFieldDoubleBuildSubPart1();
2569 CppSnippetUMeshStdBuild1();
2570 CppSnippetUMeshAdvBuild1();
2571 CppSnippetDataArrayBuild1();
2572 CppSnippetCMeshStdBuild1();
2573 CppSnippetFieldDoubleBuild1();
2574 CppSnippetFieldDoubleBuild2();
2575 CppSnippetFieldDoubleBuild3();
2576 CppSnippetFieldDoubleBuild4();