Salome HOME
Windows compatibility.
[tools/medcoupling.git] / src / MEDCoupling / Test / MEDCouplingBasicsTest1.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingBasicsTest1.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingCMesh.hxx"
24 #include "MEDCouplingMappedExtrudedMesh.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingMemArray.hxx"
27
28 #include <sstream>
29 #include <cmath>
30 #include <algorithm>
31 #include <functional>
32
33 #ifdef WIN32
34 #include "MEDCouplingMemArray.txx"
35 #endif
36
37 using namespace MEDCoupling;
38
39 void MEDCouplingBasicsTest1::testArray()
40 {
41   int tmp1[6]={7,6,5,4,3,2};
42   const int tmp2[3]={8,9,10};
43   {
44     MemArray<int> mem;
45     mem.useArray(tmp1,false,CPP_DEALLOC,6);
46     CPPUNIT_ASSERT(tmp1==mem.getConstPointer());
47     CPPUNIT_ASSERT_THROW(mem.getPointer(),INTERP_KERNEL::Exception);
48     CPPUNIT_ASSERT_THROW(mem[2]=7,INTERP_KERNEL::Exception);
49     CPPUNIT_ASSERT_THROW(mem.writeOnPlace(0,12,tmp2,3),INTERP_KERNEL::Exception);
50     mem.writeOnPlace(4,12,tmp2,3);
51   }
52   {
53     int *tmp3=new int[6];
54     std::copy(tmp1,tmp1+6,tmp3);
55     MemArray<int> mem2;
56     mem2.useArray(tmp3,true,CPP_DEALLOC,6);
57     CPPUNIT_ASSERT(tmp3==mem2.getConstPointer());
58     CPPUNIT_ASSERT(tmp3==mem2.getPointer());
59     CPPUNIT_ASSERT_EQUAL(5,mem2[2]);
60     mem2[2]=7;
61     CPPUNIT_ASSERT_EQUAL(7,mem2[2]);
62     mem2.writeOnPlace(0,12,tmp2,3);
63     CPPUNIT_ASSERT_EQUAL(9,mem2[2]);
64     CPPUNIT_ASSERT_EQUAL(12,mem2[0]);
65     mem2.writeOnPlace(4,12,tmp2,3);
66   }
67 }
68
69 void MEDCouplingBasicsTest1::testArray2()
70 {
71   DataArrayDouble *arr=DataArrayDouble::New();
72   arr->alloc(3,4);
73   double *tmp=arr->getPointer();
74   const double arrRef[12]={12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.};
75   std::copy(arrRef,arrRef+12,tmp);
76   arr->setInfoOnComponent(0,"ggg");
77   arr->setInfoOnComponent(1,"hhhh");
78   arr->setInfoOnComponent(2,"jj");
79   arr->setInfoOnComponent(3,"kkkkkk");
80   DataArrayInt *arr2=arr->convertToIntArr();
81   DataArrayDouble *arr3=arr2->convertToDblArr();
82   arr2->decrRef();
83   CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
84   arr3->decrRef();
85   arr->decrRef();
86 }
87
88 void MEDCouplingBasicsTest1::testArray3()
89 {
90   DataArrayInt *arr1=DataArrayInt::New();
91   arr1->alloc(7,2);
92   int *tmp=arr1->getPointer();
93   const int arr1Ref[14]={0,10,1,11,2,12,3,13,4,14,5,15,6,16};
94   std::copy(arr1Ref,arr1Ref+14,tmp);
95   CPPUNIT_ASSERT_EQUAL(7,(int)arr1->getNumberOfTuples());
96   CPPUNIT_ASSERT_EQUAL(2,(int)arr1->getNumberOfComponents());
97   CPPUNIT_ASSERT(std::equal(arr1Ref,arr1Ref+14,arr1->getConstPointer()));
98   DataArrayInt *arr2=arr1->subArray(3);
99   CPPUNIT_ASSERT_EQUAL(4,(int)arr2->getNumberOfTuples());
100   CPPUNIT_ASSERT_EQUAL(2,(int)arr2->getNumberOfComponents());
101   CPPUNIT_ASSERT(std::equal(arr1Ref+6,arr1Ref+14,arr2->getConstPointer()));
102   arr2->decrRef();
103   DataArrayInt *arr3=arr1->subArray(2,5);
104   CPPUNIT_ASSERT_EQUAL(3,(int)arr3->getNumberOfTuples());
105   CPPUNIT_ASSERT_EQUAL(2,(int)arr3->getNumberOfComponents());
106   CPPUNIT_ASSERT(std::equal(arr1Ref+4,arr1Ref+10,arr3->getConstPointer()));
107   arr1->decrRef();
108   arr3->decrRef();
109   //
110   DataArrayDouble *arr4=DataArrayDouble::New();
111   arr4->alloc(7,2);
112   double *tmp2=arr4->getPointer();
113   const double arr4Ref[14]={0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5};
114   std::copy(arr4Ref,arr4Ref+14,tmp2);
115   CPPUNIT_ASSERT_EQUAL(7,(int)arr4->getNumberOfTuples());
116   CPPUNIT_ASSERT_EQUAL(2,(int)arr4->getNumberOfComponents());
117   CPPUNIT_ASSERT(std::equal(arr4Ref,arr4Ref+14,arr4->getConstPointer()));
118   DataArrayDouble *arr5=arr4->subArray(3);
119   CPPUNIT_ASSERT_EQUAL(4,(int)arr5->getNumberOfTuples());
120   CPPUNIT_ASSERT_EQUAL(2,(int)arr5->getNumberOfComponents());
121   CPPUNIT_ASSERT(std::equal(arr4Ref+6,arr4Ref+14,arr5->getConstPointer()));
122   arr5->decrRef();
123   DataArrayDouble *arr6=arr4->subArray(2,5);
124   CPPUNIT_ASSERT_EQUAL(3,(int)arr6->getNumberOfTuples());
125   CPPUNIT_ASSERT_EQUAL(2,(int)arr6->getNumberOfComponents());
126   CPPUNIT_ASSERT(std::equal(arr4Ref+4,arr4Ref+10,arr6->getConstPointer()));
127   arr4->decrRef();
128   arr6->decrRef();
129 }
130
131 void MEDCouplingBasicsTest1::testMesh()
132 {
133   const int nbOfCells=6;
134   const int nbOfNodes=12;
135   
136   double coords[3*nbOfNodes]={ 
137     0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17, -0.305, 0.09662000000000001, -1.832979297858306e-18, 
138     -0.305, 0.120775, 0.04183768725682623, -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001, 
139     0.08367537451365246, -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863, 
140     0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001, 0.08367537451365245, 
141     -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863, };
142   
143   int tab4[4*nbOfCells]={ 
144     1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 0, 6, 11, 
145     0, 1, 7, 6, };
146   CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI3),3);
147   CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI3));
148   CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI3));
149   CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI3),2);
150   CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI3)),std::string("NORM_TRI3"));
151   CPPUNIT_ASSERT_THROW(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_POLYGON),INTERP_KERNEL::Exception);
152   CPPUNIT_ASSERT(!MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_POLYGON));
153   CPPUNIT_ASSERT(MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_POLYGON));
154   CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_POLYGON),2);
155   CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_POLYGON)),std::string("NORM_POLYGON"));
156   CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NORM_TRI6),6);
157   CPPUNIT_ASSERT(MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NORM_TRI6));
158   CPPUNIT_ASSERT(!MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NORM_TRI6));
159   CPPUNIT_ASSERT_EQUAL(MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NORM_TRI6),2);
160   CPPUNIT_ASSERT_EQUAL(std::string(MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NORM_TRI6)),std::string("NORM_TRI6"));
161   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
162   mesh->setMeshDimension(2);
163   mesh->allocateCells(8);
164   const int *curConn=tab4;
165   for(int i=0;i<nbOfCells;i++,curConn+=4)
166     mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,curConn);
167   mesh->finishInsertingCells();
168   CPPUNIT_ASSERT_EQUAL((std::size_t)30,mesh->getNodalConnectivity()->getNbOfElems());
169   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
170   //test 0 - no copy no ownership
171   DataArrayDouble *myCoords=DataArrayDouble::New();
172   myCoords->useArray(coords,false,CPP_DEALLOC,nbOfNodes,3);
173   mesh->setCoords(myCoords);
174   mesh->setCoords(myCoords);
175   myCoords->decrRef();
176   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
177   mesh->checkConsistencyLight();
178   //test 1 - no copy ownership C++
179   myCoords=DataArrayDouble::New();
180   double *tmp=new double[3*nbOfNodes];
181   std::copy(coords,coords+3*nbOfNodes,tmp);
182   myCoords->useArray(tmp,true,CPP_DEALLOC,nbOfNodes,3);
183   mesh->setCoords(myCoords);
184   myCoords->decrRef();
185   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
186   mesh->checkConsistencyLight();
187   //test 2 - no copy ownership C
188   myCoords=DataArrayDouble::New();
189   tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
190   std::copy(coords,coords+3*nbOfNodes,tmp);
191   myCoords->useArray(tmp,true,C_DEALLOC,nbOfNodes,3);
192   mesh->setCoords(myCoords);
193   myCoords->decrRef();
194   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
195   mesh->checkConsistencyLight();
196   //test 3 - copy.
197   myCoords=DataArrayDouble::New();
198   myCoords->alloc(nbOfNodes,3);
199   tmp=myCoords->getPointer();
200   std::copy(coords,coords+3*nbOfNodes,tmp);
201   // test 3 bis deepcopy
202   DataArrayDouble *myCoords2=DataArrayDouble::New();
203   *myCoords2=*myCoords;
204   myCoords2->decrRef();
205   //
206   mesh->setCoords(myCoords);
207   myCoords->decrRef();
208   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
209   mesh->checkConsistencyLight();
210   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
211   // test clone not recursively
212   MEDCouplingUMesh *mesh2=mesh->clone(false);
213   CPPUNIT_ASSERT(mesh2!=mesh);
214   mesh2->checkConsistencyLight();
215   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh2->getNumberOfCells());
216   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh2->getNumberOfNodes());
217   CPPUNIT_ASSERT_EQUAL(3,mesh2->getSpaceDimension());
218   CPPUNIT_ASSERT(mesh!=mesh2);
219   CPPUNIT_ASSERT(mesh->getCoords()==mesh2->getCoords());
220   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh2->getCoords()->getIJ(11,2),1e-14);
221   CPPUNIT_ASSERT(mesh->getNodalConnectivity()==mesh2->getNodalConnectivity());
222   CPPUNIT_ASSERT_EQUAL(3,mesh2->getNodalConnectivity()->getIJ(7,0));
223   CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()==mesh2->getNodalConnectivityIndex());
224   CPPUNIT_ASSERT_EQUAL(15,mesh2->getNodalConnectivityIndex()->getIJ(3,0));
225   mesh2->decrRef();
226   // test clone not recursively
227   MEDCouplingUMesh *mesh3=mesh->clone(true);
228   CPPUNIT_ASSERT(mesh3!=mesh);
229   mesh3->checkConsistencyLight();
230   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh3->getNumberOfCells());
231   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh3->getNumberOfNodes());
232   CPPUNIT_ASSERT_EQUAL(3,mesh3->getSpaceDimension());
233   CPPUNIT_ASSERT(mesh!=mesh3);
234   CPPUNIT_ASSERT(mesh->getCoords()!=mesh3->getCoords());
235   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh3->getCoords()->getIJ(11,2),1e-14);
236   CPPUNIT_ASSERT(mesh->getNodalConnectivity()!=mesh3->getNodalConnectivity());
237   CPPUNIT_ASSERT_EQUAL(3,mesh3->getNodalConnectivity()->getIJ(7,0));
238   CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()!=mesh3->getNodalConnectivityIndex());
239   CPPUNIT_ASSERT_EQUAL(15,mesh3->getNodalConnectivityIndex()->getIJ(3,0));
240   mesh3->decrRef();
241   //test 4 - Field on cells
242   MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
243   fieldOnCells->setMesh(mesh);
244   DataArrayDouble *array=DataArrayDouble::New();
245   array->alloc(nbOfCells,9);
246   fieldOnCells->setArray(array);
247   tmp=array->getPointer();
248   array->decrRef();
249   std::fill(tmp,tmp+9*nbOfCells,7.);
250   //content of field changed -> declare it.
251   fieldOnCells->declareAsNew();
252   fieldOnCells->checkConsistencyLight();
253   // testing clone of fields - no recursive
254   MEDCouplingFieldDouble *fieldOnCells2=fieldOnCells->clone(false);
255   CPPUNIT_ASSERT(fieldOnCells2!=fieldOnCells);
256   fieldOnCells2->checkConsistencyLight();
257   CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)fieldOnCells2->getNumberOfTuples());
258   CPPUNIT_ASSERT_EQUAL(9,(int)fieldOnCells2->getNumberOfComponents());
259   CPPUNIT_ASSERT(fieldOnCells2->getArray()==fieldOnCells->getArray());
260   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells2->getArray()->getIJ(3,7),1e-14);
261   CPPUNIT_ASSERT(fieldOnCells2->getMesh()==fieldOnCells->getMesh());
262   // testing clone of fields - recursive
263   MEDCouplingFieldDouble *fieldOnCells3=fieldOnCells->clone(true);
264   CPPUNIT_ASSERT(fieldOnCells3!=fieldOnCells);
265   fieldOnCells3->checkConsistencyLight();
266   CPPUNIT_ASSERT_EQUAL(nbOfCells,(int)fieldOnCells3->getNumberOfTuples());
267   CPPUNIT_ASSERT_EQUAL(9,(int)fieldOnCells3->getNumberOfComponents());
268   CPPUNIT_ASSERT(fieldOnCells3->getArray()!=fieldOnCells->getArray());
269   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells3->getArray()->getIJ(3,7),1e-14);
270   CPPUNIT_ASSERT(fieldOnCells3->getMesh()==fieldOnCells->getMesh());
271   fieldOnCells2->decrRef();
272   fieldOnCells3->decrRef();
273   //
274   fieldOnCells->decrRef();
275   //clean-up
276   mesh->decrRef();
277 }
278
279 void MEDCouplingBasicsTest1::testMeshPointsCloud()
280 {
281   double targetCoords[27]={-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5, -0.3,0.2,0.5, 0.2,0.2,1., 0.7,0.2,1.5, -0.3,0.7,0.5, 0.2,0.7,1., 0.7,0.7,1.5};
282   const int targetConn[]={0,1,2,3,4,5,7,6};
283   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
284   targetMesh->setMeshDimension(0);
285   targetMesh->allocateCells(8);
286   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
287   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
288   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
289   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
290   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
291   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
292   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
293   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
294   targetMesh->finishInsertingCells();
295   CPPUNIT_ASSERT_THROW(targetMesh->checkConsistencyLight(),INTERP_KERNEL::Exception);
296   DataArrayDouble *myCoords=DataArrayDouble::New();
297   myCoords->alloc(9,3);
298   std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
299   targetMesh->setCoords(myCoords);
300   myCoords->decrRef();
301   //
302   targetMesh->checkConsistencyLight();
303   CPPUNIT_ASSERT_EQUAL(3,targetMesh->getSpaceDimension());
304   CPPUNIT_ASSERT_EQUAL(8,targetMesh->getNumberOfCells());
305   CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
306   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getMeshDimension());
307   //
308   targetMesh->decrRef();
309 }
310
311 void MEDCouplingBasicsTest1::testMeshM1D()
312 {
313   MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New();
314   CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception);
315   CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
316   CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception);
317   CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception);
318   CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception);
319   CPPUNIT_ASSERT_THROW(meshM1D->checkConsistencyLight(),INTERP_KERNEL::Exception);
320   meshM1D->setMeshDimension(-1);
321   meshM1D->checkConsistencyLight();
322   CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension());
323   CPPUNIT_ASSERT_EQUAL(1,meshM1D->getNumberOfCells());
324   CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
325   CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception);
326   MEDCouplingUMesh *cpy=meshM1D->clone(true);
327   CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12));
328   cpy->decrRef();
329   MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
330   fieldOnCells->setMesh(meshM1D);
331   DataArrayDouble *array=DataArrayDouble::New();
332   array->alloc(1,6);
333   fieldOnCells->setArray(array);
334   double *tmp=array->getPointer();
335   array->decrRef();
336   std::fill(tmp,tmp+6,7.);
337   fieldOnCells->checkConsistencyLight();
338   //
339   fieldOnCells->decrRef();
340   meshM1D->decrRef();
341 }
342
343 void MEDCouplingBasicsTest1::testDeepCopy()
344 {
345   DataArrayDouble *array=DataArrayDouble::New();
346   array->alloc(5,3);
347   std::fill(array->getPointer(),array->getPointer()+5*3,7.);
348   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14);
349   double *tmp1=array->getPointer();
350   DataArrayDouble *array2=array->deepCopy();
351   double *tmp2=array2->getPointer();
352   CPPUNIT_ASSERT(tmp1!=tmp2);
353   array->decrRef();
354   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array2->getIJ(3,2),1e-14);
355   array2->decrRef();
356   //
357   DataArrayInt *array3=DataArrayInt::New();
358   array3->alloc(5,3);
359   std::fill(array3->getPointer(),array3->getPointer()+5*3,17);
360   CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2));
361   int *tmp3=array3->getPointer();
362   DataArrayInt *array4=array3->deepCopy();
363   int *tmp4=array4->getPointer();
364   CPPUNIT_ASSERT(tmp3!=tmp4);
365   array3->decrRef();
366   CPPUNIT_ASSERT_EQUAL(17,array4->getIJ(3,2));
367   array4->decrRef();
368 }
369
370 void MEDCouplingBasicsTest1::testRevNodal()
371 {
372   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
373   DataArrayInt *revNodal=DataArrayInt::New();
374   DataArrayInt *revNodalIndx=DataArrayInt::New();
375   //
376   mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
377   const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
378   const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
379   CPPUNIT_ASSERT_EQUAL((std::size_t)18,revNodal->getNbOfElems());
380   CPPUNIT_ASSERT_EQUAL((std::size_t)10,revNodalIndx->getNbOfElems());
381   CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
382   CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
383   //
384   revNodal->decrRef();
385   revNodalIndx->decrRef();
386   mesh->decrRef();
387 }
388
389 void MEDCouplingBasicsTest1::testConvertToPolyTypes()
390 {
391   ////// 2D
392   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
393   //
394   const int elts[2]={1,3};
395   std::vector<int> eltsV(elts,elts+2);
396   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
397   mesh->checkConsistencyLight();
398   CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
399   CPPUNIT_ASSERT_EQUAL(23,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
400   const int *pt=mesh->getNodalConnectivity()->getConstPointer();
401   const int expected1[23]={4, 0, 3, 4, 1, 5, 1, 4, 2, 3, 4, 5, 2, 5, 6, 7, 4, 3, 4, 7, 8, 5, 4};
402   CPPUNIT_ASSERT(std::equal(expected1,expected1+23,pt));
403   //
404   mesh->decrRef();
405   ////// 3D
406   mesh=build3DTargetMesh_1();
407   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
408   mesh->checkConsistencyLight();
409   CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
410   CPPUNIT_ASSERT_EQUAL(114,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
411   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
412   mesh->checkConsistencyLight();
413   CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
414   CPPUNIT_ASSERT_EQUAL(114,(int)mesh->getNodalConnectivity()->getNumberOfTuples());
415   //
416   mesh->decrRef();
417 }
418
419 void MEDCouplingBasicsTest1::testDescConn2D()
420 {
421   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
422   DataArrayInt *desc=DataArrayInt::New();
423   DataArrayInt *descIndx=DataArrayInt::New();
424   DataArrayInt *revDesc=DataArrayInt::New();
425   DataArrayInt *revDescIndx=DataArrayInt::New();
426   //
427   MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
428   mesh2->checkConsistencyLight();
429   CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
430   CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
431   CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,(int)revDescIndx->getNumberOfTuples());
432   CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,(int)descIndx->getNumberOfTuples());
433   CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)desc->getNumberOfTuples());
434   CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)revDesc->getNumberOfTuples());
435   const int expected1[18]={0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
436   CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
437   const int expected2[6]={0,4,7,10,14,18};
438   CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
439   const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
440   CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
441   const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
442   CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
443   DataArrayInt *conn=mesh2->getNodalConnectivity();
444   DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
445   const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
446   CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
447   const int expected6[39]={1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5};
448   CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
449   //
450   desc->decrRef();
451   descIndx->decrRef();
452   revDesc->decrRef();
453   revDescIndx->decrRef();
454   mesh2->decrRef();
455   //
456   const int elts[2]={1,3};
457   std::vector<int> eltsV(elts,elts+2);
458   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
459   mesh->checkConsistencyLight();
460   //
461   desc=DataArrayInt::New();
462   descIndx=DataArrayInt::New();
463   revDesc=DataArrayInt::New();
464   revDescIndx=DataArrayInt::New();
465   //
466   mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
467   mesh2->checkConsistencyLight();
468   CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
469   CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
470   CPPUNIT_ASSERT_EQUAL((std::size_t)14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,(int)revDescIndx->getNumberOfTuples());
471   CPPUNIT_ASSERT_EQUAL((std::size_t)6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,(int)descIndx->getNumberOfTuples());
472   CPPUNIT_ASSERT_EQUAL((std::size_t)18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)desc->getNumberOfTuples());
473   CPPUNIT_ASSERT_EQUAL((std::size_t)18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,(int)revDesc->getNumberOfTuples());
474   CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
475   CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
476   CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
477   CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
478   conn=mesh2->getNodalConnectivity();
479   connIndex=mesh2->getNodalConnectivityIndex();
480   CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
481   CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
482   //
483   desc->decrRef();
484   descIndx->decrRef();
485   revDesc->decrRef();
486   revDescIndx->decrRef();
487   mesh2->decrRef();
488   mesh->decrRef();
489 }
490
491 void MEDCouplingBasicsTest1::testDescConn3D()
492 {
493   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
494   DataArrayInt *desc=DataArrayInt::New();
495   DataArrayInt *descIndx=DataArrayInt::New();
496   DataArrayInt *revDesc=DataArrayInt::New();
497   DataArrayInt *revDescIndx=DataArrayInt::New();
498   //
499   MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
500   mesh2->checkConsistencyLight();
501   CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
502   CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
503   CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,(int)revDescIndx->getNumberOfTuples());
504   CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,(int)descIndx->getNumberOfTuples());
505   CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)desc->getNumberOfTuples());
506   CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)revDesc->getNumberOfTuples());
507   const int expected1[9]={0, 6, 12, 18, 24, 30, 36, 42, 48};
508   const int expected2[48]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 11, 12, 4, 13, 14, 15, 16, 17, 10, 18, 19, 13, 1, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 22, 12, 29, 23, 30, 31, 32, 17, 33, 28, 34, 35, 30};
509   const int expected3[37]={0, 1, 3, 4, 6, 8, 9, 10, 12, 13, 14, 16, 17, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 38, 40, 41, 43, 44, 45, 46, 47, 48};
510   const int expected4[48]={0, 0, 4, 0, 0, 1, 0, 2, 0, 1, 1, 5, 1, 1, 1, 3, 2, 2, 6, 2, 3, 2, 2, 3, 3, 7, 3, 3, 4, 4, 4, 5, 4, 6, 4, 5, 5, 5, 5, 7, 6, 6, 7, 6, 6, 7, 7, 7};
511   const int expected5[37]={0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180};
512   const int expected6[180]={4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 4, 1, 2, 5, 4, 4, 10, 13, 14, 11, 4, 1, 10, 11, 2, 4, 2, 11, 14,
513                             5, 4, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 4, 4, 5, 8, 7, 4, 13, 16, 17, 14, 4, 5, 14, 17, 8, 4, 8,
514                             17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
515                             14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16};
516   const int expected7[180]={4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 5, 1, 2, 5, 4, 5, 10, 13, 14, 11, 5, 1, 10, 11, 2, 5, 2, 11, 14,
517                             5, 5, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 5, 4, 5, 8, 7, 5, 13, 16, 17, 14, 5, 5, 14, 17, 8, 5, 8,
518                             17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
519                             14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16};
520
521   CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
522   CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
523   CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
524   CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
525   CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
526   CPPUNIT_ASSERT(std::equal(expected6,expected6+180,mesh2->getNodalConnectivity()->getConstPointer()));
527   //
528   desc->decrRef();
529   descIndx->decrRef();
530   revDesc->decrRef();
531   revDescIndx->decrRef();
532   mesh2->decrRef();
533   //
534   const int elts[2]={1,3};
535   std::vector<int> eltsV(elts,elts+2);
536   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
537   mesh->checkConsistencyLight();
538   desc=DataArrayInt::New();
539   descIndx=DataArrayInt::New();
540   revDesc=DataArrayInt::New();
541   revDescIndx=DataArrayInt::New();
542   mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
543   mesh2->checkConsistencyLight();
544   CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
545   CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
546   CPPUNIT_ASSERT_EQUAL((std::size_t)37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,(int)revDescIndx->getNumberOfTuples());
547   CPPUNIT_ASSERT_EQUAL((std::size_t)9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,(int)descIndx->getNumberOfTuples());
548   CPPUNIT_ASSERT_EQUAL((std::size_t)48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)desc->getNumberOfTuples());
549   CPPUNIT_ASSERT_EQUAL((std::size_t)48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,(int)revDesc->getNumberOfTuples());
550   CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
551   CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
552   CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
553   CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
554   CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
555   CPPUNIT_ASSERT(std::equal(expected7,expected7+180,mesh2->getNodalConnectivity()->getConstPointer()));
556   //
557   desc->decrRef();
558   descIndx->decrRef();
559   revDesc->decrRef();
560   revDescIndx->decrRef();
561   mesh2->decrRef();
562   mesh->decrRef();
563 }
564
565 void MEDCouplingBasicsTest1::testFindBoundaryNodes()
566 {
567   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
568   DataArrayInt *boundaryNodes=mesh->findBoundaryNodes();
569   CPPUNIT_ASSERT_EQUAL(26,(int)boundaryNodes->getNumberOfTuples());
570   CPPUNIT_ASSERT_EQUAL(1,(int)boundaryNodes->getNumberOfComponents());
571   const int expected1[26]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
572   CPPUNIT_ASSERT(std::equal(expected1,expected1+26,boundaryNodes->begin()));
573   boundaryNodes->decrRef();
574   mesh->decrRef();
575 }
576
577 void MEDCouplingBasicsTest1::testBoundaryMesh()
578 {
579   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
580   MEDCouplingPointSet *mesh2=mesh->buildBoundaryMesh(false);
581   CPPUNIT_ASSERT_EQUAL(24,mesh2->getNumberOfCells());
582   CPPUNIT_ASSERT_EQUAL(26,mesh2->getNumberOfNodes());
583   mesh2->decrRef();
584   mesh->decrRef();
585 }
586
587 void MEDCouplingBasicsTest1::testBuildPartOfMySelf()
588 {
589   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
590   mesh->setName("Toto");
591   const int tab1[2]={0,4};
592   const int tab2[3]={0,2,3};
593   //
594   MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelf(tab1,tab1+2,true);
595   MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
596   CPPUNIT_ASSERT(subMesh);
597   std::string name(subMesh->getName());
598   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
599   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllGeoTypes().begin());
600   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllGeoTypes().begin())));
601   CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
602   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
603   CPPUNIT_ASSERT(name=="Toto");
604   CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
605   CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
606   const int subConn[10]={4,0,3,4,1,4,7,8,5,4};
607   const int subConnIndex[3]={0,5,10};
608   CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
609   CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
610   CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
611   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
612   subMesh->decrRef();
613   //
614   subMeshSimple=mesh->buildPartOfMySelf(tab2,tab2+3,true);
615   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
616   CPPUNIT_ASSERT(subMesh);
617   name=subMesh->getName();
618   CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
619   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
620   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllGeoTypes().begin())));
621   CPPUNIT_ASSERT(name=="Toto");
622   CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
623   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
624   const int subConn2[14]={4,0,3,4,1,3,4,5,2,4,6,7,4,3};
625   const int subConnIndex2[4]={0,5,9,14};
626   CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
627   CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
628   CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
629   CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
630   const int tab3[3]={0,1,2};
631   MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
632   subMesh->decrRef();
633   name=subMeshSimple2->getName();
634   CPPUNIT_ASSERT(name=="Toto");
635   subMeshSimple2->decrRef();
636   //
637   mesh->decrRef();
638 }
639
640 void MEDCouplingBasicsTest1::testBuildPartOfMySelfNode()
641 {
642   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
643   const int tab1[4]={5,7,8,4};
644   MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+4,true);
645   MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
646   CPPUNIT_ASSERT(subMesh);
647   CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllGeoTypes().size());
648   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
649   CPPUNIT_ASSERT_EQUAL(1,subMesh->getNumberOfCells());
650   CPPUNIT_ASSERT_EQUAL((std::size_t)5,subMesh->getNodalConnectivity()->getNbOfElems());
651   CPPUNIT_ASSERT_EQUAL((std::size_t)2,subMesh->getNodalConnectivityIndex()->getNbOfElems());
652   const int subConn[5]={4,7,8,5,4};
653   const int subConnIndex[3]={0,5};
654   CPPUNIT_ASSERT(std::equal(subConn,subConn+5,subMesh->getNodalConnectivity()->getPointer()));
655   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+2,subMesh->getNodalConnectivityIndex()->getPointer()));
656   CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
657   subMeshSimple->decrRef();
658   //
659   subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+2,false);
660   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
661   CPPUNIT_ASSERT(subMesh);
662   CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
663   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
664   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
665   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
666   CPPUNIT_ASSERT_EQUAL((std::size_t)14,subMesh->getNodalConnectivity()->getNbOfElems());
667   CPPUNIT_ASSERT_EQUAL((std::size_t)4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
668   const int subConn2[14]={3,4,5,2,4,6,7,4,3,4,7,8,5,4};
669   const int subConnIndex2[4]={0,4,9,14};
670   CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
671   CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
672   CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
673   subMeshSimple->decrRef();
674   //testing the case where length of tab2 is greater than max number of node per cell.
675   const int tab2[7]={0,3,2,1,4,5,6};
676   subMeshSimple=mesh->buildPartOfMySelfNode(tab2,tab2+7,true);
677   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
678   CPPUNIT_ASSERT(subMesh);
679   CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllGeoTypes().size());
680   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllGeoTypes().begin());
681   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllGeoTypes().begin()));
682   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
683   subMeshSimple->decrRef();
684   //
685   mesh->decrRef();
686 }
687
688 void MEDCouplingBasicsTest1::testZipCoords()
689 {
690   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
691   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
692   CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
693   CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
694   CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
695   std::vector<int> oldConn(mesh->getNodalConnectivity()->getNbOfElems());
696   std::vector<int> oldConnIndex(mesh->getNumberOfCells()+1);
697   std::copy(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+oldConn.size(),oldConn.begin());
698   std::copy(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+mesh->getNumberOfCells()+1,oldConnIndex.begin());
699   DataArrayDouble *oldCoords=mesh->getCoords();
700   oldCoords->incrRef();
701   mesh->zipCoords();
702   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllGeoTypes().size());
703   CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
704   CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
705   CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
706   CPPUNIT_ASSERT(mesh->getCoords()!=oldCoords);
707   CPPUNIT_ASSERT(std::equal(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+2*9,oldCoords->getPointer()));
708   CPPUNIT_ASSERT(std::equal(oldConn.begin(),oldConn.end(),mesh->getNodalConnectivity()->getPointer()));
709   CPPUNIT_ASSERT(std::equal(oldConnIndex.begin(),oldConnIndex.end(),mesh->getNodalConnectivityIndex()->getPointer()));
710   oldCoords->decrRef();
711   //
712   const int tab1[2]={0,4};
713   MEDCouplingPointSet *subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,true);
714   MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
715   CPPUNIT_ASSERT(subMesh);
716   DataArrayInt *traducer=subMesh->zipCoordsTraducer();
717   const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
718   CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
719   traducer->decrRef();
720   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
721   CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
722   const int subConn[10]={4,0,2,3,1,4,5,6,4,3};
723   const int subConnIndex[3]={0,5,10};
724   CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
725   CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
726   CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
727   CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
728   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
729   subMesh->decrRef();
730   //
731   subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,false);
732   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
733   CPPUNIT_ASSERT(subMesh);
734   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllGeoTypes().begin());
735   CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
736   CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
737   CPPUNIT_ASSERT_EQUAL((std::size_t)10,subMesh->getNodalConnectivity()->getNbOfElems());
738   CPPUNIT_ASSERT_EQUAL((std::size_t)3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
739   CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
740   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
741   subMesh->decrRef();
742   //
743   mesh->decrRef();
744 }
745
746 void MEDCouplingBasicsTest1::testZipConnectivity()
747 {
748   MEDCouplingUMesh *m1=build2DTargetMesh_1();
749   MEDCouplingUMesh *m2=build2DTargetMesh_1();
750   int cells1[3]={2,3,4};
751   MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
752   MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
753   CPPUNIT_ASSERT(m3);
754   m2->decrRef();
755   MEDCouplingUMesh *m4=build2DSourceMesh_1();
756   MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
757   m1->decrRef();
758   m3->decrRef();
759   MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
760   m4->decrRef();
761   m5->decrRef();
762   //
763   bool areNodesMerged;
764   int newNbOfNodes;
765   CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
766   CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
767   DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
768   arr->decrRef();
769   CPPUNIT_ASSERT(areNodesMerged);
770   CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
771   CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
772   CPPUNIT_ASSERT_EQUAL(9,newNbOfNodes);
773   //
774   arr=m6->zipConnectivityTraducer(0);
775   CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
776   arr->decrRef();
777   MEDCouplingUMesh *m7=m6->clone(true);
778   arr=m6->zipConnectivityTraducer(0);
779   CPPUNIT_ASSERT(m7->isEqual(m6,1e-12));
780   CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
781   arr->decrRef();
782   //
783   m7->decrRef();
784   m6->decrRef();
785 }
786
787 void MEDCouplingBasicsTest1::testEqualMesh()
788 {
789   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
790   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
791   //
792   CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12));
793   //
794   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
795   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
796   double *pt=mesh2->getCoords()->getPointer();
797   double tmp=pt[1];
798   pt[1]=5.999;
799   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
800   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
801   pt[1]=tmp;
802   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
803   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
804   //
805   int *pt2=mesh1->getNodalConnectivity()->getPointer();
806   pt2[5]++;
807   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
808   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
809   pt2[5]--;
810   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
811   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
812   //
813   pt2=mesh1->getNodalConnectivityIndex()->getPointer();
814   pt2[1]++;
815   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
816   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
817   pt2[1]--;
818   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
819   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
820   //
821   std::string tmp3=mesh1->getName();
822   mesh1->setName("lllll");
823   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
824   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
825   mesh1->setName(tmp3.c_str());
826   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
827   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
828   //
829   tmp3=mesh2->getCoords()->getInfoOnComponent(1);
830   mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk");
831   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
832   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
833   mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str());
834   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
835   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
836   //
837   mesh1->decrRef();
838   mesh2->decrRef();
839 }
840
841 void MEDCouplingBasicsTest1::testEqualFieldDouble()
842 {
843   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
844   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
845   //
846   MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
847   fieldOnCells1->setMesh(mesh1);
848   MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
849   fieldOnCells2->setMesh(mesh2);
850   //
851   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
852   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
853   fieldOnCells2->decrRef();
854   //
855   MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
856   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15));
857   CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15));
858   fieldOnNodes1->decrRef();
859   //
860   fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
861   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
862   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
863   fieldOnCells1->decrRef();
864   fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
865   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
866   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
867   fieldOnCells1->setTime(4.,6,7);
868   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
869   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
870   fieldOnCells2->setTime(4.,6,7);
871   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
872   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
873   fieldOnCells1->setName("Power");
874   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
875   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
876   fieldOnCells2->setName("Power");
877   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
878   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
879   //
880   fieldOnCells1->setMesh(mesh1);
881   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
882   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
883   fieldOnCells2->setMesh(mesh1);
884   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
885   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
886   DataArrayDouble *arr=DataArrayDouble::New();
887   arr->setName("popo");
888   arr->alloc(mesh1->getNumberOfCells(),3);
889   double *pt=arr->getPointer();
890   std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.);
891   fieldOnCells1->setArray(arr);
892   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
893   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
894   fieldOnCells2->setArray(arr);
895   arr->decrRef();
896   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
897   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
898   //
899   DataArrayDouble *arr2=arr->deepCopy();
900   fieldOnCells2->setArray(arr2);
901   arr2->decrRef();
902   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
903   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
904   pt[4]=6.1;
905   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
906   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
907   pt[4]=6.;
908   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
909   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
910   arr2->setName("popo2");
911   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
912   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
913   //
914   arr2->setName("popo");
915   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
916   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
917   //
918   arr2->setInfoOnComponent(2,"jjj");
919   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
920   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
921   arr->setInfoOnComponent(2,"jjj");
922   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
923   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
924   //
925   fieldOnCells1->decrRef();
926   fieldOnCells2->decrRef();
927   //
928   mesh1->decrRef();
929   mesh2->decrRef();
930 }
931
932 void MEDCouplingBasicsTest1::testNatureChecking()
933 {
934   MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
935   field->setNature(ExtensiveMaximum);
936   field->setNature(IntensiveMaximum);
937   field->setNature(ExtensiveConservation);
938   field->decrRef();
939   field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
940   field->setNature(IntensiveMaximum);
941   CPPUNIT_ASSERT_THROW(field->setNature(ExtensiveMaximum),INTERP_KERNEL::Exception);
942   CPPUNIT_ASSERT_THROW(field->setNature(ExtensiveConservation),INTERP_KERNEL::Exception);
943   field->decrRef();
944 }
945
946 void MEDCouplingBasicsTest1::testBuildSubMeshData()
947 {
948   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
949   //check buildSubMesh on field on cells
950   MEDCouplingFieldDouble *fieldCells=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
951   fieldCells->setMesh(targetMesh);
952   const int elts[3]={1,2,4};
953   DataArrayInt *di;
954   MEDCouplingMesh *ret1=fieldCells->buildSubMeshData(elts,elts+3,di);
955   CPPUNIT_ASSERT_EQUAL(3,ret1->getNumberOfCells());
956   CPPUNIT_ASSERT_EQUAL(9,ret1->getNumberOfNodes());
957   CPPUNIT_ASSERT_EQUAL(3,(int)di->getNumberOfTuples());
958   CPPUNIT_ASSERT_EQUAL(1,(int)di->getNumberOfComponents());
959   const int *toCheck=di->getConstPointer();
960   CPPUNIT_ASSERT(std::equal(elts,elts+3,toCheck));
961   MEDCouplingUMesh *ret1DC=dynamic_cast<MEDCouplingUMesh *>(ret1);
962   CPPUNIT_ASSERT(ret1DC);
963   ret1->decrRef();
964   di->decrRef();
965   fieldCells->decrRef();
966   //check buildSubMesh on field on nodes
967   MEDCouplingFieldDouble *fieldNodes=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
968   fieldNodes->setMesh(targetMesh);
969   MEDCouplingMesh *ret2=fieldNodes->buildSubMeshData(elts,elts+3,di);
970   MEDCouplingUMesh *ret2DC=dynamic_cast<MEDCouplingUMesh *>(ret2);
971   CPPUNIT_ASSERT(ret2DC);
972   CPPUNIT_ASSERT_EQUAL(3,ret2->getNumberOfCells());
973   CPPUNIT_ASSERT_EQUAL(6,ret2->getNumberOfNodes());
974   CPPUNIT_ASSERT_EQUAL(6,(int)di->getNumberOfTuples());
975   CPPUNIT_ASSERT_EQUAL(1,(int)di->getNumberOfComponents());
976   toCheck=di->getConstPointer();
977   const int expected[6]={1,2,4,5,7,8};
978   CPPUNIT_ASSERT(std::equal(expected,expected+6,toCheck));
979   ret2->decrRef();
980   di->decrRef();
981   fieldNodes->decrRef();
982   targetMesh->decrRef();
983 }
984
985 void MEDCouplingBasicsTest1::testExtrudedMesh1()
986 {
987   MEDCouplingUMesh *mesh2D=0;
988   MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
989   MEDCouplingMappedExtrudedMesh *ext=MEDCouplingMappedExtrudedMesh::New(mesh3D,mesh2D,1);
990   CPPUNIT_ASSERT_EQUAL(18,ext->getNumberOfCells());
991   CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
992   DataArrayInt *ids3D=ext->getMesh3DIds();
993   const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
994   CPPUNIT_ASSERT_EQUAL(18,(int)ids3D->getNumberOfTuples());
995   CPPUNIT_ASSERT_EQUAL(1,(int)ids3D->getNumberOfComponents());
996   CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
997   MEDCouplingUMesh *mesh1D=ext->getMesh1D();
998   CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
999   CPPUNIT_ASSERT_EQUAL(3,mesh1D->getNumberOfCells());
1000   const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
1001   DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
1002   CPPUNIT_ASSERT_EQUAL(4,(int)mesh1DCoords->getNumberOfTuples());
1003   CPPUNIT_ASSERT_EQUAL(3,(int)mesh1DCoords->getNumberOfComponents());
1004   CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
1005   DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
1006   CPPUNIT_ASSERT_EQUAL(9,(int)conn1D->getNumberOfTuples());
1007   CPPUNIT_ASSERT_EQUAL(1,(int)conn1D->getNumberOfComponents());
1008   const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
1009   CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
1010   ext->decrRef();
1011   mesh3D->decrRef();
1012   mesh2D->decrRef();
1013 }
1014
1015 void MEDCouplingBasicsTest1::testExtrudedMesh2()
1016 {
1017   MEDCouplingUMesh *mN,*mTT,*mTF;
1018   build3DExtrudedUMesh_2(mN,mTT,mTF);
1019   //
1020   bool b=false;
1021   int newNbOfNodes;
1022   DataArrayInt *da=mTT->mergeNodes(1e-12,b,newNbOfNodes);
1023   CPPUNIT_ASSERT(b);
1024   da->decrRef();
1025   std::vector<int> n;
1026   double pt[3]={300.,300.,0.};
1027   double v[3]={0.,0.,2.};
1028   mTT->findNodesOnPlane(pt,v,1e-12,n);
1029   CPPUNIT_ASSERT_EQUAL(43,(int)n.size());
1030   MEDCouplingUMesh *mTT3dSurf=(MEDCouplingUMesh *)mTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1031   MEDCouplingMappedExtrudedMesh *meTT=MEDCouplingMappedExtrudedMesh::New(mTT,mTT3dSurf,0);
1032   CPPUNIT_ASSERT_EQUAL(200,meTT->getNumberOfCells());
1033   CPPUNIT_ASSERT_EQUAL(10,meTT->getMesh2D()->getNumberOfCells());
1034   CPPUNIT_ASSERT_EQUAL(20,meTT->getMesh1D()->getNumberOfCells());
1035   mTT3dSurf->decrRef();
1036   //
1037   b=false;
1038   da=mN->mergeNodes(1e-12,b,newNbOfNodes);
1039   da->decrRef();
1040   CPPUNIT_ASSERT(!b);
1041   n.clear();
1042   mN->findNodesOnPlane(pt,v,1e-12,n);
1043   CPPUNIT_ASSERT_EQUAL(30,(int)n.size());
1044   MEDCouplingUMesh *mN3dSurf=(MEDCouplingUMesh *)mN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1045   MEDCouplingMappedExtrudedMesh *meN=MEDCouplingMappedExtrudedMesh::New(mN,mN3dSurf,0);
1046   CPPUNIT_ASSERT_EQUAL(40,meN->getNumberOfCells());
1047   CPPUNIT_ASSERT_EQUAL(20,meN->getMesh2D()->getNumberOfCells());
1048   CPPUNIT_ASSERT_EQUAL(2,meN->getMesh1D()->getNumberOfCells());
1049   mN3dSurf->decrRef();
1050   //
1051   b=false;
1052   da=mTF->mergeNodes(1e-12,b,newNbOfNodes);
1053   da->decrRef();
1054   CPPUNIT_ASSERT(!b);
1055   n.clear();
1056   mTF->findNodesOnPlane(pt,v,1e-12,n);
1057   CPPUNIT_ASSERT_EQUAL(27,(int)n.size());
1058   MEDCouplingUMesh *mTF3dSurf=(MEDCouplingUMesh *)mTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
1059   MEDCouplingMappedExtrudedMesh *meTF=MEDCouplingMappedExtrudedMesh::New(mTF,mTF3dSurf,0);
1060   CPPUNIT_ASSERT_EQUAL(340,meTF->getNumberOfCells());
1061   CPPUNIT_ASSERT_EQUAL(17,meTF->getMesh2D()->getNumberOfCells());
1062   CPPUNIT_ASSERT_EQUAL(20,meTF->getMesh1D()->getNumberOfCells());
1063   mTF3dSurf->decrRef();
1064   //
1065   meTT->decrRef();
1066   meN->decrRef();
1067   meTF->decrRef();
1068   //
1069   mN->decrRef();
1070   mTT->decrRef();
1071   mTF->decrRef();
1072 }
1073
1074 /*!
1075  * This test check MEDCouplingUMesh::buildExtrudedMesh method.
1076  */
1077 void MEDCouplingBasicsTest1::testExtrudedMesh3()
1078 {
1079   MEDCouplingUMesh *m1=build2DTargetMesh_1();
1080   m1->changeSpaceDimension(3);
1081   MEDCouplingUMesh *m2=buildCU1DMesh_U();
1082   m2->changeSpaceDimension(3);
1083   double center[3]={0.,0.,0.};
1084   double vector[3]={0,1,0};
1085   m2->rotate(center,vector,-M_PI/2.);
1086   MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1087   //
1088   MEDCouplingMappedExtrudedMesh *m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1089   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1090   CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1091   CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1092   const int *m3DIds=m4->getMesh3DIds()->getConstPointer();
1093   for(int i=0;i<15;i++)
1094     CPPUNIT_ASSERT_EQUAL(i,m3DIds[i]);
1095   m4->decrRef();
1096   //some random in cells to check that extrusion alg find it correctly
1097   const int expected1[15]={1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1098   m3->renumberCells(expected1,false);
1099   m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1100   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1101   CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1102   CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1103   m3DIds=m4->getMesh3DIds()->getConstPointer();
1104   for(int i=0;i<15;i++)
1105     CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1106   m4->decrRef();
1107   m3->decrRef();
1108   //play with polygons and polyedrons
1109   std::vector<int> cells(2); cells[0]=2; cells[1]=3;
1110   m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1111   m3=m1->buildExtrudedMesh(m2,0);
1112   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0));
1113   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1));
1114   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2));
1115   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(3));
1116   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(4));
1117   m3->renumberCells(expected1,false);
1118   m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1119   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1120   CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
1121   CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
1122   m3DIds=m4->getMesh3DIds()->getConstPointer();
1123   for(int i=0;i<15;i++)
1124     CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
1125   m4->decrRef();
1126   m3->decrRef();
1127   //
1128   m2->decrRef();
1129   m1->decrRef();
1130 }
1131
1132 /*!
1133  * This test check MEDCouplingUMesh::buildExtrudedMesh method, but also, MEDCouplingMappedExtrudedMesh following methods :
1134  * getCellContainingPoint getMeasureField getNodeIdsOfCell getCoordinateOfNode getTypeOfCell build3DUnstructuredMesh.
1135  */
1136 void MEDCouplingBasicsTest1::testExtrudedMesh4()
1137 {
1138   MEDCouplingUMesh *m1=build2DTargetMesh_1();
1139   std::vector<int> cells(2); cells[0]=2; cells[1]=4;
1140   m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1141   m1->changeSpaceDimension(3);
1142   MEDCouplingUMesh *m2=buildCU1DMesh_U();
1143   m2->changeSpaceDimension(3);
1144   double center[3]={0.,0.,0.};
1145   double vector[3]={0.,1.,0.};
1146   m2->rotate(center,vector,-M_PI/2.);
1147   m1->zipCoords();
1148   MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
1149   const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
1150   const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
1151   m3->renumberCells(expected1,false);
1152   MEDCouplingMappedExtrudedMesh *m4=MEDCouplingMappedExtrudedMesh::New(m3,m1,0);
1153   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
1154   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
1155   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
1156   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
1157   MEDCouplingFieldDouble *f=m4->getMeasureField(true);
1158   DataArrayDouble *arr=f->getArray();
1159   CPPUNIT_ASSERT_EQUAL(15,(int)arr->getNumberOfTuples());
1160   CPPUNIT_ASSERT_EQUAL(1,(int)arr->getNumberOfComponents());
1161   const double *arrPtr=arr->getConstPointer();
1162   const double expected2[15]={0.075,0.0375,0.0375,0.075,0.075,   0.1125,0.05625,0.05625,0.1125,0.1125,   0.0625,0.03125,0.03125,0.0625,0.0625};
1163   for(int i=0;i<15;i++)
1164     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1165   f->decrRef();
1166   MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
1167   m5->zipCoords();
1168   CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
1169   f=m5->getMeasureField(true);
1170   arr=f->getArray();
1171   arrPtr=arr->getConstPointer();
1172   for(int i=0;i<15;i++)
1173     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
1174   f->decrRef();
1175   m5->decrRef();
1176   //
1177   m4->decrRef();
1178   m3->decrRef();
1179   m2->decrRef();
1180   m1->decrRef();
1181 }
1182
1183 void MEDCouplingBasicsTest1::testFindCommonNodes()
1184 {
1185   DataArrayInt *comm,*commI;
1186   MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
1187   targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1188   CPPUNIT_ASSERT_EQUAL(1,commI->getNumberOfTuples());
1189   CPPUNIT_ASSERT_EQUAL(0,comm->getNumberOfTuples());
1190   int newNbOfNodes;
1191   DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1192   CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1193   CPPUNIT_ASSERT_EQUAL(27,o2n->getNumberOfTuples());
1194   const int o2nExp1[27]=
1195     {
1196       0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1197       21,22,23,24,25,26
1198     };
1199   CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
1200   o2n->decrRef();
1201   comm->decrRef();
1202   commI->decrRef();
1203   targetMesh->decrRef();
1204   //
1205   targetMesh=build3DTargetMeshMergeNode_1();
1206   CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
1207   targetMesh->findCommonNodes(1e-10,-1,comm,commI);
1208   CPPUNIT_ASSERT_EQUAL(3,commI->getNumberOfTuples());
1209   CPPUNIT_ASSERT_EQUAL(6,comm->getNumberOfTuples());
1210   const int commExpected[6]={1,27,28,29,23,30};
1211   const int commIExpected[3]={0,4,6};
1212   CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
1213   CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
1214   o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
1215   CPPUNIT_ASSERT_EQUAL(31,o2n->getNumberOfTuples());
1216   CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
1217   const int o2nExp2[31]=
1218     {
1219       0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
1220       21,22,23,24,25,26,1,1,1,23
1221     };
1222   CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
1223   o2n->decrRef();
1224   comm->decrRef();
1225   commI->decrRef();
1226   targetMesh->decrRef();
1227   //
1228   targetMesh=build3DTargetMesh_1();
1229   bool areNodesMerged;
1230   unsigned int time=targetMesh->getTimeOfThis();
1231   o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1232   targetMesh->updateTime();
1233   CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
1234   CPPUNIT_ASSERT(!areNodesMerged);
1235   targetMesh->decrRef();
1236   o2n->decrRef();
1237   //
1238   targetMesh=build3DTargetMeshMergeNode_1();
1239   time=targetMesh->getTimeOfThis();
1240   o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1241   targetMesh->updateTime();
1242   CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1243   CPPUNIT_ASSERT(areNodesMerged);
1244   int connExp[72]={18,0,1,4,3,9,10,13,12, 18,1,2,5,4,10,11,14,13, 18,3,4,7,6,12,13,16,15,
1245                    18,4,5,8,7,13,14,17,16,
1246                    18,9,10,13,12,18,19,22,21, 18,10,11,14,13,19,20,23,22, 18,12,13,16,15,21,22,25,24,
1247                    18,13,14,17,16,22,23,26,25};
1248   CPPUNIT_ASSERT_EQUAL(72,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1249   CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
1250   CPPUNIT_ASSERT_EQUAL(27,targetMesh->getCoords()->getNumberOfTuples());
1251   double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. ,
1252                          200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
1253                          0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50.,
1254                          50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. ,
1255                          200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.  
1256                          , 0., 50., 200., 50., 50., 200. , 200., 50., 200., 
1257                          0., 200., 200., 50., 200., 200. , 200., 200., 200. };
1258   CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
1259   targetMesh->decrRef();
1260   o2n->decrRef();
1261   //2D
1262   targetMesh=build2DTargetMeshMergeNode_1();
1263   CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
1264   time=targetMesh->getTimeOfThis();
1265   o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
1266   CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
1267   CPPUNIT_ASSERT(areNodesMerged);
1268   CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
1269   int connExp2[23]={4,0,4,3,1, 3,1,3,2, 3,3,5,2, 4,4,6,7,3, 4,7,8,5,3};
1270   CPPUNIT_ASSERT_EQUAL(23,targetMesh->getNodalConnectivity()->getNumberOfTuples());
1271   CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
1272   double coordsExp2[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, 0.2,0.2, -0.3,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7};
1273   CPPUNIT_ASSERT_EQUAL(9,targetMesh->getCoords()->getNumberOfTuples());
1274   CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
1275   targetMesh->decrRef();
1276   o2n->decrRef();
1277 }
1278
1279 void MEDCouplingBasicsTest1::testCheckButterflyCells()
1280 {
1281   std::vector<int> cells;
1282   MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
1283   sourceMesh->checkButterflyCells(cells);
1284   CPPUNIT_ASSERT(cells.empty());
1285   int *pt=sourceMesh->getNodalConnectivity()->getPointer();
1286   std::swap(pt[15],pt[16]);
1287   sourceMesh->checkButterflyCells(cells);
1288   CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1289   CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1290   cells.clear();
1291   std::swap(pt[15],pt[16]);
1292   sourceMesh->checkButterflyCells(cells);
1293   CPPUNIT_ASSERT(cells.empty());
1294   sourceMesh->decrRef();
1295   // 3D surf
1296   sourceMesh=build3DSurfTargetMesh_1();
1297   sourceMesh->checkButterflyCells(cells);
1298   CPPUNIT_ASSERT(cells.empty());
1299   pt=sourceMesh->getNodalConnectivity()->getPointer();
1300   std::swap(pt[15],pt[16]);
1301   sourceMesh->checkButterflyCells(cells);
1302   CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
1303   CPPUNIT_ASSERT_EQUAL(3,cells[0]);
1304   cells.clear();
1305   std::swap(pt[15],pt[16]);
1306   sourceMesh->checkButterflyCells(cells);
1307   CPPUNIT_ASSERT(cells.empty());
1308   sourceMesh->decrRef();
1309 }
1310
1311 void MEDCouplingBasicsTest1::testMergeMesh1()
1312 {
1313   MEDCouplingUMesh *m1=build2DTargetMesh_1();
1314   MEDCouplingUMesh *m2=build2DSourceMesh_1();
1315   const double vec[2]={1.,0.};
1316   m2->translate(vec);
1317   MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
1318   MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
1319   CPPUNIT_ASSERT(m3C);
1320   m3->checkConsistencyLight();
1321   MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1322   CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
1323   m4->decrRef();
1324   bool isMerged;
1325   int newNbOfNodes;
1326   DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
1327   CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
1328   CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
1329   CPPUNIT_ASSERT(isMerged);
1330   da->decrRef();
1331   m3->decrRef();
1332   m1->decrRef();
1333   m2->decrRef();
1334 }
1335
1336 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
1337 {
1338   MEDCouplingUMesh *m1=build2DTargetMesh_1();
1339   MEDCouplingUMesh *m2=build2DTargetMesh_1();
1340   std::vector<int> cells(5);
1341   for(int i=0;i<5;i++)
1342     cells[i]=i;
1343   m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
1344   m1->tryToShareSameCoords(*m2,1e-12);
1345   MEDCouplingUMesh *m3=build2DTargetMesh_1();
1346   m3->tryToShareSameCoords(*m2,1e-12);
1347   std::vector<const MEDCouplingUMesh *> meshes;
1348   meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
1349   MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
1350   m4->checkConsistencyLight();
1351   CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
1352   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
1353   const int cells1[5]={0,1,2,3,4};
1354   MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
1355   m1_1->setName(m1->getName().c_str());
1356   CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
1357   const int cells2[5]={5,6,7,8,9};
1358   MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
1359   m2_1->setName(m2->getName().c_str());
1360   CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
1361   const int cells3[5]={10,11,12,13,14};
1362   MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
1363   m3_1->setName(m3->getName().c_str());
1364   CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
1365   m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
1366   //
1367   m4->decrRef();
1368   m1->decrRef();
1369   m2->decrRef();
1370   m3->decrRef();
1371 }
1372
1373 void MEDCouplingBasicsTest1::testMergeField1()
1374 {
1375   MEDCouplingUMesh *m1=build2DTargetMesh_1();
1376   MEDCouplingUMesh *m2=build2DSourceMesh_1();
1377   const double vec[2]={1.,0.};
1378   m2->translate(vec);
1379   MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
1380   MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
1381   MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
1382   f3->checkConsistencyLight();
1383   MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
1384   CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1385   std::string name=f3->getName();
1386   CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1387   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1388   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1389   CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1390   CPPUNIT_ASSERT_EQUAL(7,(int)f3->getNumberOfTuples());
1391   double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1392   const double *tmp=f3->getArray()->getConstPointer();
1393   std::transform(tmp,tmp+7,values,values,std::minus<double>());
1394   std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1395   double max=*std::max_element(values,values+7);
1396   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1397   m4->decrRef();
1398   f3->decrRef();
1399   f1->decrRef();
1400   f2->decrRef();
1401   m1->decrRef();
1402   m2->decrRef();
1403 }
1404
1405 bool func1(const double *pt, double *res);
1406 bool func2(const double *pt, double *res);
1407 bool func3(const double *pt, double *res);
1408 bool func4(const double *pt, double *res);
1409
1410 bool func1(const double *pt, double *res)
1411 {
1412   res[0]=pt[0]+pt[1];
1413   return true;
1414 }
1415
1416 bool func2(const double *pt, double *res)
1417 {
1418   res[0]=pt[0]+pt[1];
1419   res[1]=2.*(pt[0]+pt[1]);
1420   return true;
1421 }
1422
1423 bool func3(const double *pt, double *res)
1424 {
1425   if(fabs(pt[0]-0.2)<1e-12)
1426     return false;
1427   res[0]=1./(pt[0]-0.2);
1428   return true;
1429 }
1430
1431 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1432 {
1433   MEDCouplingUMesh *m=build2DTargetMesh_1();
1434   m->setTime(3.4,5,6); m->setTimeUnit("us");
1435   int a,b;
1436   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1437   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1438   CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1439   CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1440   f1->checkConsistencyLight();
1441   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1442   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1443   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1444   CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1445   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1446   const double *tmp=f1->getArray()->getConstPointer();
1447   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1448   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1449   double max=*std::max_element(values1,values1+5);
1450   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1451   f1->decrRef();
1452   //
1453   f1=m->fillFromAnalytic(ON_NODES,1,func1);
1454   f1->checkConsistencyLight();
1455   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1456   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1457   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1458   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1459   double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1460   tmp=f1->getArray()->getConstPointer();
1461   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1462   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1463   max=*std::max_element(values2,values2+9);
1464   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1465   f1->decrRef();
1466   //
1467   f1=m->fillFromAnalytic(ON_NODES,2,func2);
1468   f1->checkConsistencyLight();
1469   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1470   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1471   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1472   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1473   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};
1474   tmp=f1->getArray()->getConstPointer();
1475   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1476   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1477   max=*std::max_element(values3,values3+18);
1478   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1479   double values4[2];
1480   f1->accumulate(values4);
1481   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1482   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1483   f1->integral(true,values4);
1484   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1485   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1486   f1->decrRef();
1487   //
1488   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1489   //
1490   m->decrRef();
1491 }
1492
1493 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1494 {
1495   MEDCouplingUMesh *m=build2DTargetMesh_1();
1496   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1497   f1->checkConsistencyLight();
1498   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1499   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1500   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1501   CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1502   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1503   const double *tmp=f1->getArray()->getConstPointer();
1504   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1505   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1506   double max=*std::max_element(values1,values1+5);
1507   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1508   f1->decrRef();
1509   //
1510   f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1511   f1->checkConsistencyLight();
1512   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1513   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1514   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1515   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1516   double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1517   tmp=f1->getArray()->getConstPointer();
1518   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1519   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1520   max=*std::max_element(values2,values2+9);
1521   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1522   f1->decrRef();
1523   f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1524   f1->checkConsistencyLight();
1525   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1526   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1527   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1528   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1529   tmp=f1->getArray()->getConstPointer();
1530   double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1531   std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1532   std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1533   max=*std::max_element(values2Bis,values2Bis+9);
1534   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1535   f1->decrRef();
1536   //
1537   f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1538   f1->checkConsistencyLight();
1539   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1540   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1541   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1542   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1543   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};
1544   tmp=f1->getArray()->getConstPointer();
1545   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1546   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1547   max=*std::max_element(values3,values3+18);
1548   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1549   double values4[2];
1550   f1->accumulate(values4);
1551   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1552   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1553   f1->integral(true,values4);
1554   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
1555   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
1556   f1->decrRef();
1557   //
1558   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1559   //
1560   m->decrRef();
1561 }
1562
1563 void MEDCouplingBasicsTest1::testApplyFunc()
1564 {
1565   MEDCouplingUMesh *m=build2DTargetMesh_1();
1566   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1567   f1->checkConsistencyLight();
1568   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1569   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1570   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1571   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1572   f1->applyFunc(1,func1);
1573   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1574   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1575   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1576   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1577   double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1578   const double *tmp=f1->getArray()->getConstPointer();
1579   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1580   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1581   double max=*std::max_element(values1,values1+9);
1582   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1583   f1->decrRef();
1584   m->decrRef();
1585 }
1586
1587 void MEDCouplingBasicsTest1::testApplyFunc2()
1588 {
1589   MEDCouplingUMesh *m=build2DTargetMesh_1();
1590   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1591   f1->checkConsistencyLight();
1592   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1593   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1594   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1595   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1596   //
1597   MEDCouplingFieldDouble *f2=f1->clone(true);
1598   CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1599   CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1600   CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1601   f2->applyFunc("abs(u)^2.4+2*u");
1602   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1603   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1604   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1605   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1606   double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1607                       0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1608                       0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1609                       0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1610                       5.0423700574830965, 17.435300118916864};
1611   const double *tmp=f2->getArray()->getConstPointer();
1612   std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1613   std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1614   double max=*std::max_element(values2,values2+18);
1615   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1616   f2->decrRef();
1617   //
1618   f1->applyFunc(1,"x+y");
1619   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1620   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1621   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1622   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1623   double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1624   tmp=f1->getArray()->getConstPointer();
1625   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1626   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1627   max=*std::max_element(values1,values1+9);
1628   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1629   f1->decrRef();
1630   m->decrRef();
1631 }
1632
1633 void MEDCouplingBasicsTest1::testOperationsOnFields()
1634 {
1635   MEDCouplingUMesh *m=build2DTargetMesh_1();
1636   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1637   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1638   f1->checkConsistencyLight();
1639   f2->checkConsistencyLight();
1640   MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1641   f3->checkConsistencyLight();
1642   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1643   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1644   double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1645   const double *tmp=f3->getArray()->getConstPointer();
1646   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1647   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1648   double max=*std::max_element(values1,values1+9);
1649   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1650   f3->decrRef();
1651   //
1652   f3=(*f1)*(*f2);
1653   f3->checkConsistencyLight();
1654   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1655   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1656   double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1657   tmp=f3->getArray()->getConstPointer();
1658   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1659   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1660   max=*std::max_element(values2,values2+9);
1661   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1662   f3->decrRef();
1663   //
1664   f3=(*f1)+(*f2);
1665   MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1666   f4->checkConsistencyLight();
1667   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1668   CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1669   double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1670   tmp=f4->getArray()->getConstPointer();
1671   std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1672   std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1673   max=*std::max_element(values3,values3+9);
1674   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1675   f3->decrRef();
1676   f4->decrRef();
1677   //
1678   f3=(*f1)+(*f2);
1679   f4=(*f3)/(*f2);
1680   f4->checkConsistencyLight();
1681   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1682   CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1683   tmp=f4->getArray()->getConstPointer();
1684   for(int i=0;i<9;i++)
1685     CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1686   f3->decrRef();
1687   f4->decrRef();
1688   //
1689   f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1690   f4->checkConsistencyLight();
1691   CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1692   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1693   CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1694   CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1695   MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(ONE_TIME,false);
1696   CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1697   CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1698   CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1699   f3=(*f1)+(*f5);
1700   tmp=f3->getArray()->getConstPointer();
1701   double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1702   std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1703   std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1704   max=*std::max_element(values4,values4+9);
1705   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1706   f5->decrRef();
1707   f4->decrRef();
1708   f3->decrRef();
1709   //
1710   f4=f2->buildNewTimeReprFromThis(NO_TIME,true);
1711   f4->checkConsistencyLight();
1712   CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1713   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1714   CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1715   CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1716   f5=f4->buildNewTimeReprFromThis(ONE_TIME,true);
1717   CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1718   CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1719   CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1720   CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1721   f3=(*f1)+(*f5);
1722   tmp=f3->getArray()->getConstPointer();
1723   double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1724   std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1725   std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1726   max=*std::max_element(values5,values5+9);
1727   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1728   f5->decrRef();
1729   f4->decrRef();
1730   f3->decrRef();
1731   //
1732   f1->decrRef();
1733   f2->decrRef();
1734   m->decrRef();
1735 }
1736
1737 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1738 {
1739   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1740   m->setTime(3.4,5,6); m->setTimeUnit("us");
1741   int a,b;
1742   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1743   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1744   MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1745   f3->checkConsistencyLight();
1746   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1747   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1748   const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1749                              0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1750                              0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1751   CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1752   CPPUNIT_ASSERT_EQUAL(9,(int)f3->getNumberOfTuples());
1753   const double *val=f3->getArray()->getConstPointer();
1754   for(int i=0;i<9;i++)
1755     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1756   f3->decrRef();
1757   f1->decrRef();
1758   f2->decrRef();
1759   //
1760   f1=m->buildOrthogonalField();
1761   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1762   CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1763   CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1764   f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1765   f3=(*f1)*(*f2);
1766   const double expected2[15]={-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637};
1767   val=f3->getArray()->getConstPointer();
1768   for(int i=0;i<15;i++)
1769     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1770   f3->decrRef();
1771   //
1772   f3=(*f2)*(*f1);
1773   val=f3->getArray()->getConstPointer();
1774   for(int i=0;i<15;i++)
1775     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1776   f3->decrRef();
1777   //
1778   f1->decrRef();
1779   f2->decrRef();
1780   //
1781   m->decrRef();
1782 }
1783
1784 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1785 {
1786   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1787   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1788   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1789   (*f1)/=(*f2);
1790   f1->checkConsistencyLight();
1791   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1792   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1793   const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1794                              0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1795                              0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1796   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1797   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1798   const double *val=f1->getArray()->getConstPointer();
1799   for(int i=0;i<9;i++)
1800     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1801   f1->decrRef();
1802   f2->decrRef();
1803   //
1804   f1=m->buildOrthogonalField();
1805   f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1806   (*f1)*=(*f2);
1807   const double expected2[15]={-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637};
1808   val=f1->getArray()->getConstPointer();
1809   for(int i=0;i<15;i++)
1810     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1811   f1->decrRef();
1812   //
1813   f1=m->buildOrthogonalField();
1814   CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1815   f1->decrRef();
1816   f2->decrRef();
1817   //
1818   m->decrRef();
1819 }
1820
1821 /*!
1822  * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1823  */
1824 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1825 {
1826   MEDCouplingUMesh *m=build2DTargetMesh_1();
1827   int nbOfCells=m->getNumberOfCells();
1828   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1829   f1->setMesh(m);
1830   DataArrayDouble *array=DataArrayDouble::New();
1831   array->alloc(nbOfCells,3);
1832   f1->setArray(array);
1833   CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1834   CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1835   array->decrRef();
1836   double *tmp=array->getPointer();
1837   const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1838   const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1839   std::copy(arr1,arr1+15,tmp);
1840   f1->setStartTime(2.,0,0);
1841   f1->setEndTime(3.,0,0);
1842   f1->checkConsistencyLight();
1843   double res[3];
1844   const double pos[2]={0.3,-0.2};
1845   f1->getValueOn(pos,res);
1846   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1847   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1848   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1849   std::fill(res,res+3,0.);
1850   f1->getValueOn(pos,2.2,res);
1851   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1852   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1853   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1854   std::fill(res,res+3,0.);
1855   CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1856   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1857   f2->setMesh(m);
1858   f2->setArray(f1->getArray());
1859   f2->setStartTime(2.,3,0);
1860   f2->setEndTime(4.,13,0);
1861   CPPUNIT_ASSERT_THROW(f2->checkConsistencyLight(),INTERP_KERNEL::Exception);
1862   DataArrayDouble *array2=DataArrayDouble::New();
1863   array2->alloc(nbOfCells,3);
1864   tmp=array2->getPointer();
1865   std::copy(arr2,arr2+15,tmp);
1866   f2->setEndArray(array2);
1867   array2->decrRef();
1868   f2->checkConsistencyLight();
1869   //
1870   std::fill(res,res+3,0.);
1871   f2->getValueOn(pos,3.21,res);
1872   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1873   CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1874   CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1875   MEDCouplingFieldDouble *f3=f2->clone(true);
1876   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1877   f3->getEndArray()->getPointer()[0]=5.001;
1878   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1879   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1880   f3->setStartTime(2.1,3,0);
1881   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1882   f3->setStartTime(2.,3,0);
1883   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1884   f3->setStartTime(2.,4,0);
1885   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1886   f3->setStartTime(2.,3,1);
1887   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1888   f3->setStartTime(2.,3,0);
1889   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1890   f3->setEndTime(4.1,13,0);
1891   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1892   f3->setEndTime(4.,13,0);
1893   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1894   f3->setEndTime(4.,14,0);
1895   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1896   f3->setEndTime(4.,13,1);
1897   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1898   f3->setEndTime(4.,13,0);
1899   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1900   f3->decrRef();
1901   MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1902   std::fill(res,res+3,0.);
1903   f4->getValueOn(pos,3.21,res);
1904   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1905   CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1906   CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1907   (*f4)+=*f2;
1908   std::fill(res,res+3,0.);
1909   f4->getValueOn(pos,3.21,res);
1910   CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1911   CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1912   CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1913   f4->decrRef();
1914   //
1915   f2->decrRef();
1916   f1->decrRef();
1917   m->decrRef();
1918 }
1919
1920 bool func4(const double *pt, double *res)
1921 {
1922   res[0]=pt[0]+pt[1]+pt[2];
1923   return true;
1924 }
1925
1926 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1927 {
1928   double *tmp;
1929   MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1930   MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1931   f1->mergeNodes(1e-10);
1932   f1->decrRef();
1933   targetMesh->decrRef();
1934   //
1935   targetMesh=build3DTargetMeshMergeNode_1();
1936   f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1937   tmp=f1->getArray()->getPointer();
1938   tmp[0]=1000.;
1939   f1->mergeNodes(1e-10);
1940   f1->decrRef();
1941   targetMesh->decrRef();
1942   //
1943   targetMesh=build3DTargetMeshMergeNode_1();
1944   f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1945   tmp=f1->getArray()->getPointer();
1946   tmp[1]=1000.;
1947   CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1948   f1->decrRef();
1949   targetMesh->decrRef();
1950 }
1951
1952 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1953 {
1954   MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1955   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1956   CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1957   const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1958   const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1959   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1960   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1961   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1962   DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1963   CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1964   CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1965   const int expected1[5]={2,0,1,3,4};
1966   CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1967   da->decrRef();
1968   da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1969   CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1970   CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1971   const int expected2[5]={0,3,4,1,2};
1972   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1973   da->decrRef();
1974   const int renumber1[5]={4,0,1,2,3};
1975   targetMesh->renumberCells(renumber1,false);
1976   CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1977   CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1978   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1979   targetMesh->decrRef();
1980   sourceMesh->decrRef();
1981 }
1982
1983 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1984 {
1985   MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1986   MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1987   DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1988   MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1989   CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1990   const int expected1[2]={0,1};
1991   CPPUNIT_ASSERT_EQUAL(2,(int)arr1->getNumberOfTuples());
1992   CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1993   CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1994   arr1->decrRef();
1995   const int expected2[5]={0,3,4,1,2};
1996   arr1=m2_1->rearrange2ConsecutiveCellTypes();
1997   CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
1998   CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1999   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
2000   MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
2001   CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
2002   CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
2003   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
2004   CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
2005   m2_2->renumberCells(expected2,false);
2006   CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
2007   arr1->decrRef();
2008   m1_1->decrRef();
2009   m1_2->decrRef();
2010   m2_1->decrRef();
2011   m2_2->decrRef();
2012 }
2013
2014 void MEDCouplingBasicsTest1::testSplitByType()
2015 {
2016   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2017   std::vector<MEDCouplingUMesh *> v=m1->splitByType();
2018   CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
2019   std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
2020   MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
2021   m2->setName(m1->getName().c_str());
2022   CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
2023   for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
2024     (*iter)->decrRef();
2025   m2->decrRef();
2026   m1->decrRef();
2027 }
2028
2029 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
2030 {
2031   std::vector<const MEDCouplingUMesh *> meshes;
2032   MEDCouplingUMesh *m2=build2DTargetMesh_1();
2033   int cells1[3]={2,3,4};
2034   MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2035   MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2036   CPPUNIT_ASSERT(m3);
2037   meshes.push_back(m3);
2038   int cells2[3]={1,2,4};
2039   MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2040   MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2041   CPPUNIT_ASSERT(m4);
2042   meshes.push_back(m4);
2043   int cells3[2]={1,2};
2044   MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2045   MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2046   CPPUNIT_ASSERT(m5);
2047   meshes.push_back(m5);
2048   m2->decrRef();
2049   //
2050   std::vector<DataArrayInt *> corr;
2051   MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2052   CPPUNIT_ASSERT_EQUAL(4,m7->getNumberOfCells());
2053   CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2054   const int expectedVals1[3]={3,3,2};
2055   const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2056   for(int i=0;i<3;i++)
2057     {
2058       DataArrayInt *arr=corr[i];
2059       CPPUNIT_ASSERT_EQUAL(1,(int)arr->getNumberOfComponents());
2060       int nbOfVals=expectedVals1[i];
2061       CPPUNIT_ASSERT_EQUAL(nbOfVals,arr->getNumberOfTuples());
2062       const int *vals=arr->getConstPointer();
2063       for(int j=0;j<nbOfVals;j++)
2064         CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2065     }
2066   std::vector< std::vector<int> > fidsOfGroups;
2067   std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2068   DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2069   const int fidExp[4]={5,1,3,4};
2070   const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2071   CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2072   CPPUNIT_ASSERT_EQUAL(1,(int)arr2->getNumberOfComponents());
2073   CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
2074   CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2075   for(int i=0;i<3;i++)
2076     {
2077       int nbOfVals=expectedVals1[i];
2078       CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2079       CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2080     }
2081   for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2082     (*iter)->decrRef();
2083   arr2->decrRef();
2084   m7->decrRef();
2085   //
2086   m3->decrRef();
2087   m4->decrRef();
2088   m5->decrRef();
2089 }
2090
2091 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2092 {
2093   MEDCouplingUMesh *m2;
2094   MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2095   m2->decrRef();
2096   const int part1[5]={2,3,6,4,10};
2097   MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2098   const int part2[4]={5,6,4,7};
2099   MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2100   std::vector<const MEDCouplingUMesh *> meshes;
2101   meshes.push_back(m1);
2102   meshes.push_back(m3);
2103   meshes.push_back(m3);
2104   meshes.push_back(m4);
2105   std::vector<DataArrayInt *> corr;
2106   MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2107   CPPUNIT_ASSERT_EQUAL(18,m5->getNumberOfCells());
2108   std::vector<DataArrayInt *>::iterator it=corr.begin();
2109   const int exp1[4]={18,5,5,4};
2110   const int exp2[4][18]={
2111     {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2112     {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2113     {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2114     {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2115   };
2116   int i=0;
2117   for(;it!=corr.end();it++,i++)
2118     {
2119       int sz=(*it)->getNumberOfTuples();
2120       CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2121       CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2122     }
2123   for(it=corr.begin();it!=corr.end();it++)
2124     (*it)->decrRef();
2125   m5->decrRef();
2126   m4->decrRef();
2127   m3->decrRef();
2128   m1->decrRef();
2129 }
2130
2131 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2132 {
2133   MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2134   MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2135   double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2136   CPPUNIT_ASSERT_EQUAL(5,(int)field->getNumberOfTuples());
2137   CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2138   const double *vals=field->getArray()->getConstPointer();
2139   for(int i=0;i<15;i++)
2140     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2141   field->decrRef();
2142   targetMesh->decrRef();
2143   // testing 
2144   double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2145   int targetConn[4]={0,1,2,3};
2146   targetMesh=MEDCouplingUMesh::New();
2147   targetMesh->setMeshDimension(2);
2148   targetMesh->allocateCells(1);
2149   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2150   targetMesh->finishInsertingCells();
2151   DataArrayDouble *myCoords=DataArrayDouble::New();
2152   myCoords->alloc(4,3);
2153   std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2154   targetMesh->setCoords(myCoords);
2155   myCoords->decrRef();
2156   field=targetMesh->buildOrthogonalField();
2157   CPPUNIT_ASSERT_EQUAL(1,(int)field->getNumberOfTuples());
2158   CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2159   vals=field->getArray()->getConstPointer();
2160   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2161   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2162   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2163   field->decrRef();
2164   targetMesh->decrRef();
2165 }
2166
2167 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2168 {
2169   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2170   double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2171   MCAuto<DataArrayInt> t1,t2;
2172   //2D basic
2173   targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2174   CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2175   CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2176   const int expectedValues1[6]={0,4,3,0,1,2};
2177   const int expectedValues2[7]={0,1,2,3,4,5,6};
2178   CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2179   CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2180   //2D with no help of bounding box.
2181   double center[2]={0.2,0.2};
2182   DataArrayDouble::Rotate2DAlg(center,0.78539816339744830962,6,pos,pos);
2183   targetMesh->rotate(center,0,0.78539816339744830962);
2184   targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2185   CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2186   CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2187   CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2188   CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2189   //2D outside
2190   const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2191   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2192   targetMesh->decrRef();
2193   //test limits 2D
2194   targetMesh=build2DTargetMesh_1();
2195   const double pos2[2]={0.2,-0.05};
2196   std::vector<int> t11;
2197   t11.clear();
2198   targetMesh->getCellsContainingPoint(pos2,1e-12,t11);
2199   CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2200   const int expectedValues3[2]={0,1};
2201   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues3));
2202   const double pos3[2]={0.2,0.2};
2203   t11.clear();
2204   targetMesh->getCellsContainingPoint(pos3,1e-12,t11);
2205   CPPUNIT_ASSERT_EQUAL(5,(int)t11.size());
2206   const int expectedValues4[5]={0,1,2,3,4};
2207   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues4));
2208   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2209   targetMesh->decrRef();
2210   //3D
2211   targetMesh=build3DTargetMesh_1();
2212   const double pos4[3]={25.,25.,25.};
2213   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2214   const double pos5[3]={50.,50.,50.};
2215   t11.clear();
2216   targetMesh->getCellsContainingPoint(pos5,1e-12,t11);
2217   CPPUNIT_ASSERT_EQUAL(8,(int)t11.size());
2218   const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2219   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues5));
2220   const double pos6[3]={0., 50., 0.};
2221   t11.clear();
2222   targetMesh->getCellsContainingPoint(pos6,1e-12,t11);
2223   CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2224   const int expectedValues6[2]={0,2};
2225   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues6));
2226   //3D outside
2227   const double pos7[3]={-1.0,-1.0,0.};
2228   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2229   //3D outside 2
2230   const double center2[3]={0.,0.,0.};
2231   const double vec2[3]={0.,-1.,0.};
2232   targetMesh->rotate(center2,vec2,0.78539816339744830962);
2233   const double pos8[3]={-25,25.,12.};
2234   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2235   //
2236   targetMesh->decrRef();
2237 }
2238
2239 void MEDCouplingBasicsTest1::testGetValueOn1()
2240 {
2241   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2242   MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2243   int nbOfCells=targetMesh->getNumberOfCells();
2244   fieldOnCells->setMesh(targetMesh);
2245   DataArrayDouble *array=DataArrayDouble::New();
2246   array->alloc(nbOfCells,2);
2247   fieldOnCells->setArray(array);
2248   double *tmp=array->getPointer();
2249   for(int i=0;i<nbOfCells;i++)
2250     { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2251   array->decrRef();
2252   //
2253   const double pos1[2]={0.25,0.};
2254   double res[2];
2255   fieldOnCells->getValueOn(pos1,res);
2256   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2257   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2258   //
2259   fieldOnCells->decrRef();
2260   targetMesh->decrRef();
2261   //
2262   targetMesh=build2DSourceMesh_1();
2263   MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2264   int nbOfNodes=targetMesh->getNumberOfNodes();
2265   fieldOnNodes->setMesh(targetMesh);
2266   array=DataArrayDouble::New();
2267   array->alloc(nbOfNodes,2);
2268   fieldOnNodes->setArray(array);
2269   tmp=array->getPointer();
2270   for(int i=0;i<nbOfNodes;i++)
2271     { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2272   array->decrRef();
2273   //
2274   const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2275   fieldOnNodes->getValueOn(pos2,res);
2276   CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2277   CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2278   const double pos3[2]={0.033333333333333326,0.36666666666666664};
2279   fieldOnNodes->getValueOn(pos3,res);
2280   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2281   CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2282   //
2283   fieldOnNodes->decrRef();
2284   targetMesh->decrRef();
2285 }
2286
2287 void MEDCouplingBasicsTest1::testCMesh0()
2288 {
2289   MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2290   MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2291   CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2292   
2293   DataArrayDouble* coordsX=DataArrayDouble::New();
2294   double arrX[4] = { -1., 1., 2., 4. };
2295   coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
2296   DataArrayDouble* coordsY=DataArrayDouble::New();
2297   double arrY[4] = { -2., 2., 4., 8. };
2298   coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
2299   DataArrayDouble* coordsZ=DataArrayDouble::New();
2300   double arrZ[4] = { -3., 3., 6., 12. };
2301   coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
2302   mesh->setCoords(coordsX,coordsY,coordsZ);
2303   coordsX->decrRef();
2304   coordsY->decrRef();
2305   coordsZ->decrRef();
2306   //
2307   MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2308   CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnNodes->getNumberOfComponents());
2309   CPPUNIT_ASSERT_EQUAL(64,(int)fieldOnNodes->getNumberOfTuples());
2310   const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2311                               4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2312                               7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2313                               7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2314   const double *val=fieldOnNodes->getArray()->getConstPointer();
2315   for(int i=0;i<64;i++)
2316     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2317   double res[1];  //size fieldOnNodes->getNumberOfComponents()
2318   fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2319   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2320   fieldOnNodes->decrRef();
2321   //
2322   MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2323   CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnCells->getNumberOfComponents());
2324   CPPUNIT_ASSERT_EQUAL(27,(int)fieldOnCells->getNumberOfTuples());
2325   val=fieldOnCells->getArray()->getConstPointer();
2326   const double expected2[27]={0, 1.5, 3, 1.5, 3, 4.5, 3, 4.5, 6, 1.5, 3, 4.5, 3, 4.5,
2327                               6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2328   for(int i=0;i<27;i++)
2329     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2330   fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2331   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2332   fieldOnCells->decrRef();
2333   //
2334   MEDCouplingMesh* meshDeepCopy=mesh->deepCopy();
2335   MEDCouplingCMesh* meshClone=mesh->clone(false);
2336   
2337   CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2338   meshEmpty->copyTinyStringsFrom(mesh);
2339   //no data in meshEmpty, expected false
2340   CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2341   
2342   CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2343   meshDeepCopy->copyTinyStringsFrom(mesh);
2344   CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2345   CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2346   
2347   CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2348   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2349   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2350   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2351   
2352   mesh->decrRef();
2353   meshEmpty->decrRef();
2354   meshDeepCopy->decrRef();
2355   meshClone->decrRef();
2356 }
2357
2358 void MEDCouplingBasicsTest1::testCMesh1()
2359 {
2360   MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2361   mesh1=MEDCouplingCMesh::New();
2362   DataArrayDouble* coordsX1=DataArrayDouble::New();
2363   double arrX1[4] = { -1., 1., 2., 4. };
2364   coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2365   DataArrayDouble* coordsY1=DataArrayDouble::New();
2366   double arrY1[4] = { -2., 2., 4., 8. };
2367   coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2368   DataArrayDouble* coordsZ1=DataArrayDouble::New();
2369   double arrZ1[4] = { -3., 3., 6., 12. };
2370   coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2371   mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2372   
2373   mesh2=MEDCouplingCMesh::New();
2374   DataArrayDouble* coordsX2=DataArrayDouble::New();
2375   double arrX2[4] = { -1., 1., 2., 4. };
2376   coordsX2->useArray(arrX2,false, CPP_DEALLOC,4,1);
2377   DataArrayDouble* coordsY2=DataArrayDouble::New();
2378   double arrY2[4] = { -2., 2., 4., 8. };
2379   coordsY2->useArray(arrY2,false, CPP_DEALLOC,4,1);
2380   DataArrayDouble* coordsZ2=DataArrayDouble::New();
2381   double arrZ2[4] = { -3., 3., 6., 12.+1e-6 };   //here is not equal
2382   coordsZ2->useArray(arrZ2,false, CPP_DEALLOC,4,1);
2383   mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2384   
2385   mesh3=MEDCouplingCMesh::New();
2386   DataArrayDouble* coordsX3=DataArrayDouble::New();
2387   double arrX3[1] = { -1.};
2388   coordsX3->useArray(arrX3,false, CPP_DEALLOC,1,1);
2389   DataArrayDouble* coordsY3=DataArrayDouble::New();
2390   double arrY3[1] = { -2.};
2391   coordsY3->useArray(arrY3,false, CPP_DEALLOC,1,1);
2392   DataArrayDouble* coordsZ3=DataArrayDouble::New();
2393   double arrZ3[1] = { -3.};
2394   coordsZ3->useArray(arrZ3,false, CPP_DEALLOC,1,1);
2395   mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2396   
2397   CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2398   CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2399   
2400   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2401   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2402   CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2403   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2404   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2405   
2406   CPPUNIT_ASSERT_THROW(mesh3->checkConsistency(1e-12),INTERP_KERNEL::Exception);
2407   mesh1->checkConsistency(1e-12);
2408   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2409   
2410   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2411   CPPUNIT_ASSERT_EQUAL(27,mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2412   CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2413   
2414   std::vector<double> coo;
2415   mesh1->getCoordinatesOfNode(0, coo);
2416   CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2417   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2418   CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2419   CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2420   coo.clear();
2421   mesh1->getCoordinatesOfNode(63, coo);
2422   CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2423   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2424   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2425   CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2426   
2427   std::string repr;
2428   repr=mesh1->simpleRepr();
2429   repr=mesh1->advancedRepr();
2430   CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2431   CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2432   CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2433   CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2434   coordsX1->decrRef();
2435   coordsY1->decrRef();
2436   coordsZ1->decrRef();
2437   coordsX2->decrRef();
2438   coordsY2->decrRef();
2439   coordsZ2->decrRef();
2440   coordsX3->decrRef();
2441   coordsY3->decrRef();
2442   coordsZ3->decrRef();
2443   mesh1->decrRef();
2444   mesh2->decrRef();
2445   mesh3->decrRef();
2446 }
2447   
2448 void MEDCouplingBasicsTest1::testCMesh2()
2449 {
2450   MEDCouplingCMesh *mesh1;
2451   mesh1=MEDCouplingCMesh::New();
2452   DataArrayDouble* coordsX1=DataArrayDouble::New();
2453   double arrX1[4] = { -1., 1., 2., 4. };
2454   coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
2455   DataArrayDouble* coordsY1=DataArrayDouble::New();
2456   double arrY1[4] = { -2., 2., 4., 8. };
2457   coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
2458   DataArrayDouble* coordsZ1=DataArrayDouble::New();
2459   double arrZ1[4] = { -3., 3., 6., 12. };
2460   coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
2461   mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2462   
2463   std::vector<int> dis=mesh1->getDistributionOfTypes();
2464   CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2465   CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2466   CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2467   CPPUNIT_ASSERT_EQUAL(-1,dis[2]);
2468   
2469   std::vector<const DataArrayInt *> idsPerType;
2470   CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2471   dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2472   CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2473   
2474   dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2475   dis[2]=0;
2476   DataArrayInt *ids=DataArrayInt::New();
2477   ids->alloc(10,1);
2478   ids->fillWithValue(23);
2479   idsPerType.push_back(ids);
2480   DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2481   CPPUNIT_ASSERT(check);
2482   CPPUNIT_ASSERT(check->isEqual(*ids));
2483   
2484   std::vector<int> code;
2485   std::vector<DataArrayInt *> idsInPflPerType;
2486   std::vector<DataArrayInt *> pfls;
2487   mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2488   CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2489   CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2490   CPPUNIT_ASSERT_EQUAL(10,code[1]);
2491   CPPUNIT_ASSERT_EQUAL(0,code[2]);
2492   CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2493   CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2494   DataArrayInt *exp=DataArrayInt::New(); exp->alloc(10,1); exp->iota(0);
2495   CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*exp));
2496   exp->decrRef();
2497   CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2498   idsInPflPerType[0]->decrRef();
2499   pfls[0]->decrRef();
2500
2501   ids->decrRef();
2502   check->decrRef();
2503   int cells1[4]={0,1,25,26};
2504   MEDCouplingUMesh *partMesh1=
2505     dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2506   CPPUNIT_ASSERT(partMesh1);
2507   CPPUNIT_ASSERT_EQUAL(4,partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2508   CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2509   CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2510   
2511   int cells2[2]={25,26};
2512   DataArrayInt* arr1;
2513   MEDCouplingCMesh *partMesh2=
2514     dynamic_cast<MEDCouplingCMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2515   CPPUNIT_ASSERT(partMesh2);
2516   CPPUNIT_ASSERT_EQUAL(2,partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2517   CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2518   
2519   int cells3[2]={2,3};
2520   DataArrayInt* arr2;
2521   MEDCouplingUMesh *partMesh3=
2522     dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2523   CPPUNIT_ASSERT(partMesh3);
2524   CPPUNIT_ASSERT_EQUAL(2,partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2525   CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2526   
2527   CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2528   CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2529
2530   double bbox1[6];
2531   double bbox2[6];
2532   mesh1->getBoundingBox(bbox1);
2533   partMesh1->getBoundingBox(bbox2);
2534   for(int i=0;i<6;i++)
2535     CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2536   partMesh3->getBoundingBox(bbox1);
2537   partMesh2->getBoundingBox(bbox2);
2538   for(int i=0;i<6;i++)
2539     CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2540   
2541   CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2542   MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2543   mesh2d->setCoords(coordsX1,coordsY1);
2544   MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2545   
2546   std::vector<double> tinyInfoD;
2547   std::vector<int> tinyInfo;
2548   std::vector<std::string> littleStrings;
2549   mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2550   CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2551   CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]);   //x
2552   CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]);   //y
2553   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]);  //z
2554   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]);  //it
2555   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]);   //order
2556   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2557   DataArrayInt* d1=DataArrayInt::New();
2558   DataArrayDouble* d2=DataArrayDouble::New();
2559   mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2560   CPPUNIT_ASSERT_EQUAL(0,d1->getNumberOfTuples());
2561   CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples());
2562  
2563   partMesh1->decrRef();
2564   partMesh2->decrRef();
2565   partMesh3->decrRef();
2566   mesh2d->decrRef();
2567   arr1->decrRef();
2568   arr2->decrRef();
2569   f1->decrRef();
2570   d1->decrRef();
2571   d2->decrRef();
2572   coordsX1->decrRef();
2573   coordsY1->decrRef();
2574   coordsZ1->decrRef();
2575   mesh1->decrRef();
2576 }
2577
2578 void MEDCouplingBasicsTest1::testScale()
2579 {
2580   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2581   const double pos[2]={0.2,0.2};
2582   mesh->scale(pos,0.5);
2583   const double expected1[18]={-0.05,-0.05, 0.2,-0.05, 0.45,-0.05, -0.05,0.2, 0.2,0.2, 0.45,0.2,
2584                               -0.05,0.45, 0.2,0.45, 0.45,0.45};
2585   const double *val=mesh->getCoords()->getConstPointer();
2586   for(int i=0;i<18;i++)
2587     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2588   //
2589   mesh->decrRef();
2590 }
2591
2592 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2593 {
2594   MEDCouplingUMesh *m1=build2DTargetMesh_1();
2595   MEDCouplingUMesh *m2=build2DTargetMesh_1();
2596   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2597   m1->tryToShareSameCoords(*m2,1e-12);
2598   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2599   m1->tryToShareSameCoords(*m2,1e-12);
2600   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2601   m2->tryToShareSameCoords(*m1,1e-12);
2602   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2603   m1->decrRef();
2604   m2->decrRef();
2605   //
2606   m1=build2DTargetMesh_1();
2607   m2=build2DTargetMesh_2();
2608   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2609   m1->tryToShareSameCoords(*m2,1e-12);
2610   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2611   m1->tryToShareSameCoords(*m2,1e-12);
2612   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2613   m2->tryToShareSameCoords(*m1,1e-12);
2614   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2615   m1->decrRef();
2616   m2->decrRef();
2617   //
2618   m1=build2DTargetMesh_1();
2619   m2=build2DSourceMesh_1();
2620   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2621   CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2622   m1->decrRef();
2623   m2->decrRef();
2624 }
2625
2626 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2627 {
2628   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2629   std::vector<int> n;
2630   double pt[3]={300.,300.,0.};
2631   double v[3]={0.,0.,2.};
2632   mesh->findNodesOnPlane(pt,v,1e-12,n);
2633   CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2634   MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2635   MEDCouplingMappedExtrudedMesh *me=MEDCouplingMappedExtrudedMesh::New(mesh,m3dSurf,0);
2636   const DataArrayInt *da=me->getMesh3DIds();
2637   CPPUNIT_ASSERT_EQUAL(8,me->getNumberOfCells());
2638   const int expected[8]={0,1,2,3,4,5,6,7};
2639   const int *val=da->getConstPointer();
2640   for(int i=0;i<8;i++)
2641     CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2642   me->decrRef();
2643   m3dSurf->decrRef();
2644   mesh->decrRef();
2645 }
2646
2647 void MEDCouplingBasicsTest1::testRenumberCells()
2648 {
2649   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2650   MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2651   CPPUNIT_ASSERT(m->isEqual(m2,0));
2652   const int arr[5]={12,3,25,2,26};
2653   m->renumberCells(arr,true);
2654   CPPUNIT_ASSERT(!m->isEqual(m2,0));
2655   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2656   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2657   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2658   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2659   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2660   const int arr2[5]={5,-1,-5,4,8};
2661   m->renumberCells(arr2,true);
2662   CPPUNIT_ASSERT(m->isEqual(m2,0));
2663   m->decrRef();
2664   m2->decrRef();
2665 }
2666
2667 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2668 {
2669   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2670   MEDCouplingUMesh *m2=build2DTargetMesh_1();
2671   //
2672   CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2673   m1->changeSpaceDimension(2);
2674   CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2675   m1->setName(m2->getName().c_str());
2676   CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2677   m1->changeSpaceDimension(3);
2678   CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2679   const double expected[27]={-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0.};
2680   const double *val=m1->getCoords()->getConstPointer();
2681   for(int i=0;i<27;i++)
2682     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
2683   //
2684   m1->decrRef();
2685   m2->decrRef();
2686 }
2687
2688 void MEDCouplingBasicsTest1::testSetConnectivity()
2689 {
2690   MEDCouplingUMesh *m1 = build1DTargetMesh_1();
2691
2692   DataArrayInt * conn = DataArrayInt::New();
2693   DataArrayInt * connI = DataArrayInt::New();
2694   m1->setConnectivity(conn, connI, true); // was SEG-Faulting with empty arrays
2695   conn->decrRef();
2696   connI->decrRef();
2697   m1->decrRef();
2698 }