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