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