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