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