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