Back to index

salome-med  6.5.0
MEDCouplingBasicsTest1.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDCouplingBasicsTest1.hxx"
00021 #include "MEDCouplingUMesh.hxx"
00022 #include "MEDCouplingCMesh.hxx"
00023 #include "MEDCouplingExtrudedMesh.hxx"
00024 #include "MEDCouplingFieldDouble.hxx"
00025 #include "MEDCouplingMemArray.hxx"
00026 
00027 #include <sstream>
00028 #include <cmath>
00029 #include <algorithm>
00030 #include <functional>
00031 
00032 using namespace ParaMEDMEM;
00033 
00034 void MEDCouplingBasicsTest1::testArray()
00035 {
00036   int tmp1[6]={7,6,5,4,3,2};
00037   const int tmp2[3]={8,9,10};
00038   {
00039     MemArray<int> mem;
00040     mem.useArray(tmp1,false,CPP_DEALLOC,6);
00041     CPPUNIT_ASSERT(tmp1==mem.getConstPointer());
00042     CPPUNIT_ASSERT_THROW(mem.getPointer(),INTERP_KERNEL::Exception);
00043     CPPUNIT_ASSERT_THROW(mem[2]=7,INTERP_KERNEL::Exception);
00044     CPPUNIT_ASSERT_THROW(mem.writeOnPlace(0,12,tmp2,3),INTERP_KERNEL::Exception);
00045     mem.writeOnPlace(4,12,tmp2,3);
00046   }
00047   {
00048     int *tmp3=new int[6];
00049     std::copy(tmp1,tmp1+6,tmp3);
00050     MemArray<int> mem2;
00051     mem2.useArray(tmp3,true,CPP_DEALLOC,6);
00052     CPPUNIT_ASSERT(tmp3==mem2.getConstPointer());
00053     CPPUNIT_ASSERT(tmp3==mem2.getPointer());
00054     CPPUNIT_ASSERT_EQUAL(5,mem2[2]);
00055     mem2[2]=7;
00056     CPPUNIT_ASSERT_EQUAL(7,mem2[2]);
00057     mem2.writeOnPlace(0,12,tmp2,3);
00058     CPPUNIT_ASSERT_EQUAL(9,mem2[2]);
00059     CPPUNIT_ASSERT_EQUAL(12,mem2[0]);
00060     mem2.writeOnPlace(4,12,tmp2,3);
00061   }
00062 }
00063 
00064 void MEDCouplingBasicsTest1::testArray2()
00065 {
00066   DataArrayDouble *arr=DataArrayDouble::New();
00067   arr->alloc(3,4);
00068   double *tmp=arr->getPointer();
00069   const double arrRef[12]={12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.};
00070   std::copy(arrRef,arrRef+12,tmp);
00071   arr->setInfoOnComponent(0,"ggg");
00072   arr->setInfoOnComponent(1,"hhhh");
00073   arr->setInfoOnComponent(2,"jj");
00074   arr->setInfoOnComponent(3,"kkkkkk");
00075   DataArrayInt *arr2=arr->convertToIntArr();
00076   DataArrayDouble *arr3=arr2->convertToDblArr();
00077   arr2->decrRef();
00078   CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14));
00079   arr3->decrRef();
00080   arr->decrRef();
00081 }
00082 
00083 void MEDCouplingBasicsTest1::testArray3()
00084 {
00085   DataArrayInt *arr1=DataArrayInt::New();
00086   arr1->alloc(7,2);
00087   int *tmp=arr1->getPointer();
00088   const int arr1Ref[14]={0,10,1,11,2,12,3,13,4,14,5,15,6,16};
00089   std::copy(arr1Ref,arr1Ref+14,tmp);
00090   CPPUNIT_ASSERT_EQUAL(7,arr1->getNumberOfTuples());
00091   CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfComponents());
00092   CPPUNIT_ASSERT(std::equal(arr1Ref,arr1Ref+14,arr1->getConstPointer()));
00093   DataArrayInt *arr2=arr1->substr(3);
00094   CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
00095   CPPUNIT_ASSERT_EQUAL(2,arr2->getNumberOfComponents());
00096   CPPUNIT_ASSERT(std::equal(arr1Ref+6,arr1Ref+14,arr2->getConstPointer()));
00097   arr2->decrRef();
00098   DataArrayInt *arr3=arr1->substr(2,5);
00099   CPPUNIT_ASSERT_EQUAL(3,arr3->getNumberOfTuples());
00100   CPPUNIT_ASSERT_EQUAL(2,arr3->getNumberOfComponents());
00101   CPPUNIT_ASSERT(std::equal(arr1Ref+4,arr1Ref+10,arr3->getConstPointer()));
00102   arr1->decrRef();
00103   arr3->decrRef();
00104   //
00105   DataArrayDouble *arr4=DataArrayDouble::New();
00106   arr4->alloc(7,2);
00107   double *tmp2=arr4->getPointer();
00108   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};
00109   std::copy(arr4Ref,arr4Ref+14,tmp2);
00110   CPPUNIT_ASSERT_EQUAL(7,arr4->getNumberOfTuples());
00111   CPPUNIT_ASSERT_EQUAL(2,arr4->getNumberOfComponents());
00112   CPPUNIT_ASSERT(std::equal(arr4Ref,arr4Ref+14,arr4->getConstPointer()));
00113   DataArrayDouble *arr5=arr4->substr(3);
00114   CPPUNIT_ASSERT_EQUAL(4,arr5->getNumberOfTuples());
00115   CPPUNIT_ASSERT_EQUAL(2,arr5->getNumberOfComponents());
00116   CPPUNIT_ASSERT(std::equal(arr4Ref+6,arr4Ref+14,arr5->getConstPointer()));
00117   arr5->decrRef();
00118   DataArrayDouble *arr6=arr4->substr(2,5);
00119   CPPUNIT_ASSERT_EQUAL(3,arr6->getNumberOfTuples());
00120   CPPUNIT_ASSERT_EQUAL(2,arr6->getNumberOfComponents());
00121   CPPUNIT_ASSERT(std::equal(arr4Ref+4,arr4Ref+10,arr6->getConstPointer()));
00122   arr4->decrRef();
00123   arr6->decrRef();
00124 }
00125 
00126 void MEDCouplingBasicsTest1::testMesh()
00127 {
00128   const int nbOfCells=6;
00129   const int nbOfNodes=12;
00130   
00131   double coords[3*nbOfNodes]={ 
00132     0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17, -0.305, 0.09662000000000001, -1.832979297858306e-18, 
00133     -0.305, 0.120775, 0.04183768725682623, -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001, 
00134     0.08367537451365246, -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863, 
00135     0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001, 0.08367537451365245, 
00136     -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863, };
00137   
00138   int tab4[4*nbOfCells]={ 
00139     1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, 0, 6, 11, 
00140     0, 1, 7, 6, };
00141   
00142   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
00143   mesh->setMeshDimension(2);
00144   mesh->allocateCells(8);
00145   const int *curConn=tab4;
00146   for(int i=0;i<nbOfCells;i++,curConn+=4)
00147     mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,curConn);
00148   mesh->finishInsertingCells();
00149   CPPUNIT_ASSERT_EQUAL(30,mesh->getNodalConnectivity()->getNbOfElems());
00150   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
00151   //test 0 - no copy no ownership
00152   DataArrayDouble *myCoords=DataArrayDouble::New();
00153   myCoords->useArray(coords,false,CPP_DEALLOC,nbOfNodes,3);
00154   mesh->setCoords(myCoords);
00155   mesh->setCoords(myCoords);
00156   myCoords->decrRef();
00157   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
00158   mesh->checkCoherency();
00159   //test 1 - no copy ownership C++
00160   myCoords=DataArrayDouble::New();
00161   double *tmp=new double[3*nbOfNodes];
00162   std::copy(coords,coords+3*nbOfNodes,tmp);
00163   myCoords->useArray(tmp,true,CPP_DEALLOC,nbOfNodes,3);
00164   mesh->setCoords(myCoords);
00165   myCoords->decrRef();
00166   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh->getNumberOfCells());
00167   mesh->checkCoherency();
00168   //test 2 - no copy ownership C
00169   myCoords=DataArrayDouble::New();
00170   tmp=(double *)malloc(3*nbOfNodes*sizeof(double));
00171   std::copy(coords,coords+3*nbOfNodes,tmp);
00172   myCoords->useArray(tmp,true,C_DEALLOC,nbOfNodes,3);
00173   mesh->setCoords(myCoords);
00174   myCoords->decrRef();
00175   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
00176   mesh->checkCoherency();
00177   //test 3 - copy.
00178   myCoords=DataArrayDouble::New();
00179   myCoords->alloc(nbOfNodes,3);
00180   tmp=myCoords->getPointer();
00181   std::copy(coords,coords+3*nbOfNodes,tmp);
00182   // test 3 bis deepcopy
00183   DataArrayDouble *myCoords2=DataArrayDouble::New();
00184   *myCoords2=*myCoords;
00185   myCoords2->decrRef();
00186   //
00187   mesh->setCoords(myCoords);
00188   myCoords->decrRef();
00189   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh->getNumberOfNodes());
00190   mesh->checkCoherency();
00191   CPPUNIT_ASSERT_EQUAL(3,mesh->getSpaceDimension());
00192   // test clone not recursively
00193   MEDCouplingUMesh *mesh2=mesh->clone(false);
00194   CPPUNIT_ASSERT(mesh2!=mesh);
00195   mesh2->checkCoherency();
00196   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh2->getNumberOfCells());
00197   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh2->getNumberOfNodes());
00198   CPPUNIT_ASSERT_EQUAL(3,mesh2->getSpaceDimension());
00199   CPPUNIT_ASSERT(mesh!=mesh2);
00200   CPPUNIT_ASSERT(mesh->getCoords()==mesh2->getCoords());
00201   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh2->getCoords()->getIJ(11,2),1e-14);
00202   CPPUNIT_ASSERT(mesh->getNodalConnectivity()==mesh2->getNodalConnectivity());
00203   CPPUNIT_ASSERT_EQUAL(3,mesh2->getNodalConnectivity()->getIJ(7,0));
00204   CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()==mesh2->getNodalConnectivityIndex());
00205   CPPUNIT_ASSERT_EQUAL(15,mesh2->getNodalConnectivityIndex()->getIJ(3,0));
00206   mesh2->decrRef();
00207   // test clone not recursively
00208   MEDCouplingUMesh *mesh3=mesh->clone(true);
00209   CPPUNIT_ASSERT(mesh3!=mesh);
00210   mesh3->checkCoherency();
00211   CPPUNIT_ASSERT_EQUAL(nbOfCells,mesh3->getNumberOfCells());
00212   CPPUNIT_ASSERT_EQUAL(nbOfNodes,mesh3->getNumberOfNodes());
00213   CPPUNIT_ASSERT_EQUAL(3,mesh3->getSpaceDimension());
00214   CPPUNIT_ASSERT(mesh!=mesh3);
00215   CPPUNIT_ASSERT(mesh->getCoords()!=mesh3->getCoords());
00216   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2863,mesh3->getCoords()->getIJ(11,2),1e-14);
00217   CPPUNIT_ASSERT(mesh->getNodalConnectivity()!=mesh3->getNodalConnectivity());
00218   CPPUNIT_ASSERT_EQUAL(3,mesh3->getNodalConnectivity()->getIJ(7,0));
00219   CPPUNIT_ASSERT(mesh->getNodalConnectivityIndex()!=mesh3->getNodalConnectivityIndex());
00220   CPPUNIT_ASSERT_EQUAL(15,mesh3->getNodalConnectivityIndex()->getIJ(3,0));
00221   mesh3->decrRef();
00222   //test 4 - Field on cells
00223   MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
00224   fieldOnCells->setMesh(mesh);
00225   DataArrayDouble *array=DataArrayDouble::New();
00226   array->alloc(nbOfCells,9);
00227   fieldOnCells->setArray(array);
00228   tmp=array->getPointer();
00229   array->decrRef();
00230   std::fill(tmp,tmp+9*nbOfCells,7.);
00231   //content of field changed -> declare it.
00232   fieldOnCells->declareAsNew();
00233   fieldOnCells->checkCoherency();
00234   // testing clone of fields - no recursive
00235   MEDCouplingFieldDouble *fieldOnCells2=fieldOnCells->clone(false);
00236   CPPUNIT_ASSERT(fieldOnCells2!=fieldOnCells);
00237   fieldOnCells2->checkCoherency();
00238   CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells2->getNumberOfTuples());
00239   CPPUNIT_ASSERT_EQUAL(9,fieldOnCells2->getNumberOfComponents());
00240   CPPUNIT_ASSERT(fieldOnCells2->getArray()==fieldOnCells->getArray());
00241   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells2->getArray()->getIJ(3,7),1e-14);
00242   CPPUNIT_ASSERT(fieldOnCells2->getMesh()==fieldOnCells->getMesh());
00243   // testing clone of fields - recursive
00244   MEDCouplingFieldDouble *fieldOnCells3=fieldOnCells->clone(true);
00245   CPPUNIT_ASSERT(fieldOnCells3!=fieldOnCells);
00246   fieldOnCells3->checkCoherency();
00247   CPPUNIT_ASSERT_EQUAL(nbOfCells,fieldOnCells3->getNumberOfTuples());
00248   CPPUNIT_ASSERT_EQUAL(9,fieldOnCells3->getNumberOfComponents());
00249   CPPUNIT_ASSERT(fieldOnCells3->getArray()!=fieldOnCells->getArray());
00250   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,fieldOnCells3->getArray()->getIJ(3,7),1e-14);
00251   CPPUNIT_ASSERT(fieldOnCells3->getMesh()==fieldOnCells->getMesh());
00252   fieldOnCells2->decrRef();
00253   fieldOnCells3->decrRef();
00254   //
00255   fieldOnCells->decrRef();
00256   //clean-up
00257   mesh->decrRef();
00258 }
00259 
00260 void MEDCouplingBasicsTest1::testMeshPointsCloud()
00261 {
00262   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};
00263   const int targetConn[]={0,1,2,3,4,5,7,6};
00264   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
00265   targetMesh->setMeshDimension(0);
00266   targetMesh->allocateCells(8);
00267   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn);
00268   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+1);
00269   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+2);
00270   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+3);
00271   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+4);
00272   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+5);
00273   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+6);
00274   targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn+7);
00275   targetMesh->finishInsertingCells();
00276   DataArrayDouble *myCoords=DataArrayDouble::New();
00277   myCoords->alloc(9,3);
00278   std::copy(targetCoords,targetCoords+27,myCoords->getPointer());
00279   targetMesh->setCoords(myCoords);
00280   myCoords->decrRef();
00281   //
00282   targetMesh->checkCoherency();
00283   CPPUNIT_ASSERT_EQUAL(3,targetMesh->getSpaceDimension());
00284   CPPUNIT_ASSERT_EQUAL(8,targetMesh->getNumberOfCells());
00285   CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
00286   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getMeshDimension());
00287   //
00288   targetMesh->decrRef();
00289 }
00290 
00291 void MEDCouplingBasicsTest1::testMeshM1D()
00292 {
00293   MEDCouplingUMesh *meshM1D=MEDCouplingUMesh::New();
00294   CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception);
00295   CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
00296   CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception);
00297   CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception);
00298   CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception);
00299   CPPUNIT_ASSERT_THROW(meshM1D->checkCoherency(),INTERP_KERNEL::Exception);
00300   meshM1D->setMeshDimension(-1);
00301   meshM1D->checkCoherency();
00302   CPPUNIT_ASSERT_EQUAL(-1,meshM1D->getMeshDimension());
00303   CPPUNIT_ASSERT_EQUAL(1,meshM1D->getNumberOfCells());
00304   CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception);
00305   CPPUNIT_ASSERT_THROW(meshM1D->getSpaceDimension(),INTERP_KERNEL::Exception);
00306   MEDCouplingUMesh *cpy=meshM1D->clone(true);
00307   CPPUNIT_ASSERT(cpy->isEqual(meshM1D,1e-12));
00308   cpy->decrRef();
00309   MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
00310   fieldOnCells->setMesh(meshM1D);
00311   DataArrayDouble *array=DataArrayDouble::New();
00312   array->alloc(1,6);
00313   fieldOnCells->setArray(array);
00314   double *tmp=array->getPointer();
00315   array->decrRef();
00316   std::fill(tmp,tmp+6,7.);
00317   fieldOnCells->checkCoherency();
00318   //
00319   fieldOnCells->decrRef();
00320   meshM1D->decrRef();
00321 }
00322 
00323 void MEDCouplingBasicsTest1::testDeepCopy()
00324 {
00325   DataArrayDouble *array=DataArrayDouble::New();
00326   array->alloc(5,3);
00327   std::fill(array->getPointer(),array->getPointer()+5*3,7.);
00328   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array->getIJ(3,2),1e-14);
00329   double *tmp1=array->getPointer();
00330   DataArrayDouble *array2=array->deepCpy();
00331   double *tmp2=array2->getPointer();
00332   CPPUNIT_ASSERT(tmp1!=tmp2);
00333   array->decrRef();
00334   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,array2->getIJ(3,2),1e-14);
00335   array2->decrRef();
00336   //
00337   DataArrayInt *array3=DataArrayInt::New();
00338   array3->alloc(5,3);
00339   std::fill(array3->getPointer(),array3->getPointer()+5*3,17);
00340   CPPUNIT_ASSERT_EQUAL(17,array3->getIJ(3,2));
00341   int *tmp3=array3->getPointer();
00342   DataArrayInt *array4=array3->deepCpy();
00343   int *tmp4=array4->getPointer();
00344   CPPUNIT_ASSERT(tmp3!=tmp4);
00345   array3->decrRef();
00346   CPPUNIT_ASSERT_EQUAL(17,array4->getIJ(3,2));
00347   array4->decrRef();
00348 }
00349 
00350 void MEDCouplingBasicsTest1::testRevNodal()
00351 {
00352   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
00353   DataArrayInt *revNodal=DataArrayInt::New();
00354   DataArrayInt *revNodalIndx=DataArrayInt::New();
00355   //
00356   mesh->getReverseNodalConnectivity(revNodal,revNodalIndx);
00357   const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4};
00358   const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18};
00359   CPPUNIT_ASSERT_EQUAL(18,revNodal->getNbOfElems());
00360   CPPUNIT_ASSERT_EQUAL(10,revNodalIndx->getNbOfElems());
00361   CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer()));
00362   CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer()));
00363   //
00364   revNodal->decrRef();
00365   revNodalIndx->decrRef();
00366   mesh->decrRef();
00367 }
00368 
00369 void MEDCouplingBasicsTest1::testConvertToPolyTypes()
00370 {
00372   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
00373   //
00374   const int elts[2]={1,3};
00375   std::vector<int> eltsV(elts,elts+2);
00376   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
00377   mesh->checkCoherency();
00378   CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
00379   CPPUNIT_ASSERT_EQUAL(23,mesh->getNodalConnectivity()->getNumberOfTuples());
00380   const int *pt=mesh->getNodalConnectivity()->getConstPointer();
00381   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};
00382   CPPUNIT_ASSERT(std::equal(expected1,expected1+23,pt));
00383   //
00384   mesh->decrRef();
00386   mesh=build3DTargetMesh_1();
00387   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
00388   mesh->checkCoherency();
00389   CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
00390   CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
00391   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
00392   mesh->checkCoherency();
00393   CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells());
00394   CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples());
00395   //
00396   mesh->decrRef();
00397 }
00398 
00399 void MEDCouplingBasicsTest1::testDescConn2D()
00400 {
00401   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
00402   DataArrayInt *desc=DataArrayInt::New();
00403   DataArrayInt *descIndx=DataArrayInt::New();
00404   DataArrayInt *revDesc=DataArrayInt::New();
00405   DataArrayInt *revDescIndx=DataArrayInt::New();
00406   //
00407   MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00408   mesh2->checkCoherency();
00409   CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
00410   CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
00411   CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
00412   CPPUNIT_ASSERT_EQUAL(6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
00413   CPPUNIT_ASSERT_EQUAL(18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
00414   CPPUNIT_ASSERT_EQUAL(18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
00415   const int expected1[18]={0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9};
00416   CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
00417   const int expected2[6]={0,4,7,10,14,18};
00418   CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
00419   const int expected3[14]={0,1,3,5,6,8,9,11,12,13,15,16,17,18};
00420   CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
00421   const int expected4[18]={0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4};
00422   CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
00423   DataArrayInt *conn=mesh2->getNodalConnectivity();
00424   DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
00425   const int expected5[14]={0,3,6,9,12,15,18,21,24,27,30,33,36,39};
00426   CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
00427   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};
00428   CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
00429   //
00430   desc->decrRef();
00431   descIndx->decrRef();
00432   revDesc->decrRef();
00433   revDescIndx->decrRef();
00434   mesh2->decrRef();
00435   //
00436   const int elts[2]={1,3};
00437   std::vector<int> eltsV(elts,elts+2);
00438   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
00439   mesh->checkCoherency();
00440   //
00441   desc=DataArrayInt::New();
00442   descIndx=DataArrayInt::New();
00443   revDesc=DataArrayInt::New();
00444   revDescIndx=DataArrayInt::New();
00445   //
00446   mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00447   mesh2->checkCoherency();
00448   CPPUNIT_ASSERT_EQUAL(1,mesh2->getMeshDimension());
00449   CPPUNIT_ASSERT_EQUAL(13,mesh2->getNumberOfCells());
00450   CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(14,revDescIndx->getNumberOfTuples());
00451   CPPUNIT_ASSERT_EQUAL(6,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(6,descIndx->getNumberOfTuples());
00452   CPPUNIT_ASSERT_EQUAL(18,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,desc->getNumberOfTuples());
00453   CPPUNIT_ASSERT_EQUAL(18,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(18,revDesc->getNumberOfTuples());
00454   CPPUNIT_ASSERT(std::equal(expected1,expected1+18,desc->getConstPointer()));
00455   CPPUNIT_ASSERT(std::equal(expected2,expected2+6,descIndx->getConstPointer()));
00456   CPPUNIT_ASSERT(std::equal(expected3,expected3+14,revDescIndx->getConstPointer()));
00457   CPPUNIT_ASSERT(std::equal(expected4,expected4+18,revDesc->getConstPointer()));
00458   conn=mesh2->getNodalConnectivity();
00459   connIndex=mesh2->getNodalConnectivityIndex();
00460   CPPUNIT_ASSERT(std::equal(expected5,expected5+14,connIndex->getConstPointer()));
00461   CPPUNIT_ASSERT(std::equal(expected6,expected6+39,conn->getConstPointer()));
00462   //
00463   desc->decrRef();
00464   descIndx->decrRef();
00465   revDesc->decrRef();
00466   revDescIndx->decrRef();
00467   mesh2->decrRef();
00468   mesh->decrRef();
00469 }
00470 
00471 void MEDCouplingBasicsTest1::testDescConn3D()
00472 {
00473   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
00474   DataArrayInt *desc=DataArrayInt::New();
00475   DataArrayInt *descIndx=DataArrayInt::New();
00476   DataArrayInt *revDesc=DataArrayInt::New();
00477   DataArrayInt *revDescIndx=DataArrayInt::New();
00478   //
00479   MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00480   mesh2->checkCoherency();
00481   CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
00482   CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
00483   CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
00484   CPPUNIT_ASSERT_EQUAL(9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
00485   CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
00486   CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
00487   const int expected1[9]={0, 6, 12, 18, 24, 30, 36, 42, 48};
00488   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};
00489   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};
00490   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};
00491   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};
00492   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,
00493                             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,
00494                             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,
00495                             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};
00496   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,
00497                             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,
00498                             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,
00499                             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};
00500 
00501   CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
00502   CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
00503   CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
00504   CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
00505   CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
00506   CPPUNIT_ASSERT(std::equal(expected6,expected6+180,mesh2->getNodalConnectivity()->getConstPointer()));
00507   //
00508   desc->decrRef();
00509   descIndx->decrRef();
00510   revDesc->decrRef();
00511   revDescIndx->decrRef();
00512   mesh2->decrRef();
00513   //
00514   const int elts[2]={1,3};
00515   std::vector<int> eltsV(elts,elts+2);
00516   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
00517   mesh->checkCoherency();
00518   desc=DataArrayInt::New();
00519   descIndx=DataArrayInt::New();
00520   revDesc=DataArrayInt::New();
00521   revDescIndx=DataArrayInt::New();
00522   mesh2=mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00523   mesh2->checkCoherency();
00524   CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
00525   CPPUNIT_ASSERT_EQUAL(36,mesh2->getNumberOfCells());
00526   CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(37,revDescIndx->getNumberOfTuples());
00527   CPPUNIT_ASSERT_EQUAL(9,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(9,descIndx->getNumberOfTuples());
00528   CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
00529   CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
00530   CPPUNIT_ASSERT(std::equal(expected1,expected1+9,descIndx->getConstPointer()));
00531   CPPUNIT_ASSERT(std::equal(expected2,expected2+48,desc->getConstPointer()));
00532   CPPUNIT_ASSERT(std::equal(expected3,expected3+37,revDescIndx->getConstPointer()));
00533   CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
00534   CPPUNIT_ASSERT(std::equal(expected5,expected5+37,mesh2->getNodalConnectivityIndex()->getConstPointer()));
00535   CPPUNIT_ASSERT(std::equal(expected7,expected7+180,mesh2->getNodalConnectivity()->getConstPointer()));
00536   //
00537   desc->decrRef();
00538   descIndx->decrRef();
00539   revDesc->decrRef();
00540   revDescIndx->decrRef();
00541   mesh2->decrRef();
00542   mesh->decrRef();
00543 }
00544 
00545 void MEDCouplingBasicsTest1::testFindBoundaryNodes()
00546 {
00547   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
00548   std::vector<int> boundaryNodes;
00549   mesh->findBoundaryNodes(boundaryNodes);
00550   CPPUNIT_ASSERT_EQUAL(26,(int)boundaryNodes.size());
00551   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};
00552   CPPUNIT_ASSERT(std::equal(expected1,expected1+26,boundaryNodes.begin()));
00553   mesh->decrRef();
00554 }
00555 
00556 void MEDCouplingBasicsTest1::testBoundaryMesh()
00557 {
00558   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
00559   MEDCouplingPointSet *mesh2=mesh->buildBoundaryMesh(false);
00560   CPPUNIT_ASSERT_EQUAL(24,mesh2->getNumberOfCells());
00561   CPPUNIT_ASSERT_EQUAL(26,mesh2->getNumberOfNodes());
00562   mesh2->decrRef();
00563   mesh->decrRef();
00564 }
00565 
00566 void MEDCouplingBasicsTest1::testBuildPartOfMySelf()
00567 {
00568   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
00569   mesh->setName("Toto");
00570   const int tab1[2]={0,4};
00571   const int tab2[3]={0,2,3};
00572   //
00573   MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelf(tab1,tab1+2,true);
00574   MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
00575   CPPUNIT_ASSERT(subMesh);
00576   std::string name(subMesh->getName());
00577   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
00578   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*mesh->getAllTypes().begin());
00579   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(mesh->getAllTypes().begin())));
00580   CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllTypes().size());
00581   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
00582   CPPUNIT_ASSERT(name=="PartOf_Toto");
00583   CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
00584   CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
00585   const int subConn[10]={4,0,3,4,1,4,7,8,5,4};
00586   const int subConnIndex[3]={0,5,10};
00587   CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
00588   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
00589   CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
00590   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
00591   subMesh->decrRef();
00592   //
00593   subMeshSimple=mesh->buildPartOfMySelf(tab2,tab2+3,true);
00594   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
00595   CPPUNIT_ASSERT(subMesh);
00596   name=subMesh->getName();
00597   CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
00598   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
00599   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++(subMesh->getAllTypes().begin())));
00600   CPPUNIT_ASSERT(name=="PartOf_Toto");
00601   CPPUNIT_ASSERT(mesh->getCoords()==subMesh->getCoords());
00602   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
00603   const int subConn2[14]={4,0,3,4,1,3,4,5,2,4,6,7,4,3};
00604   const int subConnIndex2[4]={0,5,9,14};
00605   CPPUNIT_ASSERT_EQUAL(14,subMesh->getNodalConnectivity()->getNbOfElems());
00606   CPPUNIT_ASSERT_EQUAL(4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
00607   CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
00608   CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
00609   const int tab3[3]={0,1,2};
00610   MEDCouplingPointSet *subMeshSimple2=subMeshSimple->buildPartOfMySelf(tab3,tab3+3,true);
00611   subMesh->decrRef();
00612   name=subMeshSimple2->getName();
00613   CPPUNIT_ASSERT(name=="PartOf_Toto");
00614   subMeshSimple2->decrRef();
00615   //
00616   mesh->decrRef();
00617 }
00618 
00619 void MEDCouplingBasicsTest1::testBuildPartOfMySelfNode()
00620 {
00621   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
00622   const int tab1[4]={5,7,8,4};
00623   MEDCouplingPointSet *subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+4,true);
00624   MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
00625   CPPUNIT_ASSERT(subMesh);
00626   CPPUNIT_ASSERT_EQUAL(1,(int)subMesh->getAllTypes().size());
00627   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
00628   CPPUNIT_ASSERT_EQUAL(1,subMesh->getNumberOfCells());
00629   CPPUNIT_ASSERT_EQUAL(5,subMesh->getNodalConnectivity()->getNbOfElems());
00630   CPPUNIT_ASSERT_EQUAL(2,subMesh->getNodalConnectivityIndex()->getNbOfElems());
00631   const int subConn[5]={4,7,8,5,4};
00632   const int subConnIndex[3]={0,5};
00633   CPPUNIT_ASSERT(std::equal(subConn,subConn+5,subMesh->getNodalConnectivity()->getPointer()));
00634   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+2,subMesh->getNodalConnectivityIndex()->getPointer()));
00635   CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
00636   subMeshSimple->decrRef();
00637   //
00638   subMeshSimple=mesh->buildPartOfMySelfNode(tab1,tab1+2,false);
00639   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
00640   CPPUNIT_ASSERT(subMesh);
00641   CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
00642   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
00643   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().begin()));
00644   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
00645   CPPUNIT_ASSERT_EQUAL(14,subMesh->getNodalConnectivity()->getNbOfElems());
00646   CPPUNIT_ASSERT_EQUAL(4,subMesh->getNodalConnectivityIndex()->getNbOfElems());
00647   const int subConn2[14]={3,4,5,2,4,6,7,4,3,4,7,8,5,4};
00648   const int subConnIndex2[4]={0,4,9,14};
00649   CPPUNIT_ASSERT(std::equal(subConn2,subConn2+14,subMesh->getNodalConnectivity()->getPointer()));
00650   CPPUNIT_ASSERT(std::equal(subConnIndex2,subConnIndex2+4,subMesh->getNodalConnectivityIndex()->getPointer()));
00651   CPPUNIT_ASSERT(subMesh->getCoords()==mesh->getCoords());
00652   subMeshSimple->decrRef();
00653   //testing the case where length of tab2 is greater than max number of node per cell.
00654   const int tab2[7]={0,3,2,1,4,5,6};
00655   subMeshSimple=mesh->buildPartOfMySelfNode(tab2,tab2+7,true);
00656   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshSimple);
00657   CPPUNIT_ASSERT(subMesh);
00658   CPPUNIT_ASSERT_EQUAL(2,(int)subMesh->getAllTypes().size());
00659   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*subMesh->getAllTypes().begin());
00660   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*(++subMesh->getAllTypes().begin()));
00661   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNumberOfCells());
00662   subMeshSimple->decrRef();
00663   //
00664   mesh->decrRef();
00665 }
00666 
00667 void MEDCouplingBasicsTest1::testZipCoords()
00668 {
00669   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
00670   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
00671   CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
00672   CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
00673   CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
00674   std::vector<int> oldConn(mesh->getNodalConnectivity()->getNbOfElems());
00675   std::vector<int> oldConnIndex(mesh->getNumberOfCells()+1);
00676   std::copy(mesh->getNodalConnectivity()->getPointer(),mesh->getNodalConnectivity()->getPointer()+oldConn.size(),oldConn.begin());
00677   std::copy(mesh->getNodalConnectivityIndex()->getPointer(),mesh->getNodalConnectivityIndex()->getPointer()+mesh->getNumberOfCells()+1,oldConnIndex.begin());
00678   DataArrayDouble *oldCoords=mesh->getCoords();
00679   oldCoords->incrRef();
00680   mesh->zipCoords();
00681   CPPUNIT_ASSERT_EQUAL(2,(int)mesh->getAllTypes().size());
00682   CPPUNIT_ASSERT_EQUAL(2,mesh->getSpaceDimension());
00683   CPPUNIT_ASSERT_EQUAL(9,mesh->getNumberOfNodes());
00684   CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells());
00685   CPPUNIT_ASSERT(mesh->getCoords()!=oldCoords);
00686   CPPUNIT_ASSERT(std::equal(mesh->getCoords()->getPointer(),mesh->getCoords()->getPointer()+2*9,oldCoords->getPointer()));
00687   CPPUNIT_ASSERT(std::equal(oldConn.begin(),oldConn.end(),mesh->getNodalConnectivity()->getPointer()));
00688   CPPUNIT_ASSERT(std::equal(oldConnIndex.begin(),oldConnIndex.end(),mesh->getNodalConnectivityIndex()->getPointer()));
00689   oldCoords->decrRef();
00690   //
00691   const int tab1[2]={0,4};
00692   MEDCouplingPointSet *subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,true);
00693   MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
00694   CPPUNIT_ASSERT(subMesh);
00695   DataArrayInt *traducer=subMesh->zipCoordsTraducer();
00696   const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
00697   CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
00698   traducer->decrRef();
00699   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
00700   CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
00701   const int subConn[10]={4,0,2,3,1,4,5,6,4,3};
00702   const int subConnIndex[3]={0,5,10};
00703   CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
00704   CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
00705   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
00706   CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
00707   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
00708   subMesh->decrRef();
00709   //
00710   subMeshPtSet=mesh->buildPartOfMySelf(tab1,tab1+2,false);
00711   subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
00712   CPPUNIT_ASSERT(subMesh);
00713   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
00714   CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
00715   CPPUNIT_ASSERT_EQUAL(7,subMesh->getNumberOfNodes());
00716   CPPUNIT_ASSERT_EQUAL(10,subMesh->getNodalConnectivity()->getNbOfElems());
00717   CPPUNIT_ASSERT_EQUAL(3,subMesh->getNodalConnectivityIndex()->getNbOfElems());
00718   CPPUNIT_ASSERT(std::equal(subConn,subConn+10,subMesh->getNodalConnectivity()->getPointer()));
00719   CPPUNIT_ASSERT(std::equal(subConnIndex,subConnIndex+3,subMesh->getNodalConnectivityIndex()->getPointer()));
00720   subMesh->decrRef();
00721   //
00722   mesh->decrRef();
00723 }
00724 
00725 void MEDCouplingBasicsTest1::testZipConnectivity()
00726 {
00727   MEDCouplingUMesh *m1=build2DTargetMesh_1();
00728   MEDCouplingUMesh *m2=build2DTargetMesh_1();
00729   int cells1[3]={2,3,4};
00730   MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
00731   MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
00732   CPPUNIT_ASSERT(m3);
00733   m2->decrRef();
00734   MEDCouplingUMesh *m4=build2DSourceMesh_1();
00735   MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
00736   m1->decrRef();
00737   m3->decrRef();
00738   MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
00739   m4->decrRef();
00740   m5->decrRef();
00741   //
00742   bool areNodesMerged;
00743   int newNbOfNodes;
00744   CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
00745   CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
00746   DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
00747   arr->decrRef();
00748   CPPUNIT_ASSERT(areNodesMerged);
00749   CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
00750   CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
00751   CPPUNIT_ASSERT_EQUAL(9,newNbOfNodes);
00752   //
00753   arr=m6->zipConnectivityTraducer(0);
00754   CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
00755   arr->decrRef();
00756   MEDCouplingUMesh *m7=m6->clone(true);
00757   arr=m6->zipConnectivityTraducer(0);
00758   CPPUNIT_ASSERT(m7->isEqual(m6,1e-12));
00759   CPPUNIT_ASSERT_EQUAL(7,m6->getNumberOfCells());
00760   arr->decrRef();
00761   //
00762   m7->decrRef();
00763   m6->decrRef();
00764 }
00765 
00766 void MEDCouplingBasicsTest1::testEqualMesh()
00767 {
00768   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
00769   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
00770   //
00771   CPPUNIT_ASSERT(mesh1->isEqual(mesh1,1e-12));
00772   //
00773   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
00774   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
00775   double *pt=mesh2->getCoords()->getPointer();
00776   double tmp=pt[1];
00777   pt[1]=5.999;
00778   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
00779   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
00780   pt[1]=tmp;
00781   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
00782   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
00783   //
00784   int *pt2=mesh1->getNodalConnectivity()->getPointer();
00785   pt2[5]++;
00786   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
00787   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
00788   pt2[5]--;
00789   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
00790   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
00791   //
00792   pt2=mesh1->getNodalConnectivityIndex()->getPointer();
00793   pt2[1]++;
00794   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
00795   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
00796   pt2[1]--;
00797   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
00798   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
00799   //
00800   std::string tmp3=mesh1->getName();
00801   mesh1->setName("lllll");
00802   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
00803   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
00804   mesh1->setName(tmp3.c_str());
00805   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
00806   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
00807   //
00808   tmp3=mesh2->getCoords()->getInfoOnComponent(1);
00809   mesh2->getCoords()->setInfoOnComponent(1,"kkkkkk");
00810   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
00811   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
00812   mesh2->getCoords()->setInfoOnComponent(1,tmp3.c_str());
00813   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
00814   CPPUNIT_ASSERT(mesh2->isEqual(mesh1,1e-12));
00815   //
00816   mesh1->decrRef();
00817   mesh2->decrRef();
00818 }
00819 
00820 void MEDCouplingBasicsTest1::testEqualFieldDouble()
00821 {
00822   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
00823   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
00824   //
00825   MEDCouplingFieldDouble *fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00826   fieldOnCells1->setMesh(mesh1);
00827   MEDCouplingFieldDouble *fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00828   fieldOnCells2->setMesh(mesh2);
00829   //
00830   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00831   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00832   fieldOnCells2->decrRef();
00833   //
00834   MEDCouplingFieldDouble *fieldOnNodes1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00835   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnNodes1,1e-12,1e-15));
00836   CPPUNIT_ASSERT(!fieldOnNodes1->isEqual(fieldOnCells1,1e-12,1e-15));
00837   fieldOnNodes1->decrRef();
00838   //
00839   fieldOnCells2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00840   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00841   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00842   fieldOnCells1->decrRef();
00843   fieldOnCells1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00844   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00845   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00846   fieldOnCells1->setTime(4.,6,7);
00847   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00848   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00849   fieldOnCells2->setTime(4.,6,7);
00850   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00851   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00852   fieldOnCells1->setName("Power");
00853   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00854   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00855   fieldOnCells2->setName("Power");
00856   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00857   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00858   //
00859   fieldOnCells1->setMesh(mesh1);
00860   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00861   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00862   fieldOnCells2->setMesh(mesh1);
00863   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00864   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00865   DataArrayDouble *arr=DataArrayDouble::New();
00866   arr->setName("popo");
00867   arr->alloc(mesh1->getNumberOfCells(),3);
00868   double *pt=arr->getPointer();
00869   std::fill(pt,pt+mesh1->getNumberOfCells()*3,6.);
00870   fieldOnCells1->setArray(arr);
00871   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00872   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00873   fieldOnCells2->setArray(arr);
00874   arr->decrRef();
00875   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00876   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00877   //
00878   DataArrayDouble *arr2=arr->deepCpy();
00879   fieldOnCells2->setArray(arr2);
00880   arr2->decrRef();
00881   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00882   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00883   pt[4]=6.1;
00884   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00885   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00886   pt[4]=6.;
00887   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00888   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00889   arr2->setName("popo2");
00890   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00891   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00892   //
00893   arr2->setName("popo");
00894   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00895   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00896   //
00897   arr2->setInfoOnComponent(2,"jjj");
00898   CPPUNIT_ASSERT(!fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00899   CPPUNIT_ASSERT(!fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00900   arr->setInfoOnComponent(2,"jjj");
00901   CPPUNIT_ASSERT(fieldOnCells1->isEqual(fieldOnCells2,1e-12,1e-15));
00902   CPPUNIT_ASSERT(fieldOnCells2->isEqual(fieldOnCells1,1e-12,1e-15));
00903   //
00904   fieldOnCells1->decrRef();
00905   fieldOnCells2->decrRef();
00906   //
00907   mesh1->decrRef();
00908   mesh2->decrRef();
00909 }
00910 
00911 void MEDCouplingBasicsTest1::testNatureChecking()
00912 {
00913   MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00914   field->setNature(Integral);
00915   field->setNature(ConservativeVolumic);
00916   field->setNature(IntegralGlobConstraint);
00917   field->decrRef();
00918   field=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
00919   field->setNature(ConservativeVolumic);
00920   CPPUNIT_ASSERT_THROW(field->setNature(Integral),INTERP_KERNEL::Exception);
00921   CPPUNIT_ASSERT_THROW(field->setNature(IntegralGlobConstraint),INTERP_KERNEL::Exception);
00922   field->decrRef();
00923 }
00924 
00925 void MEDCouplingBasicsTest1::testBuildSubMeshData()
00926 {
00927   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
00928   //check buildSubMesh on field on cells
00929   MEDCouplingFieldDouble *fieldCells=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00930   fieldCells->setMesh(targetMesh);
00931   const int elts[3]={1,2,4};
00932   DataArrayInt *di;
00933   MEDCouplingMesh *ret1=fieldCells->buildSubMeshData(elts,elts+3,di);
00934   CPPUNIT_ASSERT_EQUAL(3,ret1->getNumberOfCells());
00935   CPPUNIT_ASSERT_EQUAL(9,ret1->getNumberOfNodes());
00936   CPPUNIT_ASSERT_EQUAL(3,di->getNumberOfTuples());
00937   CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
00938   const int *toCheck=di->getConstPointer();
00939   CPPUNIT_ASSERT(std::equal(elts,elts+3,toCheck));
00940   MEDCouplingUMesh *ret1DC=dynamic_cast<MEDCouplingUMesh *>(ret1);
00941   CPPUNIT_ASSERT(ret1DC);
00942   ret1->decrRef();
00943   di->decrRef();
00944   fieldCells->decrRef();
00945   //check buildSubMesh on field on nodes
00946   MEDCouplingFieldDouble *fieldNodes=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
00947   fieldNodes->setMesh(targetMesh);
00948   MEDCouplingMesh *ret2=fieldNodes->buildSubMeshData(elts,elts+3,di);
00949   MEDCouplingUMesh *ret2DC=dynamic_cast<MEDCouplingUMesh *>(ret2);
00950   CPPUNIT_ASSERT(ret2DC);
00951   CPPUNIT_ASSERT_EQUAL(3,ret2->getNumberOfCells());
00952   CPPUNIT_ASSERT_EQUAL(6,ret2->getNumberOfNodes());
00953   CPPUNIT_ASSERT_EQUAL(6,di->getNumberOfTuples());
00954   CPPUNIT_ASSERT_EQUAL(1,di->getNumberOfComponents());
00955   toCheck=di->getConstPointer();
00956   const int expected[6]={1,2,4,5,7,8};
00957   CPPUNIT_ASSERT(std::equal(expected,expected+6,toCheck));
00958   ret2->decrRef();
00959   di->decrRef();
00960   fieldNodes->decrRef();
00961   targetMesh->decrRef();
00962 }
00963 
00964 void MEDCouplingBasicsTest1::testExtrudedMesh1()
00965 {
00966   MEDCouplingUMesh *mesh2D=0;
00967   MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
00968   MEDCouplingExtrudedMesh *ext=MEDCouplingExtrudedMesh::New(mesh3D,mesh2D,1);
00969   CPPUNIT_ASSERT_EQUAL(18,ext->getNumberOfCells());
00970   CPPUNIT_ASSERT_EQUAL(60,ext->getNumberOfNodes());
00971   DataArrayInt *ids3D=ext->getMesh3DIds();
00972   const int ids3DExpected[18]={5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12};
00973   CPPUNIT_ASSERT_EQUAL(18,ids3D->getNumberOfTuples());
00974   CPPUNIT_ASSERT_EQUAL(1,ids3D->getNumberOfComponents());
00975   CPPUNIT_ASSERT(std::equal(ids3DExpected,ids3DExpected+18,ids3D->getConstPointer()));
00976   MEDCouplingUMesh *mesh1D=ext->getMesh1D();
00977   CPPUNIT_ASSERT_EQUAL(4,mesh1D->getNumberOfNodes());
00978   CPPUNIT_ASSERT_EQUAL(3,mesh1D->getNumberOfCells());
00979   const double mesh1DExpected[12]={0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, 2, 0.66666666666666663, 1.4583333333333333, 3};
00980   DataArrayDouble *mesh1DCoords=mesh1D->getCoords();
00981   CPPUNIT_ASSERT_EQUAL(4,mesh1DCoords->getNumberOfTuples());
00982   CPPUNIT_ASSERT_EQUAL(3,mesh1DCoords->getNumberOfComponents());
00983   CPPUNIT_ASSERT(std::equal(mesh1DExpected,mesh1DExpected+12,mesh1DCoords->getConstPointer()));
00984   DataArrayInt *conn1D=mesh1D->getNodalConnectivity();
00985   CPPUNIT_ASSERT_EQUAL(9,conn1D->getNumberOfTuples());
00986   CPPUNIT_ASSERT_EQUAL(1,conn1D->getNumberOfComponents());
00987   const int conn1DExpected[9]={1,0,1,1,1,2,1,2,3};
00988   CPPUNIT_ASSERT(std::equal(conn1DExpected,conn1DExpected+9,conn1D->getConstPointer()));
00989   ext->decrRef();
00990   mesh3D->decrRef();
00991   mesh2D->decrRef();
00992 }
00993 
00994 void MEDCouplingBasicsTest1::testExtrudedMesh2()
00995 {
00996   MEDCouplingUMesh *mN,*mTT,*mTF;
00997   build3DExtrudedUMesh_2(mN,mTT,mTF);
00998   //
00999   bool b=false;
01000   int newNbOfNodes;
01001   DataArrayInt *da=mTT->mergeNodes(1e-12,b,newNbOfNodes);
01002   CPPUNIT_ASSERT(b);
01003   da->decrRef();
01004   std::vector<int> n;
01005   double pt[3]={300.,300.,0.};
01006   double v[3]={0.,0.,2.};
01007   mTT->findNodesOnPlane(pt,v,1e-12,n);
01008   CPPUNIT_ASSERT_EQUAL(43,(int)n.size());
01009   MEDCouplingUMesh *mTT3dSurf=(MEDCouplingUMesh *)mTT->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
01010   MEDCouplingExtrudedMesh *meTT=MEDCouplingExtrudedMesh::New(mTT,mTT3dSurf,0);
01011   CPPUNIT_ASSERT_EQUAL(200,meTT->getNumberOfCells());
01012   CPPUNIT_ASSERT_EQUAL(10,meTT->getMesh2D()->getNumberOfCells());
01013   CPPUNIT_ASSERT_EQUAL(20,meTT->getMesh1D()->getNumberOfCells());
01014   mTT3dSurf->decrRef();
01015   //
01016   b=false;
01017   da=mN->mergeNodes(1e-12,b,newNbOfNodes);
01018   da->decrRef();
01019   CPPUNIT_ASSERT(!b);
01020   n.clear();
01021   mN->findNodesOnPlane(pt,v,1e-12,n);
01022   CPPUNIT_ASSERT_EQUAL(30,(int)n.size());
01023   MEDCouplingUMesh *mN3dSurf=(MEDCouplingUMesh *)mN->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
01024   MEDCouplingExtrudedMesh *meN=MEDCouplingExtrudedMesh::New(mN,mN3dSurf,0);
01025   CPPUNIT_ASSERT_EQUAL(40,meN->getNumberOfCells());
01026   CPPUNIT_ASSERT_EQUAL(20,meN->getMesh2D()->getNumberOfCells());
01027   CPPUNIT_ASSERT_EQUAL(2,meN->getMesh1D()->getNumberOfCells());
01028   mN3dSurf->decrRef();
01029   //
01030   b=false;
01031   da=mTF->mergeNodes(1e-12,b,newNbOfNodes);
01032   da->decrRef();
01033   CPPUNIT_ASSERT(!b);
01034   n.clear();
01035   mTF->findNodesOnPlane(pt,v,1e-12,n);
01036   CPPUNIT_ASSERT_EQUAL(27,(int)n.size());
01037   MEDCouplingUMesh *mTF3dSurf=(MEDCouplingUMesh *)mTF->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
01038   MEDCouplingExtrudedMesh *meTF=MEDCouplingExtrudedMesh::New(mTF,mTF3dSurf,0);
01039   CPPUNIT_ASSERT_EQUAL(340,meTF->getNumberOfCells());
01040   CPPUNIT_ASSERT_EQUAL(17,meTF->getMesh2D()->getNumberOfCells());
01041   CPPUNIT_ASSERT_EQUAL(20,meTF->getMesh1D()->getNumberOfCells());
01042   mTF3dSurf->decrRef();
01043   //
01044   meTT->decrRef();
01045   meN->decrRef();
01046   meTF->decrRef();
01047   //
01048   mN->decrRef();
01049   mTT->decrRef();
01050   mTF->decrRef();
01051 }
01052 
01056 void MEDCouplingBasicsTest1::testExtrudedMesh3()
01057 {
01058   MEDCouplingUMesh *m1=build2DTargetMesh_1();
01059   m1->changeSpaceDimension(3);
01060   MEDCouplingUMesh *m2=buildCU1DMesh_U();
01061   m2->changeSpaceDimension(3);
01062   double center[3]={0.,0.,0.};
01063   double vector[3]={0,1,0};
01064   m2->rotate(center,vector,-M_PI/2.);
01065   MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
01066   //
01067   MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
01068   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
01069   CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
01070   CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
01071   const int *m3DIds=m4->getMesh3DIds()->getConstPointer();
01072   for(int i=0;i<15;i++)
01073     CPPUNIT_ASSERT_EQUAL(i,m3DIds[i]);
01074   m4->decrRef();
01075   //some random in cells to check that extrusion alg find it correctly
01076   const int expected1[15]={1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
01077   m3->renumberCells(expected1,false);
01078   m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
01079   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
01080   CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
01081   CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
01082   m3DIds=m4->getMesh3DIds()->getConstPointer();
01083   for(int i=0;i<15;i++)
01084     CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
01085   m4->decrRef();
01086   m3->decrRef();
01087   //play with polygons and polyedrons
01088   std::vector<int> cells(2); cells[0]=2; cells[1]=3;
01089   m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
01090   m3=m1->buildExtrudedMesh(m2,0);
01091   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0));
01092   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1));
01093   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(2));
01094   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_POLYHED,(int)m3->getTypeOfCell(3));
01095   CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(4));
01096   m3->renumberCells(expected1,false);
01097   m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
01098   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
01099   CPPUNIT_ASSERT_EQUAL(5,m4->getMesh2D()->getNumberOfCells());
01100   CPPUNIT_ASSERT_EQUAL(3,m4->getMesh1D()->getNumberOfCells());
01101   m3DIds=m4->getMesh3DIds()->getConstPointer();
01102   for(int i=0;i<15;i++)
01103     CPPUNIT_ASSERT_EQUAL(expected1[i],m3DIds[i]);
01104   m4->decrRef();
01105   m3->decrRef();
01106   //
01107   m2->decrRef();
01108   m1->decrRef();
01109 }
01110 
01115 void MEDCouplingBasicsTest1::testExtrudedMesh4()
01116 {
01117   MEDCouplingUMesh *m1=build2DTargetMesh_1();
01118   std::vector<int> cells(2); cells[0]=2; cells[1]=4;
01119   m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
01120   m1->changeSpaceDimension(3);
01121   MEDCouplingUMesh *m2=buildCU1DMesh_U();
01122   m2->changeSpaceDimension(3);
01123   double center[3]={0.,0.,0.};
01124   double vector[3]={0.,1.,0.};
01125   m2->rotate(center,vector,-M_PI/2.);
01126   MEDCouplingUMesh *m3=m1->buildExtrudedMesh(m2,0);
01127   const int expected1[15]= {1,3,2,0,6,5,7,10,11,8,12,9,14,13,4};
01128   const int rexpected1[15]={3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12};
01129   m3->renumberCells(expected1,false);
01130   MEDCouplingExtrudedMesh *m4=MEDCouplingExtrudedMesh::New(m3,m1,0);
01131   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(0));
01132   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,m4->getTypeOfCell(1));
01133   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYHED,m4->getTypeOfCell(2));
01134   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,m4->getTypeOfCell(7));
01135   MEDCouplingFieldDouble *f=m4->getMeasureField(true);
01136   DataArrayDouble *arr=f->getArray();
01137   CPPUNIT_ASSERT_EQUAL(15,arr->getNumberOfTuples());
01138   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01139   const double *arrPtr=arr->getConstPointer();
01140   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};
01141   for(int i=0;i<15;i++)
01142     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
01143   f->decrRef();
01144   MEDCouplingUMesh *m5=m4->build3DUnstructuredMesh();
01145   CPPUNIT_ASSERT(m5->isEqual(m3,1e-12));
01146   f=m5->getMeasureField(true);
01147   arr=f->getArray();
01148   arrPtr=arr->getConstPointer();
01149   for(int i=0;i<15;i++)
01150     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[rexpected1[i]],arrPtr[i],1e-16);
01151   f->decrRef();
01152   m5->decrRef();
01153   //
01154   m4->decrRef();
01155   m3->decrRef();
01156   m2->decrRef();
01157   m1->decrRef();
01158 }
01159 
01160 void MEDCouplingBasicsTest1::testFindCommonNodes()
01161 {
01162   DataArrayInt *comm,*commI;
01163   MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
01164   targetMesh->findCommonNodes(1e-10,-1,comm,commI);
01165   CPPUNIT_ASSERT_EQUAL(1,commI->getNumberOfTuples());
01166   CPPUNIT_ASSERT_EQUAL(0,comm->getNumberOfTuples());
01167   int newNbOfNodes;
01168   DataArrayInt *o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
01169   CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
01170   CPPUNIT_ASSERT_EQUAL(27,o2n->getNumberOfTuples());
01171   const int o2nExp1[27]=
01172     {
01173       0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
01174       21,22,23,24,25,26
01175     };
01176   CPPUNIT_ASSERT(std::equal(o2nExp1,o2nExp1+27,o2n->getConstPointer()));
01177   o2n->decrRef();
01178   comm->decrRef();
01179   commI->decrRef();
01180   targetMesh->decrRef();
01181   //
01182   targetMesh=build3DTargetMeshMergeNode_1();
01183   CPPUNIT_ASSERT_EQUAL(31,targetMesh->getNumberOfNodes());
01184   targetMesh->findCommonNodes(1e-10,-1,comm,commI);
01185   CPPUNIT_ASSERT_EQUAL(3,commI->getNumberOfTuples());
01186   CPPUNIT_ASSERT_EQUAL(6,comm->getNumberOfTuples());
01187   const int commExpected[6]={1,27,28,29,23,30};
01188   const int commIExpected[3]={0,4,6};
01189   CPPUNIT_ASSERT(std::equal(commExpected,commExpected+6,comm->getConstPointer()));
01190   CPPUNIT_ASSERT(std::equal(commIExpected,commIExpected+3,commI->getConstPointer()));
01191   o2n=targetMesh->buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes);
01192   CPPUNIT_ASSERT_EQUAL(31,o2n->getNumberOfTuples());
01193   CPPUNIT_ASSERT_EQUAL(27,newNbOfNodes);
01194   const int o2nExp2[31]=
01195     {
01196       0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
01197       21,22,23,24,25,26,1,1,1,23
01198     };
01199   CPPUNIT_ASSERT(std::equal(o2nExp2,o2nExp2+31,o2n->getConstPointer()));
01200   o2n->decrRef();
01201   comm->decrRef();
01202   commI->decrRef();
01203   targetMesh->decrRef();
01204   //
01205   targetMesh=build3DTargetMesh_1();
01206   bool areNodesMerged;
01207   unsigned int time=targetMesh->getTimeOfThis();
01208   o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
01209   targetMesh->updateTime();
01210   CPPUNIT_ASSERT(time==targetMesh->getTimeOfThis());
01211   CPPUNIT_ASSERT(!areNodesMerged);
01212   targetMesh->decrRef();
01213   o2n->decrRef();
01214   //
01215   targetMesh=build3DTargetMeshMergeNode_1();
01216   time=targetMesh->getTimeOfThis();
01217   o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
01218   targetMesh->updateTime();
01219   CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
01220   CPPUNIT_ASSERT(areNodesMerged);
01221   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,
01222                    18,4,5,8,7,13,14,17,16,
01223                    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,
01224                    18,13,14,17,16,22,23,26,25};
01225   CPPUNIT_ASSERT_EQUAL(72,targetMesh->getNodalConnectivity()->getNumberOfTuples());
01226   CPPUNIT_ASSERT(std::equal(connExp,connExp+72,targetMesh->getNodalConnectivity()->getConstPointer()));
01227   CPPUNIT_ASSERT_EQUAL(27,targetMesh->getCoords()->getNumberOfTuples());
01228   double coordsExp[81]={ 0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. ,
01229                          200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
01230                          0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50.,
01231                          50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. ,
01232                          200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.  
01233                          , 0., 50., 200., 50., 50., 200. , 200., 50., 200., 
01234                          0., 200., 200., 50., 200., 200. , 200., 200., 200. };
01235   CPPUNIT_ASSERT(std::equal(coordsExp,coordsExp+81,targetMesh->getCoords()->getConstPointer()));
01236   targetMesh->decrRef();
01237   o2n->decrRef();
01238   //2D
01239   targetMesh=build2DTargetMeshMergeNode_1();
01240   CPPUNIT_ASSERT_EQUAL(18,targetMesh->getNumberOfNodes());
01241   time=targetMesh->getTimeOfThis();
01242   o2n=targetMesh->mergeNodes(1e-10,areNodesMerged,newNbOfNodes);
01243   CPPUNIT_ASSERT(time!=targetMesh->getTimeOfThis());
01244   CPPUNIT_ASSERT(areNodesMerged);
01245   CPPUNIT_ASSERT_EQUAL(9,targetMesh->getNumberOfNodes());
01246   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};
01247   CPPUNIT_ASSERT_EQUAL(23,targetMesh->getNodalConnectivity()->getNumberOfTuples());
01248   CPPUNIT_ASSERT(std::equal(connExp2,connExp2+23,targetMesh->getNodalConnectivity()->getConstPointer()));
01249   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};
01250   CPPUNIT_ASSERT_EQUAL(9,targetMesh->getCoords()->getNumberOfTuples());
01251   CPPUNIT_ASSERT(std::equal(coordsExp2,coordsExp2+18,targetMesh->getCoords()->getConstPointer()));
01252   targetMesh->decrRef();
01253   o2n->decrRef();
01254 }
01255 
01256 void MEDCouplingBasicsTest1::testCheckButterflyCells()
01257 {
01258   std::vector<int> cells;
01259   MEDCouplingUMesh *sourceMesh=build2DTargetMesh_1();
01260   sourceMesh->checkButterflyCells(cells);
01261   CPPUNIT_ASSERT(cells.empty());
01262   int *pt=sourceMesh->getNodalConnectivity()->getPointer();
01263   std::swap(pt[15],pt[16]);
01264   sourceMesh->checkButterflyCells(cells);
01265   CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
01266   CPPUNIT_ASSERT_EQUAL(3,cells[0]);
01267   cells.clear();
01268   std::swap(pt[15],pt[16]);
01269   sourceMesh->checkButterflyCells(cells);
01270   CPPUNIT_ASSERT(cells.empty());
01271   sourceMesh->decrRef();
01272   // 3D surf
01273   sourceMesh=build3DSurfTargetMesh_1();
01274   sourceMesh->checkButterflyCells(cells);
01275   CPPUNIT_ASSERT(cells.empty());
01276   pt=sourceMesh->getNodalConnectivity()->getPointer();
01277   std::swap(pt[15],pt[16]);
01278   sourceMesh->checkButterflyCells(cells);
01279   CPPUNIT_ASSERT_EQUAL(1,(int)cells.size());
01280   CPPUNIT_ASSERT_EQUAL(3,cells[0]);
01281   cells.clear();
01282   std::swap(pt[15],pt[16]);
01283   sourceMesh->checkButterflyCells(cells);
01284   CPPUNIT_ASSERT(cells.empty());
01285   sourceMesh->decrRef();
01286 }
01287 
01288 void MEDCouplingBasicsTest1::testMergeMesh1()
01289 {
01290   MEDCouplingUMesh *m1=build2DTargetMesh_1();
01291   MEDCouplingUMesh *m2=build2DSourceMesh_1();
01292   const double vec[2]={1.,0.};
01293   m2->translate(vec);
01294   MEDCouplingMesh *m3=m1->mergeMyselfWith(m2);
01295   MEDCouplingUMesh *m3C=dynamic_cast<MEDCouplingUMesh *>(m3);
01296   CPPUNIT_ASSERT(m3C);
01297   m3->checkCoherency();
01298   MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
01299   CPPUNIT_ASSERT(m3->isEqual(m4,1.e-12));
01300   m4->decrRef();
01301   bool isMerged;
01302   int newNbOfNodes;
01303   DataArrayInt *da=m3C->mergeNodes(1.e-12,isMerged,newNbOfNodes);
01304   CPPUNIT_ASSERT_EQUAL(11,m3C->getNumberOfNodes());
01305   CPPUNIT_ASSERT_EQUAL(11,newNbOfNodes);
01306   CPPUNIT_ASSERT(isMerged);
01307   da->decrRef();
01308   m3->decrRef();
01309   m1->decrRef();
01310   m2->decrRef();
01311 }
01312 
01313 void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1()
01314 {
01315   MEDCouplingUMesh *m1=build2DTargetMesh_1();
01316   MEDCouplingUMesh *m2=build2DTargetMesh_1();
01317   std::vector<int> cells(5);
01318   for(int i=0;i<5;i++)
01319     cells[i]=i;
01320   m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size());
01321   m1->tryToShareSameCoords(*m2,1e-12);
01322   MEDCouplingUMesh *m3=build2DTargetMesh_1();
01323   m3->tryToShareSameCoords(*m2,1e-12);
01324   std::vector<const MEDCouplingUMesh *> meshes;
01325   meshes.push_back(m1); meshes.push_back(m2); meshes.push_back(m3);
01326   MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes);
01327   m4->checkCoherency();
01328   CPPUNIT_ASSERT(m4->getCoords()==m1->getCoords());
01329   CPPUNIT_ASSERT_EQUAL(15,m4->getNumberOfCells());
01330   const int cells1[5]={0,1,2,3,4};
01331   MEDCouplingPointSet *m1_1=m4->buildPartOfMySelf(cells1,cells1+5,true);
01332   m1_1->setName(m1->getName());
01333   CPPUNIT_ASSERT(m1->isEqual(m1_1,1e-12));
01334   const int cells2[5]={5,6,7,8,9};
01335   MEDCouplingPointSet *m2_1=m4->buildPartOfMySelf(cells2,cells2+5,true);
01336   m2_1->setName(m2->getName());
01337   CPPUNIT_ASSERT(m2->isEqual(m2_1,1e-12));
01338   const int cells3[5]={10,11,12,13,14};
01339   MEDCouplingPointSet *m3_1=m4->buildPartOfMySelf(cells3,cells3+5,true);
01340   m3_1->setName(m3->getName());
01341   CPPUNIT_ASSERT(m3->isEqual(m3_1,1e-12));
01342   m1_1->decrRef(); m2_1->decrRef(); m3_1->decrRef();
01343   //
01344   m4->decrRef();
01345   m1->decrRef();
01346   m2->decrRef();
01347   m3->decrRef();
01348 }
01349 
01350 void MEDCouplingBasicsTest1::testMergeField1()
01351 {
01352   MEDCouplingUMesh *m1=build2DTargetMesh_1();
01353   MEDCouplingUMesh *m2=build2DSourceMesh_1();
01354   const double vec[2]={1.,0.};
01355   m2->translate(vec);
01356   MEDCouplingFieldDouble *f1=m1->getMeasureField(true);
01357   MEDCouplingFieldDouble *f2=m2->getMeasureField(true);
01358   MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MergeFields(f1,f2);
01359   f3->checkCoherency();
01360   MEDCouplingUMesh *m4=build2DTargetMeshMerged_1();
01361   CPPUNIT_ASSERT(f3->getMesh()->isEqual(m4,1.e-12));
01362   std::string name=f3->getName();
01363   CPPUNIT_ASSERT(name=="MeasureOfMesh_");
01364   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_CELLS);
01365   CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
01366   CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
01367   CPPUNIT_ASSERT_EQUAL(7,f3->getNumberOfTuples());
01368   double values[7]={0.25,0.125,0.125,0.25,0.25,0.5,0.5};
01369   const double *tmp=f3->getArray()->getConstPointer();
01370   std::transform(tmp,tmp+7,values,values,std::minus<double>());
01371   std::transform(values,values+7,values,std::ptr_fun<double,double>(fabs));
01372   double max=*std::max_element(values,values+7);
01373   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01374   m4->decrRef();
01375   f3->decrRef();
01376   f1->decrRef();
01377   f2->decrRef();
01378   m1->decrRef();
01379   m2->decrRef();
01380 }
01381 
01382 bool func1(const double *pt, double *res);
01383 bool func2(const double *pt, double *res);
01384 bool func3(const double *pt, double *res);
01385 bool func4(const double *pt, double *res);
01386 
01387 bool func1(const double *pt, double *res)
01388 {
01389   res[0]=pt[0]+pt[1];
01390   return true;
01391 }
01392 
01393 bool func2(const double *pt, double *res)
01394 {
01395   res[0]=pt[0]+pt[1];
01396   res[1]=2.*(pt[0]+pt[1]);
01397   return true;
01398 }
01399 
01400 bool func3(const double *pt, double *res)
01401 {
01402   if(fabs(pt[0]-0.2)<1e-12)
01403     return false;
01404   res[0]=1./(pt[0]-0.2);
01405   return true;
01406 }
01407 
01408 void MEDCouplingBasicsTest1::testFillFromAnalytic()
01409 {
01410   MEDCouplingUMesh *m=build2DTargetMesh_1();
01411   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,func1);
01412   f1->checkCoherency();
01413   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
01414   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01415   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01416   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
01417   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
01418   const double *tmp=f1->getArray()->getConstPointer();
01419   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
01420   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
01421   double max=*std::max_element(values1,values1+5);
01422   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01423   f1->decrRef();
01424   //
01425   f1=m->fillFromAnalytic(ON_NODES,1,func1);
01426   f1->checkCoherency();
01427   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01428   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01429   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01430   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01431   double values2[9]={-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4};
01432   tmp=f1->getArray()->getConstPointer();
01433   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
01434   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
01435   max=*std::max_element(values2,values2+9);
01436   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01437   f1->decrRef();
01438   //
01439   f1=m->fillFromAnalytic(ON_NODES,2,func2);
01440   f1->checkCoherency();
01441   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01442   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01443   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
01444   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01445   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};
01446   tmp=f1->getArray()->getConstPointer();
01447   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
01448   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
01449   max=*std::max_element(values3,values3+18);
01450   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01451   double values4[2];
01452   f1->accumulate(values4);
01453   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
01454   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
01455   f1->integral(true,values4);
01456   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
01457   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
01458   f1->decrRef();
01459   //
01460   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,func3),INTERP_KERNEL::Exception);
01461   //
01462   m->decrRef();
01463 }
01464 
01465 void MEDCouplingBasicsTest1::testFillFromAnalytic2()
01466 {
01467   MEDCouplingUMesh *m=build2DTargetMesh_1();
01468   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_CELLS,1,"y+x");
01469   f1->checkCoherency();
01470   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
01471   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01472   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01473   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
01474   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
01475   const double *tmp=f1->getArray()->getConstPointer();
01476   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
01477   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
01478   double max=*std::max_element(values1,values1+5);
01479   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01480   f1->decrRef();
01481   //
01482   f1=m->fillFromAnalytic(ON_NODES,1,"y+2*x");
01483   f1->checkCoherency();
01484   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01485   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01486   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01487   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01488   double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
01489   tmp=f1->getArray()->getConstPointer();
01490   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
01491   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
01492   max=*std::max_element(values2,values2+9);
01493   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01494   f1->decrRef();
01495   f1=m->fillFromAnalytic(ON_NODES,1,"2.*x+y");
01496   f1->checkCoherency();
01497   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01498   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01499   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01500   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01501   tmp=f1->getArray()->getConstPointer();
01502   double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
01503   std::transform(tmp,tmp+9,values2Bis,values2Bis,std::minus<double>());
01504   std::transform(values2,values2+9,values2Bis,std::ptr_fun<double,double>(fabs));
01505   max=*std::max_element(values2Bis,values2Bis+9);
01506   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01507   f1->decrRef();
01508   //
01509   f1=m->fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
01510   f1->checkCoherency();
01511   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01512   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01513   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
01514   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01515   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};
01516   tmp=f1->getArray()->getConstPointer();
01517   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
01518   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
01519   max=*std::max_element(values3,values3+18);
01520   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01521   double values4[2];
01522   f1->accumulate(values4);
01523   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
01524   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
01525   f1->integral(true,values4);
01526   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
01527   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
01528   f1->decrRef();
01529   //
01530   CPPUNIT_ASSERT_THROW(f1=m->fillFromAnalytic(ON_NODES,1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
01531   //
01532   m->decrRef();
01533 }
01534 
01535 void MEDCouplingBasicsTest1::testApplyFunc()
01536 {
01537   MEDCouplingUMesh *m=build2DTargetMesh_1();
01538   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
01539   f1->checkCoherency();
01540   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01541   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01542   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
01543   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01544   f1->applyFunc(1,func1);
01545   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01546   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01547   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01548   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01549   double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
01550   const double *tmp=f1->getArray()->getConstPointer();
01551   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
01552   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
01553   double max=*std::max_element(values1,values1+9);
01554   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01555   f1->decrRef();
01556   m->decrRef();
01557 }
01558 
01559 void MEDCouplingBasicsTest1::testApplyFunc2()
01560 {
01561   MEDCouplingUMesh *m=build2DTargetMesh_1();
01562   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,2,func2);
01563   f1->checkCoherency();
01564   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01565   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01566   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
01567   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01568   //
01569   MEDCouplingFieldDouble *f2=f1->clone(true);
01570   CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a+b+c+d"),INTERP_KERNEL::Exception);
01571   CPPUNIT_ASSERT_THROW(f2->applyFunc(1,"a/0"),INTERP_KERNEL::Exception);
01572   CPPUNIT_ASSERT_THROW(f2->applyFunc("a/0"),INTERP_KERNEL::Exception);
01573   f2->applyFunc("abs(u)^2.4+2*u");
01574   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01575   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01576   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
01577   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01578   double values2[18]={-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
01579                       0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
01580                       0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
01581                       0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
01582                       5.0423700574830965, 17.435300118916864};
01583   const double *tmp=f2->getArray()->getConstPointer();
01584   std::transform(tmp,tmp+18,values2,values2,std::minus<double>());
01585   std::transform(values2,values2+18,values2,std::ptr_fun<double,double>(fabs));
01586   double max=*std::max_element(values2,values2+18);
01587   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01588   f2->decrRef();
01589   //
01590   f1->applyFunc(1,"x+y");
01591   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01592   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01593   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01594   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01595   double values1[9]={-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2};
01596   tmp=f1->getArray()->getConstPointer();
01597   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
01598   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
01599   max=*std::max_element(values1,values1+9);
01600   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01601   f1->decrRef();
01602   m->decrRef();
01603 }
01604 
01605 void MEDCouplingBasicsTest1::testOperationsOnFields()
01606 {
01607   MEDCouplingUMesh *m=build2DTargetMesh_1();
01608   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,func1);
01609   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,func1);
01610   f1->checkCoherency();
01611   f2->checkCoherency();
01612   MEDCouplingFieldDouble *f3=(*f1)+(*f2);
01613   f3->checkCoherency();
01614   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
01615   CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
01616   double values1[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
01617   const double *tmp=f3->getArray()->getConstPointer();
01618   std::transform(tmp,tmp+9,values1,values1,std::minus<double>());
01619   std::transform(values1,values1+9,values1,std::ptr_fun<double,double>(fabs));
01620   double max=*std::max_element(values1,values1+9);
01621   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01622   f3->decrRef();
01623   //
01624   f3=(*f1)*(*f2);
01625   f3->checkCoherency();
01626   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
01627   CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
01628   double values2[9]={0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96};
01629   tmp=f3->getArray()->getConstPointer();
01630   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
01631   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
01632   max=*std::max_element(values2,values2+9);
01633   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01634   f3->decrRef();
01635   //
01636   f3=(*f1)+(*f2);
01637   MEDCouplingFieldDouble *f4=(*f1)-(*f3);
01638   f4->checkCoherency();
01639   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
01640   CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
01641   double values3[9]={0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4};
01642   tmp=f4->getArray()->getConstPointer();
01643   std::transform(tmp,tmp+9,values3,values3,std::minus<double>());
01644   std::transform(values3,values3+9,values3,std::ptr_fun<double,double>(fabs));
01645   max=*std::max_element(values3,values3+9);
01646   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01647   f3->decrRef();
01648   f4->decrRef();
01649   //
01650   f3=(*f1)+(*f2);
01651   f4=(*f3)/(*f2);
01652   f4->checkCoherency();
01653   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
01654   CPPUNIT_ASSERT(f4->getTimeDiscretization()==NO_TIME);
01655   tmp=f4->getArray()->getConstPointer();
01656   for(int i=0;i<9;i++)
01657     CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,tmp[i],1.e-12);
01658   f3->decrRef();
01659   f4->decrRef();
01660   //
01661   f4=f2->buildNewTimeReprFromThis(ONE_TIME,false);
01662   f4->checkCoherency();
01663   CPPUNIT_ASSERT(f4->getArray()==f2->getArray());
01664   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
01665   CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
01666   CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
01667   MEDCouplingFieldDouble *f5=f4->buildNewTimeReprFromThis(NO_TIME,false);
01668   CPPUNIT_ASSERT(f4->getArray()==f5->getArray());
01669   CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
01670   CPPUNIT_ASSERT(f5->getTimeDiscretization()==NO_TIME);
01671   f3=(*f1)+(*f5);
01672   tmp=f3->getArray()->getConstPointer();
01673   double values4[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
01674   std::transform(tmp,tmp+9,values4,values4,std::minus<double>());
01675   std::transform(values4,values4+9,values4,std::ptr_fun<double,double>(fabs));
01676   max=*std::max_element(values4,values4+9);
01677   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01678   f5->decrRef();
01679   f4->decrRef();
01680   f3->decrRef();
01681   //
01682   f4=f2->buildNewTimeReprFromThis(ONE_TIME,true);
01683   f4->checkCoherency();
01684   CPPUNIT_ASSERT(f4->getArray()!=f2->getArray());
01685   CPPUNIT_ASSERT(f4->getTypeOfField()==ON_NODES);
01686   CPPUNIT_ASSERT(f4->getTimeDiscretization()==ONE_TIME);
01687   CPPUNIT_ASSERT_THROW(f3=(*f1)+(*f4),INTERP_KERNEL::Exception);
01688   f5=f4->buildNewTimeReprFromThis(NO_TIME,true);
01689   CPPUNIT_ASSERT(f4->getArray()!=f5->getArray());
01690   CPPUNIT_ASSERT(f2->getArray()!=f5->getArray());
01691   CPPUNIT_ASSERT(f5->getTypeOfField()==ON_NODES);
01692   CPPUNIT_ASSERT(f5->getTimeDiscretization()==NO_TIME);
01693   f3=(*f1)+(*f5);
01694   tmp=f3->getArray()->getConstPointer();
01695   double values5[9]={-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8};
01696   std::transform(tmp,tmp+9,values5,values5,std::minus<double>());
01697   std::transform(values5,values5+9,values5,std::ptr_fun<double,double>(fabs));
01698   max=*std::max_element(values5,values5+9);
01699   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
01700   f5->decrRef();
01701   f4->decrRef();
01702   f3->decrRef();
01703   //
01704   f1->decrRef();
01705   f2->decrRef();
01706   m->decrRef();
01707 }
01708 
01709 void MEDCouplingBasicsTest1::testOperationsOnFields2()
01710 {
01711   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
01712   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
01713   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
01714   MEDCouplingFieldDouble *f3=(*f1)/(*f2);
01715   f3->checkCoherency();
01716   CPPUNIT_ASSERT(f3->getTypeOfField()==ON_NODES);
01717   CPPUNIT_ASSERT(f3->getTimeDiscretization()==NO_TIME);
01718   const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
01719                              0.7407407407407407, 1.129032258064516, 0.81632653061224492,
01720                              0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
01721   CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
01722   CPPUNIT_ASSERT_EQUAL(9,f3->getNumberOfTuples());
01723   const double *val=f3->getArray()->getConstPointer();
01724   for(int i=0;i<9;i++)
01725     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
01726   f3->decrRef();
01727   f1->decrRef();
01728   f2->decrRef();
01729   //
01730   f1=m->buildOrthogonalField();
01731   f2=m->fillFromAnalytic(ON_CELLS,1,"x");
01732   f3=(*f1)*(*f2);
01733   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};
01734   val=f3->getArray()->getConstPointer();
01735   for(int i=0;i<15;i++)
01736     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
01737   f3->decrRef();
01738   //
01739   f3=(*f2)*(*f1);
01740   val=f3->getArray()->getConstPointer();
01741   for(int i=0;i<15;i++)
01742     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
01743   f3->decrRef();
01744   //
01745   f1->decrRef();
01746   f2->decrRef();
01747   //
01748   m->decrRef();
01749 }
01750 
01751 void MEDCouplingBasicsTest1::testOperationsOnFields3()
01752 {
01753   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
01754   MEDCouplingFieldDouble *f1=m->fillFromAnalytic(ON_NODES,1,"x+y+z");
01755   MEDCouplingFieldDouble *f2=m->fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
01756   (*f1)/=(*f2);
01757   f1->checkCoherency();
01758   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
01759   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
01760   const double expected1[9]={-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
01761                              0.7407407407407407, 1.129032258064516, 0.81632653061224492,
01762                              0.86538461538461531, 1.0919540229885056, 0.84302325581395343};
01763   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01764   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
01765   const double *val=f1->getArray()->getConstPointer();
01766   for(int i=0;i<9;i++)
01767     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1.e-12);
01768   f1->decrRef();
01769   f2->decrRef();
01770   //
01771   f1=m->buildOrthogonalField();
01772   f2=m->fillFromAnalytic(ON_CELLS,1,"x");
01773   (*f1)*=(*f2);
01774   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};
01775   val=f1->getArray()->getConstPointer();
01776   for(int i=0;i<15;i++)
01777     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1.e-12);
01778   f1->decrRef();
01779   //
01780   f1=m->buildOrthogonalField();
01781   CPPUNIT_ASSERT_THROW((*f2)*=(*f1),INTERP_KERNEL::Exception);
01782   f1->decrRef();
01783   f2->decrRef();
01784   //
01785   m->decrRef();
01786 }
01787 
01791 void MEDCouplingBasicsTest1::testOperationsOnFields4()
01792 {
01793   MEDCouplingUMesh *m=build2DTargetMesh_1();
01794   int nbOfCells=m->getNumberOfCells();
01795   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
01796   f1->setMesh(m);
01797   DataArrayDouble *array=DataArrayDouble::New();
01798   array->alloc(nbOfCells,3);
01799   f1->setArray(array);
01800   CPPUNIT_ASSERT_THROW(f1->setEndArray(array),INTERP_KERNEL::Exception);
01801   CPPUNIT_ASSERT_THROW(f1->getEndArray(),INTERP_KERNEL::Exception);
01802   array->decrRef();
01803   double *tmp=array->getPointer();
01804   const double arr1[15]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.};
01805   const double arr2[15]={5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.};
01806   std::copy(arr1,arr1+15,tmp);
01807   f1->setStartTime(2.,0,0);
01808   f1->setEndTime(3.,0,0);
01809   f1->checkCoherency();
01810   double res[3];
01811   const double pos[2]={0.3,-0.2};
01812   f1->getValueOn(pos,res);
01813   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
01814   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
01815   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
01816   std::fill(res,res+3,0.);
01817   f1->getValueOn(pos,2.2,res);
01818   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],res[0],1.e-12);
01819   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],res[1],1.e-12);
01820   CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[5],res[2],1.e-12);
01821   std::fill(res,res+3,0.);
01822   CPPUNIT_ASSERT_THROW(f1->getValueOn(pos,3.2,res),INTERP_KERNEL::Exception);
01823   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
01824   f2->setMesh(m);
01825   f2->setArray(f1->getArray());
01826   f2->setStartTime(2.,3,0);
01827   f2->setEndTime(4.,13,0);
01828   CPPUNIT_ASSERT_THROW(f2->checkCoherency(),INTERP_KERNEL::Exception);
01829   DataArrayDouble *array2=DataArrayDouble::New();
01830   array2->alloc(nbOfCells,3);
01831   tmp=array2->getPointer();
01832   std::copy(arr2,arr2+15,tmp);
01833   f2->setEndArray(array2);
01834   array2->decrRef();
01835   f2->checkCoherency();
01836   //
01837   std::fill(res,res+3,0.);
01838   f2->getValueOn(pos,3.21,res);
01839   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.025,res[0],1.e-12);
01840   CPPUNIT_ASSERT_DOUBLES_EQUAL(14.025,res[1],1.e-12);
01841   CPPUNIT_ASSERT_DOUBLES_EQUAL(24.025,res[2],1.e-12);
01842   MEDCouplingFieldDouble *f3=f2->clone(true);
01843   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-12));
01844   f3->getEndArray()->getPointer()[0]=5.001;
01845   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-12));
01846   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
01847   f3->setStartTime(2.1,3,0);
01848   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
01849   f3->setStartTime(2.,3,0);
01850   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
01851   f3->setStartTime(2.,4,0);
01852   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
01853   f3->setStartTime(2.,3,1);
01854   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
01855   f3->setStartTime(2.,3,0);
01856   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
01857   f3->setEndTime(4.1,13,0);
01858   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
01859   f3->setEndTime(4.,13,0);
01860   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
01861   f3->setEndTime(4.,14,0);
01862   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
01863   f3->setEndTime(4.,13,1);
01864   CPPUNIT_ASSERT(!f2->isEqual(f3,1e-12,1e-2));
01865   f3->setEndTime(4.,13,0);
01866   CPPUNIT_ASSERT(f2->isEqual(f3,1e-12,1e-2));
01867   f3->decrRef();
01868   MEDCouplingFieldDouble *f4=(*f2)+(*f2);
01869   std::fill(res,res+3,0.);
01870   f4->getValueOn(pos,3.21,res);
01871   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.05,res[0],1.e-12);
01872   CPPUNIT_ASSERT_DOUBLES_EQUAL(28.05,res[1],1.e-12);
01873   CPPUNIT_ASSERT_DOUBLES_EQUAL(48.05,res[2],1.e-12);
01874   (*f4)+=*f2;
01875   std::fill(res,res+3,0.);
01876   f4->getValueOn(pos,3.21,res);
01877   CPPUNIT_ASSERT_DOUBLES_EQUAL(12.075,res[0],1.e-12);
01878   CPPUNIT_ASSERT_DOUBLES_EQUAL(42.075,res[1],1.e-12);
01879   CPPUNIT_ASSERT_DOUBLES_EQUAL(72.075,res[2],1.e-12);
01880   f4->decrRef();
01881   //
01882   f2->decrRef();
01883   f1->decrRef();
01884   m->decrRef();
01885 }
01886 
01887 bool func4(const double *pt, double *res)
01888 {
01889   res[0]=pt[0]+pt[1]+pt[2];
01890   return true;
01891 }
01892 
01893 void MEDCouplingBasicsTest1::testMergeNodesOnField()
01894 {
01895   double *tmp;
01896   MEDCouplingUMesh *targetMesh=build3DTargetMeshMergeNode_1();
01897   MEDCouplingFieldDouble *f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
01898   f1->mergeNodes(1e-10);
01899   f1->decrRef();
01900   targetMesh->decrRef();
01901   //
01902   targetMesh=build3DTargetMeshMergeNode_1();
01903   f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
01904   tmp=f1->getArray()->getPointer();
01905   tmp[0]=1000.;
01906   f1->mergeNodes(1e-10);
01907   f1->decrRef();
01908   targetMesh->decrRef();
01909   //
01910   targetMesh=build3DTargetMeshMergeNode_1();
01911   f1=targetMesh->fillFromAnalytic(ON_NODES,1,func4);
01912   tmp=f1->getArray()->getPointer();
01913   tmp[1]=1000.;
01914   CPPUNIT_ASSERT_THROW(f1->mergeNodes(1e-10),INTERP_KERNEL::Exception);
01915   f1->decrRef();
01916   targetMesh->decrRef();
01917 }
01918 
01919 void MEDCouplingBasicsTest1::testCheckConsecutiveCellTypes()
01920 {
01921   MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
01922   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
01923   CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
01924   const INTERP_KERNEL::NormalizedCellType order1[]={INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
01925   const INTERP_KERNEL::NormalizedCellType order2[]={INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI3};
01926   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
01927   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
01928   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
01929   DataArrayInt *da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order1,order1+2);
01930   CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
01931   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
01932   const int expected1[5]={2,0,1,3,4};
01933   CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
01934   da->decrRef();
01935   da=targetMesh->getRenumArrForConsecutiveCellTypesSpec(order2,order2+2);
01936   CPPUNIT_ASSERT_EQUAL(5,da->getNumberOfTuples());
01937   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
01938   const int expected2[5]={0,3,4,1,2};
01939   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,da->getConstPointer()));
01940   da->decrRef();
01941   const int renumber1[5]={4,0,1,2,3};
01942   targetMesh->renumberCells(renumber1,false);
01943   CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypes());
01944   CPPUNIT_ASSERT(targetMesh->checkConsecutiveCellTypesAndOrder(order1,order1+2));
01945   CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypesAndOrder(order2,order2+2));
01946   targetMesh->decrRef();
01947   sourceMesh->decrRef();
01948 }
01949 
01950 void MEDCouplingBasicsTest1::testRearrange2ConsecutiveCellTypes()
01951 {
01952   MEDCouplingUMesh *m1_1=build2DSourceMesh_1();
01953   MEDCouplingUMesh *m2_1=build2DTargetMesh_1();
01954   DataArrayInt *arr1=m1_1->rearrange2ConsecutiveCellTypes();
01955   MEDCouplingUMesh *m1_2=build2DSourceMesh_1();
01956   CPPUNIT_ASSERT(m1_2->isEqual(m1_1,1e-12));
01957   const int expected1[2]={0,1};
01958   CPPUNIT_ASSERT_EQUAL(2,arr1->getNumberOfTuples());
01959   CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
01960   CPPUNIT_ASSERT(std::equal(expected1,expected1+2,arr1->getConstPointer()));
01961   arr1->decrRef();
01962   const int expected2[5]={0,3,4,1,2};
01963   arr1=m2_1->rearrange2ConsecutiveCellTypes();
01964   CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
01965   CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
01966   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
01967   MEDCouplingUMesh *m2_2=build2DTargetMesh_1();
01968   CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
01969   CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
01970   CPPUNIT_ASSERT(std::equal(expected2,expected2+5,arr1->getConstPointer()));
01971   CPPUNIT_ASSERT(!m2_2->isEqual(m2_1,1e-12));
01972   m2_2->renumberCells(expected2,false);
01973   CPPUNIT_ASSERT(m2_2->isEqual(m2_1,1e-12));
01974   arr1->decrRef();
01975   m1_1->decrRef();
01976   m1_2->decrRef();
01977   m2_1->decrRef();
01978   m2_2->decrRef();
01979 }
01980 
01981 void MEDCouplingBasicsTest1::testSplitByType()
01982 {
01983   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
01984   std::vector<MEDCouplingUMesh *> v=m1->splitByType();
01985   CPPUNIT_ASSERT_EQUAL(3,(int)v.size());
01986   std::vector<const MEDCouplingUMesh *> v2(v.begin(),v.end());
01987   MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(v2);
01988   m2->setName(m1->getName());
01989   CPPUNIT_ASSERT(m1->isEqual(m2,1.e-12));
01990   for(std::vector<MEDCouplingUMesh *>::const_iterator iter=v.begin();iter!=v.end();iter++)
01991     (*iter)->decrRef();
01992   m2->decrRef();
01993   m1->decrRef();
01994 }
01995 
01996 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords()
01997 {
01998   std::vector<const MEDCouplingUMesh *> meshes;
01999   MEDCouplingUMesh *m2=build2DTargetMesh_1();
02000   int cells1[3]={2,3,4};
02001   MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
02002   MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
02003   CPPUNIT_ASSERT(m3);
02004   meshes.push_back(m3);
02005   int cells2[3]={1,2,4};
02006   MEDCouplingPointSet *m4_1=m2->buildPartOfMySelf(cells2,cells2+3,true);
02007   MEDCouplingUMesh *m4=dynamic_cast<MEDCouplingUMesh *>(m4_1);
02008   CPPUNIT_ASSERT(m4);
02009   meshes.push_back(m4);
02010   int cells3[2]={1,2};
02011   MEDCouplingPointSet *m5_1=m2->buildPartOfMySelf(cells3,cells3+2,true);
02012   MEDCouplingUMesh *m5=dynamic_cast<MEDCouplingUMesh *>(m5_1);
02013   CPPUNIT_ASSERT(m5);
02014   meshes.push_back(m5);
02015   m2->decrRef();
02016   //
02017   std::vector<DataArrayInt *> corr;
02018   MEDCouplingUMesh *m7=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
02019   CPPUNIT_ASSERT_EQUAL(4,m7->getNumberOfCells());
02020   CPPUNIT_ASSERT_EQUAL(3,(int)corr.size());
02021   const int expectedVals1[3]={3,3,2};
02022   const int expectedVals2[3][3]={{0,1,2},{3,0,2},{3,0,111111}};
02023   for(int i=0;i<3;i++)
02024     {
02025       DataArrayInt *arr=corr[i];
02026       CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
02027       int nbOfVals=expectedVals1[i];
02028       CPPUNIT_ASSERT_EQUAL(nbOfVals,arr->getNumberOfTuples());
02029       const int *vals=arr->getConstPointer();
02030       for(int j=0;j<nbOfVals;j++)
02031         CPPUNIT_ASSERT_EQUAL(expectedVals2[i][j],vals[j]);
02032     }
02033   std::vector< std::vector<int> > fidsOfGroups;
02034   std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
02035   DataArrayInt *arr2=DataArrayInt::MakePartition(corr2,m7->getNumberOfCells(),fidsOfGroups);
02036   const int fidExp[4]={5,1,3,4};
02037   const int fidsGrp[3][3]={{1,3,5},{3,4,5},{4,5,23344}};
02038   CPPUNIT_ASSERT_EQUAL(3,(int)fidsOfGroups.size());
02039   CPPUNIT_ASSERT_EQUAL(1,arr2->getNumberOfComponents());
02040   CPPUNIT_ASSERT_EQUAL(4,arr2->getNumberOfTuples());
02041   CPPUNIT_ASSERT(std::equal(fidExp,fidExp+4,arr2->getConstPointer()));
02042   for(int i=0;i<3;i++)
02043     {
02044       int nbOfVals=expectedVals1[i];
02045       CPPUNIT_ASSERT_EQUAL(nbOfVals,(int)fidsOfGroups[i].size());
02046       CPPUNIT_ASSERT(std::equal(fidsOfGroups[i].begin(),fidsOfGroups[i].end(),fidsGrp[i]));
02047     }
02048   for(std::vector<DataArrayInt *>::iterator iter=corr.begin();iter!=corr.end();iter++)
02049     (*iter)->decrRef();
02050   arr2->decrRef();
02051   m7->decrRef();
02052   //
02053   m3->decrRef();
02054   m4->decrRef();
02055   m5->decrRef();
02056 }
02057 
02058 void MEDCouplingBasicsTest1::testFuseUMeshesOnSameCoords2()
02059 {
02060   MEDCouplingUMesh *m2;
02061   MEDCouplingUMesh *m1=build3DExtrudedUMesh_1(m2);
02062   m2->decrRef();
02063   const int part1[5]={2,3,6,4,10};
02064   MEDCouplingUMesh *m3=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part1,part1+5,true);
02065   const int part2[4]={5,6,4,7};
02066   MEDCouplingUMesh *m4=(MEDCouplingUMesh *)m1->buildPartOfMySelf(part2,part2+4,true);
02067   std::vector<const MEDCouplingUMesh *> meshes;
02068   meshes.push_back(m1);
02069   meshes.push_back(m3);
02070   meshes.push_back(m3);
02071   meshes.push_back(m4);
02072   std::vector<DataArrayInt *> corr;
02073   MEDCouplingUMesh *m5=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
02074   CPPUNIT_ASSERT_EQUAL(18,m5->getNumberOfCells());
02075   std::vector<DataArrayInt *>::iterator it=corr.begin();
02076   const int exp1[4]={18,5,5,4};
02077   const int exp2[4][18]={
02078     {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},
02079     {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
02080     {2,3,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
02081     {5,6,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
02082   };
02083   int i=0;
02084   for(;it!=corr.end();it++,i++)
02085     {
02086       int sz=(*it)->getNumberOfTuples();
02087       CPPUNIT_ASSERT_EQUAL(exp1[i],sz);
02088       CPPUNIT_ASSERT(std::equal(exp2[i],exp2[i]+sz,(*it)->getConstPointer()));
02089     }
02090   for(it=corr.begin();it!=corr.end();it++)
02091     (*it)->decrRef();
02092   m5->decrRef();
02093   m4->decrRef();
02094   m3->decrRef();
02095   m1->decrRef();
02096 }
02097 
02098 void MEDCouplingBasicsTest1::testBuildOrthogonalField()
02099 {
02100   MEDCouplingUMesh *targetMesh=build3DSurfTargetMesh_1();
02101   MEDCouplingFieldDouble *field=targetMesh->buildOrthogonalField();
02102   double expected[3]={0.70710678118654746,0.,-0.70710678118654746};
02103   CPPUNIT_ASSERT_EQUAL(5,field->getNumberOfTuples());
02104   CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
02105   const double *vals=field->getArray()->getConstPointer();
02106   for(int i=0;i<15;i++)
02107     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i%3],vals[i],1e-12);
02108   field->decrRef();
02109   targetMesh->decrRef();
02110   // testing 
02111   double targetCoords[12]={0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.};
02112   int targetConn[4]={0,1,2,3};
02113   targetMesh=MEDCouplingUMesh::New();
02114   targetMesh->setMeshDimension(2);
02115   targetMesh->allocateCells(1);
02116   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
02117   targetMesh->finishInsertingCells();
02118   DataArrayDouble *myCoords=DataArrayDouble::New();
02119   myCoords->alloc(4,3);
02120   std::copy(targetCoords,targetCoords+12,myCoords->getPointer());
02121   targetMesh->setCoords(myCoords);
02122   myCoords->decrRef();
02123   field=targetMesh->buildOrthogonalField();
02124   CPPUNIT_ASSERT_EQUAL(1,field->getNumberOfTuples());
02125   CPPUNIT_ASSERT_EQUAL(3,field->getNumberOfComponents());
02126   vals=field->getArray()->getConstPointer();
02127   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.70710678118654746,vals[0],1e-12);
02128   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,vals[1],1e-12);
02129   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.70710678118654746,vals[2],1e-12);
02130   field->decrRef();
02131   targetMesh->decrRef();
02132 }
02133 
02134 void MEDCouplingBasicsTest1::testGetCellsContainingPoint()
02135 {
02136   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
02137   double pos[12]={0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.};
02138   std::vector<int> t1,t2;
02139   //2D basic
02140   targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
02141   CPPUNIT_ASSERT_EQUAL(6,(int)t1.size());
02142   CPPUNIT_ASSERT_EQUAL(7,(int)t2.size());
02143   const int expectedValues1[6]={0,4,3,0,1,2};
02144   const int expectedValues2[7]={0,1,2,3,4,5,6};
02145   CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
02146   CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
02147   //2D with no help of bounding box.
02148   double center[2]={0.2,0.2};
02149   MEDCouplingPointSet::Rotate2DAlg(center,0.78539816339744830962,6,pos);
02150   targetMesh->rotate(center,0,0.78539816339744830962);
02151   t1.clear(); t2.clear();
02152   targetMesh->getCellsContainingPoints(pos,6,1e-12,t1,t2);
02153   CPPUNIT_ASSERT_EQUAL(6,(int)t1.size());
02154   CPPUNIT_ASSERT_EQUAL(7,(int)t2.size());
02155   CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues1));
02156   CPPUNIT_ASSERT(std::equal(t2.begin(),t2.end(),expectedValues2));
02157   //2D outside
02158   const double pos1bis[2]={-0.3303300858899107,-0.11819805153394641};
02159   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos1bis,1e-12));
02160   targetMesh->decrRef();
02161   //test limits 2D
02162   targetMesh=build2DTargetMesh_1();
02163   const double pos2[2]={0.2,-0.05};
02164   t1.clear();
02165   targetMesh->getCellsContainingPoint(pos2,1e-12,t1);
02166   CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
02167   const int expectedValues3[2]={0,1};
02168   CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues3));
02169   const double pos3[2]={0.2,0.2};
02170   t1.clear();
02171   targetMesh->getCellsContainingPoint(pos3,1e-12,t1);
02172   CPPUNIT_ASSERT_EQUAL(5,(int)t1.size());
02173   const int expectedValues4[5]={0,1,2,3,4};
02174   CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues4));
02175   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos3,1e-12));
02176   targetMesh->decrRef();
02177   //3D
02178   targetMesh=build3DTargetMesh_1();
02179   const double pos4[3]={25.,25.,25.};
02180   CPPUNIT_ASSERT_EQUAL(0,targetMesh->getCellContainingPoint(pos4,1e-12));
02181   const double pos5[3]={50.,50.,50.};
02182   t1.clear();
02183   targetMesh->getCellsContainingPoint(pos5,1e-12,t1);
02184   CPPUNIT_ASSERT_EQUAL(8,(int)t1.size());
02185   const int expectedValues5[8]={0,1,2,3,4,5,6,7};
02186   CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues5));
02187   const double pos6[3]={0., 50., 0.};
02188   t1.clear();
02189   targetMesh->getCellsContainingPoint(pos6,1e-12,t1);
02190   CPPUNIT_ASSERT_EQUAL(2,(int)t1.size());
02191   const int expectedValues6[2]={0,2};
02192   CPPUNIT_ASSERT(std::equal(t1.begin(),t1.end(),expectedValues6));
02193   //3D outside
02194   const double pos7[3]={-1.0,-1.0,0.};
02195   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos7,1e-12));
02196   //3D outside 2
02197   const double center2[3]={0.,0.,0.};
02198   const double vec2[3]={0.,-1.,0.};
02199   targetMesh->rotate(center2,vec2,0.78539816339744830962);
02200   const double pos8[3]={-25,25.,12.};
02201   CPPUNIT_ASSERT_EQUAL(-1,targetMesh->getCellContainingPoint(pos8,1e-12));
02202   //
02203   targetMesh->decrRef();
02204 }
02205 
02206 void MEDCouplingBasicsTest1::testGetValueOn1()
02207 {
02208   MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
02209   MEDCouplingFieldDouble *fieldOnCells=MEDCouplingFieldDouble::New(ON_CELLS);
02210   int nbOfCells=targetMesh->getNumberOfCells();
02211   fieldOnCells->setMesh(targetMesh);
02212   DataArrayDouble *array=DataArrayDouble::New();
02213   array->alloc(nbOfCells,2);
02214   fieldOnCells->setArray(array);
02215   double *tmp=array->getPointer();
02216   for(int i=0;i<nbOfCells;i++)
02217     { tmp[2*i]=7.+(double)i; tmp[2*i+1]=17.+(double)i; }
02218   array->decrRef();
02219   //
02220   const double pos1[2]={0.25,0.};
02221   double res[2];
02222   fieldOnCells->getValueOn(pos1,res);
02223   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,res[0],1e-12);
02224   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,res[1],1e-12);
02225   //
02226   fieldOnCells->decrRef();
02227   targetMesh->decrRef();
02228   //
02229   targetMesh=build2DSourceMesh_1();
02230   MEDCouplingFieldDouble *fieldOnNodes=MEDCouplingFieldDouble::New(ON_NODES);
02231   int nbOfNodes=targetMesh->getNumberOfNodes();
02232   fieldOnNodes->setMesh(targetMesh);
02233   array=DataArrayDouble::New();
02234   array->alloc(nbOfNodes,2);
02235   fieldOnNodes->setArray(array);
02236   tmp=array->getPointer();
02237   for(int i=0;i<nbOfNodes;i++)
02238     { tmp[2*i]=17.+(double)i; tmp[2*i+1]=27.+(double)i; }
02239   array->decrRef();
02240   //
02241   const double pos2[2]={-0.13333333333333333,-0.13333333333333333};
02242   fieldOnNodes->getValueOn(pos2,res);
02243   CPPUNIT_ASSERT_DOUBLES_EQUAL(17.5,res[0],1e-12);
02244   CPPUNIT_ASSERT_DOUBLES_EQUAL(27.5,res[1],1e-12);
02245   const double pos3[2]={0.033333333333333326,0.36666666666666664};
02246   fieldOnNodes->getValueOn(pos3,res);
02247   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.666666666666667,res[0],1e-12);
02248   CPPUNIT_ASSERT_DOUBLES_EQUAL(28.666666666666667,res[1],1e-12);
02249   //
02250   fieldOnNodes->decrRef();
02251   targetMesh->decrRef();
02252 }
02253 
02254 void MEDCouplingBasicsTest1::testCMesh0()
02255 {
02256   MEDCouplingCMesh* mesh=MEDCouplingCMesh::New();
02257   MEDCouplingCMesh* meshEmpty=mesh->clone(true);
02258   CPPUNIT_ASSERT(meshEmpty->isEqual(mesh,1e-12));
02259   
02260   DataArrayDouble* coordsX=DataArrayDouble::New();
02261   double arrX[4] = { -1., 1., 2., 4. };
02262   coordsX->useArray(arrX,false, CPP_DEALLOC,4,1);
02263   DataArrayDouble* coordsY=DataArrayDouble::New();
02264   double arrY[4] = { -2., 2., 4., 8. };
02265   coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
02266   DataArrayDouble* coordsZ=DataArrayDouble::New();
02267   double arrZ[4] = { -3., 3., 6., 12. };
02268   coordsZ->useArray(arrZ,false, CPP_DEALLOC,4,1);
02269   mesh->setCoords(coordsX,coordsY,coordsZ);
02270   coordsX->decrRef();
02271   coordsY->decrRef();
02272   coordsZ->decrRef();
02273   //
02274   MEDCouplingFieldDouble *fieldOnNodes=mesh->fillFromAnalytic(ON_NODES,1,"x+y/2.+z/3.");
02275   CPPUNIT_ASSERT_EQUAL(1,fieldOnNodes->getNumberOfComponents());
02276   CPPUNIT_ASSERT_EQUAL(64,fieldOnNodes->getNumberOfTuples());
02277   const double expected1[64]={-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
02278                               4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
02279                               7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
02280                               7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.};
02281   const double *val=fieldOnNodes->getArray()->getConstPointer();
02282   for(int i=0;i<64;i++)
02283     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
02284   double res[1];  //size fieldOnNodes->getNumberOfComponents()
02285   fieldOnNodes->getValueOnPos(1,3,2,&res[0]);
02286   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.,res[0],1e-12);
02287   fieldOnNodes->decrRef();
02288   //
02289   MEDCouplingFieldDouble *fieldOnCells=mesh->fillFromAnalytic(ON_CELLS,1,"x+y/2.+z/3.");
02290   CPPUNIT_ASSERT_EQUAL(1,fieldOnCells->getNumberOfComponents());
02291   CPPUNIT_ASSERT_EQUAL(27,fieldOnCells->getNumberOfTuples());
02292   val=fieldOnCells->getArray()->getConstPointer();
02293   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,
02294                               6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9};
02295   for(int i=0;i<27;i++)
02296     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],val[i],1e-12);
02297   fieldOnCells->getValueOnPos(1,2,1,&res[0]);
02298   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.,res[0],1e-12);
02299   fieldOnCells->decrRef();
02300   //
02301   MEDCouplingMesh* meshDeepCopy=mesh->deepCpy();
02302   MEDCouplingCMesh* meshClone=mesh->clone(false);
02303   
02304   CPPUNIT_ASSERT_THROW(meshEmpty->copyTinyStringsFrom(0),INTERP_KERNEL::Exception);
02305   meshEmpty->copyTinyStringsFrom(mesh);
02306   //no data in meshEmpty, expected false
02307   CPPUNIT_ASSERT(!meshEmpty->isEqual(mesh,1e-12));
02308   
02309   CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
02310   meshDeepCopy->copyTinyStringsFrom(mesh);
02311   CPPUNIT_ASSERT(meshDeepCopy->isEqual(mesh,1e-12));
02312   CPPUNIT_ASSERT(meshClone->isEqual(mesh,1e-12));
02313   
02314   CPPUNIT_ASSERT_EQUAL(CARTESIAN,mesh->getType());
02315   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshEmpty->getType());
02316   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshDeepCopy->getType());
02317   CPPUNIT_ASSERT_EQUAL(CARTESIAN,meshClone->getType());
02318   
02319   mesh->decrRef();
02320   meshEmpty->decrRef();
02321   meshDeepCopy->decrRef();
02322   meshClone->decrRef();
02323 }
02324 
02325 void MEDCouplingBasicsTest1::testCMesh1()
02326 {
02327   MEDCouplingCMesh *mesh1,*mesh2,*mesh3;
02328   mesh1=MEDCouplingCMesh::New();
02329   DataArrayDouble* coordsX1=DataArrayDouble::New();
02330   double arrX1[4] = { -1., 1., 2., 4. };
02331   coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
02332   DataArrayDouble* coordsY1=DataArrayDouble::New();
02333   double arrY1[4] = { -2., 2., 4., 8. };
02334   coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
02335   DataArrayDouble* coordsZ1=DataArrayDouble::New();
02336   double arrZ1[4] = { -3., 3., 6., 12. };
02337   coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
02338   mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
02339   
02340   mesh2=MEDCouplingCMesh::New();
02341   DataArrayDouble* coordsX2=DataArrayDouble::New();
02342   double arrX2[4] = { -1., 1., 2., 4. };
02343   coordsX2->useArray(arrX2,false, CPP_DEALLOC,4,1);
02344   DataArrayDouble* coordsY2=DataArrayDouble::New();
02345   double arrY2[4] = { -2., 2., 4., 8. };
02346   coordsY2->useArray(arrY2,false, CPP_DEALLOC,4,1);
02347   DataArrayDouble* coordsZ2=DataArrayDouble::New();
02348   double arrZ2[4] = { -3., 3., 6., 12.+1e-6 };   //here is not equal
02349   coordsZ2->useArray(arrZ2,false, CPP_DEALLOC,4,1);
02350   mesh2->setCoords(coordsX2,coordsY2,coordsZ2);
02351   
02352   mesh3=MEDCouplingCMesh::New();
02353   DataArrayDouble* coordsX3=DataArrayDouble::New();
02354   double arrX3[1] = { -1.};
02355   coordsX3->useArray(arrX3,false, CPP_DEALLOC,1,1);
02356   DataArrayDouble* coordsY3=DataArrayDouble::New();
02357   double arrY3[1] = { -2.};
02358   coordsY3->useArray(arrY3,false, CPP_DEALLOC,1,1);
02359   DataArrayDouble* coordsZ3=DataArrayDouble::New();
02360   double arrZ3[1] = { -3.};
02361   coordsZ3->useArray(arrZ3,false, CPP_DEALLOC,1,1);
02362   mesh3->setCoords(coordsX3,coordsY3,coordsZ3);
02363   
02364   CPPUNIT_ASSERT_EQUAL(3,mesh1->getSpaceDimension());
02365   CPPUNIT_ASSERT_EQUAL(3,mesh1->getMeshDimension());
02366   
02367   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
02368   CPPUNIT_ASSERT(!mesh2->isEqual(mesh1,1e-12));
02369   CPPUNIT_ASSERT(!mesh2->isEqualWithoutConsideringStr(mesh1,1e-12));
02370   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-5));
02371   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-7));
02372   
02373   CPPUNIT_ASSERT_THROW(mesh3->checkCoherency1(1e-12),INTERP_KERNEL::Exception);
02374   mesh1->checkCoherency2(1e-12);
02375   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh1->getTypeOfCell(1));
02376   
02377   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,*((mesh1->getAllGeoTypes()).begin()));
02378   CPPUNIT_ASSERT_EQUAL(27,mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
02379   CPPUNIT_ASSERT_THROW(mesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4),INTERP_KERNEL::Exception);
02380   
02381   std::vector<double> coo;
02382   mesh1->getCoordinatesOfNode(0, coo);
02383   CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
02384   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.,coo[0],1e-14);
02385   CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.,coo[1],1e-14);
02386   CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.,coo[2],1e-14);
02387   coo.clear();
02388   mesh1->getCoordinatesOfNode(63, coo);
02389   CPPUNIT_ASSERT_EQUAL(3,(int) coo.size());
02390   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.,coo[0],1e-14);
02391   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,coo[1],1e-14);
02392   CPPUNIT_ASSERT_DOUBLES_EQUAL(12.,coo[2],1e-14);
02393   
02394   std::string repr;
02395   repr=mesh1->simpleRepr();
02396   repr=mesh1->advancedRepr();
02397   CPPUNIT_ASSERT(!(repr.find("Cartesian")==std::string::npos));
02398   CPPUNIT_ASSERT(!(repr.find("Number of components : 1")==std::string::npos));
02399   CPPUNIT_ASSERT(!(repr.find("Number of tuples : 4")==std::string::npos));
02400   CPPUNIT_ASSERT(!(repr.find("Z Array :")==std::string::npos));
02401   coordsX1->decrRef();
02402   coordsY1->decrRef();
02403   coordsZ1->decrRef();
02404   coordsX2->decrRef();
02405   coordsY2->decrRef();
02406   coordsZ2->decrRef();
02407   coordsX3->decrRef();
02408   coordsY3->decrRef();
02409   coordsZ3->decrRef();
02410   mesh1->decrRef();
02411   mesh2->decrRef();
02412   mesh3->decrRef();
02413 }
02414   
02415 void MEDCouplingBasicsTest1::testCMesh2()
02416 {
02417   MEDCouplingCMesh *mesh1;
02418   mesh1=MEDCouplingCMesh::New();
02419   DataArrayDouble* coordsX1=DataArrayDouble::New();
02420   double arrX1[4] = { -1., 1., 2., 4. };
02421   coordsX1->useArray(arrX1,false, CPP_DEALLOC,4,1);
02422   DataArrayDouble* coordsY1=DataArrayDouble::New();
02423   double arrY1[4] = { -2., 2., 4., 8. };
02424   coordsY1->useArray(arrY1,false, CPP_DEALLOC,4,1);
02425   DataArrayDouble* coordsZ1=DataArrayDouble::New();
02426   double arrZ1[4] = { -3., 3., 6., 12. };
02427   coordsZ1->useArray(arrZ1,false, CPP_DEALLOC,4,1);
02428   mesh1->setCoords(coordsX1,coordsY1,coordsZ1);
02429   
02430   std::vector<int> dis=mesh1->getDistributionOfTypes();
02431   CPPUNIT_ASSERT_EQUAL(3,(int) dis.size());
02432   CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,dis[0]);
02433   CPPUNIT_ASSERT_EQUAL(27,dis[1]);
02434   CPPUNIT_ASSERT_EQUAL(0,dis[2]);
02435   
02436   std::vector<const DataArrayInt *> idsPerType;
02437   CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
02438   dis[2]=-1;
02439   CPPUNIT_ASSERT(!(mesh1->checkTypeConsistencyAndContig(dis, idsPerType)));
02440   dis[0]=(int) INTERP_KERNEL::NORM_QUAD4;
02441   CPPUNIT_ASSERT_THROW(mesh1->checkTypeConsistencyAndContig(dis, idsPerType),INTERP_KERNEL::Exception);
02442   
02443   dis[0]=(int) INTERP_KERNEL::NORM_HEXA8;
02444   dis[2]=0;
02445   DataArrayInt *ids=DataArrayInt::New();
02446   ids->alloc(10,1);
02447   ids->fillWithValue(111);
02448   idsPerType.push_back(ids);
02449   DataArrayInt* check=mesh1->checkTypeConsistencyAndContig(dis, idsPerType);
02450   CPPUNIT_ASSERT(check);
02451   CPPUNIT_ASSERT(check->isEqual(*ids));
02452   
02453   std::vector<int> code;
02454   std::vector<DataArrayInt *> idsInPflPerType;
02455   std::vector<DataArrayInt *> pfls;
02456   mesh1->splitProfilePerType(ids,code,idsInPflPerType,pfls);
02457   CPPUNIT_ASSERT_EQUAL(3,(int)code.size());
02458   CPPUNIT_ASSERT_EQUAL((int) INTERP_KERNEL::NORM_HEXA8,code[0]);
02459   CPPUNIT_ASSERT_EQUAL(27,code[1]);
02460   CPPUNIT_ASSERT_EQUAL(0,code[2]);
02461   CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size());
02462   CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size());
02463   CPPUNIT_ASSERT(idsInPflPerType[0]->isEqual(*ids));
02464   CPPUNIT_ASSERT(pfls[0]->isEqual(*ids));
02465   idsInPflPerType[0]->decrRef();
02466   pfls[0]->decrRef();
02467 
02468   ids->decrRef();
02469   check->decrRef();
02470   int cells1[4]={0,1,25,26};
02471   MEDCouplingUMesh *partMesh1=
02472     dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPart(cells1,cells1+4));
02473   CPPUNIT_ASSERT(partMesh1);
02474   CPPUNIT_ASSERT_EQUAL(4,partMesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
02475   CPPUNIT_ASSERT_EQUAL(64,mesh1->getNumberOfNodes());
02476   CPPUNIT_ASSERT_EQUAL(64,partMesh1->getNumberOfNodes());
02477   
02478   int cells2[2]={25,26};
02479   DataArrayInt* arr1;
02480   MEDCouplingUMesh *partMesh2=
02481     dynamic_cast<MEDCouplingUMesh *>(mesh1->buildPartAndReduceNodes(cells2,cells2+2,arr1));
02482   CPPUNIT_ASSERT(partMesh2);
02483   CPPUNIT_ASSERT_EQUAL(2,partMesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
02484   CPPUNIT_ASSERT_EQUAL(12,partMesh2->getNumberOfNodes());
02485   
02486   int cells3[2]={2,3};
02487   DataArrayInt* arr2;
02488   MEDCouplingUMesh *partMesh3=
02489     dynamic_cast<MEDCouplingUMesh *>(partMesh1->buildPartAndReduceNodes(cells3,cells3+2,arr2));
02490   CPPUNIT_ASSERT(partMesh3);
02491   CPPUNIT_ASSERT_EQUAL(2,partMesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8));
02492   CPPUNIT_ASSERT_EQUAL(12,partMesh3->getNumberOfNodes());
02493   
02494   CPPUNIT_ASSERT_THROW(mesh1->simplexize(0),INTERP_KERNEL::Exception);
02495   CPPUNIT_ASSERT_THROW(mesh1->getMeasureFieldOnNode(true),INTERP_KERNEL::Exception);
02496 
02497   double bbox1[6];
02498   double bbox2[6];
02499   mesh1->getBoundingBox(bbox1);
02500   partMesh1->getBoundingBox(bbox2);
02501   for(int i=0;i<6;i++)
02502     CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
02503   partMesh3->getBoundingBox(bbox1);
02504   partMesh2->getBoundingBox(bbox2);
02505   for(int i=0;i<6;i++)
02506     CPPUNIT_ASSERT_DOUBLES_EQUAL(bbox1[i],bbox2[i],1e-12);
02507   
02508   CPPUNIT_ASSERT_THROW(mesh1->buildOrthogonalField(),INTERP_KERNEL::Exception);
02509   MEDCouplingCMesh *mesh2d=MEDCouplingCMesh::New();
02510   mesh2d->setCoords(coordsX1,coordsY1);
02511   MEDCouplingFieldDouble *f1=mesh2d->buildOrthogonalField();
02512   
02513   std::vector<double> tinyInfoD;
02514   std::vector<int> tinyInfo;
02515   std::vector<std::string> littleStrings;
02516   mesh2d->getTinySerializationInformation(tinyInfoD, tinyInfo, littleStrings);
02517   CPPUNIT_ASSERT_EQUAL(5,(int)tinyInfo.size());
02518   CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[0]);   //x
02519   CPPUNIT_ASSERT_EQUAL(4,(int)tinyInfo[1]);   //y
02520   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[2]);  //z
02521   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[3]);  //it
02522   CPPUNIT_ASSERT_EQUAL(-1,(int)tinyInfo[4]);   //order
02523   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,tinyInfoD[0],1e-14); //time
02524   DataArrayInt* d1=DataArrayInt::New();
02525   DataArrayDouble* d2=DataArrayDouble::New();
02526   mesh2d->resizeForUnserialization(tinyInfo, d1, d2, littleStrings);
02527   CPPUNIT_ASSERT_EQUAL(0,d1->getNumberOfTuples());
02528   CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples());
02529  
02530   partMesh1->decrRef();
02531   partMesh2->decrRef();
02532   partMesh3->decrRef();
02533   mesh2d->decrRef();
02534   arr1->decrRef();
02535   arr2->decrRef();
02536   f1->decrRef();
02537   d1->decrRef();
02538   d2->decrRef();
02539   coordsX1->decrRef();
02540   coordsY1->decrRef();
02541   coordsZ1->decrRef();
02542   mesh1->decrRef();
02543 }
02544 
02545 void MEDCouplingBasicsTest1::testScale()
02546 {
02547   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
02548   const double pos[2]={0.2,0.2};
02549   mesh->scale(pos,0.5);
02550   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,
02551                               -0.05,0.45, 0.2,0.45, 0.45,0.45};
02552   const double *val=mesh->getCoords()->getConstPointer();
02553   for(int i=0;i<18;i++)
02554     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],val[i],1e-12);
02555   //
02556   mesh->decrRef();
02557 }
02558 
02559 void MEDCouplingBasicsTest1::testTryToShareSameCoords()
02560 {
02561   MEDCouplingUMesh *m1=build2DTargetMesh_1();
02562   MEDCouplingUMesh *m2=build2DTargetMesh_1();
02563   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
02564   m1->tryToShareSameCoords(*m2,1e-12);
02565   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
02566   m1->tryToShareSameCoords(*m2,1e-12);
02567   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
02568   m2->tryToShareSameCoords(*m1,1e-12);
02569   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
02570   m1->decrRef();
02571   m2->decrRef();
02572   //
02573   m1=build2DTargetMesh_1();
02574   m2=build2DTargetMesh_2();
02575   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
02576   m1->tryToShareSameCoords(*m2,1e-12);
02577   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
02578   m1->tryToShareSameCoords(*m2,1e-12);
02579   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
02580   m2->tryToShareSameCoords(*m1,1e-12);
02581   CPPUNIT_ASSERT(m1->getCoords()==m2->getCoords());
02582   m1->decrRef();
02583   m2->decrRef();
02584   //
02585   m1=build2DTargetMesh_1();
02586   m2=build2DSourceMesh_1();
02587   CPPUNIT_ASSERT(m1->getCoords()!=m2->getCoords());
02588   CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoords(*m2,1e-12),INTERP_KERNEL::Exception);
02589   m1->decrRef();
02590   m2->decrRef();
02591 }
02592 
02593 void MEDCouplingBasicsTest1::testFindNodeOnPlane()
02594 {
02595   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
02596   std::vector<int> n;
02597   double pt[3]={300.,300.,0.};
02598   double v[3]={0.,0.,2.};
02599   mesh->findNodesOnPlane(pt,v,1e-12,n);
02600   CPPUNIT_ASSERT_EQUAL(9,(int)n.size());
02601   MEDCouplingUMesh *m3dSurf=(MEDCouplingUMesh *)mesh->buildFacePartOfMySelfNode(&n[0],&n[0]+n.size(),true);
02602   MEDCouplingExtrudedMesh *me=MEDCouplingExtrudedMesh::New(mesh,m3dSurf,0);
02603   const DataArrayInt *da=me->getMesh3DIds();
02604   CPPUNIT_ASSERT_EQUAL(8,me->getNumberOfCells());
02605   const int expected[8]={0,1,2,3,4,5,6,7};
02606   const int *val=da->getConstPointer();
02607   for(int i=0;i<8;i++)
02608     CPPUNIT_ASSERT_EQUAL(expected[i],val[i]);
02609   me->decrRef();
02610   m3dSurf->decrRef();
02611   mesh->decrRef();
02612 }
02613 
02614 void MEDCouplingBasicsTest1::testRenumberCells()
02615 {
02616   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
02617   MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
02618   CPPUNIT_ASSERT(m->isEqual(m2,0));
02619   const int arr[5]={12,3,25,2,26};
02620   m->renumberCells(arr,true);
02621   CPPUNIT_ASSERT(!m->isEqual(m2,0));
02622   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(0));
02623   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
02624   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(2));
02625   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
02626   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,m->getTypeOfCell(4));
02627   const int arr2[5]={5,-1,-5,4,8};
02628   m->renumberCells(arr2,true);
02629   CPPUNIT_ASSERT(m->isEqual(m2,0));
02630   m->decrRef();
02631   m2->decrRef();
02632 }
02633 
02634 void MEDCouplingBasicsTest1::testChangeSpaceDimension()
02635 {
02636   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
02637   MEDCouplingUMesh *m2=build2DTargetMesh_1();
02638   //
02639   CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
02640   m1->changeSpaceDimension(2);
02641   CPPUNIT_ASSERT_EQUAL(2,m1->getSpaceDimension());
02642   m1->setName(m2->getName());
02643   CPPUNIT_ASSERT(m1->isEqual(m2,1e-12));
02644   m1->changeSpaceDimension(3);
02645   CPPUNIT_ASSERT_EQUAL(3,m1->getSpaceDimension());
02646   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.};
02647   const double *val=m1->getCoords()->getConstPointer();
02648   for(int i=0;i<27;i++)
02649     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i],val[i],1e-14);
02650   //
02651   m1->decrRef();
02652   m2->decrRef();
02653 }