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