Salome HOME
Merge from V6_main_20120808 08Aug12
[tools/medcoupling.git] / src / MEDCoupling / Test / MEDCouplingBasicsTest2.cxx
1 // Copyright (C) 2007-2012  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.
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
20 #include "MEDCouplingBasicsTest2.hxx"
21 #include "MEDCouplingUMesh.hxx"
22 #include "MEDCouplingCMesh.hxx"
23 #include "MEDCouplingExtrudedMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingMemArray.hxx"
26 #include "MEDCouplingGaussLocalization.hxx"
27
28 #include <cmath>
29 #include <algorithm>
30 #include <functional>
31 #include <iterator>
32
33 using namespace ParaMEDMEM;
34
35 void MEDCouplingBasicsTest2::testGaussPointField1()
36 {
37   const double _a=0.446948490915965;
38   const double _b=0.091576213509771;
39   const double _p1=0.11169079483905;
40   const double _p2=0.0549758718227661;
41   const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
42   const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
43                             2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
44   const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
45   std::vector<double> _refCoo1(refCoo1,refCoo1+6);
46   std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
47   std::vector<double> _wg1(wg1,wg1+6);
48   //
49   MEDCouplingUMesh *m=build2DTargetMesh_1();
50   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME);
51   f->setMesh(m);
52   CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected());
53   CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization());
54   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
55   CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo1,_gsCoo1,_wg1),INTERP_KERNEL::Exception);
56   CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization());
57   const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
58   std::vector<double> _refCoo2(refCoo2,refCoo2+8);
59   _gsCoo1.resize(4); _wg1.resize(2);
60   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
61   CPPUNIT_ASSERT_EQUAL(2,f->getNbOfGaussLocalization());
62   DataArrayDouble *array=DataArrayDouble::New();
63   array->alloc(18,2);
64   double *ptr=array->getPointer();
65   for(int i=0;i<18*2;i++)
66     ptr[i]=(double)(i+1);
67   f->setArray(array);
68   f->setName("MyFirstFieldOnGaussPoint");
69   array->decrRef();
70   f->checkCoherency();
71   CPPUNIT_ASSERT_DOUBLES_EQUAL(27.,f->getIJK(2,5,0),1e-14);
72   CPPUNIT_ASSERT_DOUBLES_EQUAL(16.,f->getIJK(1,5,1),1e-14);
73   //
74   f->clearGaussLocalizations();
75   CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization());
76   CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);
77   int ids1[4]={0,1,3,4};
78   CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnCells(ids1,ids1+4,_refCoo2,_gsCoo1,_wg1),INTERP_KERNEL::Exception);
79   CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization());
80   int ids2[2]={0,4};
81   f->setGaussLocalizationOnCells(ids2,ids2+2,_refCoo2,_gsCoo1,_wg1);
82   CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization());
83   CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0));
84   CPPUNIT_ASSERT_THROW(f->getGaussLocalizationIdOfOneCell(1),INTERP_KERNEL::Exception);
85   int ids3[2]={1,2};
86   f->setGaussLocalizationOnCells(ids3,ids3+2,_refCoo1,_gsCoo1,_wg1);
87   CPPUNIT_ASSERT_EQUAL(2,f->getNbOfGaussLocalization());
88   CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0));
89   CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(1));
90   CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(2));
91   CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);//<- cell 3 has no localization
92   int ids4[1]={3};
93   std::vector<double> _gsCoo2(_gsCoo1);
94   std::vector<double> _wg2(_wg1);
95   _gsCoo2[0]=0.8888777776666; _wg2[0]=0.1234567892377;
96   f->setGaussLocalizationOnCells(ids4,ids4+1,_refCoo2,_gsCoo2,_wg2);
97   CPPUNIT_ASSERT_EQUAL(3,f->getNbOfGaussLocalization());
98   std::vector<int> tmpIds;
99   f->getCellIdsHavingGaussLocalization(0,tmpIds);
100   CPPUNIT_ASSERT_EQUAL(2,(int)tmpIds.size());
101   CPPUNIT_ASSERT(std::equal(ids2,ids2+2,tmpIds.begin()));
102   CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);//<- it's always not ok because undelying array not with the good size.
103   DataArrayDouble *array2=f->getArray()->substr(0,10);
104   f->setArray(array2);
105   array2->decrRef();
106   f->checkCoherency();//<- here it is OK
107   MEDCouplingFieldDouble *f2=f->clone(true);
108   CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
109   MEDCouplingGaussLocalization& gl1=f2->getGaussLocalization(0);
110   double tmp=gl1.getGaussCoord(1,1);
111   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.07*_b-1,tmp,1e-14);
112   gl1.setGaussCoord(1,1,0.07);
113   CPPUNIT_ASSERT(!f->isEqual(f2,1e-14,1e-14));
114   gl1.setGaussCoord(1,1,tmp);
115   CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
116   f->decrRef();
117   f2->checkCoherency();
118   //
119   f2->decrRef();
120   m->decrRef();
121 }
122
123 void MEDCouplingBasicsTest2::testGaussPointNEField1()
124 {
125   MEDCouplingUMesh *m=build2DTargetMesh_1();
126   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
127   f->setMesh(m);
128   CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected());
129   f->setName("MyFirstFieldOnNE");
130   f->setDescription("MyDescriptionNE");
131   DataArrayDouble *array=DataArrayDouble::New();
132   array->alloc(18,2);
133   double *ptr=array->getPointer();
134   for(int i=0;i<18*2;i++)
135     ptr[i]=(double)(i+7);
136   f->setArray(array);
137   array->decrRef();
138   //
139   f->checkCoherency();
140   MEDCouplingFieldDouble *f2=f->clone(true);
141   CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
142   CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,f->getIJK(2,0,0),1e-14);
143   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,f->getIJK(1,1,1),1e-14);
144   f2->decrRef();
145   //
146   f->decrRef();
147   m->decrRef();
148 }
149
150 void MEDCouplingBasicsTest2::testCellOrientation1()
151 {
152   MEDCouplingUMesh *m=build2DTargetMesh_1();
153   double vec[3]={0.,0.,-1.};
154   std::vector<int> res1;
155   CPPUNIT_ASSERT_THROW(m->are2DCellsNotCorrectlyOriented(vec,false,res1),INTERP_KERNEL::Exception);
156   m->changeSpaceDimension(3);
157   res1.clear();
158   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
159   CPPUNIT_ASSERT(res1.empty());
160   vec[2]=1;
161   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
162   CPPUNIT_ASSERT_EQUAL(5,(int)res1.size());
163   res1.clear();
164   //
165   vec[2]=-1.;
166   // connectivity inversion
167   int *conn=m->getNodalConnectivity()->getPointer();
168   int tmp=conn[11];
169   conn[11]=conn[12];
170   conn[12]=tmp;
171   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
172   CPPUNIT_ASSERT_EQUAL(1,(int)res1.size());
173   CPPUNIT_ASSERT_EQUAL(2,res1[0]);
174   res1.clear();
175   m->orientCorrectly2DCells(vec,false);
176   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
177   CPPUNIT_ASSERT(res1.empty());
178   MEDCouplingUMesh *m2=build2DTargetMesh_1();
179   m2->changeSpaceDimension(3);
180   CPPUNIT_ASSERT(m->isEqual(m2,1e-12));
181   m2->decrRef();
182   //
183   m->decrRef();
184 }
185
186 void MEDCouplingBasicsTest2::testCellOrientation2()
187 {
188   MEDCouplingUMesh *m1=0;
189   MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
190   m1->decrRef();
191   std::vector<int> res1;
192   m2->arePolyhedronsNotCorrectlyOriented(res1);
193   CPPUNIT_ASSERT_EQUAL(6,(int)res1.size());
194   m2->orientCorrectlyPolyhedrons();
195   res1.clear();
196   m2->arePolyhedronsNotCorrectlyOriented(res1);
197   CPPUNIT_ASSERT(res1.empty());
198   m2->checkCoherency();
199   CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
200   int cellIds[3]={0,6,12};
201   std::vector<int> cellIds2(cellIds,cellIds+3);
202   m2->convertToPolyTypes(&cellIds2[0],&cellIds2[0]+cellIds2.size());
203   m2->orientCorrectlyPolyhedrons();
204   res1.clear();
205   m2->arePolyhedronsNotCorrectlyOriented(res1);
206   CPPUNIT_ASSERT(res1.empty());
207   MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
208   //Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation
209   MEDCouplingUMesh *m3=build2DTargetMesh_1();
210   double vec[3]={0.,0.,1.};
211   m3->changeSpaceDimension(3);
212   const int ids1[5]={0,1,2,3,4};
213   std::vector<int> ids2(ids1,ids1+5);
214   m3->convertToPolyTypes(&ids2[0],&ids2[0]+ids2.size());
215   m3->orientCorrectly2DCells(vec,false);
216   MEDCouplingUMesh *m4=buildCU1DMesh_U();
217   m4->changeSpaceDimension(3);
218   double center[3]={0.,0.,0.};
219   double vector[3]={0.,1.,0.};
220   m4->rotate(center,vector,-M_PI/2.);
221   MEDCouplingUMesh *m5=m3->buildExtrudedMesh(m4,0);
222   res1.clear();
223   m5->arePolyhedronsNotCorrectlyOriented(res1);
224   CPPUNIT_ASSERT_EQUAL(15,(int)res1.size());
225   m5->orientCorrectlyPolyhedrons();
226   res1.clear();
227   m5->arePolyhedronsNotCorrectlyOriented(res1);
228   CPPUNIT_ASSERT(res1.empty());
229   MEDCouplingFieldDouble *f3=m5->getMeasureField(false);
230   CPPUNIT_ASSERT_EQUAL(15,f3->getArray()->getNumberOfTuples());
231   CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
232   const double *f3Ptr=f3->getArray()->getConstPointer();
233   const double expected1[15]={
234     0.075,0.0375,0.0375,0.075,0.075,
235     0.1125,0.05625,0.05625,0.1125,0.1125,
236     0.0625,0.03125,0.03125,0.0625,0.0625
237   };
238   for(int i=0;i<15;i++)
239     CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),f3Ptr[i],1e-12);
240   f3->decrRef();
241   DataArrayDouble *f4=m5->getBarycenterAndOwner();
242   CPPUNIT_ASSERT_EQUAL(15,f4->getNumberOfTuples());
243   CPPUNIT_ASSERT_EQUAL(3,f4->getNumberOfComponents());
244   const double *f4Ptr=f4->getConstPointer();
245   const double expected2[45]={
246     -0.05,-0.05,0.15, 0.3666666666666667,-0.13333333333333333,0.15, 0.53333333333333333,0.033333333333333333,0.15, -0.05,0.45,0.15, 0.45,0.45,0.15,
247     -0.05,-0.05,0.525, 0.3666666666666667,-0.13333333333333333,0.525, 0.53333333333333333,0.033333333333333333,0.525, -0.05,0.45,0.525, 0.45,0.45,0.525,
248     -0.05,-0.05,0.875, 0.3666666666666667,-0.13333333333333333,0.875, 0.53333333333333333,0.033333333333333333,0.875, -0.05,0.45,0.875, 0.45,0.45,0.875
249   };
250   for(int i=0;i<45;i++)
251     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4Ptr[i],1e-12);
252   f4->decrRef();
253   m5->decrRef();
254   m3->decrRef();
255   m4->decrRef();
256   //
257   f2->decrRef();
258   m2->decrRef();
259 }
260
261 /*!
262  * This test check polyhedron true barycenter computation. 
263  */
264 void MEDCouplingBasicsTest2::testPolyhedronBarycenter()
265 {
266   int connN[]={0,3,2,1, -1, 4,5,6,7, -1, 0,4,7,3, -1, 3,7,6,2, -1, 2,6,5,1, -1, 1,5,4,0};
267   double coords[]={0.,0.,0., 1.,0.,0., 1.,1.,0., 0.,1.,0., 0.,0.,1., 1.,0.,1., 1.,1.,1., 0.,1.,1., 0.5, 0.5, 0.5};
268   MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
269   meshN->setName("ForBary");
270   meshN->setMeshDimension(3);
271   meshN->allocateCells(4);
272   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,29,connN);
273   meshN->finishInsertingCells();
274   DataArrayDouble *myCoords=DataArrayDouble::New();
275   myCoords->alloc(9,3);
276   std::copy(coords,coords+27,myCoords->getPointer());
277   meshN->setCoords(myCoords);
278   myCoords->decrRef();
279   meshN->checkCoherency();
280   //
281   std::vector<int> res1;
282   meshN->arePolyhedronsNotCorrectlyOriented(res1);
283   meshN->orientCorrectlyPolyhedrons();
284   CPPUNIT_ASSERT(res1.empty());
285   const double *ref,*daPtr;
286   DataArrayDouble *da=meshN->getBarycenterAndOwner();
287   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfTuples());
288   CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents());
289   daPtr=da->getConstPointer();
290   ref=meshN->getCoords()->getConstPointer()+24;
291   for(int i=0;i<3;i++)
292     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
293   da->decrRef();
294   //
295   const double center[]={0.,0.,0.};
296   const double vec[]={0.,2.78,0.};
297   da=meshN->getBarycenterAndOwner();
298   daPtr=da->getConstPointer();
299   ref=meshN->getCoords()->getConstPointer()+24;
300   for(int i=0;i<3;i++)
301     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
302   da->decrRef();
303   //
304   meshN->rotate(center,vec,M_PI/7.);
305   meshN->translate(vec);
306   da=meshN->getBarycenterAndOwner();
307   daPtr=da->getConstPointer();
308   ref=meshN->getCoords()->getConstPointer()+24;
309   for(int i=0;i<3;i++)
310     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
311   da->decrRef();
312   //
313   const double center2[]={1.12,3.45,6.78};
314   const double vec2[]={4.5,9.3,2.8};
315   meshN->rotate(center2,vec2,M_E);
316   meshN->translate(vec2);
317   da=meshN->getBarycenterAndOwner();
318   daPtr=da->getConstPointer();
319   ref=meshN->getCoords()->getConstPointer()+24;
320   for(int i=0;i<3;i++)
321     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-10);
322   da->decrRef();
323   //
324   meshN->decrRef();
325 }
326
327 void MEDCouplingBasicsTest2::testNormL12Integ1D()
328 {
329   MEDCouplingUMesh *m1=build1DTargetMesh_3();
330   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
331   f1->setMesh(m1);
332   DataArrayDouble *array=DataArrayDouble::New();
333   array->alloc(m1->getNumberOfCells(),3);
334   const double arr[12]={-5.23,15.45,-25.56,6.67,-16.78,26.89,-7.91,17.23,-27.43,8.21,-18.63,28.72};
335   std::copy(arr,arr+12,array->getPointer());
336   f1->setArray(array);
337   array->decrRef();
338   //
339   const double *ptr;
340   DataArrayDouble *f3=m1->getBarycenterAndOwner();
341   CPPUNIT_ASSERT_EQUAL(4,f3->getNumberOfTuples());
342   CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
343   double expected9[4]={0.75,5.105,0.8,5.155};
344   ptr=f3->getConstPointer();
345    for(int i=0;i<4;i++)
346     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected9[i],ptr[i],1e-12);
347   f3->decrRef();
348   //
349   MEDCouplingFieldDouble *f2=m1->getMeasureField(false);
350   CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
351   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
352   double expected1[4]={0.5,0.21,-0.6,-0.31};
353   ptr=f2->getArray()->getConstPointer();
354   for(int i=0;i<4;i++)
355     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
356   f2->decrRef();
357   double expected2[4]={0.5,0.21,0.6,0.31};
358   f2=m1->getMeasureField(true);
359   ptr=f2->getArray()->getConstPointer();
360   for(int i=0;i<4;i++)
361     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
362   f2->decrRef();
363   //integral
364   double res[3];
365   f1->integral(false,res);
366   double expected3[3]={0.9866,-0.3615,0.4217};
367   for(int i=0;i<3;i++)
368     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],res[i],1e-12);
369   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f1->integral(0,false),1e-12);
370   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f1->integral(1,false),1e-12);
371   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f1->integral(2,false),1e-12);
372   f1->integral(true,res);
373   double expected4[3]={-3.4152,8.7639,-14.6879};
374   for(int i=0;i<3;i++)
375     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],res[i],1e-12);
376   //normL1
377   f1->normL1(res);
378   double expected5[3]={6.979506172839505, 16.89018518518518, 27.02969135802469};
379   for(int i=0;i<3;i++)
380     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
381   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[0],f1->normL1(0),1e-12);
382   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[1],f1->normL1(1),1e-12);
383   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[2],f1->normL1(2),1e-12);
384   //normL2
385   f1->normL2(res);
386   double expected7[3]={7.090910979452395, 16.9275542960123, 27.053271464160858};
387   for(int i=0;i<3;i++)
388     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-9);
389   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[0],f1->normL2(0),1e-9);
390   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[1],f1->normL2(1),1e-9);
391   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[2],f1->normL2(2),1e-9);
392   //buildMeasureField
393   MEDCouplingFieldDouble *f4=f1->buildMeasureField(false);
394   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2,f4->accumulate(0),1e-12);
395   f4->decrRef();
396   f4=f1->buildMeasureField(true);
397   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.62,f4->accumulate(0),1e-12);
398   f4->decrRef();
399   //
400   f1->decrRef();
401   m1->decrRef();
402   // Testing with 2D Curve
403   m1=build2DCurveTargetMesh_3();
404   f2=m1->getMeasureField(false);
405   CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
406   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
407   ptr=f2->getArray()->getConstPointer();
408   for(int i=0;i<4;i++)
409     CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected2[i],ptr[i],1e-12);
410   f2->decrRef();
411   f2=m1->getMeasureField(true);
412   CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
413   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
414   ptr=f2->getArray()->getConstPointer();
415   for(int i=0;i<4;i++)
416     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i]*sqrt(2.),ptr[i],1e-12);
417   f2->decrRef();
418   //bary
419   f3=m1->getBarycenterAndOwner();
420   CPPUNIT_ASSERT_EQUAL(4,f3->getNumberOfTuples());
421   CPPUNIT_ASSERT_EQUAL(2,f3->getNumberOfComponents());
422   double expected10[8]={0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155};
423   ptr=f3->getConstPointer();
424    for(int i=0;i<8;i++)
425      CPPUNIT_ASSERT_DOUBLES_EQUAL(expected10[i],ptr[i],1e-12);
426   f3->decrRef();
427   //
428   f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
429   f1->setMesh(m1);
430   array=DataArrayDouble::New();
431   array->alloc(m1->getNumberOfCells(),3);
432   std::copy(arr,arr+12,array->getPointer());
433   f1->setArray(array);
434   array->decrRef();
435   f1->integral(false,res);
436   for(int i=0;i<3;i++)
437     CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
438   f1->integral(true,res);
439   for(int i=0;i<3;i++)
440     CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
441   f1->normL1(res);
442   for(int i=0;i<3;i++)
443     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
444   f1->normL2(res);
445   for(int i=0;i<3;i++)
446     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-12);
447   //
448   f1->decrRef();
449   m1->decrRef();
450 }
451
452 void MEDCouplingBasicsTest2::testAreaBary2D()
453 {
454   MEDCouplingUMesh *m1=build2DTargetMesh_3();
455   MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
456   CPPUNIT_ASSERT_EQUAL(10,f1->getArray()->getNumberOfTuples());
457   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
458   double expected1[10]={-0.5,-1,-1.5,-0.5,-1,  0.5,1,1.5,0.5,1};
459   const double *ptr=f1->getArray()->getConstPointer();
460   for(int i=0;i<10;i++)
461     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
462   f1->decrRef();
463   f1=m1->getMeasureField(true);
464   ptr=f1->getArray()->getConstPointer();
465   for(int i=0;i<10;i++)
466     CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
467   f1->decrRef();
468   DataArrayDouble *f2=m1->getBarycenterAndOwner();
469   CPPUNIT_ASSERT_EQUAL(10,f2->getNumberOfTuples());
470   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
471   double expected2[20]={
472     0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
473     0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
474   };
475   ptr=f2->getConstPointer();
476   for(int i=0;i<20;i++)
477     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
478   f2->decrRef();
479   m1->changeSpaceDimension(3);
480   f1=m1->getMeasureField(false);
481   CPPUNIT_ASSERT_EQUAL(10,f1->getArray()->getNumberOfTuples());
482   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
483   ptr=f1->getArray()->getConstPointer();
484   for(int i=0;i<10;i++)
485     CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
486   f1->decrRef();
487   f2=m1->getBarycenterAndOwner();
488   CPPUNIT_ASSERT_EQUAL(10,f2->getNumberOfTuples());
489   CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfComponents());
490   ptr=f2->getConstPointer();
491   double expected3[30]={
492     0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.,
493     0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.
494   };
495   for(int i=0;i<30;i++)
496     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
497   f2->decrRef();
498   m1->decrRef();
499 }
500
501 /*!
502  * This test check polyhedron true barycenter computation 2. 
503  */
504 void MEDCouplingBasicsTest2::testAreaBary3D()
505 {
506   double coords [] = { 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
507                        0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
508                        0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
509                        0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
510                        -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
511                        -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
512                        0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
513                        0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
514                        -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
515                        0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
516                        -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
517                        -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
518                        -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
519                        -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
520                        -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
521                        -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
522                        0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
523                        0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
524                        0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
525                        -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
526                        -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
527                        -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
528                        -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
529                        0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
530                        0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
531                        0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
532                        -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
533                        -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
534                        0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
535                        0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
536                        -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
537                        0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
538                        0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
539                        0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
540                        -0.0372812069535 , -0.286740286332 , 0.00963701291166 };
541
542   int connN [] = { /*polyhedron 0*/
543     0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
544     , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
545     , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
546     , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
547     /* polyhedron 1*/
548     0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
549     , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
550     , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
551     , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
552     /* polyhedron 2*/
553     6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
554     , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
555     /*polyhedron 3*/
556     35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
557     , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
558     , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
559     , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65};
560
561   double barys[]={ -0.0165220465527 , -0.0190922868195 , 0.158882733414 ,
562                    0.0287618656076 , 0.135874379934 , -0.14601588119 ,
563                    -0.147128055553 , 0.0465995097041 , -0.049391174453 ,
564                    -0.00142506732317 , -0.0996953090351 , -0.115159183132 };
565   MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
566   meshN->setName("ForBary");
567   meshN->setMeshDimension(3);
568   meshN->allocateCells(4);
569   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,113,connN);
570   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,99,connN+113);
571   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,connN+212);
572   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,92,connN+255);
573   meshN->finishInsertingCells();
574   DataArrayDouble *myCoords=DataArrayDouble::New();
575   myCoords->alloc(69,3);
576   std::copy(coords,coords+207,myCoords->getPointer());
577   meshN->setCoords(myCoords);
578   myCoords->decrRef();
579   meshN->checkCoherency();
580   std::vector<int> res1;
581   meshN->arePolyhedronsNotCorrectlyOriented(res1);
582   meshN->orientCorrectlyPolyhedrons();
583   res1.clear();
584   meshN->arePolyhedronsNotCorrectlyOriented(res1);
585   CPPUNIT_ASSERT(res1.empty());
586   //
587   DataArrayDouble *da=meshN->getBarycenterAndOwner();
588   CPPUNIT_ASSERT_EQUAL(4,da->getNumberOfTuples());
589   CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents());
590   const double *daPtr=da->getConstPointer();
591   for(int i=0;i<12;i++)
592     CPPUNIT_ASSERT_DOUBLES_EQUAL(barys[i],daPtr[i],1e-12);
593   da->decrRef();
594   //
595   meshN->decrRef();
596 }
597
598 void MEDCouplingBasicsTest2::testRenumberCellsForFields()
599 {
600   MEDCouplingUMesh *m=build2DTargetMesh_1();
601   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
602   f->setMesh(m);
603   DataArrayDouble *arr=DataArrayDouble::New();
604   int nbOfCells=m->getNumberOfCells();
605   arr->alloc(nbOfCells,3);
606   f->setArray(arr);
607   arr->decrRef();
608   const double values1[15]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.};
609   std::copy(values1,values1+15,arr->getPointer());
610   const int renumber1[5]={3,1,0,4,2};
611   double res[3];
612   const double loc[]={-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45};
613   for(int j=0;j<5;j++)
614     {
615       f->getValueOn(loc+2*j,res);
616       for(int i=0;i<3;i++)
617         CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
618     }
619   f->renumberCells(renumber1,false);
620   const double *ptr=f->getArray()->getConstPointer();
621   const double expected1[15]={9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.};
622   for(int i=0;i<15;i++)
623     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
624   //check that fields remains the same geometrically
625   for(int j=0;j<5;j++)
626     {
627       f->getValueOn(loc+2*j,res);
628       for(int i=0;i<3;i++)
629         CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
630     }
631   f->decrRef();
632   //On gauss
633   f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME);
634   f->setMesh(m);
635   const double _a=0.446948490915965;
636   const double _b=0.091576213509771;
637   const double _p1=0.11169079483905;
638   const double _p2=0.0549758718227661;
639   const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
640   const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
641                             2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
642   const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
643   std::vector<double> _refCoo1(refCoo1,refCoo1+6);
644   std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
645   std::vector<double> _wg1(wg1,wg1+6);
646   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
647   const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
648   std::vector<double> _refCoo2(refCoo2,refCoo2+8);
649   _gsCoo1.resize(4); _wg1.resize(2);
650   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
651   arr=DataArrayDouble::New();
652   arr->alloc(18,2);
653   const double values2[36]={1.,1001.,2.,1002., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 31.,1031.,32.,1032., 41.,1041.,42.,1042.};
654   std::copy(values2,values2+36,arr->getPointer());
655   f->setArray(arr);
656   arr->decrRef();
657   f->checkCoherency();
658   MEDCouplingFieldDouble *fCpy=f->clone(true);
659   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
660   f->renumberCells(renumber1,false);
661   CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
662   double expected2[36]={21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 41.,1041.,42.,1042., 1.,1001.,2.,1002., 31.,1031.,32.,1032.};
663   ptr=f->getArray()->getConstPointer();
664   for(int i=0;i<36;i++)
665     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
666   const int renumber2[5]={2,1,4,0,3};//reverse renumber1
667   f->renumberCells(renumber2,false);
668   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
669   fCpy->decrRef();
670   f->decrRef();
671   //GaussNE
672   f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
673   f->setMesh(m);
674   arr=DataArrayDouble::New();
675   arr->alloc(18,2);
676   const double values3[36]={1.,1001.,2.,1002.,3.,1003.,4.,1004., 11.,1011.,12.,1012.,13.,1013., 21.,1021.,22.,1022.,23.,1023., 31.,1031.,32.,1032.,33.,1033.,34.,1034., 41.,1041.,42.,1042.,43.,1043.,44.,1044.};
677   std::copy(values3,values3+36,arr->getPointer());
678   f->setArray(arr);
679   arr->decrRef();
680   f->checkCoherency();
681   fCpy=f->clone(true);
682   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
683   f->renumberCells(renumber1,false);
684   CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
685   double expected3[36]={21.,1021.,22.,1022.,23.,1023.,11.,1011.,12.,1012.,13.,1013.,41.,1041.,42.,1042.,43.,1043.,44.,1044.,1.,1001.,2.,1002.,3.,1003.,4.,1004.,31.,1031.,32.,1032.,33.,1033.,34.,1034.};
686   ptr=f->getArray()->getConstPointer();
687   for(int i=0;i<36;i++)
688     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
689   f->renumberCells(renumber2,false);//perform reverse operation of renumbering to check that the resulting field is equal.
690   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
691   fCpy->decrRef();
692   f->decrRef();
693   //
694   m->decrRef();
695 }
696
697 void MEDCouplingBasicsTest2::testRenumberNodesForFields()
698 {
699   MEDCouplingUMesh *m=build2DTargetMesh_1();
700   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
701   f->setMesh(m);
702   CPPUNIT_ASSERT_EQUAL(9,f->getNumberOfMeshPlacesExpected());
703   DataArrayDouble *arr=DataArrayDouble::New();
704   int nbOfNodes=m->getNumberOfNodes();
705   arr->alloc(nbOfNodes,3);
706   f->setArray(arr);
707   arr->decrRef();
708   const double values1[27]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.};
709   std::copy(values1,values1+27,arr->getPointer());
710   f->checkCoherency();
711   const int renumber1[9]={0,4,1,3,5,2,6,7,8};
712   double res[3];
713   const double loc[]={0.5432,-0.2432, 0.5478,0.1528};
714   const double expected1[6]={9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124};
715   for(int j=0;j<2;j++)
716     {
717       f->getValueOn(loc+2*j,res);
718       for(int i=0;i<3;i++)
719         CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
720     }
721   MEDCouplingFieldDouble *fCpy=f->clone(true);
722   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
723   f->renumberNodes(renumber1);
724   CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
725   for(int j=0;j<2;j++)
726     {
727       f->getValueOn(loc+2*j,res);
728       for(int i=0;i<3;i++)
729         CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
730     }
731   const double expected2[27]={7.,107.,10007.,9.,109.,10009.,12.,112.,10012.,10.,110.,10010.,8.,108.,10008.,11.,111.,10011.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.};
732   for(int i=0;i<27;i++)
733     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getArray()->getConstPointer()[i],1e-12);
734   const int renumber2[9]={0,2,5,3,1,4,6,7,8};//reverse of renumber2
735   f->renumberNodes(renumber2);
736   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
737   fCpy->decrRef();
738   //
739   m->decrRef();
740   f->decrRef();
741 }
742
743 void MEDCouplingBasicsTest2::testConvertQuadraticCellsToLinear()
744 {
745   MEDCouplingUMesh *mesh=build2DTargetMesh_3();
746   mesh->checkCoherency();
747   const std::set<INTERP_KERNEL::NormalizedCellType>& types=mesh->getAllTypes();
748   CPPUNIT_ASSERT_EQUAL(5,(int)types.size());
749   INTERP_KERNEL::NormalizedCellType expected1[5]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QUAD8};
750   std::set<INTERP_KERNEL::NormalizedCellType> expected1Bis(expected1,expected1+5);
751   CPPUNIT_ASSERT(expected1Bis==types);
752   CPPUNIT_ASSERT(mesh->isPresenceOfQuadratic());
753   CPPUNIT_ASSERT_EQUAL(62,mesh->getMeshLength());
754   MEDCouplingFieldDouble *f1=mesh->getMeasureField(false);
755   //
756   mesh->convertQuadraticCellsToLinear();
757   CPPUNIT_ASSERT(!mesh->isPresenceOfQuadratic());
758   //
759   mesh->checkCoherency();
760   MEDCouplingFieldDouble *f2=mesh->getMeasureField(false);
761   CPPUNIT_ASSERT(f1->getArray()->isEqual(*f2->getArray(),1e-12));
762   CPPUNIT_ASSERT_EQUAL(48,mesh->getMeshLength());
763   const std::set<INTERP_KERNEL::NormalizedCellType>& types2=mesh->getAllTypes();
764   CPPUNIT_ASSERT_EQUAL(3,(int)types.size());
765   INTERP_KERNEL::NormalizedCellType expected2[3]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
766   std::set<INTERP_KERNEL::NormalizedCellType> expected2Bis(expected2,expected2+3);
767   CPPUNIT_ASSERT(expected2Bis==types2);
768   //
769   f1->decrRef();
770   f2->decrRef();
771   mesh->decrRef();
772 }
773
774 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith()
775 {
776   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
777   MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
778   DataArrayInt *cellCor,*nodeCor;
779   //First test mesh1
780   mesh1->checkGeoEquivalWith(mesh1,0,1e-12,cellCor,nodeCor);//deepEqual
781   CPPUNIT_ASSERT(cellCor==0);
782   CPPUNIT_ASSERT(nodeCor==0);
783   mesh1->checkGeoEquivalWith(mesh1,1,1e-12,cellCor,nodeCor);//fastEqual
784   CPPUNIT_ASSERT(cellCor==0);
785   CPPUNIT_ASSERT(nodeCor==0);
786   mesh1->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
787   CPPUNIT_ASSERT(cellCor==0);
788   CPPUNIT_ASSERT(nodeCor==0);
789   //Second test mesh1 and mesh2 are 2 different meshes instance
790   mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual
791   CPPUNIT_ASSERT(cellCor==0);
792   CPPUNIT_ASSERT(nodeCor==0);
793   mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual
794   CPPUNIT_ASSERT(cellCor==0);
795   CPPUNIT_ASSERT(nodeCor==0);
796   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
797   CPPUNIT_ASSERT(cellCor==0);
798   CPPUNIT_ASSERT(nodeCor==0);
799   //Third test : cell permutation by keeping the first the middle and the last as it is.
800   const int renum[]={0,2,1,3,4,5,6,8,7,9};
801   mesh2->renumberCells(renum,false);
802   CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
803   CPPUNIT_ASSERT(cellCor==0);
804   CPPUNIT_ASSERT(nodeCor==0);
805   mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
806   CPPUNIT_ASSERT(cellCor==0);
807   CPPUNIT_ASSERT(nodeCor==0);
808   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
809   CPPUNIT_ASSERT(cellCor);
810   CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
811   CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
812   CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
813   CPPUNIT_ASSERT(nodeCor==0);
814   cellCor->decrRef();
815   cellCor=0;
816   CPPUNIT_ASSERT(nodeCor==0);
817   //4th test : cell and node permutation by keeping the first the middle and the last as it is.
818   mesh2->decrRef();
819   mesh2=build2DTargetMesh_3();
820   const int renum2[]={0,2,1,3,4,5,6,8,7,9,10};
821   mesh2->renumberCells(renum,false);
822   mesh2->renumberNodes(renum2,11);
823   CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
824   CPPUNIT_ASSERT(cellCor==0);
825   CPPUNIT_ASSERT(nodeCor==0);
826   mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
827   CPPUNIT_ASSERT(cellCor==0);
828   CPPUNIT_ASSERT(nodeCor==0);
829   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
830   CPPUNIT_ASSERT(cellCor);
831   CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
832   CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
833   CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
834   CPPUNIT_ASSERT(nodeCor);
835   CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
836   CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
837   CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
838   cellCor->decrRef();
839   cellCor=0;
840   nodeCor->decrRef();
841   nodeCor=0;
842   //5th test : modification of the last cell to check fastCheck detection.
843   mesh2->decrRef();
844   mesh2=build2DTargetMesh_3();
845   const int renum3[]={0,2,1,3,4,5,6,8,9,7};
846   mesh2->renumberCells(renum3,false);
847   mesh2->renumberNodes(renum2,11);
848   bool isExcep=false;
849   try { mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual fails
850   }
851   catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
852   CPPUNIT_ASSERT(isExcep); isExcep=false;
853   CPPUNIT_ASSERT(cellCor==0);
854   CPPUNIT_ASSERT(nodeCor==0);
855   try { mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual has detected something
856   }
857   catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
858   CPPUNIT_ASSERT(isExcep); isExcep=false;
859   CPPUNIT_ASSERT(cellCor==0);
860   CPPUNIT_ASSERT(nodeCor==0);
861   mesh2->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
862   CPPUNIT_ASSERT(cellCor);
863   CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
864   CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
865   CPPUNIT_ASSERT(std::equal(renum3,renum3+10,cellCor->getConstPointer()));
866   CPPUNIT_ASSERT(nodeCor);
867   CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
868   CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
869   CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
870   cellCor->decrRef();
871   cellCor=0;
872   nodeCor->decrRef();
873   nodeCor=0;
874   //
875   mesh1->decrRef();
876   mesh2->decrRef();
877 }
878
879 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith2()
880 {
881   MEDCouplingUMesh *mesh1=build2DTargetMesh_4();
882   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
883   DataArrayInt *cellCor,*nodeCor;
884   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);
885   CPPUNIT_ASSERT(cellCor==0);
886   CPPUNIT_ASSERT(nodeCor!=0);
887   const int expected1[9]={0, 1, 3, 4, 5, 6, 7, 8, 9};
888   for(int i=0;i<9;i++)
889     CPPUNIT_ASSERT_EQUAL(expected1[i],nodeCor->getIJ(i,0));
890   nodeCor->decrRef();
891   //
892   mesh1->decrRef();
893   mesh2->decrRef();
894 }
895
896 void MEDCouplingBasicsTest2::testCopyTinyStringsFromOnFields()
897 {
898   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
899   int nbOfCells=m->getNumberOfCells();
900   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
901   f->setMesh(m);
902   CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected());
903   f->setName("a");
904   f->setDescription("b");
905   DataArrayDouble *a1=DataArrayDouble::New();
906   a1->alloc(nbOfCells,2);
907   a1->fillWithZero();
908   a1->setInfoOnComponent(0,"c");
909   a1->setInfoOnComponent(1,"d");
910   DataArrayDouble *a2=a1->deepCpy();
911   a2->setInfoOnComponent(0,"e");
912   a2->setInfoOnComponent(1,"f");
913   f->setArray(a1);
914   f->setEndArray(a2);
915   f->setEndTime(3.,3,4);
916   a2->decrRef();
917   a1->decrRef();
918   m->setName("g");
919   m->getCoords()->setInfoOnComponent(0,"h");
920   m->getCoords()->setInfoOnComponent(1,"i");
921   m->getCoords()->setInfoOnComponent(2,"j");
922   //
923   f->checkCoherency();
924   MEDCouplingFieldDouble *f2=f->clone(true);
925   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
926   f2->setName("smth");
927   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
928   f2->copyTinyStringsFrom(f);
929   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
930   f2->setDescription("GGG");
931   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
932   f2->copyTinyStringsFrom(f);
933   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
934   f2->getArray()->setInfoOnComponent(0,"mmmm");
935   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
936   f2->copyTinyStringsFrom(f);
937   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
938   f2->getEndArray()->setInfoOnComponent(1,"mmmm");
939   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
940   f2->copyTinyStringsFrom(f);
941   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
942   f2->decrRef();
943   MEDCouplingUMesh *m2=m->clone(true);
944   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
945   m2->setName("123");
946   CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
947   m2->copyTinyStringsFrom(m);
948   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
949   m2->getCoords()->setInfoOnComponent(1,"eee");
950   CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
951   m2->copyTinyStringsFrom(m);
952   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
953   m2->decrRef();
954   //
955   f->decrRef();
956   m->decrRef();
957 }
958
959 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute()
960 {
961   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
962   MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
963   CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
964   m->tryToShareSameCoordsPermute(*m2,1e-12);
965   CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
966   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
967   const int renum1[9]={1,2,0,5,8,7,4,3,6};
968   m->renumberNodes(renum1,9);
969   CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
970   CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
971   m->tryToShareSameCoordsPermute(*m2,1e-12);
972   CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
973   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
974   m2->decrRef();
975   m->decrRef();
976 }
977
978 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute2()
979 {
980   MEDCouplingUMesh *m1=build2DTargetMesh_4();
981   double targetCoords[8]={-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 };
982   int targetConn[4]={0,2,3,1};
983   MEDCouplingUMesh *m2=MEDCouplingUMesh::New();
984   m2->setMeshDimension(2);
985   m2->allocateCells(1);
986   m2->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
987   m2->finishInsertingCells();
988   DataArrayDouble *myCoords=DataArrayDouble::New();
989   myCoords->alloc(4,2);
990   std::copy(targetCoords,targetCoords+8,myCoords->getPointer());
991   m2->setCoords(myCoords);
992   myCoords->decrRef();
993   m2->checkCoherency();
994   m1->checkCoherency();
995   //
996   const double expected1[5]={0.25,0.125,0.125,0.25,0.25};
997   MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
998   MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
999   CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
1000   CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
1001   for(int i=0;i<5;i++)
1002     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
1003   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
1004   f2->decrRef();
1005   f1->decrRef();
1006   CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoordsPermute(*m2,1e-12),INTERP_KERNEL::Exception);// <- here in this order the sharing is impossible.
1007   // Let's go for deeper test of tryToShareSameCoordsPermute
1008   m2->tryToShareSameCoordsPermute(*m1,1e-12);
1009   f1=m1->getMeasureField(false);
1010   f2=m2->getMeasureField(false);
1011   CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
1012   CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
1013   for(int i=0;i<5;i++)
1014     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
1015   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
1016   //
1017   f2->decrRef();
1018   f1->decrRef();
1019   //
1020   m1->decrRef();
1021   m2->decrRef();
1022 }
1023
1024 void MEDCouplingBasicsTest2::testChangeUnderlyingMesh1()
1025 {
1026   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1027   MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
1028   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1029   f1->setMesh(mesh1);
1030   DataArrayDouble *array=DataArrayDouble::New();
1031   array->alloc(mesh1->getNumberOfCells(),2);
1032   const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1033   std::copy(arr,arr+20,array->getPointer());
1034   f1->setArray(array);
1035   array->decrRef();
1036   //
1037   const int renum[]={0,2,1,3,4,5,6,8,7,9};
1038   mesh2->renumberCells(renum,false);
1039   CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1040   f1->changeUnderlyingMesh(mesh1,10,1e-12);// nothing done only to check that nothing done.
1041   CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1042   f1->changeUnderlyingMesh(mesh2,10,1e-12);
1043   CPPUNIT_ASSERT(f1->getMesh()==mesh2);
1044   const double expected1[20]={7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.};
1045   for(int i=0;i<20;i++)
1046     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
1047   f1->decrRef();
1048   //
1049   f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
1050   f1->setMesh(mesh1);
1051   array=DataArrayDouble::New();
1052   array->alloc(mesh1->getNumberOfNodes(),2);
1053   const double arr2[22]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.,17.,117.};
1054   std::copy(arr2,arr2+22,array->getPointer());
1055   f1->setArray(array);
1056   array->decrRef();
1057   //
1058   const int renum2[]={0,2,10,3,4,5,6,8,7,9,1};
1059   mesh2->renumberNodes(renum2,11);
1060   CPPUNIT_ASSERT(f1->getMesh()==mesh1);
1061   f1->changeUnderlyingMesh(mesh2,10,1e-12);
1062   CPPUNIT_ASSERT(f1->getMesh()==mesh2);
1063   const double expected2[22]={7.,107.,17.,117.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,9.,109.};
1064   for(int i=0;i<22;i++)
1065     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getArray()->getIJ(0,i),1e-12);
1066   f1->decrRef();
1067   //
1068   mesh1->decrRef();
1069   mesh2->decrRef();
1070 }
1071
1072 void MEDCouplingBasicsTest2::testGetMaxValue1()
1073 {
1074   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1075   int nbOfCells=m->getNumberOfCells();
1076   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1077   f->setMesh(m);
1078   DataArrayDouble *a1=DataArrayDouble::New();
1079   a1->alloc(nbOfCells,1);
1080   const double val1[5]={3.,4.,5.,6.,7.};
1081   std::copy(val1,val1+5,a1->getPointer());
1082   DataArrayDouble *a2=DataArrayDouble::New();
1083   a2->alloc(nbOfCells,1);
1084   const double val2[5]={0.,1.,2.,8.,7.};
1085   std::copy(val2,val2+5,a2->getPointer());
1086   f->setArray(a1);
1087   f->setEndArray(a2);
1088   f->setEndTime(3.,3,4);
1089   f->checkCoherency();
1090   //
1091   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,f->getMaxValue(),1e-14);
1092   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
1093   CPPUNIT_ASSERT_DOUBLES_EQUAL(5.,f->getAverageValue(),1e-14);
1094   CPPUNIT_ASSERT_DOUBLES_EQUAL(5.125,f->getWeightedAverageValue(),1e-14);
1095   a1->setIJ(0,2,9.5);
1096   CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
1097   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
1098   a2->setIJ(0,0,9.);
1099   CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
1100   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,f->getMinValue(),1e-14);
1101   //
1102   a2->decrRef();
1103   a1->decrRef();
1104   m->decrRef();
1105   f->decrRef();
1106 }
1107
1108 void MEDCouplingBasicsTest2::testSubstractInPlaceDM1()
1109 {
1110   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1111   MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
1112   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1113   f1->setMesh(mesh1);
1114   DataArrayDouble *array=DataArrayDouble::New();
1115   array->alloc(mesh1->getNumberOfCells(),2);
1116   const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1117   std::copy(arr,arr+20,array->getPointer());
1118   f1->setArray(array);
1119   array->decrRef();
1120   //
1121   CPPUNIT_ASSERT_EQUAL(10,f1->getNumberOfTuples());
1122   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
1123   CPPUNIT_ASSERT_EQUAL(20,f1->getNumberOfValues());
1124   //
1125   const int renum[]={0,2,3,1,4,5,6,8,7,9};
1126   mesh2->renumberCells(renum,false);
1127   //
1128   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1129   f2->setMesh(mesh2);
1130   array=DataArrayDouble::New();
1131   array->alloc(mesh2->getNumberOfCells(),2);
1132   const double arr2[20]={7.1,107.1,10.1,110.1,8.1,108.1,9.1,109.1,11.1,111.1,12.1,112.1,13.1,113.1,15.1,115.1,14.1,114.1,16.1,116.1};
1133   std::copy(arr2,arr2+20,array->getPointer());
1134   f2->setArray(array);
1135   array->decrRef();
1136   //
1137   f1->substractInPlaceDM(f2,10,1e-12);
1138   f1->applyFunc(1,"abs(x+y+0.2)");
1139   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f1->getMaxValue(),1e-14);
1140   //
1141   f1->decrRef();
1142   f2->decrRef();
1143   mesh1->decrRef();
1144   mesh2->decrRef();
1145 }
1146
1147 void MEDCouplingBasicsTest2::testDotCrossProduct1()
1148 {
1149   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1150   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1151   f1->setTime(2.3,5,6);
1152   f1->setMesh(mesh1);
1153   DataArrayDouble *array=DataArrayDouble::New();
1154   array->alloc(mesh1->getNumberOfCells(),3);
1155   const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.};
1156   std::copy(arr1,arr1+30,array->getPointer());
1157   f1->setArray(array);
1158   array->decrRef();
1159   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1160   f2->setTime(7.8,4,5);
1161   f2->setMesh(mesh1);
1162   array=DataArrayDouble::New();
1163   array->alloc(mesh1->getNumberOfCells(),3);
1164   const double arr2[30]={1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.};
1165   std::copy(arr2,arr2+30,array->getPointer());
1166   f2->setArray(array);
1167   array->decrRef();
1168   //
1169   MEDCouplingFieldDouble *f3=f1->dot(*f2);
1170   const double expected1[10]={842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.};
1171   for(int i=0;i<10;i++)
1172     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(i,0),1e-9);
1173   f3->decrRef();
1174   //
1175   MEDCouplingFieldDouble *f4=f1->crossProduct(*f2);
1176   const double expected2[30]={-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.};
1177   for(int i=0;i<30;i++)
1178     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
1179   f4->decrRef();
1180   //
1181   f2->decrRef();
1182   f1->decrRef();
1183   mesh1->decrRef();
1184 }
1185
1186 void MEDCouplingBasicsTest2::testMinMaxFields1()
1187 {
1188   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1189   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1190   f1->setTime(2.3,5,6);
1191   f1->setMesh(mesh1);
1192   DataArrayDouble *array=DataArrayDouble::New();
1193   array->alloc(mesh1->getNumberOfCells(),3);
1194   const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.};
1195   std::copy(arr1,arr1+30,array->getPointer());
1196   f1->setArray(array);
1197   array->decrRef();
1198   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1199   f2->setTime(7.8,4,5);
1200   f2->setMesh(mesh1);
1201   array=DataArrayDouble::New();
1202   array->alloc(mesh1->getNumberOfCells(),3);
1203   const double arr2[30]={6.,108.,206.,9.,107.,209.,8.,110.,208.,11.,109.,211.,10.,112.,210.,13.,111.,213.,12.,114.,212.,15.,113.,215.,14.,116.,214.,17.,115.,217.};
1204   std::copy(arr2,arr2+30,array->getPointer());
1205   f2->setArray(array);
1206   array->decrRef();
1207   //
1208   MEDCouplingFieldDouble *f3=f1->max(*f2);
1209   const double expected1[30]={7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.};
1210   for(int i=0;i<30;i++)
1211     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-9);
1212   f3->decrRef();
1213   //
1214   MEDCouplingFieldDouble *f4=f1->min(*f2);
1215   const double expected2[30]={6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.};
1216   for(int i=0;i<30;i++)
1217     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
1218   f4->decrRef();
1219   //
1220   f2->decrRef();
1221   f1->decrRef();
1222   mesh1->decrRef();
1223 }
1224
1225 void MEDCouplingBasicsTest2::testApplyLin1()
1226 {
1227   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1228   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1229   f1->setMesh(mesh1);
1230   DataArrayDouble *array=DataArrayDouble::New();
1231   array->alloc(mesh1->getNumberOfCells(),2);
1232   const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
1233   std::copy(arr,arr+20,array->getPointer());
1234   f1->setArray(array);
1235   array->decrRef();
1236   //
1237   f1->applyLin(2.,3.,0);
1238   const double expected1[20]={17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.};
1239   for(int i=0;i<20;i++)
1240     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-9);
1241   //
1242   const double arr2[20]={2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
1243   array=DataArrayDouble::New();
1244   array->alloc(mesh1->getNumberOfCells(),2);
1245   std::copy(arr2,arr2+20,array->getPointer());
1246   f1->setEndArray(array);
1247   array->decrRef();
1248   //
1249   f1->applyLin(4.,5.,1);
1250   //
1251   const double expected2[20]={17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.};
1252   for(int i=0;i<20;i++)
1253     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-9);
1254   const double expected3[20]={2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.};
1255   for(int i=0;i<20;i++)
1256     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f1->getEndArray()->getIJ(0,i),1e-9);
1257   //
1258   mesh1->decrRef();
1259   f1->decrRef();
1260 }
1261
1262 void MEDCouplingBasicsTest2::testGetIdsInRange1()
1263 {
1264   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
1265   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1266   f1->setTime(2.3,5,6);
1267   f1->setMesh(mesh1);
1268   DataArrayDouble *array=DataArrayDouble::New();
1269   array->alloc(mesh1->getNumberOfCells(),1);
1270   const double arr1[10]={2.,8.,6.,5.,11.,7.,9.,3.,10.,4.};
1271   std::copy(arr1,arr1+10,array->getPointer());
1272   f1->setArray(array);
1273   array->decrRef();
1274   //
1275   f1->checkCoherency();
1276   DataArrayInt *da=f1->getIdsInRange(2.9,7.1);
1277   CPPUNIT_ASSERT_EQUAL(5,da->getNbOfElems());
1278   const int expected1[5]={2,3,5,7,9};
1279   CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1280   da->decrRef();
1281   da=f1->getIdsInRange(8.,12.);
1282   CPPUNIT_ASSERT_EQUAL(4,da->getNbOfElems());
1283   const int expected2[4]={1,4,6,8};
1284   CPPUNIT_ASSERT(std::equal(expected2,expected2+4,da->getConstPointer()));
1285   da->decrRef();
1286   //
1287   f1->decrRef();
1288   mesh1->decrRef();
1289 }
1290
1291 void MEDCouplingBasicsTest2::testBuildSubPart1()
1292 {
1293   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1294   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1295   f1->setTime(2.3,5,6);
1296   f1->setMesh(mesh1);
1297   DataArrayDouble *array=DataArrayDouble::New();
1298   array->alloc(mesh1->getNumberOfCells(),2);
1299   const double arr1[10]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.};
1300   std::copy(arr1,arr1+10,array->getPointer());
1301   f1->setArray(array);
1302   array->decrRef();
1303   //
1304   const int part1[3]={2,1,4};
1305   MEDCouplingFieldDouble *f2=f1->buildSubPart(part1,part1+3);
1306   f2->zipCoords();
1307   CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfTuples());
1308   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1309   const double expected1[6]={5.,105.,4.,104.,7.,107.};
1310   for(int i=0;i<6;i++)
1311     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected1[i],1e-12);
1312   CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
1313   CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
1314   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1315   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1316   MEDCouplingUMesh *m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1317   CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
1318   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};
1319   for(int i=0;i<12;i++)
1320     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1321   const double expected3[13]={3,2,3,1,3,0,2,1,4,4,5,3,2};
1322   CPPUNIT_ASSERT(std::equal(expected3,expected3+13,m2C->getNodalConnectivity()->getConstPointer()));
1323   const double expected4[4]={0,4,8,13};
1324   CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
1325   f2->decrRef();
1326   f1->decrRef();
1327   // Test with field on nodes.
1328   f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
1329   f1->setTime(2.3,5,6);
1330   f1->setMesh(mesh1);
1331   array=DataArrayDouble::New();
1332   array->alloc(mesh1->getNumberOfNodes(),2);
1333   const double arr2[18]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
1334   std::copy(arr2,arr2+18,array->getPointer());  
1335   f1->setArray(array);
1336   array->decrRef();
1337   const int part2[2]={1,2};
1338   f2=f1->buildSubPart(part2,part2+2);
1339   CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfTuples());
1340   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1341   const double expected5[8]={4.,104.,5.,105.,7.,107.,8.,108.};
1342   for(int i=0;i<8;i++)
1343     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
1344   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getNumberOfCells());
1345   CPPUNIT_ASSERT_EQUAL(4,f2->getMesh()->getNumberOfNodes());
1346   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1347   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1348   m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1349   CPPUNIT_ASSERT_EQUAL(8,m2C->getMeshLength());
1350   for(int i=0;i<8;i++)//8 is not an error
1351     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1352   CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1353   CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1354   CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
1355   f2->decrRef();
1356   //idem previous because nodes of cell#4 are not fully present in part3 
1357   const int part3[2]={1,2};
1358   DataArrayInt *arrr=DataArrayInt::New();
1359   arrr->alloc(2,1);
1360   std::copy(part3,part3+2,arrr->getPointer());
1361   f2=f1->buildSubPart(arrr);
1362   arrr->decrRef();
1363   CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfTuples());
1364   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1365   for(int i=0;i<8;i++)
1366     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
1367   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getNumberOfCells());
1368   CPPUNIT_ASSERT_EQUAL(4,f2->getMesh()->getNumberOfNodes());
1369   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1370   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1371   m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1372   CPPUNIT_ASSERT_EQUAL(8,m2C->getMeshLength());
1373   for(int i=0;i<8;i++)//8 is not an error
1374     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1375   CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1376   CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1377   CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
1378   f2->decrRef();
1379   //
1380   const int part4[3]={1,2,4};
1381   f2=f1->buildSubPart(part4,part4+3);
1382   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfTuples());
1383   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
1384   const double expected6[12]={4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.};
1385   for(int i=0;i<12;i++)
1386     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected6[i],1e-12);
1387   CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
1388   CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
1389   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
1390   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
1391   m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1392   CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
1393   for(int i=0;i<12;i++)
1394     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
1395   CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
1396   CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
1397   CPPUNIT_ASSERT(std::equal(expected3+8,expected3+13,m2C->getNodalConnectivity()->getConstPointer()+8));
1398   CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
1399   f2->decrRef();
1400   //
1401   f1->decrRef();
1402   mesh1->decrRef();
1403 }
1404
1405 void MEDCouplingBasicsTest2::testDoublyContractedProduct1()
1406 {
1407   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1408   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1409   f1->setMesh(mesh1);
1410   DataArrayDouble *array=DataArrayDouble::New();
1411   array->alloc(mesh1->getNumberOfCells(),6);
1412   const double arr1[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1413   std::copy(arr1,arr1+30,array->getPointer());
1414   f1->setArray(array);
1415   array->decrRef();
1416   f1->checkCoherency();
1417   //
1418   MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
1419   f2->checkCoherency();
1420   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1421   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1422   for(int i=0;i<5;i++)
1423     CPPUNIT_ASSERT_DOUBLES_EQUAL(3906.56,f2->getIJ(i,0),1e-9);
1424   f2->decrRef();
1425   //
1426   mesh1->decrRef();
1427   f1->decrRef();
1428 }
1429
1430 void MEDCouplingBasicsTest2::testDeterminant1()
1431 {
1432   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1433   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1434   f1->setTime(2.3,5,6);
1435   f1->setEndTime(3.8,7,3);
1436   f1->setMesh(mesh1);
1437   DataArrayDouble *array=DataArrayDouble::New();
1438   array->alloc(mesh1->getNumberOfCells(),4);
1439   const double arr1[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
1440   std::copy(arr1,arr1+20,array->getPointer());
1441   f1->setArray(array);
1442   array->decrRef();
1443   //4 components
1444   f1->checkCoherency();
1445   MEDCouplingFieldDouble *f2=f1->determinant();
1446   f2->checkCoherency();
1447   CPPUNIT_ASSERT_EQUAL(CONST_ON_TIME_INTERVAL,f2->getTimeDiscretization());
1448   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1449   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfValues());
1450   for(int i=0;i<5;i++)
1451     CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.42,f2->getIJ(i,0),1e-13);
1452   f2->decrRef();
1453   f1->decrRef();
1454   //6 components multi arrays with end array not defined
1455   f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
1456   f1->setTime(2.3,5,6);
1457   f1->setEndTime(3.8,7,3);
1458   f1->setMesh(mesh1);
1459   array=DataArrayDouble::New();
1460   array->alloc(mesh1->getNumberOfNodes(),6);
1461   const double arr2[54]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7,
1462                          1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1463   std::copy(arr2,arr2+54,array->getPointer());
1464   f1->setArray(array);
1465   array->decrRef();
1466   CPPUNIT_ASSERT_THROW(f1->checkCoherency(),INTERP_KERNEL::Exception);//no end array specified !
1467   //
1468   f2=f1->determinant();
1469   CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
1470   CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfComponents());
1471   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
1472   for(int i=0;i<9;i++)
1473     CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
1474   f2->decrRef();
1475   //6 components multi arrays with end array defined
1476   array=DataArrayDouble::New();
1477   array->alloc(mesh1->getNumberOfNodes(),6);
1478   const double arr3[54]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5,
1479                          7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1480   std::copy(arr3,arr3+54,array->getPointer());
1481   f1->setEndArray(array);
1482   array->decrRef();
1483   f1->checkCoherency();
1484   f2=f1->determinant();
1485   f2->checkCoherency();
1486   CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
1487   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1488   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
1489   int it,order;
1490   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(it,order),1e-12);
1491   CPPUNIT_ASSERT_EQUAL(5,it); CPPUNIT_ASSERT_EQUAL(6,order);
1492   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.8,f2->getEndTime(it,order),1e-12);
1493   CPPUNIT_ASSERT_EQUAL(7,it); CPPUNIT_ASSERT_EQUAL(3,order);
1494   for(int i=0;i<9;i++)
1495     {
1496       CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
1497       CPPUNIT_ASSERT_DOUBLES_EQUAL(1289.685,f2->getEndArray()->getIJ(i,0),1e-9);
1498     }
1499   f2->decrRef();
1500   f1->decrRef();
1501   //9 components
1502   f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
1503   f1->setTime(7.8,10,2);
1504   f1->setMesh(mesh1);
1505   array=DataArrayDouble::New();
1506   array->alloc(mesh1->getNumberOfCells(),9);
1507   const double arr4[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
1508   std::copy(arr4,arr4+45,array->getPointer());
1509   f1->setArray(array);
1510   array->decrRef();
1511   //
1512   f1->checkCoherency();
1513   f2=f1->determinant();
1514   f2->checkCoherency();
1515   CPPUNIT_ASSERT_EQUAL(ONE_TIME,f2->getTimeDiscretization());
1516   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1517   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1518   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8,f2->getTime(it,order),1e-12);
1519   CPPUNIT_ASSERT_EQUAL(10,it); CPPUNIT_ASSERT_EQUAL(2,order);
1520   for(int i=0;i<5;i++)
1521     CPPUNIT_ASSERT_DOUBLES_EQUAL(3.267,f2->getIJ(i,0),1e-13);
1522   f2->decrRef();
1523   //
1524   mesh1->decrRef();
1525   f1->decrRef();
1526 }
1527
1528 void MEDCouplingBasicsTest2::testEigenValues1()
1529 {
1530   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1531   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1532   f1->setMesh(mesh1);
1533   DataArrayDouble *array=DataArrayDouble::New();
1534   array->alloc(mesh1->getNumberOfCells(),6);
1535   const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1536   std::copy(arr1,arr1+30,array->getPointer());
1537   f1->setArray(array);
1538   array->decrRef();
1539   f1->checkCoherency();
1540   //
1541   MEDCouplingFieldDouble *f2=f1->eigenValues();
1542   f2->checkCoherency();
1543   CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfComponents());
1544   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1545   const double expected1[3]={13.638813677891717,-4.502313844635971,-2.2364998332557486};
1546   for(int i=0;i<5;i++)
1547     {
1548       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1549       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1550       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1551     }
1552   f2->decrRef();
1553   //
1554   mesh1->decrRef();
1555   f1->decrRef();
1556 }
1557
1558 void MEDCouplingBasicsTest2::testEigenVectors1()
1559 {
1560   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1561   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1562   f1->setMesh(mesh1);
1563   DataArrayDouble *array=DataArrayDouble::New();
1564   array->alloc(mesh1->getNumberOfCells(),6);
1565   const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1566   std::copy(arr1,arr1+30,array->getPointer());
1567   f1->setArray(array);
1568   array->decrRef();
1569   f1->checkCoherency();
1570   //
1571   MEDCouplingFieldDouble *f2=f1->eigenVectors();
1572   f2->checkCoherency();
1573   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents());
1574   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1575   const double expected1[9]={
1576     0.5424262364180696, 0.5351201064614425, 0.6476266283176001,//eigenvect 0
1577     0.7381111277307373, 0.06458838384003074, -0.6715804522117897,//eigenvect 1
1578     -0.4012053603397987, 0.8423032781211455, -0.3599436712889738//eigenvect 2
1579   };
1580   for(int i=0;i<5;i++)
1581     {
1582       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1583       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1584       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1585       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1586       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1587       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1588       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
1589       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
1590       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
1591     }
1592   f2->decrRef();
1593   //
1594   mesh1->decrRef();
1595   f1->decrRef();
1596 }
1597
1598 void MEDCouplingBasicsTest2::testInverse1()
1599 {
1600   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1601   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1602   f1->setMesh(mesh1);
1603   DataArrayDouble *array=DataArrayDouble::New();
1604   array->alloc(mesh1->getNumberOfCells(),9);
1605   const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
1606   std::copy(arr1,arr1+45,array->getPointer());
1607   f1->setArray(array);
1608   array->decrRef();
1609   f1->checkCoherency();
1610   //
1611   MEDCouplingFieldDouble *f2=f1->inverse();
1612   f2->checkCoherency();
1613   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents());
1614   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1615   const double expected1[9]={-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072};
1616   for(int i=0;i<5;i++)
1617     {
1618       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1619       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1620       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1621       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1622       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1623       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1624       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
1625       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
1626       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
1627     }
1628   f2->decrRef();
1629   //
1630   array=DataArrayDouble::New();
1631   array->alloc(mesh1->getNumberOfCells(),6);
1632   const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1633   std::copy(arr3,arr3+30,array->getPointer());
1634   f1->setArray(array);
1635   array->decrRef();
1636   f1->checkCoherency();
1637   //
1638   f2=f1->inverse();
1639   f2->checkCoherency();
1640   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
1641   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1642   const double expected3[6]={-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887};
1643   for(int i=0;i<5;i++)
1644     {
1645       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f2->getIJ(i,0),1e-13);
1646       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f2->getIJ(i,1),1e-13);
1647       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f2->getIJ(i,2),1e-13);
1648       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[3],f2->getIJ(i,3),1e-13);
1649       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[4],f2->getIJ(i,4),1e-13);
1650       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[5],f2->getIJ(i,5),1e-13);
1651     }
1652   f2->decrRef();
1653   //
1654   array=DataArrayDouble::New();
1655   array->alloc(mesh1->getNumberOfCells(),4);
1656   const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
1657   std::copy(arr2,arr2+20,array->getPointer());
1658   f1->setArray(array);
1659   array->decrRef();
1660   f1->checkCoherency();
1661   //
1662   f2=f1->inverse();
1663   f2->checkCoherency();
1664   CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfComponents());
1665   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1666   const double expected2[4]={-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156};
1667   for(int i=0;i<5;i++)
1668     {
1669       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[0],f2->getIJ(i,0),1e-13);
1670       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[1],f2->getIJ(i,1),1e-13);
1671       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[2],f2->getIJ(i,2),1e-13);
1672       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[3],f2->getIJ(i,3),1e-13);
1673     }
1674   f2->decrRef();
1675   //
1676   mesh1->decrRef();
1677   f1->decrRef();
1678 }
1679
1680 void MEDCouplingBasicsTest2::testTrace1()
1681 {
1682   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1683   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1684   f1->setMesh(mesh1);
1685   DataArrayDouble *array=DataArrayDouble::New();
1686   array->alloc(mesh1->getNumberOfCells(),9);
1687   const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
1688   std::copy(arr1,arr1+45,array->getPointer());
1689   f1->setArray(array);
1690   array->decrRef();
1691   f1->checkCoherency();
1692   //
1693   MEDCouplingFieldDouble *f2=f1->trace();
1694   f2->checkCoherency();
1695   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1696   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1697   for(int i=0;i<5;i++)
1698     CPPUNIT_ASSERT_DOUBLES_EQUAL(15.9,f2->getIJ(i,0),1e-13);
1699   f2->decrRef();
1700   //
1701   array=DataArrayDouble::New();
1702   array->alloc(mesh1->getNumberOfCells(),6);
1703   const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
1704   std::copy(arr3,arr3+30,array->getPointer());
1705   f1->setArray(array);
1706   array->decrRef();
1707   f1->checkCoherency();
1708   //
1709   f2=f1->trace();
1710   f2->checkCoherency();
1711   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1712   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1713   for(int i=0;i<5;i++)
1714     CPPUNIT_ASSERT_DOUBLES_EQUAL(25.8,f2->getIJ(i,0),1e-13);
1715   f2->decrRef();
1716   //
1717   array=DataArrayDouble::New();
1718   array->alloc(mesh1->getNumberOfCells(),4);
1719   const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
1720   std::copy(arr2,arr2+20,array->getPointer());
1721   f1->setArray(array);
1722   array->decrRef();
1723   f1->checkCoherency();
1724   //
1725   f2=f1->trace();
1726   f2->checkCoherency();
1727   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1728   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1729   for(int i=0;i<5;i++)
1730     CPPUNIT_ASSERT_DOUBLES_EQUAL(5.7,f2->getIJ(i,0),1e-13);
1731   f2->decrRef();
1732   //
1733   mesh1->decrRef();
1734   f1->decrRef();
1735 }
1736
1737 void MEDCouplingBasicsTest2::testDeviator1()
1738 {
1739   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1740   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1741   f1->setMesh(mesh1);
1742   DataArrayDouble *array=DataArrayDouble::New();
1743   array->alloc(mesh1->getNumberOfCells(),6);
1744   const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
1745   std::copy(arr1,arr1+30,array->getPointer());
1746   f1->setArray(array);
1747   array->decrRef();
1748   f1->checkCoherency();
1749   //
1750   MEDCouplingFieldDouble *f2=f1->deviator();
1751   f2->checkCoherency();
1752   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
1753   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1754   const double expected1[6]={-1.1,0.,1.1,4.5,5.6,6.7};
1755   for(int i=0;i<5;i++)
1756     {
1757       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
1758       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
1759       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
1760       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
1761       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
1762       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
1763     }
1764   f2->decrRef();
1765   //
1766   mesh1->decrRef();
1767   f1->decrRef();
1768 }
1769
1770 void MEDCouplingBasicsTest2::testMagnitude1()
1771 {
1772   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1773   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1774   f1->setMesh(mesh1);
1775   DataArrayDouble *array=DataArrayDouble::New();
1776   array->alloc(mesh1->getNumberOfCells(),5);
1777   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6};
1778   std::copy(arr1,arr1+25,array->getPointer());
1779   f1->setArray(array);
1780   array->decrRef();
1781   f1->checkCoherency();
1782   //
1783   MEDCouplingFieldDouble *f2=f1->magnitude();
1784   f2->checkCoherency();
1785   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1786   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1787   for(int i=0;i<5;i++)
1788     CPPUNIT_ASSERT_DOUBLES_EQUAL(8.3606219864313918,f2->getIJ(i,0),1e-13);
1789   f2->decrRef();
1790   //
1791   mesh1->decrRef();
1792   f1->decrRef();
1793 }
1794
1795 void MEDCouplingBasicsTest2::testMaxPerTuple1()
1796 {
1797   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1798   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1799   f1->setMesh(mesh1);
1800   DataArrayDouble *array=DataArrayDouble::New();
1801   array->alloc(mesh1->getNumberOfCells(),5);
1802   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
1803   std::copy(arr1,arr1+25,array->getPointer());
1804   f1->setArray(array);
1805   array->decrRef();
1806   f1->checkCoherency();
1807   //
1808   MEDCouplingFieldDouble *f2=f1->maxPerTuple();
1809   f2->checkCoherency();
1810   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
1811   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
1812   for(int i=0;i<5;i++)
1813     CPPUNIT_ASSERT_DOUBLES_EQUAL(5.6,f2->getIJ(i,0),1e-13);
1814   f2->decrRef();
1815   //
1816   mesh1->decrRef();
1817   f1->decrRef();
1818 }
1819
1820 void MEDCouplingBasicsTest2::testChangeNbOfComponents()
1821 {
1822   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1823   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1824   f1->setMesh(mesh1);
1825   DataArrayDouble *array=DataArrayDouble::New();
1826   array->alloc(mesh1->getNumberOfCells(),5);
1827   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
1828   std::copy(arr1,arr1+25,array->getPointer());
1829   f1->setArray(array);
1830   array->decrRef();
1831   f1->checkCoherency();
1832   //
1833   f1->changeNbOfComponents(3,7.77);
1834   f1->checkCoherency();
1835   CPPUNIT_ASSERT_EQUAL(3,f1->getNumberOfComponents());
1836   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1837   const double expected1[15]={1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2};
1838   for(int i=0;i<15;i++)
1839     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-13);
1840   f1->changeNbOfComponents(4,7.77);
1841   f1->checkCoherency();
1842   CPPUNIT_ASSERT_EQUAL(4,f1->getNumberOfComponents());
1843   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1844   const double expected2[20]={1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77};
1845   for(int i=0;i<20;i++)
1846     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-13);
1847   //
1848   mesh1->decrRef();
1849   f1->decrRef();
1850 }
1851
1852 void MEDCouplingBasicsTest2::testSortPerTuple1()
1853 {
1854   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1855   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
1856   f1->setMesh(mesh1);
1857   DataArrayDouble *array=DataArrayDouble::New();
1858   array->alloc(mesh1->getNumberOfCells(),5);
1859   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
1860   std::copy(arr1,arr1+25,array->getPointer());
1861   f1->setArray(array);
1862   array->decrRef();
1863   f1->checkCoherency();
1864   //
1865   f1->sortPerTuple(true);
1866   f1->checkCoherency();
1867   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents());
1868   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1869   for(int i=0;i<5;i++)
1870     {
1871       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,0),1e-13);
1872       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,1),1e-13);
1873       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
1874       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,3),1e-13);
1875       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,4),1e-13);
1876     }
1877   //
1878   f1->sortPerTuple(false);
1879   f1->checkCoherency();
1880   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents());
1881   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1882   for(int i=0;i<5;i++)
1883     {
1884       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,0),1e-13);
1885       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,1),1e-13);
1886       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
1887       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,3),1e-13);
1888       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,4),1e-13);
1889     }
1890   //
1891   mesh1->decrRef();
1892   f1->decrRef();
1893 }
1894
1895 void MEDCouplingBasicsTest2::testIsEqualWithoutConsideringStr1()
1896 {
1897   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1898   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
1899   DataArrayInt *da1,*da2;
1900   //
1901   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1902   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1903   mesh2->setName("rr");
1904   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1905   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1906   mesh1->checkDeepEquivalWith(mesh2,2,1e-12,da1,da2);
1907   CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,da1,da2),INTERP_KERNEL::Exception);
1908   mesh2->setName("");
1909   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1910   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1911   mesh2->getCoords()->setInfoOnComponent(0,"tty");
1912   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1913   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1914   mesh2->getCoords()->setInfoOnComponent(0,"");
1915   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1916   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1917   mesh2->getCoords()->setInfoOnComponent(1,"tty");
1918   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1919   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1920   mesh2->getCoords()->setInfoOnComponent(1,"");
1921   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1922   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1923   double tmp=mesh2->getCoords()->getIJ(0,3);
1924   mesh2->getCoords()->setIJ(0,3,9999.);
1925   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1926   CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1927   mesh2->getCoords()->setIJ(0,3,tmp);
1928   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1929   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1930   int tmp2=mesh2->getNodalConnectivity()->getIJ(0,4);
1931   mesh2->getNodalConnectivity()->setIJ(0,4,0);
1932   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
1933   CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1934   mesh2->getNodalConnectivity()->setIJ(0,4,tmp2);
1935   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
1936   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
1937   //
1938   MEDCouplingFieldDouble *f1=mesh1->getMeasureField(true);
1939   MEDCouplingFieldDouble *f2=mesh2->getMeasureField(true);
1940   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1941   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1942   f2->setName("ftest");
1943   CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1944   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1945   f1->setName("ftest");
1946   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1947   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1948   //
1949   f2->getArray()->setInfoOnComponent(0,"eee");
1950   CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1951   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1952   f2->getArray()->setInfoOnComponent(0,"");
1953   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1954   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1955   //
1956   f2->getArray()->setIJ(1,0,0.123);
1957   CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
1958   CPPUNIT_ASSERT(!f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1959   f2->getArray()->setIJ(1,0,0.125);
1960   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
1961   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
1962   //
1963   f1->decrRef();
1964   f2->decrRef();
1965   //
1966   mesh1->decrRef();
1967   mesh2->decrRef();
1968 }
1969
1970 void MEDCouplingBasicsTest2::testGetNodeIdsOfCell1()
1971 {
1972   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
1973   std::vector<int> nodeIds;
1974   mesh1->getNodeIdsOfCell(1,nodeIds);
1975   CPPUNIT_ASSERT_EQUAL(3,(int)nodeIds.size());
1976   CPPUNIT_ASSERT_EQUAL(1,nodeIds[0]);
1977   CPPUNIT_ASSERT_EQUAL(4,nodeIds[1]);
1978   CPPUNIT_ASSERT_EQUAL(2,nodeIds[2]);
1979   std::vector<double> coords;
1980   mesh1->getCoordinatesOfNode(4,coords);
1981   CPPUNIT_ASSERT_EQUAL(2,(int)coords.size());
1982   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[0],1e-13);
1983   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[1],1e-13);
1984   mesh1->decrRef();
1985 }
1986
1987 void MEDCouplingBasicsTest2::testGetEdgeRatioField1()
1988 {
1989   MEDCouplingUMesh *m1=build2DTargetMesh_1();
1990   MEDCouplingFieldDouble *f1=m1->getEdgeRatioField();
1991   CPPUNIT_ASSERT_EQUAL(m1->getNumberOfCells(),f1->getNumberOfTuples());
1992   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
1993   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
1994   const double expected1[5]={1.,1.4142135623730951, 1.4142135623730951,1.,1.};
1995   for(int i=0;i<5;i++)
1996     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-14);
1997   f1->decrRef();
1998   m1->decrRef();
1999   //
2000   m1=build3DSurfTargetMesh_1();
2001   f1=m1->getEdgeRatioField();
2002   CPPUNIT_ASSERT_EQUAL(m1->getNumberOfCells(),f1->getNumberOfTuples());
2003   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2004   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2005   const double expected2[5]={1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951};
2006   for(int i=0;i<5;i++)
2007     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(i,0),1e-14);
2008   f1->decrRef();
2009   m1->decrRef();
2010 }
2011
2012 void MEDCouplingBasicsTest2::testFillFromAnalytic3()
2013 {
2014   MEDCouplingUMesh *m=build2DTargetMesh_1();
2015   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
2016   CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"y+x"),INTERP_KERNEL::Exception);
2017   f1->setMesh(m);
2018   f1->setName("myField");
2019   f1->fillFromAnalytic(1,"y+x");
2020   f1->checkCoherency();
2021   CPPUNIT_ASSERT(std::string(f1->getName())=="myField");
2022   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
2023   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
2024   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2025   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2026   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
2027   const double *tmp=f1->getArray()->getConstPointer();
2028   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
2029   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
2030   double max=*std::max_element(values1,values1+5);
2031   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2032   f1->decrRef();
2033   //
2034   f1=MEDCouplingFieldDouble::New(ON_NODES,CONST_ON_TIME_INTERVAL);
2035   f1->setMesh(m);
2036   f1->setEndTime(1.2,3,4);
2037   f1->fillFromAnalytic(1,"y+2*x");
2038   f1->checkCoherency();
2039   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2040   CPPUNIT_ASSERT(f1->getTimeDiscretization()==CONST_ON_TIME_INTERVAL);
2041   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2042   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2043   double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
2044   tmp=f1->getArray()->getConstPointer();
2045   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
2046   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
2047   max=*std::max_element(values2,values2+9);
2048   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2049   f1->decrRef();
2050   f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
2051   f1->setMesh(m);
2052   f1->setEndTime(1.2,3,4);
2053   f1->fillFromAnalytic(1,"2.*x+y");
2054   f1->checkCoherency();
2055   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2056   CPPUNIT_ASSERT(f1->getTimeDiscretization()==LINEAR_TIME);
2057   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2058   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2059   tmp=f1->getArray()->getConstPointer();
2060   double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
2061   double values2BisBis[9];
2062   std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
2063   std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
2064   max=*std::max_element(values2BisBis,values2BisBis+9);
2065   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2066   tmp=f1->getEndArray()->getConstPointer();
2067   std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
2068   std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
2069   max=*std::max_element(values2BisBis,values2BisBis+9);
2070   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2071   f1->decrRef();
2072   //
2073   f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
2074   f1->setMesh(m);
2075   f1->fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
2076   f1->checkCoherency();
2077   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
2078   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
2079   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
2080   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2081   double values3[18]={-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8};
2082   tmp=f1->getArray()->getConstPointer();
2083   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
2084   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
2085   max=*std::max_element(values3,values3+18);
2086   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
2087   double values4[2];
2088   f1->accumulate(values4);
2089   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
2090   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
2091   f1->integral(true,values4);
2092   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
2093   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
2094   f1->decrRef();
2095   //
2096   f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
2097   f1->setMesh(m);
2098   CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
2099   //
2100   m->decrRef();
2101   f1->decrRef();
2102 }
2103
2104 void MEDCouplingBasicsTest2::testFieldDoubleOpEqual1()
2105 {
2106   MEDCouplingUMesh *m=build2DTargetMesh_1();
2107   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
2108   CPPUNIT_ASSERT_THROW((*f1)=0.07,INTERP_KERNEL::Exception);
2109   f1->setMesh(m);
2110   (*f1)=0.07;
2111   f1->checkCoherency();
2112   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2113   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2114   for(int i=0;i<5;i++)
2115     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.07,f1->getIJ(i,0),1e-16);
2116   (*f1)=0.09;
2117   f1->checkCoherency();
2118   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2119   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
2120   for(int i=0;i<5;i++)
2121     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.09,f1->getIJ(i,0),1e-16);
2122   f1->decrRef();
2123   //
2124   f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
2125   f1->setEndTime(4.5,2,3);
2126   f1->setMesh(m);
2127   (*f1)=0.08;
2128   f1->checkCoherency();
2129   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
2130   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
2131   for(int i=0;i<9;i++)
2132     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getIJ(i,0),1e-16);
2133   CPPUNIT_ASSERT_EQUAL(1,f1->getEndArray()->getNumberOfComponents());
2134   CPPUNIT_ASSERT_EQUAL(9,f1->getEndArray()->getNumberOfTuples());
2135   for(int i=0;i<9;i++)
2136     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getEndArray()->getIJ(i,0),1e-16);
2137   f1->decrRef();
2138   //
2139   m->decrRef();
2140 }
2141
2142 void MEDCouplingBasicsTest2::testAreaBary3D2()
2143 {
2144   const double coordsForHexa8[24]={
2145     -75.45749305371, 180.95495078401, 39.515472018008,
2146     -9.755591679144, 23.394927935279, 5.108794294848,
2147     14.337630157832, 61.705351002702, 160.42422501908,
2148     -27.273893776752, 167.567731083961, 192.830034145464,
2149     //
2150     99.857193154796,264.499264735586,-8.287335493412,
2151     144.939882761126,156.38626563134,-31.896173894226,
2152     161.34096835726,182.4654895809,73.832387065572,
2153     132.680430393685,255.37973247196,96.15235602819
2154   };
2155   const double volHexa8=3258520.29637466;
2156   const double baryHexa8[3]={43.925705821778, 155.31893955289, 65.874418109644};
2157
2158   const double coordsForPenta6[18]={
2159     -68.199829618726,178.938498373416,62.608505919588,
2160     8.461744647847,76.653979804423,165.00018874933,
2161     -27.273893776752,167.567731083961,192.830034145464,
2162     //
2163     106.586501038965,262.629609408327,13.124533008813,
2164     155.465082847275,197.414118382622,78.408350795821,
2165     132.680430393685,255.37973247196,96.15235602819
2166   };
2167   const double volPenta6=944849.868507338;
2168   const double baryPenta6[3]={39.631002313543,182.692711783428,106.98540473964};
2169   
2170   const double coordsForPyra5[15]={
2171     132.680430393685,255.37973247196,96.15235602819,
2172     -27.273893776752,167.567731083961,192.830034145464,
2173     8.461744647847,76.653979804423,165.00018874933,
2174     155.465082847275,197.414118382622,78.408350795821,
2175     //
2176     -68.199829618726,178.938498373416,62.608505919588
2177   };
2178   const double volPyra5=756943.92980254;
2179   const double baryPyra5[3]={29.204294116618,172.540129749156,118.01035951483};
2180   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Bary3D2",3);
2181   DataArrayDouble *coo=DataArrayDouble::New();
2182   coo->alloc(19,3);
2183   double *tmp=std::copy(coordsForHexa8,coordsForHexa8+24,coo->getPointer());
2184   tmp=std::copy(coordsForPenta6,coordsForPenta6+18,tmp);
2185   std::copy(coordsForPyra5,coordsForPyra5+15,tmp);
2186   mesh->setCoords(coo);
2187   coo->decrRef();
2188   //
2189   int tmpConn[8]={0,1,2,3,4,5,6,7};
2190   mesh->allocateCells(3);
2191   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,tmpConn);
2192   std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),8));
2193   mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,tmpConn);
2194   std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),6));
2195   mesh->insertNextCell(INTERP_KERNEL::NORM_PYRA5,5,tmpConn);
2196   mesh->finishInsertingCells();
2197   mesh->checkCoherency();
2198   bool isMerged;
2199   int newNebOfNodes;
2200   DataArrayInt *da=mesh->mergeNodes(1e-7,isMerged,newNebOfNodes);
2201   da->decrRef();
2202   CPPUNIT_ASSERT_EQUAL(12,newNebOfNodes);
2203   MEDCouplingFieldDouble *vols=mesh->getMeasureField(true);
2204   CPPUNIT_ASSERT_EQUAL(3,vols->getNumberOfTuples());
2205   CPPUNIT_ASSERT_EQUAL(1,vols->getNumberOfComponents());
2206   CPPUNIT_ASSERT_DOUBLES_EQUAL(volHexa8,vols->getIJ(0,0),1e-6);
2207   CPPUNIT_ASSERT_DOUBLES_EQUAL(volPenta6,vols->getIJ(1,0),1e-7);
2208   CPPUNIT_ASSERT_DOUBLES_EQUAL(volPyra5,vols->getIJ(2,0),1e-7);
2209   vols->decrRef();
2210   DataArrayDouble *bary=mesh->getBarycenterAndOwner();
2211   CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfTuples());
2212   CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfComponents());
2213   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[0],bary->getIJ(0,0),1e-11);
2214   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[1],bary->getIJ(0,1),1e-11);
2215   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[2],bary->getIJ(0,2),1e-11);
2216   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[0],bary->getIJ(1,0),1e-11);
2217   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[1],bary->getIJ(1,1),1e-11);
2218   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[2],bary->getIJ(1,2),1e-11);
2219   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[0],bary->getIJ(2,0),1e-11);
2220   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[1],bary->getIJ(2,1),1e-11);
2221   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[2],bary->getIJ(2,2),1e-11);
2222   bary->decrRef();
2223   //
2224   mesh->decrRef();
2225 }