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