Salome HOME
Update copyrights
[tools/medcoupling.git] / src / MEDCoupling / Test / MEDCouplingBasicsTest1.cxx
1 // Copyright (C) 2007-2019  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   m4->setName(f1->getMesh()->getName());
1377   CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
1378   std::string name=f3->getName();
1379   CPPUNIT_ASSERT(name=="MeasureOfMesh_");
1380   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
1381   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1382   CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1383   CPPUNIT_ASSERT_EQUAL(7,(int)f3->getNumberOfTuples());
1384   double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
1385   const double *tmp=f3->getArray()->getConstPointer();
1386   std::transform(tmp,tmp+7,values,values,std::minus<double>());
1387   std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
1388   double max=*std::max_element(values,values+7);
1389   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1390   m4->decrRef();
1391   f3->decrRef();
1392   f1->decrRef();
1393   f2->decrRef();
1394   m1->decrRef();
1395   m2->decrRef();
1396 }
1397
1398 bool func1(const double *pt, double *res);
1399 bool func2(const double *pt, double *res);
1400 bool func3(const double *pt, double *res);
1401 bool func4(const double *pt, double *res);
1402
1403 bool func1(const double *pt, double *res)
1404 {
1405   res[0]=pt[0]+pt[1];
1406   return true;
1407 }
1408
1409 bool func2(const double *pt, double *res)
1410 {
1411   res[0]=pt[0]+pt[1];
1412   res[1]=2.*(pt[0]+pt[1]);
1413   return true;
1414 }
1415
1416 bool func3(const double *pt, double *res)
1417 {
1418   if(fabs(pt[0]-0.2)<1e-12)
1419     return false;
1420   res[0]=1./(pt[0]-0.2);
1421   return true;
1422 }
1423
1424 void MEDCouplingBasicsTest1::testFillFromAnalytic()
1425 {
1426   MEDCouplingUMesh *m=build2DTargetMesh_1();
1427   m->setTime(3.4,5,6); m->setTimeUnit("us");
1428   int a,b;
1429   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
1430   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1431   CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1432   CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1433   f1->checkConsistencyLight();
1434   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1435   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1436   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1437   CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1438   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1439   const double *tmp=f1->getArray()->getConstPointer();
1440   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1441   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1442   double max=*std::max_element(values1,values1+5);
1443   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1444   f1->decrRef();
1445   //
1446   f1=m->fillFromAnalytic(ON_NODES,1,func1);
1447   f1->checkConsistencyLight();
1448   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1449   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1450   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1451   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1452   double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
1453   tmp=f1->getArray()->getConstPointer();
1454   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1455   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1456   max=*std::max_element(values2,values2+9);
1457   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1458   f1->decrRef();
1459   //
1460   f1=m->fillFromAnalytic(ON_NODES,2,func2);
1461   f1->checkConsistencyLight();
1462   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1463   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1464   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1465   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1466   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};
1467   tmp=f1->getArray()->getConstPointer();
1468   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1469   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1470   max=*std::max_element(values3,values3+18);
1471   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1472   double values4[2];
1473   f1->accumulate(values4);
1474   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1475   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1476   f1->integral(true,values4);
1477   //0.4 == 0.25/4*-0.6+(0.25/4+0.125/3)*-0.1+0.4*(0.125/3.+0.125/3)+(-0.1)*(0.25/4+0.25/4)+0.4*(0.25/4+0.125/3+0.125/3+0.25/4+0.25/4)+0.9*(0.25/4+0.125/3)+0.4*0.25/4+0.9*(0.25/4+0.25/4)+1.4*0.25/4
1478   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4,values4[0],1.e-12);
1479   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8,values4[1],1.e-12);
1480   f1->decrRef();
1481   //
1482   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
1483   //
1484   m->decrRef();
1485 }
1486
1487 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
1488 {
1489   MEDCouplingUMesh *m=build2DTargetMesh_1();
1490   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
1491   f1->checkConsistencyLight();
1492   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
1493   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1494   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1495   CPPUNIT_ASSERT_EQUAL(5,(int)f1->getNumberOfTuples());
1496   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
1497   const double *tmp=f1->getArray()->getConstPointer();
1498   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
1499   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
1500   double max=*std::max_element(values1,values1+5);
1501   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1502   f1->decrRef();
1503   //
1504   f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
1505   f1->checkConsistencyLight();
1506   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1507   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1508   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1509   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1510   double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1511   tmp=f1->getArray()->getConstPointer();
1512   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1513   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1514   max=*std::max_element(values2,values2+9);
1515   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1516   f1->decrRef();
1517   f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
1518   f1->checkConsistencyLight();
1519   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1520   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1521   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1522   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1523   tmp=f1->getArray()->getConstPointer();
1524   double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
1525   std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
1526   std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
1527   max=*std::max_element(values2Bis,values2Bis+9);
1528   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1529   f1->decrRef();
1530   //
1531   f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
1532   f1->checkConsistencyLight();
1533   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1534   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1535   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1536   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1537   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};
1538   tmp=f1->getArray()->getConstPointer();
1539   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
1540   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
1541   max=*std::max_element(values3,values3+18);
1542   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1543   double values4[2];
1544   f1->accumulate(values4);
1545   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
1546   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
1547   f1->integral(true,values4);
1548   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4,values4[0],1.e-12);
1549   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8,values4[1],1.e-12);
1550   f1->decrRef();
1551   //
1552   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
1553   //
1554   m->decrRef();
1555 }
1556
1557 void MEDCouplingBasicsTest1::testApplyFunc()
1558 {
1559   MEDCouplingUMesh *m=build2DTargetMesh_1();
1560   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1561   f1->checkConsistencyLight();
1562   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1563   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1564   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1565   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1566   f1->applyFunc(1,func1);
1567   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1568   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1569   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1570   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1571   double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1572   const double *tmp=f1->getArray()->getConstPointer();
1573   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1574   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1575   double max=*std::max_element(values1,values1+9);
1576   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1577   f1->decrRef();
1578   m->decrRef();
1579 }
1580
1581 void MEDCouplingBasicsTest1::testApplyFunc2()
1582 {
1583   MEDCouplingUMesh *m=build2DTargetMesh_1();
1584   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
1585   f1->checkConsistencyLight();
1586   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1587   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1588   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1589   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1590   //
1591   MEDCouplingFieldDouble *f2=f1->clone(true);
1592   CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
1593   CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
1594   CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
1595   f2->applyFunc("abs(u)^2.4+2*u");
1596   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1597   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1598   CPPUNIT_ASSERT_EQUAL(2,(int)f1->getNumberOfComponents());
1599   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1600   double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
1601                       0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
1602                       0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1603                       0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
1604                       5.0423700574830965, 17.435300118916864};
1605   const double *tmp=f2->getArray()->getConstPointer();
1606   std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
1607   std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
1608   double max=*std::max_element(values2,values2+18);
1609   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1610   f2->decrRef();
1611   //
1612   f1->applyFunc(1,"x+y");
1613   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1614   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1615   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1616   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1617   double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
1618   tmp=f1->getArray()->getConstPointer();
1619   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1620   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1621   max=*std::max_element(values1,values1+9);
1622   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1623   f1->decrRef();
1624   m->decrRef();
1625 }
1626
1627 void MEDCouplingBasicsTest1::testOperationsOnFields()
1628 {
1629   MEDCouplingUMesh *m=build2DTargetMesh_1();
1630   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
1631   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
1632   f1->checkConsistencyLight();
1633   f2->checkConsistencyLight();
1634   MEDCouplingFieldDouble *f3=(*f1)+(*f2);
1635   f3->checkConsistencyLight();
1636   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1637   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1638   double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1639   const double *tmp=f3->getArray()->getConstPointer();
1640   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
1641   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
1642   double max=*std::max_element(values1,values1+9);
1643   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1644   f3->decrRef();
1645   //
1646   f3=(*f1)*(*f2);
1647   f3->checkConsistencyLight();
1648   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1649   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1650   double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
1651   tmp=f3->getArray()->getConstPointer();
1652   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
1653   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
1654   max=*std::max_element(values2,values2+9);
1655   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1656   f3->decrRef();
1657   //
1658   f3=(*f1)+(*f2);
1659   MEDCouplingFieldDouble *f4=(*f1)-(*f3);
1660   f4->checkConsistencyLight();
1661   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1662   CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1663   double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
1664   tmp=f4->getArray()->getConstPointer();
1665   std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
1666   std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
1667   max=*std::max_element(values3,values3+9);
1668   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1669   f3->decrRef();
1670   f4->decrRef();
1671   //
1672   f3=(*f1)+(*f2);
1673   f4=(*f3)/(*f2);
1674   f4->checkConsistencyLight();
1675   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1676   CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
1677   tmp=f4->getArray()->getConstPointer();
1678   for(int i=0;i<9;i++)
1679     CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
1680   f3->decrRef();
1681   f4->decrRef();
1682   //
1683   f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
1684   f4->checkConsistencyLight();
1685   CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
1686   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1687   CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1688   CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1689   MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(ONE_TIME,false);
1690   CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
1691   CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1692   CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1693   f3=(*f1)+(*f5);
1694   tmp=f3->getArray()->getConstPointer();
1695   double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1696   std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
1697   std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
1698   max=*std::max_element(values4,values4+9);
1699   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1700   f5->decrRef();
1701   f4->decrRef();
1702   f3->decrRef();
1703   //
1704   f4=f2->buildNewTimeReprFromThis(NO_TIME,true);
1705   f4->checkConsistencyLight();
1706   CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
1707   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
1708   CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
1709   CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
1710   f5=f4->buildNewTimeReprFromThis(ONE_TIME,true);
1711   CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
1712   CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
1713   CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
1714   CPPUNIT_ASSERT(f5->getTimeDiscretization()==ONE_TIME);
1715   f3=(*f1)+(*f5);
1716   tmp=f3->getArray()->getConstPointer();
1717   double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
1718   std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
1719   std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
1720   max=*std::max_element(values5,values5+9);
1721   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
1722   f5->decrRef();
1723   f4->decrRef();
1724   f3->decrRef();
1725   //
1726   f1->decrRef();
1727   f2->decrRef();
1728   m->decrRef();
1729 }
1730
1731 void MEDCouplingBasicsTest1::testOperationsOnFields2()
1732 {
1733   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1734   m->setTime(3.4,5,6); m->setTimeUnit("us");
1735   int a,b;
1736   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1737   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1738   MEDCouplingFieldDouble *f3=(*f1)/(*f2);
1739   f3->checkConsistencyLight();
1740   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
1741   CPPUNIT_ASSERT(f3->getTimeDiscretization()==ONE_TIME);
1742   const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1743                              0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1744                              0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1745   CPPUNIT_ASSERT_EQUAL(1,(int)f3->getNumberOfComponents());
1746   CPPUNIT_ASSERT_EQUAL(9,(int)f3->getNumberOfTuples());
1747   const double *val=f3->getArray()->getConstPointer();
1748   for(int i=0;i<9;i++)
1749     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1750   f3->decrRef();
1751   f1->decrRef();
1752   f2->decrRef();
1753   //
1754   f1=m->buildOrthogonalField();
1755   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,f1->getTime(a,b),1.e-14);
1756   CPPUNIT_ASSERT_EQUAL(5,a); CPPUNIT_ASSERT_EQUAL(6,b);
1757   CPPUNIT_ASSERT_EQUAL(std::string(f1->getTimeUnit()),std::string("us"));
1758   f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1759   f3=(*f1)*(*f2);
1760   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};
1761   val=f3->getArray()->getConstPointer();
1762   for(int i=0;i<15;i++)
1763     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1764   f3->decrRef();
1765   //
1766   f3=(*f2)*(*f1);
1767   val=f3->getArray()->getConstPointer();
1768   for(int i=0;i<15;i++)
1769     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1770   f3->decrRef();
1771   //
1772   f1->decrRef();
1773   f2->decrRef();
1774   //
1775   m->decrRef();
1776 }
1777
1778 void MEDCouplingBasicsTest1::testOperationsOnFields3()
1779 {
1780   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
1781   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
1782   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
1783   (*f1)/=(*f2);
1784   f1->checkConsistencyLight();
1785   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
1786   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
1787   const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
1788                              0.7407407407407407, 1.129032258064516, 0.81632653061224492,
1789                              0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
1790   CPPUNIT_ASSERT_EQUAL(1,(int)f1->getNumberOfComponents());
1791   CPPUNIT_ASSERT_EQUAL(9,(int)f1->getNumberOfTuples());
1792   const double *val=f1->getArray()->getConstPointer();
1793   for(int i=0;i<9;i++)
1794     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
1795   f1->decrRef();
1796   f2->decrRef();
1797   //
1798   f1=m->buildOrthogonalField();
1799   f2=m->fillFromAnalytic(ON_CELLS,1,"x");
1800   (*f1)*=(*f2);
1801   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};
1802   val=f1->getArray()->getConstPointer();
1803   for(int i=0;i<15;i++)
1804     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
1805   f1->decrRef();
1806   //
1807   f1=m->buildOrthogonalField();
1808   CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
1809   f1->decrRef();
1810   f2->decrRef();
1811   //
1812   m->decrRef();
1813 }
1814
1815 /*!
1816  * Check of LINEAR_TIME and CONST_ON_TIME_INTERVAL policies
1817  */
1818 void MEDCouplingBasicsTest1::testOperationsOnFields4()
1819 {
1820   MEDCouplingUMesh *m=build2DTargetMesh_1();
1821   int nbOfCells=m->getNumberOfCells();
1822   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
1823   f1->setMesh(m);
1824   DataArrayDouble *array=DataArrayDouble::New();
1825   array->alloc(nbOfCells,3);
1826   f1->setArray(array);
1827   CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
1828   CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
1829   array->decrRef();
1830   double *tmp=array->getPointer();
1831   const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
1832   const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
1833   std::copy(arr1,arr1+15,tmp);
1834   f1->setStartTime(2.,0,0);
1835   f1->setEndTime(3.,0,0);
1836   f1->checkConsistencyLight();
1837   double res[3];
1838   const double pos[2]={0.3,-0.2};
1839   f1->getValueOn(pos,res);
1840   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1841   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1842   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1843   std::fill(res,res+3,0.);
1844   f1->getValueOn(pos,2.2,res);
1845   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
1846   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
1847   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
1848   std::fill(res,res+3,0.);
1849   CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
1850   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
1851   f2->setMesh(m);
1852   f2->setArray(f1->getArray());
1853   f2->setStartTime(2.,3,0);
1854   f2->setEndTime(4.,13,0);
1855   CPPUNIT_ASSERT_THROW(f2->checkConsistencyLight(),INTERP_KERNEL::Exception);
1856   DataArrayDouble *array2=DataArrayDouble::New();
1857   array2->alloc(nbOfCells,3);
1858   tmp=array2->getPointer();
1859   std::copy(arr2,arr2+15,tmp);
1860   f2->setEndArray(array2);
1861   array2->decrRef();
1862   f2->checkConsistencyLight();
1863   //
1864   std::fill(res,res+3,0.);
1865   f2->getValueOn(pos,3.21,res);
1866   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
1867   CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
1868   CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
1869   MEDCouplingFieldDouble *f3=f2->clone(true);
1870   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
1871   f3->getEndArray()->getPointer()[0]=5.001;
1872   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
1873   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1874   f3->setStartTime(2.1,3,0);
1875   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1876   f3->setStartTime(2.,3,0);
1877   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1878   f3->setStartTime(2.,4,0);
1879   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1880   f3->setStartTime(2.,3,1);
1881   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1882   f3->setStartTime(2.,3,0);
1883   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1884   f3->setEndTime(4.1,13,0);
1885   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1886   f3->setEndTime(4.,13,0);
1887   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1888   f3->setEndTime(4.,14,0);
1889   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1890   f3->setEndTime(4.,13,1);
1891   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
1892   f3->setEndTime(4.,13,0);
1893   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
1894   f3->decrRef();
1895   MEDCouplingFieldDouble *f4=(*f2)+(*f2);
1896   std::fill(res,res+3,0.);
1897   f4->getValueOn(pos,3.21,res);
1898   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
1899   CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
1900   CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
1901   (*f4)+=*f2;
1902   std::fill(res,res+3,0.);
1903   f4->getValueOn(pos,3.21,res);
1904   CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
1905   CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
1906   CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
1907   f4->decrRef();
1908   //
1909   f2->decrRef();
1910   f1->decrRef();
1911   m->decrRef();
1912 }
1913
1914 bool func4(const double *pt, double *res)
1915 {
1916   res[0]=pt[0]+pt[1]+pt[2];
1917   return true;
1918 }
1919
1920 void MEDCouplingBasicsTest1::testMergeNodesOnField()
1921 {
1922   double *tmp;
1923   MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
1924   MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1925   f1->mergeNodes(1e-10);
1926   f1->decrRef();
1927   targetMesh->decrRef();
1928   //
1929   targetMesh=build3DTargetMeshMergeNode_1();
1930   f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1931   tmp=f1->getArray()->getPointer();
1932   tmp[0]=1000.;
1933   f1->mergeNodes(1e-10);
1934   f1->decrRef();
1935   targetMesh->decrRef();
1936   //
1937   targetMesh=build3DTargetMeshMergeNode_1();
1938   f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
1939   tmp=f1->getArray()->getPointer();
1940   tmp[1]=1000.;
1941   CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
1942   f1->decrRef();
1943   targetMesh->decrRef();
1944 }
1945
1946 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
1947 {
1948   MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
1949   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
1950   CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
1951   const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
1952   const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
1953   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
1954   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1955   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1956   DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
1957   CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1958   CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1959   const int expected1[5]={2,0,1,3,4};
1960   CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
1961   da->decrRef();
1962   da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
1963   CPPUNIT_ASSERT_EQUAL(5,(int)da->getNumberOfTuples());
1964   CPPUNIT_ASSERT_EQUAL(1,(int)da->getNumberOfComponents());
1965   const int expected2[5]={0,3,4,1,2};
1966   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
1967   da->decrRef();
1968   const int renumber1[5]={4,0,1,2,3};
1969   targetMesh->renumberCells(renumber1,false);
1970   CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
1971   CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
1972   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
1973   targetMesh->decrRef();
1974   sourceMesh->decrRef();
1975 }
1976
1977 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
1978 {
1979   MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
1980   MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
1981   DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
1982   MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
1983   CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
1984   const int expected1[2]={0,1};
1985   CPPUNIT_ASSERT_EQUAL(2,(int)arr1->getNumberOfTuples());
1986   CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1987   CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
1988   arr1->decrRef();
1989   const int expected2[5]={0,3,4,1,2};
1990   arr1=m2_1->rearrange2ConsecutiveCellTypes();
1991   CPPUNIT_ASSERT_EQUAL(5,(int)arr1->getNumberOfTuples());
1992   CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1993   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1994   MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
1995   CPPUNIT_ASSERT_EQUAL(5,(int)arr1->getNumberOfTuples());
1996   CPPUNIT_ASSERT_EQUAL(1,(int)arr1->getNumberOfComponents());
1997   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
1998   CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
1999   m2_2->renumberCells(expected2,false);
2000   CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
2001   arr1->decrRef();
2002   m1_1->decrRef();
2003   m1_2->decrRef();
2004   m2_1->decrRef();
2005   m2_2->decrRef();
2006 }
2007
2008 void MEDCouplingBasicsTest1::testSplitByType()
2009 {
2010   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2011   std::vector<MEDCouplingUMesh *> v=m1->splitByType();
2012   CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
2013   std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
2014   MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
2015   m2->setName(m1->getName().c_str());
2016   CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
2017   for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
2018     (*iter)->decrRef();
2019   m2->decrRef();
2020   m1->decrRef();
2021 }
2022
2023 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
2024 {
2025   std::vector<const MEDCouplingUMesh *> meshes;
2026   MEDCouplingUMesh *m2=build2DTargetMesh_1();
2027   int cells1[3]={2,3,4};
2028   MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
2029   MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
2030   CPPUNIT_ASSERT(m3);
2031   meshes.push_back(m3);
2032   int cells2[3]={1,2,4};
2033   MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
2034   MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
2035   CPPUNIT_ASSERT(m4);
2036   meshes.push_back(m4);
2037   int cells3[2]={1,2};
2038   MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
2039   MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
2040   CPPUNIT_ASSERT(m5);
2041   meshes.push_back(m5);
2042   m2->decrRef();
2043   //
2044   std::vector<DataArrayInt *> corr;
2045   MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2046   CPPUNIT_ASSERT_EQUAL(4,(int)m7->getNumberOfCells());
2047   CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
2048   const int expectedVals1[3]={3,3,2};
2049   const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
2050   for(int i=0;i<3;i++)
2051     {
2052       DataArrayInt *arr=corr[i];
2053       CPPUNIT_ASSERT_EQUAL(1,(int)arr->getNumberOfComponents());
2054       int nbOfVals=expectedVals1[i];
2055       CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)arr->getNumberOfTuples());
2056       const int *vals=arr->getConstPointer();
2057       for(int j=0;j<nbOfVals;j++)
2058         CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
2059     }
2060   std::vector< std::vector<int> > fidsOfGroups;
2061   std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2062   DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
2063   const int fidExp[4]={5,1,3,4};
2064   const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
2065   CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
2066   CPPUNIT_ASSERT_EQUAL(1,(int)arr2->getNumberOfComponents());
2067   CPPUNIT_ASSERT_EQUAL(4,(int)arr2->getNumberOfTuples());
2068   CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
2069   for(int i=0;i<3;i++)
2070     {
2071       int nbOfVals=expectedVals1[i];
2072       CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
2073       CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
2074     }
2075   for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
2076     (*iter)->decrRef();
2077   arr2->decrRef();
2078   m7->decrRef();
2079   //
2080   m3->decrRef();
2081   m4->decrRef();
2082   m5->decrRef();
2083 }
2084
2085 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
2086 {
2087   MEDCouplingUMesh *m2;
2088   MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
2089   m2->decrRef();
2090   const int part1[5]={2,3,6,4,10};
2091   MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
2092   const int part2[4]={5,6,4,7};
2093   MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
2094   std::vector<const MEDCouplingUMesh *> meshes;
2095   meshes.push_back(m1);
2096   meshes.push_back(m3);
2097   meshes.push_back(m3);
2098   meshes.push_back(m4);
2099   std::vector<DataArrayInt *> corr;
2100   MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2101   CPPUNIT_ASSERT_EQUAL(18,(int)m5->getNumberOfCells());
2102   std::vector<DataArrayInt *>::iterator it=corr.begin();
2103   const int exp1[4]={18,5,5,4};
2104   const int exp2[4][18]={
2105     {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
2106     {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2107     {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
2108     {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
2109   };
2110   int i=0;
2111   for(;it!=corr.end();it++,i++)
2112     {
2113       int sz=(*it)->getNumberOfTuples();
2114       CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
2115       CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
2116     }
2117   for(it=corr.begin();it!=corr.end();it++)
2118     (*it)->decrRef();
2119   m5->decrRef();
2120   m4->decrRef();
2121   m3->decrRef();
2122   m1->decrRef();
2123 }
2124
2125 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
2126 {
2127   MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
2128   MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
2129   double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
2130   CPPUNIT_ASSERT_EQUAL(5,(int)field->getNumberOfTuples());
2131   CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2132   const double *vals=field->getArray()->getConstPointer();
2133   for(int i=0;i<15;i++)
2134     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
2135   field->decrRef();
2136   targetMesh->decrRef();
2137   // testing 
2138   double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
2139   int targetConn[4]={0,1,2,3};
2140   targetMesh=MEDCouplingUMesh::New();
2141   targetMesh->setMeshDimension(2);
2142   targetMesh->allocateCells(1);
2143   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
2144   targetMesh->finishInsertingCells();
2145   DataArrayDouble *myCoords=DataArrayDouble::New();
2146   myCoords->alloc(4,3);
2147   std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
2148   targetMesh->setCoords(myCoords);
2149   myCoords->decrRef();
2150   field=targetMesh->buildOrthogonalField();
2151   CPPUNIT_ASSERT_EQUAL(1,(int)field->getNumberOfTuples());
2152   CPPUNIT_ASSERT_EQUAL(3,(int)field->getNumberOfComponents());
2153   vals=field->getArray()->getConstPointer();
2154   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
2155   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
2156   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
2157   field->decrRef();
2158   targetMesh->decrRef();
2159 }
2160
2161 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
2162 {
2163   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2164   double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
2165   MCAuto<DataArrayInt> t1,t2;
2166   //2D basic
2167   targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2168   CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2169   CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2170   const int expectedValues1[6]={0,4,3,0,1,2};
2171   const int expectedValues2[7]={0,1,2,3,4,5,6};
2172   CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2173   CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2174   //2D with no help of bounding box.
2175   double center[2]={0.2,0.2};
2176   DataArrayDouble::Rotate2DAlg(center,0.78539816339744830962,6,pos,pos);
2177   targetMesh->rotate(center,0,0.78539816339744830962);
2178   targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
2179   CPPUNIT_ASSERT_EQUAL(6,(int)t1->getNbOfElems());
2180   CPPUNIT_ASSERT_EQUAL(7,(int)t2->getNbOfElems());
2181   CPPUNIT_ASSERT(std::equal(t1->begin(),t1->end(),expectedValues1));
2182   CPPUNIT_ASSERT(std::equal(t2->begin(),t2->end(),expectedValues2));
2183   //2D outside
2184   const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
2185   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
2186   targetMesh->decrRef();
2187   //test limits 2D
2188   targetMesh=build2DTargetMesh_1();
2189   const double pos2[2]={0.2,-0.05};
2190   std::vector<int> t11;
2191   t11.clear();
2192   targetMesh->getCellsContainingPoint(pos2,1e-12,t11);
2193   CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2194   const int expectedValues3[2]={0,1};
2195   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues3));
2196   const double pos3[2]={0.2,0.2};
2197   t11.clear();
2198   targetMesh->getCellsContainingPoint(pos3,1e-12,t11);
2199   CPPUNIT_ASSERT_EQUAL(5,(int)t11.size());
2200   const int expectedValues4[5]={0,1,2,3,4};
2201   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues4));
2202   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
2203   targetMesh->decrRef();
2204   //3D
2205   targetMesh=build3DTargetMesh_1();
2206   const double pos4[3]={25.,25.,25.};
2207   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
2208   const double pos5[3]={50.,50.,50.};
2209   t11.clear();
2210   targetMesh->getCellsContainingPoint(pos5,1e-12,t11);
2211   CPPUNIT_ASSERT_EQUAL(8,(int)t11.size());
2212   const int expectedValues5[8]={0,1,2,3,4,5,6,7};
2213   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues5));
2214   const double pos6[3]={0., 50., 0.};
2215   t11.clear();
2216   targetMesh->getCellsContainingPoint(pos6,1e-12,t11);
2217   CPPUNIT_ASSERT_EQUAL(2,(int)t11.size());
2218   const int expectedValues6[2]={0,2};
2219   CPPUNIT_ASSERT(std::equal(t11.begin(),t11.end(),expectedValues6));
2220   //3D outside
2221   const double pos7[3]={-1.0,-1.0,0.};
2222   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
2223   //3D outside 2
2224   const double center2[3]={0.,0.,0.};
2225   const double vec2[3]={0.,-1.,0.};
2226   targetMesh->rotate(center2,vec2,0.78539816339744830962);
2227   const double pos8[3]={-25,25.,12.};
2228   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
2229   //
2230   targetMesh->decrRef();
2231 }
2232
2233 void MEDCouplingBasicsTest1::testGetValueOn1()
2234 {
2235   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
2236   MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
2237   int nbOfCells=targetMesh->getNumberOfCells();
2238   fieldOnCells->setMesh(targetMesh);
2239   DataArrayDouble *array=DataArrayDouble::New();
2240   array->alloc(nbOfCells,2);
2241   fieldOnCells->setArray(array);
2242   double *tmp=array->getPointer();
2243   for(int i=0;i<nbOfCells;i++)
2244     { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
2245   array->decrRef();
2246   //
2247   const double pos1[2]={0.25,0.};
2248   double res[2];
2249   fieldOnCells->getValueOn(pos1,res);
2250   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
2251   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
2252   //
2253   fieldOnCells->decrRef();
2254   targetMesh->decrRef();
2255   //
2256   targetMesh=build2DSourceMesh_1();
2257   MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
2258   int nbOfNodes=targetMesh->getNumberOfNodes();
2259   fieldOnNodes->setMesh(targetMesh);
2260   array=DataArrayDouble::New();
2261   array->alloc(nbOfNodes,2);
2262   fieldOnNodes->setArray(array);
2263   tmp=array->getPointer();
2264   for(int i=0;i<nbOfNodes;i++)
2265     { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
2266   array->decrRef();
2267   //
2268   const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
2269   fieldOnNodes->getValueOn(pos2,res);
2270   CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
2271   CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
2272   const double pos3[2]={0.033333333333333326,0.36666666666666664};
2273   fieldOnNodes->getValueOn(pos3,res);
2274   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
2275   CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
2276   //
2277   fieldOnNodes->decrRef();
2278   targetMesh->decrRef();
2279 }
2280
2281 void MEDCouplingBasicsTest1::testCMesh0()
2282 {
2283   MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
2284   MEDCouplingCMesh* meshEmpty=mesh->clone(true);
2285   CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
2286   
2287   DataArrayDouble* coordsX=DataArrayDouble::New();
2288   double arrX[4] = { -1., 1., 2., 4. };
2289   coordsX->useArray(arrX,false, DeallocType::CPP_DEALLOC,4,1);
2290   DataArrayDouble* coordsY=DataArrayDouble::New();
2291   double arrY[4] = { -2., 2., 4., 8. };
2292   coordsY->useArray(arrY,false, DeallocType::CPP_DEALLOC,4,1);
2293   DataArrayDouble* coordsZ=DataArrayDouble::New();
2294   double arrZ[4] = { -3., 3., 6., 12. };
2295   coordsZ->useArray(arrZ,false, DeallocType::CPP_DEALLOC,4,1);
2296   mesh->setCoords(coordsX,coordsY,coordsZ);
2297   coordsX->decrRef();
2298   coordsY->decrRef();
2299   coordsZ->decrRef();
2300   //
2301   MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
2302   CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnNodes->getNumberOfComponents());
2303   CPPUNIT_ASSERT_EQUAL(64,(int)fieldOnNodes->getNumberOfTuples());
2304   const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
2305                               4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
2306                               7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
2307                               7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
2308   const double *val=fieldOnNodes->getArray()->getConstPointer();
2309   for(int i=0;i<64;i++)
2310     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2311   double res[1];  //size fieldOnNodes->getNumberOfComponents()
2312   fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
2313   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
2314   fieldOnNodes->decrRef();
2315   //
2316   MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
2317   CPPUNIT_ASSERT_EQUAL(1,(int)fieldOnCells->getNumberOfComponents());
2318   CPPUNIT_ASSERT_EQUAL(27,(int)fieldOnCells->getNumberOfTuples());
2319   val=fieldOnCells->getArray()->getConstPointer();
2320   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,
2321                               6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
2322   for(int i=0;i<27;i++)
2323     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
2324   fieldOnCells->getValueOnPos(1,2,1,&res[0]);
2325   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
2326   fieldOnCells->decrRef();
2327   //
2328   MEDCouplingMesh* meshDeepCopy=mesh->deepCopy();
2329   MEDCouplingCMesh* meshClone=mesh->clone(false);
2330   
2331   CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
2332   meshEmpty->copyTinyStringsFrom(mesh);
2333   //no data in meshEmpty, expected false
2334   CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
2335   
2336   CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2337   meshDeepCopy->copyTinyStringsFrom(mesh);
2338   CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
2339   CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
2340   
2341   CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
2342   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
2343   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
2344   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
2345   
2346   mesh->decrRef();
2347   meshEmpty->decrRef();
2348   meshDeepCopy->decrRef();
2349   meshClone->decrRef();
2350 }
2351
2352 void MEDCouplingBasicsTest1::testCMesh1()
2353 {
2354   MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
2355   mesh1=MEDCouplingCMesh::New();
2356   DataArrayDouble* coordsX1=DataArrayDouble::New();
2357   double arrX1[4] = { -1., 1., 2., 4. };
2358   coordsX1->useArray(arrX1,false, DeallocType::CPP_DEALLOC,4,1);
2359   DataArrayDouble* coordsY1=DataArrayDouble::New();
2360   double arrY1[4] = { -2., 2., 4., 8. };
2361   coordsY1->useArray(arrY1,false, DeallocType::CPP_DEALLOC,4,1);
2362   DataArrayDouble* coordsZ1=DataArrayDouble::New();
2363   double arrZ1[4] = { -3., 3., 6., 12. };
2364   coordsZ1->useArray(arrZ1,false, DeallocType::CPP_DEALLOC,4,1);
2365   mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2366   
2367   mesh2=MEDCouplingCMesh::New();
2368   DataArrayDouble* coordsX2=DataArrayDouble::New();
2369   double arrX2[4] = { -1., 1., 2., 4. };
2370   coordsX2->useArray(arrX2,false, DeallocType::CPP_DEALLOC,4,1);
2371   DataArrayDouble* coordsY2=DataArrayDouble::New();
2372   double arrY2[4] = { -2., 2., 4., 8. };
2373   coordsY2->useArray(arrY2,false, DeallocType::CPP_DEALLOC,4,1);
2374   DataArrayDouble* coordsZ2=DataArrayDouble::New();
2375   double arrZ2[4] = { -3., 3., 6., 12.+1e-6 };   //here is not equal
2376   coordsZ2->useArray(arrZ2,false, DeallocType::CPP_DEALLOC,4,1);
2377   mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
2378   
2379   mesh3=MEDCouplingCMesh::New();
2380   DataArrayDouble* coordsX3=DataArrayDouble::New();
2381   double arrX3[1] = { -1.};
2382   coordsX3->useArray(arrX3,false, DeallocType::CPP_DEALLOC,1,1);
2383   DataArrayDouble* coordsY3=DataArrayDouble::New();
2384   double arrY3[1] = { -2.};
2385   coordsY3->useArray(arrY3,false, DeallocType::CPP_DEALLOC,1,1);
2386   DataArrayDouble* coordsZ3=DataArrayDouble::New();
2387   double arrZ3[1] = { -3.};
2388   coordsZ3->useArray(arrZ3,false, DeallocType::CPP_DEALLOC,1,1);
2389   mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
2390   
2391   CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
2392   CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
2393   
2394   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
2395   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
2396   CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
2397   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
2398   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
2399   
2400   CPPUNIT_ASSERT_THROW(mesh3->checkConsistency(1e-12),INTERP_KERNEL::Exception);
2401   mesh1->checkConsistency(1e-12);
2402   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
2403   
2404   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
2405   CPPUNIT_ASSERT_EQUAL(27,(int)mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2406   CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
2407   
2408   std::vector<double> coo;
2409   mesh1->getCoordinatesOfNode(0, coo);
2410   CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2411   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
2412   CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
2413   CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
2414   coo.clear();
2415   mesh1->getCoordinatesOfNode(63, coo);
2416   CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
2417   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
2418   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
2419   CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
2420   
2421   std::string repr;
2422   repr=mesh1->simpleRepr();
2423   repr=mesh1->advancedRepr();
2424   CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
2425   CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
2426   CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
2427   CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
2428   coordsX1->decrRef();
2429   coordsY1->decrRef();
2430   coordsZ1->decrRef();
2431   coordsX2->decrRef();
2432   coordsY2->decrRef();
2433   coordsZ2->decrRef();
2434   coordsX3->decrRef();
2435   coordsY3->decrRef();
2436   coordsZ3->decrRef();
2437   mesh1->decrRef();
2438   mesh2->decrRef();
2439   mesh3->decrRef();
2440 }
2441   
2442 void MEDCouplingBasicsTest1::testCMesh2()
2443 {
2444   MEDCouplingCMesh *mesh1;
2445   mesh1=MEDCouplingCMesh::New();
2446   DataArrayDouble* coordsX1=DataArrayDouble::New();
2447   double arrX1[4] = { -1., 1., 2., 4. };
2448   coordsX1->useArray(arrX1,false, DeallocType::CPP_DEALLOC,4,1);
2449   DataArrayDouble* coordsY1=DataArrayDouble::New();
2450   double arrY1[4] = { -2., 2., 4., 8. };
2451   coordsY1->useArray(arrY1,false, DeallocType::CPP_DEALLOC,4,1);
2452   DataArrayDouble* coordsZ1=DataArrayDouble::New();
2453   double arrZ1[4] = { -3., 3., 6., 12. };
2454   coordsZ1->useArray(arrZ1,false, DeallocType::CPP_DEALLOC,4,1);
2455   mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
2456   
2457   std::vector<int> dis=mesh1->getDistributionOfTypes();
2458   CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
2459   CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
2460   CPPUNIT_ASSERT_EQUAL(27,dis[1]);
2461   CPPUNIT_ASSERT_EQUAL(-1,dis[2]);
2462   
2463   std::vector<const DataArrayInt *> idsPerType;
2464   CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
2465   dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
2466   CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
2467   
2468   dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
2469   dis[2]=0;
2470   DataArrayInt *ids=DataArrayInt::New();
2471   ids->alloc(10,1);
2472   ids->fillWithValue(23);
2473   idsPerType.push_back(ids);
2474   DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
2475   CPPUNIT_ASSERT(check);
2476   CPPUNIT_ASSERT(check->isEqual(*ids));
2477   
2478   std::vector<int> code;
2479   std::vector<DataArrayInt *> idsInPflPerType;
2480   std::vector<DataArrayInt *> pfls;
2481   mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
2482   CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
2483   CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
2484   CPPUNIT_ASSERT_EQUAL(10,code[1]);
2485   CPPUNIT_ASSERT_EQUAL(0,code[2]);
2486   CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
2487   CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
2488   DataArrayInt *exp=DataArrayInt::New(); exp->alloc(10,1); exp->iota(0);
2489   CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*exp));
2490   exp->decrRef();
2491   CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
2492   idsInPflPerType[0]->decrRef();
2493   pfls[0]->decrRef();
2494
2495   ids->decrRef();
2496   check->decrRef();
2497   int cells1[4]={0,1,25,26};
2498   MEDCouplingUMesh *partMesh1=
2499     dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
2500   CPPUNIT_ASSERT(partMesh1);
2501   CPPUNIT_ASSERT_EQUAL(4,(int)partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2502   CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
2503   CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
2504   
2505   int cells2[2]={25,26};
2506   DataArrayInt* arr1;
2507   MEDCouplingCMesh *partMesh2=
2508     dynamic_cast<MEDCouplingCMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
2509   CPPUNIT_ASSERT(partMesh2);
2510   CPPUNIT_ASSERT_EQUAL(2,(int)partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2511   CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
2512   
2513   int cells3[2]={2,3};
2514   DataArrayInt* arr2;
2515   MEDCouplingUMesh *partMesh3=
2516     dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
2517   CPPUNIT_ASSERT(partMesh3);
2518   CPPUNIT_ASSERT_EQUAL(2,(int)partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
2519   CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
2520   
2521   CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
2522   CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
2523
2524   double bbox1[6];
2525   double bbox2[6];
2526   mesh1->getBoundingBox(bbox1);
2527   partMesh1->getBoundingBox(bbox2);
2528   for(int i=0;i<6;i++)
2529     CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2530   partMesh3->getBoundingBox(bbox1);
2531   partMesh2->getBoundingBox(bbox2);
2532   for(int i=0;i<6;i++)
2533     CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
2534   
2535   CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
2536   MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
2537   mesh2d->setCoords(coordsX1,coordsY1);
2538   MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
2539   
2540   std::vector<double> tinyInfoD;
2541   std::vector<int> tinyInfo;
2542   std::vector<std::string> littleStrings;
2543   mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
2544   CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
2545   CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]);   //x
2546   CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]);   //y
2547   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]);  //z
2548   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]);  //it
2549   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]);   //order
2550   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
2551   DataArrayInt* d1=DataArrayInt::New();
2552   DataArrayDouble* d2=DataArrayDouble::New();
2553   mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
2554   CPPUNIT_ASSERT_EQUAL(0,(int)d1->getNumberOfTuples());
2555   CPPUNIT_ASSERT_EQUAL(8,(int)d2->getNumberOfTuples());
2556  
2557   partMesh1->decrRef();
2558   partMesh2->decrRef();
2559   partMesh3->decrRef();
2560   mesh2d->decrRef();
2561   arr1->decrRef();
2562   arr2->decrRef();
2563   f1->decrRef();
2564   d1->decrRef();
2565   d2->decrRef();
2566   coordsX1->decrRef();
2567   coordsY1->decrRef();
2568   coordsZ1->decrRef();
2569   mesh1->decrRef();
2570 }
2571
2572 void MEDCouplingBasicsTest1::testScale()
2573 {
2574   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
2575   const double pos[2]={0.2,0.2};
2576   mesh->scale(pos,0.5);
2577   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,
2578                               -0.05,0.45, 0.2,0.45, 0.45,0.45};
2579   const double *val=mesh->getCoords()->getConstPointer();
2580   for(int i=0;i<18;i++)
2581     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
2582   //
2583   mesh->decrRef();
2584 }
2585
2586 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
2587 {
2588   MEDCouplingUMesh *m1=build2DTargetMesh_1();
2589   MEDCouplingUMesh *m2=build2DTargetMesh_1();
2590   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2591   m1->tryToShareSameCoords(*m2,1e-12);
2592   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2593   m1->tryToShareSameCoords(*m2,1e-12);
2594   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2595   m2->tryToShareSameCoords(*m1,1e-12);
2596   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2597   m1->decrRef();
2598   m2->decrRef();
2599   //
2600   m1=build2DTargetMesh_1();
2601   m2=build2DTargetMesh_2();
2602   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2603   m1->tryToShareSameCoords(*m2,1e-12);
2604   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2605   m1->tryToShareSameCoords(*m2,1e-12);
2606   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2607   m2->tryToShareSameCoords(*m1,1e-12);
2608   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
2609   m1->decrRef();
2610   m2->decrRef();
2611   //
2612   m1=build2DTargetMesh_1();
2613   m2=build2DSourceMesh_1();
2614   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
2615   CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
2616   m1->decrRef();
2617   m2->decrRef();
2618 }
2619
2620 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
2621 {
2622   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
2623   std::vector<int> n;
2624   double pt[3]={300.,300.,0.};
2625   double v[3]={0.,0.,2.};
2626   mesh->findNodesOnPlane(pt,v,1e-12,n);
2627   CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
2628   MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
2629   MEDCouplingMappedExtrudedMesh *me=MEDCouplingMappedExtrudedMesh::New(mesh,m3dSurf,0);
2630   const DataArrayInt *da=me->getMesh3DIds();
2631   CPPUNIT_ASSERT_EQUAL(8,(int)me->getNumberOfCells());
2632   const int expected[8]={0,1,2,3,4,5,6,7};
2633   const int *val=da->getConstPointer();
2634   for(int i=0;i<8;i++)
2635     CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
2636   me->decrRef();
2637   m3dSurf->decrRef();
2638   mesh->decrRef();
2639 }
2640
2641 void MEDCouplingBasicsTest1::testRenumberCells()
2642 {
2643   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
2644   MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
2645   CPPUNIT_ASSERT(m->isEqual(m2,0));
2646   const int arr[5]={12,3,25,2,26};
2647   m->renumberCells(arr,true);
2648   CPPUNIT_ASSERT(!m->isEqual(m2,0));
2649   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
2650   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
2651   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
2652   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
2653   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
2654   const int arr2[5]={5,-1,-5,4,8};
2655   m->renumberCells(arr2,true);
2656   CPPUNIT_ASSERT(m->isEqual(m2,0));
2657   m->decrRef();
2658   m2->decrRef();
2659 }
2660
2661 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
2662 {
2663   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
2664   MEDCouplingUMesh *m2=build2DTargetMesh_1();
2665   //
2666   CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2667   m1->changeSpaceDimension(2);
2668   CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
2669   m1->setName(m2->getName().c_str());
2670   CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
2671   m1->changeSpaceDimension(3);
2672   CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
2673   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.};
2674   const double *val=m1->getCoords()->getConstPointer();
2675   for(int i=0;i<27;i++)
2676     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
2677   //
2678   m1->decrRef();
2679   m2->decrRef();
2680 }
2681
2682 void MEDCouplingBasicsTest1::testSetConnectivity()
2683 {
2684   MEDCouplingUMesh *m1 = build1DTargetMesh_1();
2685
2686   DataArrayInt * conn = DataArrayInt::New();
2687   DataArrayInt * connI = DataArrayInt::New();
2688   m1->setConnectivity(conn, connI, true); // was SEG-Faulting with empty arrays
2689   conn->decrRef();
2690   connI->decrRef();
2691   m1->decrRef();
2692 }