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