Back to index

salome-med  6.5.0
MEDCouplingBasicsTest3.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 "MEDCouplingBasicsTest3.hxx"
00021 #include "MEDCouplingUMesh.hxx"
00022 #include "MEDCouplingCMesh.hxx"
00023 #include "MEDCouplingExtrudedMesh.hxx"
00024 #include "MEDCouplingFieldDouble.hxx"
00025 #include "MEDCouplingMemArray.hxx"
00026 #include "MEDCouplingGaussLocalization.hxx"
00027 
00028 #include <cmath>
00029 #include <functional>
00030 #include <iterator>
00031 
00032 using namespace ParaMEDMEM;
00033 
00034 void MEDCouplingBasicsTest3::testGetMeasureFieldCMesh1()
00035 {
00036   MEDCouplingCMesh *m=MEDCouplingCMesh::New();
00037   DataArrayDouble *da=DataArrayDouble::New();
00038   const double discX[4]={2.3,3.4,5.8,10.2};
00039   const double discY[3]={12.3,23.4,45.8};
00040   const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
00041   da->alloc(4,1);
00042   std::copy(discX,discX+4,da->getPointer());
00043   m->setCoordsAt(0,da);
00044   da->decrRef();
00045   m->checkCoherency();
00046   CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
00047   CPPUNIT_ASSERT_EQUAL(3,m->getNumberOfCells());
00048   CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
00049   MEDCouplingFieldDouble *f=m->getMeasureField(true);
00050   CPPUNIT_ASSERT_EQUAL(3,f->getNumberOfTuples());
00051   CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
00052   const double expected1[3]={1.1,2.4,4.4};
00053   for(int i=0;i<3;i++)
00054     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
00055   f->decrRef();
00056   DataArrayDouble *coords=m->getCoordinatesAndOwner();
00057   CPPUNIT_ASSERT_EQUAL(4,coords->getNumberOfTuples());
00058   CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
00059   for(int i=0;i<4;i++)
00060     CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
00061   coords->decrRef();
00062   coords=m->getBarycenterAndOwner();
00063   CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfTuples());
00064   CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
00065   const double expected1_3[3]={2.85,4.6,8.};
00066   for(int i=0;i<3;i++)
00067     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
00068   coords->decrRef();
00069   //
00070   da=DataArrayDouble::New();
00071   da->alloc(3,1);
00072   std::copy(discY,discY+3,da->getPointer());
00073   m->setCoordsAt(1,da);
00074   da->decrRef();
00075   m->checkCoherency();
00076   CPPUNIT_ASSERT_EQUAL(12,m->getNumberOfNodes());
00077   CPPUNIT_ASSERT_EQUAL(6,m->getNumberOfCells());
00078   CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
00079   f=m->getMeasureField(true);
00080   CPPUNIT_ASSERT_EQUAL(6,f->getNumberOfTuples());
00081   CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
00082   const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
00083   for(int i=0;i<6;i++)
00084     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
00085   f->decrRef();
00086   coords=m->getCoordinatesAndOwner();
00087   CPPUNIT_ASSERT_EQUAL(12,coords->getNumberOfTuples());
00088   CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
00089   const double expected2_2[24]={2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8};
00090   for(int i=0;i<24;i++)
00091     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
00092   coords->decrRef();
00093   coords=m->getBarycenterAndOwner();
00094   CPPUNIT_ASSERT_EQUAL(6,coords->getNumberOfTuples());
00095   CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
00096   const double expected2_3[12]={2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6};
00097   for(int i=0;i<12;i++)
00098     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
00099   coords->decrRef();
00100   //
00101   da=DataArrayDouble::New();
00102   da->alloc(5,1);
00103   std::copy(discZ,discZ+5,da->getPointer());
00104   m->setCoordsAt(2,da);
00105   da->decrRef();
00106   m->checkCoherency();
00107   CPPUNIT_ASSERT_EQUAL(60,m->getNumberOfNodes());
00108   CPPUNIT_ASSERT_EQUAL(24,m->getNumberOfCells());
00109   CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
00110   f=m->getMeasureField(true);
00111   CPPUNIT_ASSERT_EQUAL(24,f->getNumberOfTuples());
00112   CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
00113   const double expected3[24]={23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224};
00114   for(int i=0;i<24;i++)
00115     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
00116   f->decrRef();
00117   coords=m->getCoordinatesAndOwner();
00118   CPPUNIT_ASSERT_EQUAL(60,coords->getNumberOfTuples());
00119   CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
00120   const double expected3_2[180]={
00121     2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
00122     2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
00123     2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
00124     2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
00125     2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67
00126   };
00127   for(int i=0;i<180;i++)
00128     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
00129   coords->decrRef();
00130   coords=m->getBarycenterAndOwner();
00131   CPPUNIT_ASSERT_EQUAL(24,coords->getNumberOfTuples());
00132   CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
00133   const double expected3_3[72]={
00134     2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
00135     2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
00136     2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
00137     2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4
00138   };
00139   for(int i=0;i<72;i++)
00140     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
00141   coords->decrRef();
00142   //
00143   m->decrRef();
00144 }
00145 
00146 void MEDCouplingBasicsTest3::testFieldDoubleZipCoords1()
00147 {
00148   MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
00149   MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
00150   f->getArray()->setInfoOnComponent(0,"titi");
00151   f->getArray()->setInfoOnComponent(1,"tutu");
00152   f->checkCoherency();
00153   CPPUNIT_ASSERT_EQUAL(18,f->getNumberOfTuples());
00154   CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
00155   const double expected1[36]={-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
00156   for(int i=0;i<36;i++)
00157     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
00158   CPPUNIT_ASSERT(f->zipCoords());
00159   f->checkCoherency();
00160   const double expected2[30]={-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
00161   for(int i=0;i<30;i++)
00162     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
00163   CPPUNIT_ASSERT(!f->zipCoords());
00164   f->checkCoherency();
00165   for(int i=0;i<30;i++)
00166     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
00167   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
00168   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
00169   f->decrRef();
00170   m->decrRef();
00171 }
00172 
00173 void MEDCouplingBasicsTest3::testFieldDoubleZipConnectivity1()
00174 {
00175   MEDCouplingUMesh *m1=build2DTargetMesh_1();
00176   MEDCouplingUMesh *m2=build2DTargetMesh_1();
00177   const int cells1[3]={2,3,4};
00178   MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
00179   MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
00180   CPPUNIT_ASSERT(m3);
00181   m2->decrRef();
00182   MEDCouplingUMesh *m4=build2DSourceMesh_1();
00183   MEDCouplingUMesh *m5=MEDCouplingUMesh::MergeUMeshes(m1,m3);
00184   m1->decrRef();
00185   m3->decrRef();
00186   MEDCouplingUMesh *m6=MEDCouplingUMesh::MergeUMeshes(m5,m4);
00187   m4->decrRef();
00188   m5->decrRef();
00189   //
00190   CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
00191   CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
00192   bool areNodesMerged;
00193   int newNbOfNodes;
00194   DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
00195   CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
00196   arr->decrRef();
00197   MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
00198   MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
00199   CPPUNIT_ASSERT_EQUAL(10,f->getNumberOfTuples());
00200   CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
00201   const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
00202                               -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
00203                               0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
00204   for(int i=0;i<20;i++)
00205     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
00206   f->getArray()->setInfoOnComponent(0,"titi");
00207   f->getArray()->setInfoOnComponent(1,"tutu");
00208   f->checkCoherency();
00209   CPPUNIT_ASSERT(f->zipConnectivity(0));
00210   const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
00211                               -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
00212   CPPUNIT_ASSERT_EQUAL(7,f->getNumberOfTuples());
00213   CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
00214   for(int i=0;i<14;i++)
00215     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
00216   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
00217   CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
00218   CPPUNIT_ASSERT(!f->zipConnectivity(0));
00219   f->decrRef();
00220   //
00221   const double expected3[18]={-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7, 
00222                               -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
00223   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
00224   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
00225   for(int i=0;i<18;i++)
00226     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
00227   CPPUNIT_ASSERT(f2->zipConnectivity(0));
00228   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
00229   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
00230   for(int i=0;i<18;i++)
00231     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
00232   f2->decrRef();
00233   //
00234   m6->decrRef();
00235 }
00236 
00237 void MEDCouplingBasicsTest3::testDaDoubleRenumber1()
00238 {
00239   DataArrayDouble *a=DataArrayDouble::New();
00240   a->alloc(7,2);
00241   a->setInfoOnComponent(0,"toto");
00242   a->setInfoOnComponent(1,"tata");
00243   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
00244   std::copy(arr1,arr1+14,a->getPointer());
00245   //
00246   const int arr2[7]={3,1,0,6,5,4,2};
00247   DataArrayDouble *b=a->renumber(arr2);
00248   CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
00249   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
00250   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
00251   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
00252   const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
00253   for(int i=0;i<14;i++)
00254     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
00255   b->decrRef();
00256   a->decrRef();
00257   //
00258   DataArrayInt *c=DataArrayInt::New();
00259   c->alloc(7,2);
00260   c->setInfoOnComponent(0,"toto");
00261   c->setInfoOnComponent(1,"tata");
00262   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
00263   std::copy(arr3,arr3+14,c->getPointer());
00264   DataArrayInt *d=c->renumber(arr2);
00265   CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
00266   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
00267   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
00268   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
00269   const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
00270   for(int i=0;i<14;i++)
00271     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
00272   c->decrRef();
00273   d->decrRef();
00274 }
00275 
00276 void MEDCouplingBasicsTest3::testDaDoubleRenumberAndReduce1()
00277 {
00278   DataArrayDouble *a=DataArrayDouble::New();
00279   a->alloc(7,2);
00280   a->setInfoOnComponent(0,"toto");
00281   a->setInfoOnComponent(1,"tata");
00282   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
00283   std::copy(arr1,arr1+14,a->getPointer());
00284   //
00285   const int arr2[7]={2,-1,1,-1,0,4,3};
00286   DataArrayDouble *b=a->renumberAndReduce(arr2,5);
00287   CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
00288   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
00289   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
00290   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
00291   const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
00292   for(int i=0;i<10;i++)
00293     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
00294   b->decrRef();
00295   a->decrRef();
00296   //
00297   DataArrayInt *c=DataArrayInt::New();
00298   c->alloc(7,2);
00299   c->setInfoOnComponent(0,"toto");
00300   c->setInfoOnComponent(1,"tata");
00301   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
00302   std::copy(arr3,arr3+14,c->getPointer());
00303   DataArrayInt *d=c->renumberAndReduce(arr2,5);
00304   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
00305   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
00306   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
00307   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
00308   const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
00309   for(int i=0;i<10;i++)
00310     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
00311   c->decrRef();
00312   d->decrRef();
00313 }
00314 
00315 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlace1()
00316 {
00317   DataArrayDouble *a=DataArrayDouble::New();
00318   a->alloc(7,2);
00319   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
00320   std::copy(arr1,arr1+14,a->getPointer());
00321   //
00322   const int arr2[7]={3,1,0,6,5,4,2};
00323   a->renumberInPlace(arr2);
00324   CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
00325   CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
00326   const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
00327   for(int i=0;i<14;i++)
00328     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
00329   a->decrRef();
00330   //
00331   DataArrayInt *c=DataArrayInt::New();
00332   c->alloc(7,2);
00333   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
00334   std::copy(arr3,arr3+14,c->getPointer());
00335   c->renumberInPlace(arr2);
00336   CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
00337   CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
00338   const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
00339   for(int i=0;i<14;i++)
00340     CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
00341   c->decrRef();
00342 }
00343 
00344 void MEDCouplingBasicsTest3::testDaDoubleRenumberR1()
00345 {
00346   DataArrayDouble *a=DataArrayDouble::New();
00347   a->alloc(7,2);
00348   a->setInfoOnComponent(0,"toto");
00349   a->setInfoOnComponent(1,"tata");
00350   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
00351   std::copy(arr1,arr1+14,a->getPointer());
00352   //
00353   const int arr2[7]={3,1,0,6,5,4,2};
00354   DataArrayDouble *b=a->renumberR(arr2);
00355   CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
00356   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
00357   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
00358   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
00359   const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
00360   for(int i=0;i<14;i++)
00361     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
00362   b->decrRef();
00363   a->decrRef();
00364   //
00365   DataArrayInt *c=DataArrayInt::New();
00366   c->alloc(7,2);
00367   c->setInfoOnComponent(0,"toto");
00368   c->setInfoOnComponent(1,"tata");
00369   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
00370   std::copy(arr3,arr3+14,c->getPointer());
00371   DataArrayInt *d=c->renumberR(arr2);
00372   CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
00373   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
00374   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
00375   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
00376   const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
00377   for(int i=0;i<14;i++)
00378     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
00379   c->decrRef();
00380   d->decrRef();
00381 }
00382 
00383 void MEDCouplingBasicsTest3::testDaDoubleRenumberInPlaceR1()
00384 {
00385   DataArrayDouble *a=DataArrayDouble::New();
00386   a->alloc(7,2);
00387   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
00388   std::copy(arr1,arr1+14,a->getPointer());
00389   //
00390   const int arr2[7]={3,1,0,6,5,4,2};
00391   a->renumberInPlaceR(arr2);
00392   CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
00393   CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
00394   const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
00395   for(int i=0;i<14;i++)
00396     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
00397   a->decrRef();
00398   //
00399   DataArrayInt *c=DataArrayInt::New();
00400   c->alloc(7,2);
00401   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
00402   std::copy(arr3,arr3+14,c->getPointer());
00403   c->renumberInPlaceR(arr2);
00404   CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
00405   CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
00406   const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
00407   for(int i=0;i<14;i++)
00408     CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
00409   c->decrRef();
00410 }
00411 
00412 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleId1()
00413 {
00414   DataArrayDouble *a=DataArrayDouble::New();
00415   a->alloc(7,2);
00416   a->setInfoOnComponent(0,"toto");
00417   a->setInfoOnComponent(1,"tata");
00418   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
00419   std::copy(arr1,arr1+14,a->getPointer());
00420   //
00421   const int arr2[7]={4,2,0,6,5};
00422   DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
00423   CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
00424   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
00425   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
00426   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
00427   const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
00428   for(int i=0;i<10;i++)
00429     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
00430   b->decrRef();
00431   a->decrRef();
00432   //
00433   DataArrayInt *c=DataArrayInt::New();
00434   c->alloc(7,2);
00435   c->setInfoOnComponent(0,"toto");
00436   c->setInfoOnComponent(1,"tata");
00437   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
00438   std::copy(arr3,arr3+14,c->getPointer());
00439   DataArrayInt *d=c->selectByTupleId(arr2,arr2+5);
00440   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
00441   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
00442   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
00443   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
00444   const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
00445   for(int i=0;i<10;i++)
00446     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
00447   c->decrRef();
00448   d->decrRef();
00449 }
00450 
00451 void MEDCouplingBasicsTest3::testDaDoubleGetMinMaxValues1()
00452 {
00453   DataArrayDouble *a=DataArrayDouble::New();
00454   a->alloc(9,1);
00455   const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
00456   std::copy(arr1,arr1+9,a->getPointer());
00457   int where;
00458   double m=a->getMaxValue(where);
00459   CPPUNIT_ASSERT_EQUAL(1,where);
00460   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
00461   DataArrayInt *ws;
00462   m=a->getMaxValue2(ws);
00463   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
00464   CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
00465   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
00466   const int expected1[3]={1,4,8};
00467   for(int i=0;i<3;i++)
00468     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
00469   ws->decrRef();
00470   a->decrRef();
00471   a=DataArrayDouble::New();
00472   const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
00473   a->alloc(9,1);
00474   std::copy(arr2,arr2+9,a->getPointer());
00475   where=-2;
00476   m=a->getMinValue(where);
00477   CPPUNIT_ASSERT_EQUAL(1,where);
00478   CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
00479   m=a->getMinValue2(ws);
00480   CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
00481   CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
00482   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
00483   for(int i=0;i<3;i++)
00484     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
00485   ws->decrRef();
00486   a->decrRef();
00487 }
00488 
00489 void MEDCouplingBasicsTest3::testFieldDoubleGetMinMaxValues2()
00490 {
00491   MEDCouplingUMesh *m1=0;
00492   MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
00493   m1->decrRef();
00494   CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
00495   const double arr1[18]={8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71};
00496   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00497   DataArrayDouble *a=DataArrayDouble::New();
00498   a->alloc(18,1);
00499   std::copy(arr1,arr1+18,a->getPointer());
00500   f->setArray(a);
00501   a->decrRef();
00502   f->setMesh(m2);
00503   //
00504   f->checkCoherency();
00505   double m=f->getMaxValue();
00506   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
00507   DataArrayInt *ws;
00508   m=f->getMaxValue2(ws);
00509   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
00510   CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
00511   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
00512   const int expected1[4]={0,3,7,17};
00513   for(int i=0;i<4;i++)
00514     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
00515   ws->decrRef();
00516   //
00517   const double arr2[18]={-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71};
00518   std::copy(arr2,arr2+18,a->getPointer());
00519   f->checkCoherency();
00520   m=f->getMinValue();
00521   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
00522   m=f->getMinValue2(ws);
00523   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
00524   CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
00525   CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
00526   for(int i=0;i<4;i++)
00527     CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
00528   ws->decrRef();
00529   //
00530   f->decrRef();
00531   m2->decrRef();
00532 }
00533 
00534 void MEDCouplingBasicsTest3::testBuildUnstructuredCMesh1()
00535 {
00536   MEDCouplingCMesh *m=MEDCouplingCMesh::New();
00537   DataArrayDouble *da=DataArrayDouble::New();
00538   const double discX[4]={2.3,3.4,5.8,10.2};
00539   const double discY[3]={12.3,23.4,45.8};
00540   const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
00541   da->alloc(4,1);
00542   std::copy(discX,discX+4,da->getPointer());
00543   m->setCoordsAt(0,da);
00544   da->decrRef();
00545   m->checkCoherency();
00546   double pos=2.4;
00547   CPPUNIT_ASSERT_EQUAL(0,m->getCellContainingPoint(&pos,1e-12));
00548   pos=3.7;
00549   CPPUNIT_ASSERT_EQUAL(1,m->getCellContainingPoint(&pos,1e-12));
00550   pos=5.9;
00551   CPPUNIT_ASSERT_EQUAL(2,m->getCellContainingPoint(&pos,1e-12));
00552   pos=10.3;
00553   CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
00554   pos=1.3;
00555   CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
00556   //
00557   MEDCouplingUMesh *m2=m->buildUnstructured();
00558   m2->checkCoherency();
00559   MEDCouplingFieldDouble *f1=m->getMeasureField(false);
00560   MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
00561   CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),3);
00562   CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),3);
00563   CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
00564   CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
00565   for(int i=0;i<3;i++)
00566     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
00567   da=DataArrayDouble::New();
00568   da->alloc(3,1);
00569   std::copy(discY,discY+3,da->getPointer());
00570   m->setCoordsAt(1,da);
00571   da->decrRef();
00572   m2->decrRef();
00573   f1->decrRef();
00574   f2->decrRef();
00575   //
00576   m2=m->buildUnstructured();
00577   m2->checkCoherency();
00578   f1=m->getMeasureField(false);
00579   f2=m2->getMeasureField(false);
00580   CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),6);
00581   CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),6);
00582   CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
00583   CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
00584   for(int i=0;i<6;i++)
00585     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
00586   f1->decrRef();
00587   f2->decrRef();
00588   m2->decrRef();
00589   //
00590   da=DataArrayDouble::New();
00591   da->alloc(5,1);
00592   std::copy(discZ,discZ+5,da->getPointer());
00593   m->setCoordsAt(2,da);
00594   da->decrRef();
00595   m2=m->buildUnstructured();
00596   m2->checkCoherency();
00597   f1=m->getMeasureField(false);
00598   f2=m2->getMeasureField(false);
00599   CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),24);
00600   CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),24);
00601   CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
00602   CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
00603   for(int i=0;i<24;i++)
00604     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
00605   f1->decrRef();
00606   f2->decrRef();
00607   //
00608   double pos1[3]={5.,30.,2.};
00609   CPPUNIT_ASSERT_EQUAL(16,m->getCellContainingPoint(pos1,1e-12));
00610   //
00611   const double pt[3]={2.4,12.7,-3.4};
00612   m->scale(pt,3.7);
00613   MEDCouplingUMesh *m3=m->buildUnstructured();
00614   m2->scale(pt,3.7);
00615   CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
00616   m2->decrRef();
00617   m3->decrRef();
00618   //
00619   m->decrRef();
00620 }
00621 
00622 void MEDCouplingBasicsTest3::testDataArrayIntInvertO2NNO21()
00623 {
00624   const int arr1[6]={2,0,4,1,5,3};
00625   DataArrayInt *da=DataArrayInt::New();
00626   da->alloc(6,1);
00627   std::copy(arr1,arr1+6,da->getPointer());
00628   DataArrayInt *da2=da->invertArrayO2N2N2O(6);
00629   CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
00630   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
00631   const int expected1[6]={1,3,0,5,2,4};
00632   for(int i=0;i<6;i++)
00633     CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
00634   DataArrayInt *da3=da2->invertArrayN2O2O2N(6);
00635   for(int i=0;i<6;i++)
00636     CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
00637   da3->decrRef();
00638   da2->decrRef();
00639   da->decrRef();
00640   //
00641   const int arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
00642   da=DataArrayInt::New();
00643   da->alloc(10,1);
00644   std::copy(arr2,arr2+10,da->getPointer());
00645   da2=da->invertArrayO2N2N2O(6);
00646   CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
00647   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
00648   const int expected2[10]={5,7,8,0,3,2};
00649   for(int i=0;i<6;i++)
00650     CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
00651   da3=da2->invertArrayN2O2O2N(10);
00652   for(int i=0;i<10;i++)
00653     CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
00654   da3->decrRef();
00655   da2->decrRef();
00656   da->decrRef();
00657 }
00658 
00659 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1()
00660 {
00661   const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
00662   DataArrayDouble *a1=DataArrayDouble::New();
00663   a1->alloc(5,4);
00664   std::copy(arr1,arr1+20,a1->getPointer());
00665   a1->setInfoOnComponent(0,"aaaa");
00666   a1->setInfoOnComponent(1,"bbbb");
00667   a1->setInfoOnComponent(2,"cccc");
00668   a1->setInfoOnComponent(3,"dddd");
00669   const int arr2[6]={1,2,1,2,0,0};
00670   std::vector<int> arr2V(arr2,arr2+6);
00671   DataArrayDouble *a2=a1->keepSelectedComponents(arr2V);
00672   CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
00673   CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
00674   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
00675   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc");
00676   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb");
00677   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
00678   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
00679   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
00680   const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
00681   for(int i=0;i<30;i++)
00682     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14);
00683   DataArrayInt *a3=a1->convertToIntArr();
00684   DataArrayInt *a4=a3->keepSelectedComponents(arr2V);
00685   CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
00686   CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
00687   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
00688   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc");
00689   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb");
00690   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
00691   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
00692   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
00693   for(int i=0;i<30;i++)
00694     CPPUNIT_ASSERT_EQUAL(int(expected1[i]),a4->getIJ(0,i));
00695   // setSelectedComponents
00696   const int arr3[2]={3,2};
00697   std::vector<int> arr3V(arr3,arr3+2);
00698   DataArrayDouble *a5=a1->keepSelectedComponents(arr3V);
00699   a5->setInfoOnComponent(0,"eeee");
00700   a5->setInfoOnComponent(1,"ffff");
00701   const int arr4[2]={1,2};
00702   std::vector<int> arr4V(arr4,arr4+2);
00703   a2->setSelectedComponents(a5,arr4V);
00704   CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents());
00705   CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples());
00706   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb");
00707   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee");
00708   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff");
00709   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc");
00710   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa");
00711   CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa");
00712   const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
00713   for(int i=0;i<30;i++)
00714     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14);
00715   DataArrayInt *a6=a5->convertToIntArr();
00716   a6->setInfoOnComponent(0,"eeee");
00717   a6->setInfoOnComponent(1,"ffff");
00718   a4->setSelectedComponents(a6,arr4V);
00719   CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents());
00720   CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples());
00721   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb");
00722   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee");
00723   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff");
00724   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc");
00725   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa");
00726   CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa");
00727   for(int i=0;i<30;i++)
00728     CPPUNIT_ASSERT_EQUAL(int(expected2[i]),a4->getIJ(0,i));
00729   // test of throw
00730   const int arr5[3]={2,3,6};
00731   const int arr6[3]={2,7,5};
00732   const int arr7[4]={2,1,4,6};
00733   std::vector<int> arr5V(arr5,arr5+3);
00734   std::vector<int> arr6V(arr6,arr6+3);
00735   std::vector<int> arr7V(arr7,arr7+4);
00736   CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception);
00737   CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception);
00738   CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
00739   arr7V.resize(3);
00740   CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception);
00741   //
00742   a6->decrRef();
00743   a5->decrRef();
00744   a4->decrRef();
00745   a3->decrRef();
00746   a2->decrRef();
00747   a1->decrRef();
00748 }
00749 
00750 void MEDCouplingBasicsTest3::testKeepSetSelectedComponent2()
00751 {
00752   MEDCouplingUMesh *m1=build2DTargetMesh_1();
00753   const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.};
00754   DataArrayDouble *a1=DataArrayDouble::New();
00755   a1->alloc(5,4);
00756   std::copy(arr1,arr1+20,a1->getPointer());
00757   a1->setInfoOnComponent(0,"aaaa");
00758   a1->setInfoOnComponent(1,"bbbb");
00759   a1->setInfoOnComponent(2,"cccc");
00760   a1->setInfoOnComponent(3,"dddd");
00761   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00762   f1->setTime(2.3,4,5);
00763   f1->setMesh(m1);
00764   f1->setName("f1");
00765   f1->setArray(a1);
00766   f1->checkCoherency();
00767   //
00768   const int arr2[6]={1,2,1,2,0,0};
00769   std::vector<int> arr2V(arr2,arr2+6);
00770   MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V);
00771   CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh());
00772   CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME);
00773   int dt,it;
00774   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
00775   CPPUNIT_ASSERT_EQUAL(4,dt);
00776   CPPUNIT_ASSERT_EQUAL(5,it);
00777   f2->checkCoherency();
00778   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
00779   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
00780   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
00781   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc");
00782   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb");
00783   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
00784   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
00785   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
00786   const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.};
00787   for(int i=0;i<30;i++)
00788     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14);
00789   //setSelectedComponents
00790   const int arr3[2]={3,2};
00791   std::vector<int> arr3V(arr3,arr3+2);
00792   MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V);
00793   f5->setTime(6.7,8,9);
00794   f5->getArray()->setInfoOnComponent(0,"eeee");
00795   f5->getArray()->setInfoOnComponent(1,"ffff");
00796   f5->checkCoherency();
00797   const int arr4[2]={1,2};
00798   std::vector<int> arr4V(arr4,arr4+2);
00799   f2->setSelectedComponents(f5,arr4V);
00800   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
00801   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
00802   f2->checkCoherency();
00803   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13);
00804   CPPUNIT_ASSERT_EQUAL(4,dt);
00805   CPPUNIT_ASSERT_EQUAL(5,it);
00806   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb");
00807   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee");
00808   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff");
00809   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc");
00810   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa");
00811   CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa");
00812   const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.};
00813   for(int i=0;i<30;i++)
00814     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14);
00815   f5->decrRef();
00816   f1->decrRef();
00817   f2->decrRef();
00818   a1->decrRef();
00819   m1->decrRef();
00820 }
00821 
00822 void MEDCouplingBasicsTest3::testElementaryDAThrowAndSpecialCases()
00823 {
00824   DataArrayInt *da=DataArrayInt::New();
00825   CPPUNIT_ASSERT_THROW(da->checkAllocated(),INTERP_KERNEL::Exception);
00826   CPPUNIT_ASSERT_THROW(da->fillWithValue(1),INTERP_KERNEL::Exception);
00827   CPPUNIT_ASSERT_THROW(da->iota(1),INTERP_KERNEL::Exception);
00828   da->alloc(7,1);
00829   da->fillWithValue(11); //11,11,11,11...
00830   da->iota(10); //10,11,12,13...
00831   
00832   DataArrayInt *db=DataArrayInt::New();
00833   db->alloc(7,2);
00834   
00835   DataArrayDouble *dbl2=DataArrayDouble::New();
00836   dbl2->alloc(7,2);
00837   CPPUNIT_ASSERT_THROW(dbl2->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
00838   CPPUNIT_ASSERT_THROW(dbl2->sort(),INTERP_KERNEL::Exception);
00839   CPPUNIT_ASSERT_THROW(dbl2->reverse(),INTERP_KERNEL::Exception);
00840   CPPUNIT_ASSERT_THROW(dbl2->iota(10.),INTERP_KERNEL::Exception);
00841   
00842   DataArrayDouble *dbl=DataArrayDouble::New();
00843   //DataArrayDouble not allocated yet
00844   CPPUNIT_ASSERT_THROW(dbl->iota(10.),INTERP_KERNEL::Exception);
00845   CPPUNIT_ASSERT_THROW(dbl->isUniform(10.,1e-15),INTERP_KERNEL::Exception);
00846   CPPUNIT_ASSERT_THROW(dbl->sort(),INTERP_KERNEL::Exception);
00847   CPPUNIT_ASSERT_THROW(dbl->reverse(),INTERP_KERNEL::Exception);
00848   CPPUNIT_ASSERT_THROW(dbl->fromNoInterlace(),INTERP_KERNEL::Exception);
00849   CPPUNIT_ASSERT_THROW(dbl->toNoInterlace(),INTERP_KERNEL::Exception);
00850   
00851   dbl->alloc(7,1);
00852   dbl->iota(10.);
00853   CPPUNIT_ASSERT(!dbl->isUniform(10.,1e-15));
00854   dbl->sort();
00855   CPPUNIT_ASSERT(dbl->isMonotonic(true, .99));
00856   CPPUNIT_ASSERT(dbl->isMonotonic(true, -.99));
00857   CPPUNIT_ASSERT(!dbl->isMonotonic(true, 1.1));
00858   CPPUNIT_ASSERT(!dbl->isMonotonic(true, -1.1));
00859   dbl->reverse();
00860   CPPUNIT_ASSERT(dbl->isMonotonic(false, .99));
00861   CPPUNIT_ASSERT(!dbl->isMonotonic(false, 1.1));
00862   CPPUNIT_ASSERT(!dbl->isMonotonic(false, -1.1));
00863   
00864   DataArrayInt *dc=DataArrayInt::New();
00865   dc->alloc(14,1);
00866   
00867   DataArrayDouble *dd=DataArrayDouble::New();
00868   CPPUNIT_ASSERT_THROW(dd->checkAllocated(),INTERP_KERNEL::Exception);
00869   CPPUNIT_ASSERT_THROW(dd->fillWithValue(1.),INTERP_KERNEL::Exception);
00870   CPPUNIT_ASSERT_THROW(dd->iota(1.),INTERP_KERNEL::Exception);
00871   CPPUNIT_ASSERT(!((dd->repr().find("No data"))==std::string::npos));
00872   
00873   dd->alloc(0,1); //Allocated but nbOfElements==0!
00874   CPPUNIT_ASSERT(!((dd->repr().find("Number of tuples : 0"))==std::string::npos));
00875   CPPUNIT_ASSERT(!((dd->repr().find("Empty Data"))==std::string::npos));
00876   dd->fillWithValue(11); //?!...
00877   dd->iota(10); //?!...
00878   CPPUNIT_ASSERT(dd->isMonotonic(true, 1.));
00879   CPPUNIT_ASSERT(dd->isMonotonic(false, 1.));
00880  
00881   CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
00882   CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception);
00883   std::vector<int> cIds(2,2);
00884   CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
00885   cIds[0]=1;
00886   cIds[0]=-1;
00887   CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception);
00888   
00889   std::vector<std::string> info(2,"infoOfOneComponent");
00890   CPPUNIT_ASSERT_THROW(da->setInfoOnComponents(info),INTERP_KERNEL::Exception);
00891   CPPUNIT_ASSERT_THROW(da->setInfoOnComponent(1,info[0].c_str()),INTERP_KERNEL::Exception);
00892   db->setInfoOnComponents(info);
00893   
00894   CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(-1),INTERP_KERNEL::Exception);
00895   CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(2),INTERP_KERNEL::Exception);
00896   CPPUNIT_ASSERT(db->getInfoOnComponent(1)==db->getInfoOnComponent(0));
00897   CPPUNIT_ASSERT_THROW(db->getVarOnComponent(-1),INTERP_KERNEL::Exception);
00898   CPPUNIT_ASSERT_THROW(db->getVarOnComponent(2),INTERP_KERNEL::Exception);
00899   CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(-1),INTERP_KERNEL::Exception);
00900   CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(2),INTERP_KERNEL::Exception);
00901   
00902   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname unit "))==std::string("varname unit "));
00903   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname]unit["))==std::string("varname]unit["));
00904   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("[unit]"))==std::string());
00905   CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname [unit]"))==std::string("varname"));
00906   
00907   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname unit "))==std::string());
00908   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname]unit["))==std::string());
00909   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("[unit]"))==std::string("unit"));
00910   CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname [unit]"))==std::string("unit"));
00911   
00912   CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*db,"theMessageInThrow"),INTERP_KERNEL::Exception);
00913   CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
00914   CPPUNIT_ASSERT_THROW(db->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception);
00915 
00916   CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(7,2,"theMessageInThrow"),INTERP_KERNEL::Exception);
00917   da->checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
00918   
00919   CPPUNIT_ASSERT_THROW(db->checkNbOfElems(7*2+1,"theMessageInThrow"),INTERP_KERNEL::Exception);
00920   db->checkNbOfElems(7*2,"theMessageInThrow");
00921   
00922   CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(10,9,1,"theMessageInThrow"),INTERP_KERNEL::Exception);
00923   CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(0,1,-1,"theMessageInThrow"),INTERP_KERNEL::Exception);
00924   CPPUNIT_ASSERT_EQUAL(10,db->GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
00925   CPPUNIT_ASSERT_EQUAL(5,db->GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
00926   CPPUNIT_ASSERT_EQUAL(6,db->GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
00927   
00928   //std::cout<<"\n!!!!!!!!!\n"<<dd->repr()<<"\n!!!!!!!!!\n";
00929   CPPUNIT_ASSERT(!((da->repr().find("Number of components : 1"))==std::string::npos));
00930   CPPUNIT_ASSERT(!((dd->repr().find("Number of components : 1"))==std::string::npos));
00931   CPPUNIT_ASSERT(!((dbl->repr().find("Number of components : 1"))==std::string::npos));
00932   
00933   CPPUNIT_ASSERT(!((da->reprZip().find("Number of components : 1"))==std::string::npos));
00934   CPPUNIT_ASSERT(!((dd->reprZip().find("Number of components : 1"))==std::string::npos));
00935   CPPUNIT_ASSERT(!((dbl->reprZip().find("Number of components : 1"))==std::string::npos));
00936   
00937   std::ostringstream ret;
00938   dbl->writeVTK(ret,2,"file.tmp");
00939   CPPUNIT_ASSERT(!((ret.str().find("<DataArray"))==std::string::npos));
00940   CPPUNIT_ASSERT(!((ret.str().find("Float32"))==std::string::npos));
00941   CPPUNIT_ASSERT(!((ret.str().find("16 15 14 13 12 11 10"))==std::string::npos));
00942   
00943   CPPUNIT_ASSERT_THROW(dbl->selectByTupleId2(0,1,-1),INTERP_KERNEL::Exception);
00944   CPPUNIT_ASSERT_THROW(dbl->substr(-1,1),INTERP_KERNEL::Exception);
00945   CPPUNIT_ASSERT_THROW(dbl->substr(8,1),INTERP_KERNEL::Exception);
00946   CPPUNIT_ASSERT_THROW(dbl->substr(0,8),INTERP_KERNEL::Exception);
00947   CPPUNIT_ASSERT_THROW(dbl->meldWith(dd),INTERP_KERNEL::Exception);
00948   
00949   CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dbl2,da),INTERP_KERNEL::Exception); //dbl dbl2 not have the same number of components
00950   CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dd,da),INTERP_KERNEL::Exception);  //da tuple selector DataArrayInt instance not have exactly 2 components
00951   
00952   DataArrayDouble *dbl3=DataArrayDouble::New();
00953   dbl3->alloc(6,2);
00954   dbl3->fillWithValue(11.);
00955   int tupleId;
00956   //bad number of components
00957   CPPUNIT_ASSERT_THROW(dbl3->getMaxValue(tupleId),INTERP_KERNEL::Exception);
00958   CPPUNIT_ASSERT_THROW(dd->getMaxValue(tupleId),INTERP_KERNEL::Exception);
00959   CPPUNIT_ASSERT_THROW(dbl3->getMinValue(tupleId),INTERP_KERNEL::Exception);
00960   CPPUNIT_ASSERT_THROW(dd->getMinValue(tupleId),INTERP_KERNEL::Exception);
00961   CPPUNIT_ASSERT_THROW(dbl3->getAverageValue(),INTERP_KERNEL::Exception);
00962   CPPUNIT_ASSERT_THROW(dd->getAverageValue(),INTERP_KERNEL::Exception);
00963   CPPUNIT_ASSERT_THROW(dd->accumulate(100),INTERP_KERNEL::Exception);
00964   CPPUNIT_ASSERT_THROW(dbl->fromPolarToCart(),INTERP_KERNEL::Exception);
00965   CPPUNIT_ASSERT_THROW(dbl3->fromCylToCart(),INTERP_KERNEL::Exception);
00966   CPPUNIT_ASSERT_THROW(dbl3->fromSpherToCart(),INTERP_KERNEL::Exception);
00967   CPPUNIT_ASSERT_THROW(dbl3->doublyContractedProduct(),INTERP_KERNEL::Exception);
00968   CPPUNIT_ASSERT_THROW(dbl3->determinant(),INTERP_KERNEL::Exception);
00969   CPPUNIT_ASSERT_THROW(dbl3->eigenValues(),INTERP_KERNEL::Exception);
00970   CPPUNIT_ASSERT_THROW(dbl3->eigenVectors(),INTERP_KERNEL::Exception);
00971   CPPUNIT_ASSERT_THROW(dbl3->inverse(),INTERP_KERNEL::Exception);
00972   CPPUNIT_ASSERT_THROW(dbl3->trace(),INTERP_KERNEL::Exception);
00973   CPPUNIT_ASSERT_THROW(dbl3->deviator(),INTERP_KERNEL::Exception);
00974  
00975   dbl3->setIJ(5,1,12.);
00976   CPPUNIT_ASSERT(dbl3->getMaxValueInArray()==12.);
00977   CPPUNIT_ASSERT(dbl3->getMinValueInArray()==11.);
00978  
00979   db->fillWithValue(100); //bad Ids
00980   CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
00981   db->fillWithValue(-1); //bad Ids
00982   CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
00983   db->fillWithValue(6); //bad Ids for dbl3
00984   CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception);
00985   
00986   DataArrayDouble::SetArrayIn(dbl,dbl3); //dbl->dbl3 memLeaks?
00987   dbl3->checkNoNullValues();
00988   dbl3->setIJ(6,0,0.);
00989   CPPUNIT_ASSERT_THROW(dbl3->checkNoNullValues(),INTERP_KERNEL::Exception);
00990   CPPUNIT_ASSERT_THROW(dbl3->applyInv(1.),INTERP_KERNEL::Exception);  //div by zero
00991   CPPUNIT_ASSERT_THROW(dbl2->getIdsInRange(1.,2.),INTERP_KERNEL::Exception);
00992   std::vector<const DataArrayDouble *> a(0); //input list must be NON EMPTY
00993   CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
00994   CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
00995   
00996   a.push_back(dbl2);
00997   a.push_back(dbl); //Nb of components mismatch
00998   CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception);
00999   
01000   CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl2,dbl),INTERP_KERNEL::Exception);
01001   
01002   CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl),INTERP_KERNEL::Exception); //Nb of components mismatch
01003   CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl2),INTERP_KERNEL::Exception); //Nb of components must be equal to 3 
01004   DataArrayDouble *dbl4=DataArrayDouble::New();
01005   dbl4->alloc(6,3);
01006   DataArrayDouble *dbl5=DataArrayDouble::New();
01007   dbl5->alloc(7,3);
01008   CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl4,dbl5),INTERP_KERNEL::Exception); //Nb of tuples mismatch
01009   
01010   a[0]=dbl4; //Nb of tuple mismatch
01011   a[1]=dbl5; //Nb of tuple mismatch
01012   CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception);
01013   CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl4,dbl5),INTERP_KERNEL::Exception);
01014   
01015   da->decrRef();
01016   db->decrRef();
01017   dbl->decrRef();
01018   dbl2->decrRef();
01019   dbl3->decrRef();
01020   dbl4->decrRef();
01021   dbl5->decrRef();
01022   dc->decrRef();
01023   dd->decrRef();
01024 }
01025 
01026 void MEDCouplingBasicsTest3::testDAIGetIdsEqual1()
01027 {
01028   const int tab1[7]={5,-2,-4,-2,3,2,-2};
01029   DataArrayInt *da=DataArrayInt::New();
01030   da->alloc(7,1);
01031   std::copy(tab1,tab1+7,da->getPointer());
01032   DataArrayInt *da2=da->getIdsEqual(-2);
01033   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
01034   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
01035   const int expected1[3]={1,3,6};
01036   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da2->getConstPointer()));
01037   da2->decrRef();
01038   da->decrRef();
01039 }
01040 
01041 void MEDCouplingBasicsTest3::testDAIGetIdsEqualList1()
01042 {
01043   const int tab1[7]={5,-2,-4,-2,3,2,-2};
01044   DataArrayInt *da=DataArrayInt::New();
01045   da->alloc(7,1);
01046   std::copy(tab1,tab1+7,da->getPointer());
01047   const int tab2[3]={3,-2,0};
01048   std::vector<int> tab2V(tab2,tab2+3);
01049   DataArrayInt *da2=da->getIdsEqualList(tab2V);
01050   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
01051   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
01052   const int expected1[4]={1,3,4,6};
01053   CPPUNIT_ASSERT(std::equal(expected1,expected1+4,da2->getConstPointer()));
01054   da2->decrRef();
01055   da->decrRef();
01056 }
01057 
01058 void MEDCouplingBasicsTest3::testDAFromNoInterlace1()
01059 {
01060   const int tab1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
01061   DataArrayInt *da=DataArrayInt::New();
01062   da->alloc(5,3);
01063   std::copy(tab1,tab1+15,da->getPointer());
01064   DataArrayInt *da2=da->fromNoInterlace();
01065   const int expected1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
01066   CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
01067   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
01068   CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
01069   DataArrayDouble *da3=da->convertToDblArr();
01070   DataArrayDouble *da4=da3->fromNoInterlace();
01071   CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
01072   CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
01073   for(int i=0;i<15;i++)
01074     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
01075   da4->decrRef();
01076   da3->decrRef();
01077   da2->decrRef();
01078   da->decrRef();
01079 }
01080 
01081 void MEDCouplingBasicsTest3::testDAToNoInterlace1()
01082 {
01083   const int tab1[15]={1,2,3,11,12,13,21,22,23,31,32,33,41,42,43};
01084   DataArrayInt *da=DataArrayInt::New();
01085   da->alloc(5,3);
01086   std::copy(tab1,tab1+15,da->getPointer());
01087   DataArrayInt *da2=da->toNoInterlace();
01088   const int expected1[15]={1,11,21,31,41,2,12,22,32,42,3,13,23,33,43};
01089   CPPUNIT_ASSERT_EQUAL(5,da2->getNumberOfTuples());
01090   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
01091   CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer()));
01092   DataArrayDouble *da3=da->convertToDblArr();
01093   DataArrayDouble *da4=da3->toNoInterlace();
01094   CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfTuples());
01095   CPPUNIT_ASSERT_EQUAL(3,da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components !
01096   for(int i=0;i<15;i++)
01097     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14);
01098   da4->decrRef();
01099   da3->decrRef();
01100   da2->decrRef();
01101   da->decrRef();
01102 }
01103 
01104 void MEDCouplingBasicsTest3::testDAIsUniform1()
01105 {
01106   const int tab1[5]={1,1,1,1,1};
01107   DataArrayInt *da=DataArrayInt::New();
01108   da->alloc(5,1);
01109   std::copy(tab1,tab1+5,da->getPointer());
01110   CPPUNIT_ASSERT(da->isUniform(1));
01111   da->setIJ(2,0,2);
01112   CPPUNIT_ASSERT(!da->isUniform(1));
01113   da->setIJ(2,0,1);
01114   CPPUNIT_ASSERT(da->isUniform(1));
01115   DataArrayDouble *da2=da->convertToDblArr();
01116   CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
01117   da2->setIJ(1,0,1.+1.e-13);
01118   CPPUNIT_ASSERT(da2->isUniform(1.,1e-12));
01119   da2->setIJ(1,0,1.+1.e-11);
01120   CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12));
01121   da2->decrRef();
01122   da->decrRef();
01123 }
01124 
01125 void MEDCouplingBasicsTest3::testDADFromPolarToCart1()
01126 {
01127   const double tab1[4]={2.,0.2,2.5,0.7};
01128   DataArrayDouble *da=DataArrayDouble::New();
01129   da->alloc(2,2);
01130   std::copy(tab1,tab1+4,da->getPointer());
01131   DataArrayDouble *da2=da->fromPolarToCart();
01132   const double expected1[4]={1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275};
01133   for(int i=0;i<4;i++)
01134     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
01135   da2->decrRef();
01136   da->decrRef();
01137 }
01138 
01139 void MEDCouplingBasicsTest3::testDADFromCylToCart1()
01140 {
01141   const double tab1[6]={2.,0.2,4.,2.5,0.7,9.};
01142   DataArrayDouble *da=DataArrayDouble::New();
01143   da->alloc(2,3);
01144   std::copy(tab1,tab1+6,da->getPointer());
01145   DataArrayDouble *da2=da->fromCylToCart();
01146   const double expected1[6]={1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.};
01147   for(int i=0;i<6;i++)
01148     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
01149   da2->decrRef();
01150   da->decrRef();
01151 }
01152 
01153 void MEDCouplingBasicsTest3::testDADFromSpherToCart1()
01154 {
01155   const double tab1[6]={2.,0.2,0.3,2.5,0.7,0.8};
01156   DataArrayDouble *da=DataArrayDouble::New();
01157   da->alloc(2,3);
01158   std::copy(tab1,tab1+6,da->getPointer());
01159   DataArrayDouble *da2=da->fromSpherToCart();
01160   const double expected1[6]={0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213};
01161   for(int i=0;i<6;i++)
01162     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da2->getIJ(0,i),1e-13);
01163   da2->decrRef();
01164   da->decrRef();
01165 }
01166 
01167 void MEDCouplingBasicsTest3::testUnPolyze1()
01168 {
01169   const int elts[8]={0,1,2,3,4,5,6,7};
01170   std::vector<int> eltsV(elts,elts+8);
01171   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
01172   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
01173   mesh->unPolyze();
01174   MEDCouplingUMesh *mesh2=build3DTargetMesh_1();
01175   mesh->checkCoherency();
01176   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
01177   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
01178   CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
01179   mesh->getNodalConnectivity()->setIJ(0,6,10);
01180   mesh->getNodalConnectivity()->setIJ(0,7,9);
01181   mesh->getNodalConnectivity()->setIJ(0,8,12);
01182   mesh->getNodalConnectivity()->setIJ(0,9,13);
01183   mesh->unPolyze();
01184   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
01185   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
01186   mesh->getNodalConnectivity()->setIJ(0,6,12);
01187   mesh->getNodalConnectivity()->setIJ(0,7,13);
01188   mesh->getNodalConnectivity()->setIJ(0,8,10);
01189   mesh->getNodalConnectivity()->setIJ(0,9,9);
01190   mesh->unPolyze();
01191   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
01192   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
01193   mesh->getNodalConnectivity()->setIJ(0,6,12);
01194   mesh->getNodalConnectivity()->setIJ(0,7,10);
01195   mesh->getNodalConnectivity()->setIJ(0,8,13);
01196   mesh->getNodalConnectivity()->setIJ(0,9,9);
01197   mesh->unPolyze();
01198   CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
01199   mesh->decrRef();
01200   mesh2->decrRef();
01201   // Test for 2D mesh
01202   mesh=build2DTargetMesh_1();
01203   mesh2=build2DTargetMesh_1();
01204   eltsV.resize(5);
01205   mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
01206   CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12));
01207   mesh->unPolyze();
01208   CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12));
01209   mesh->decrRef();
01210   mesh2->decrRef();
01211 }
01212 
01213 void MEDCouplingBasicsTest3::testConvertDegeneratedCells1()
01214 {
01215   MEDCouplingUMesh *mesh=build3DTargetMesh_1();
01216   int conn[32]={0,1,3,3,9,10,12,12, 0,1,3,4,9,9,9,9, 1,1,1,1,10,12,9,10, 10,11,12,9,1,1,1,1};
01217   mesh->allocateCells(4);
01218   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn);
01219   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+8);
01220   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+16);
01221   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+24);
01222   mesh->finishInsertingCells();
01223   mesh->checkCoherency();
01224   CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
01225   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(0));
01226   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(1));
01227   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(2));
01228   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_HEXA8,mesh->getTypeOfCell(3));
01229   MEDCouplingFieldDouble *f1=mesh->getMeasureField(true);
01230   mesh->convertDegeneratedCells();
01231   mesh->checkCoherency();
01232   MEDCouplingFieldDouble *f2=mesh->getMeasureField(true);
01233   CPPUNIT_ASSERT_EQUAL(4,mesh->getNumberOfCells());
01234   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PENTA6,mesh->getTypeOfCell(0));
01235   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(1));
01236   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TETRA4,mesh->getTypeOfCell(2));
01237   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_PYRA5,mesh->getTypeOfCell(3));
01238   for(int i=0;i<4;i++)
01239     CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getArray()->getIJ(0,i),f2->getArray()->getIJ(0,i),1e-5);
01240   f1->decrRef();
01241   f2->decrRef();
01242   mesh->decrRef();
01243 }
01244 
01245 void MEDCouplingBasicsTest3::testGetNodeIdsNearPoints1()
01246 {
01247   MEDCouplingUMesh *mesh=build2DTargetMesh_1();
01248   DataArrayDouble *coords=mesh->getCoords();
01249   DataArrayDouble *tmp=DataArrayDouble::New();
01250   tmp->alloc(3,2);
01251   const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2};
01252   std::copy(vals,vals+6,tmp->getPointer());
01253   DataArrayDouble *tmp2=DataArrayDouble::Aggregate(coords,tmp);
01254   tmp->decrRef();
01255   mesh->setCoords(tmp2);
01256   tmp2->decrRef();
01257   const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7};
01258   std::vector<int> c=mesh->getNodeIdsNearPoint(pts,1e-7);
01259   CPPUNIT_ASSERT_EQUAL(3,(int)c.size());
01260   CPPUNIT_ASSERT_EQUAL(4,c[0]);
01261   CPPUNIT_ASSERT_EQUAL(9,c[1]);
01262   CPPUNIT_ASSERT_EQUAL(11,c[2]);
01263   c.clear();
01264   std::vector<int> cI;
01265   mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI);
01266   CPPUNIT_ASSERT_EQUAL(4,(int)cI.size());
01267   CPPUNIT_ASSERT_EQUAL(4,(int)c.size());
01268   CPPUNIT_ASSERT_EQUAL(4,c[0]);
01269   CPPUNIT_ASSERT_EQUAL(9,c[1]);
01270   CPPUNIT_ASSERT_EQUAL(11,c[2]);
01271   CPPUNIT_ASSERT_EQUAL(6,c[3]);
01272   CPPUNIT_ASSERT_EQUAL(0,cI[0]);
01273   CPPUNIT_ASSERT_EQUAL(3,cI[1]);
01274   CPPUNIT_ASSERT_EQUAL(3,cI[2]);
01275   CPPUNIT_ASSERT_EQUAL(4,cI[3]);
01276   mesh->decrRef();
01277 }
01278 
01279 void MEDCouplingBasicsTest3::testFieldCopyTinyAttrFrom1()
01280 {
01281   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01282   f1->setName("f1");
01283   f1->setTimeTolerance(1.e-5);
01284   f1->setDescription("f1Desc");
01285   f1->setTime(1.23,4,5);
01286   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01287   f2->setName("f2");
01288   f2->setDescription("f2Desc");
01289   f2->setTime(6.78,9,10);
01290   f2->setTimeTolerance(4.556e-12);
01291   //
01292   int dt,it;
01293   f1->copyTinyAttrFrom(f2);
01294   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
01295   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
01296   CPPUNIT_ASSERT_EQUAL(9,dt);
01297   CPPUNIT_ASSERT_EQUAL(10,it);
01298   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
01299   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
01300   f1->decrRef();
01301   f2->decrRef();
01302   //
01303   f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01304   f1->setName("f1");
01305   f1->setTimeTolerance(1.e-5);
01306   f1->setDescription("f1Desc");
01307   f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01308   f2->setName("f2");
01309   f2->setDescription("f2Desc");
01310   f2->setTimeTolerance(4.556e-12);
01311   //
01312   f1->copyTinyAttrFrom(f2);
01313   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
01314   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
01315   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
01316   f1->decrRef();
01317   f2->decrRef();
01318   //
01319   f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
01320   f1->setName("f1");
01321   f1->setTimeTolerance(1.e-5);
01322   f1->setDescription("f1Desc");
01323   f1->setTime(1.23,4,5);
01324   f1->setEndTime(5.43,2,1);
01325   f2=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
01326   f2->setName("f2");
01327   f2->setDescription("f2Desc");
01328   f2->setTimeTolerance(4.556e-12);
01329   f2->setTime(6.78,9,10);
01330   f2->setEndTime(10.98,7,6);
01331   //
01332   f1->copyTinyAttrFrom(f2);
01333   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
01334   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
01335   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
01336   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
01337   CPPUNIT_ASSERT_EQUAL(9,dt);
01338   CPPUNIT_ASSERT_EQUAL(10,it);
01339   CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
01340   CPPUNIT_ASSERT_EQUAL(7,dt);
01341   CPPUNIT_ASSERT_EQUAL(6,it);
01342   f1->decrRef();
01343   f2->decrRef();
01344   //
01345   f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
01346   f1->setName("f1");
01347   f1->setTimeTolerance(1.e-5);
01348   f1->setDescription("f1Desc");
01349   f1->setTime(1.23,4,5);
01350   f1->setEndTime(5.43,2,1);
01351   f2=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
01352   f2->setName("f2");
01353   f2->setDescription("f2Desc");
01354   f2->setTimeTolerance(4.556e-12);
01355   f2->setTime(6.78,9,10);
01356   f2->setEndTime(10.98,7,6);
01357   //
01358   f1->copyTinyAttrFrom(f2);
01359   CPPUNIT_ASSERT_DOUBLES_EQUAL(4.556e-12,f1->getTimeTolerance(),1e-24);
01360   CPPUNIT_ASSERT(std::string(f1->getName())=="f1");//name unchanged
01361   CPPUNIT_ASSERT(std::string(f1->getDescription())=="f1Desc");//description unchanged
01362   CPPUNIT_ASSERT_DOUBLES_EQUAL(6.78,f1->getTime(dt,it),1e-12);
01363   CPPUNIT_ASSERT_EQUAL(9,dt);
01364   CPPUNIT_ASSERT_EQUAL(10,it);
01365   CPPUNIT_ASSERT_DOUBLES_EQUAL(10.98,f1->getEndTime(dt,it),1e-12);
01366   CPPUNIT_ASSERT_EQUAL(7,dt);
01367   CPPUNIT_ASSERT_EQUAL(6,it);
01368   f1->decrRef();
01369   f2->decrRef();
01370 }
01371 
01375 void MEDCouplingBasicsTest3::testExtrudedMesh5()
01376 {
01377   const double coo1[4]={0.,1.,2.,3.5};
01378   DataArrayDouble *a=DataArrayDouble::New();
01379   a->alloc(4,1);
01380   std::copy(coo1,coo1+4,a->getPointer());
01381   MEDCouplingCMesh *b=MEDCouplingCMesh::New();
01382   b->setCoordsAt(0,a);
01383   MEDCouplingUMesh *c=b->buildUnstructured();
01384   CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
01385   c->changeSpaceDimension(2);
01386   //
01387   DataArrayDouble *d=DataArrayDouble::New();
01388   d->alloc(13,1);
01389   d->iota();
01390   MEDCouplingCMesh *e=MEDCouplingCMesh::New();
01391   e->setCoordsAt(0,d);
01392   MEDCouplingUMesh *f=e->buildUnstructured();
01393   DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
01394   DataArrayDouble *h=g->fromPolarToCart();
01395   f->setCoords(h);
01396   MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
01397   CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
01398   bool tmp2;
01399   int tmp3;
01400   DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
01401   CPPUNIT_ASSERT(tmp2);
01402   CPPUNIT_ASSERT_EQUAL(37,tmp3);
01403   tmp->decrRef();
01404   i->convertDegeneratedCells();
01405   i->checkCoherency();
01406   CPPUNIT_ASSERT_EQUAL(36,i->getNumberOfCells());
01407   CPPUNIT_ASSERT_EQUAL(37,i->getNumberOfNodes());
01408   CPPUNIT_ASSERT_EQUAL(12,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3));
01409   CPPUNIT_ASSERT_EQUAL(24,i->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4));
01410   const double expected1[3]={0.25,0.75,2.0625};
01411   MEDCouplingFieldDouble *j=i->getMeasureField(true);
01412   for(int ii=0;ii<12;ii++)
01413     for(int k=0;k<3;k++)
01414       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[k],j->getIJ(0,ii*3+k),1e-10);
01415   const double expected2[72]={0.62200846792814113, 0.16666666666681595, 1.4513530918323276, 0.38888888888923495, 2.6293994326053212, 0.7045454545460802, 0.45534180126145435, 0.45534180126150181, 1.0624642029433926, 1.0624642029435025, 1.9248539780597826, 1.9248539780599816, 0.16666666666661334, 0.62200846792815856, 0.38888888888876294, 1.4513530918323678, 0.70454545454522521, 2.629399432605394, -0.16666666666674007, 0.62200846792812436, -0.38888888888906142, 1.4513530918322881, -0.70454545454576778, 2.6293994326052488, -0.45534180126154766, 0.45534180126140844, -1.0624642029436118, 1.0624642029432834, -1.9248539780601803, 1.9248539780595841, -0.62200846792817499, 0.1666666666665495, -1.451353091832408, 0.388888888888613, -2.6293994326054668, 0.70454545454495332, -0.62200846792810593, -0.16666666666680507, -1.451353091832247, -0.38888888888921297, -2.6293994326051746, -0.70454545454604123, -0.45534180126135926, -0.45534180126159562, -1.0624642029431723, -1.0624642029437235, -1.9248539780593836, -1.9248539780603811, -0.1666666666664828, -0.62200846792819242, -0.38888888888846079, -1.4513530918324489, -0.70454545454467987, -2.6293994326055397, 0.16666666666687083, -0.62200846792808862, 0.38888888888936374, -1.4513530918322073, 0.70454545454631357, -2.6293994326051022, 0.45534180126164348, -0.45534180126131207, 1.0624642029438327, -1.0624642029430627, 1.9248539780605791, -1.9248539780591853, 0.62200846792821063, -0.16666666666641802, 1.4513530918324888, -0.38888888888831086, 2.6293994326056125, -0.70454545454440853};
01416   DataArrayDouble *m=i->getBarycenterAndOwner();
01417   for(int ii=0;ii<72;ii++)
01418     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[ii],m->getIJ(0,ii),1e-10);
01419   //
01420   m->decrRef();
01421   j->decrRef();
01422   i->decrRef();
01423   h->decrRef();
01424   g->decrRef();
01425   f->decrRef();
01426   e->decrRef();
01427   d->decrRef();
01428   c->decrRef();
01429   b->decrRef();
01430   a->decrRef();
01431 }
01432 
01436 void MEDCouplingBasicsTest3::testExtrudedMesh6()
01437 {
01438   const double coo1[4]={0.,1.,2.,3.5};
01439   DataArrayDouble *a=DataArrayDouble::New();
01440   a->alloc(4,1);
01441   std::copy(coo1,coo1+4,a->getPointer());
01442   MEDCouplingCMesh *b=MEDCouplingCMesh::New();
01443   b->setCoordsAt(0,a);
01444   MEDCouplingUMesh *c=b->buildUnstructured();
01445   CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
01446   c->changeSpaceDimension(2);
01447   //
01448   DataArrayDouble *d=DataArrayDouble::New();
01449   d->alloc(5,1);
01450   d->iota();
01451   MEDCouplingCMesh *e=MEDCouplingCMesh::New();
01452   e->setCoordsAt(0,d);
01453   MEDCouplingUMesh *f=e->buildUnstructured();
01454   DataArrayDouble *d2=f->getCoords()->applyFunc("x*x/2");
01455   f->setCoords(d2);
01456   f->changeSpaceDimension(2);
01457   //
01458   const double center[2]={0.,0.};
01459   f->rotate(center,0,M_PI/3);
01460   MEDCouplingUMesh *g=c->buildExtrudedMesh(f,0);
01461   g->checkCoherency();
01462   const double expected1[]={ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 };
01463   MEDCouplingFieldDouble *f1=g->getMeasureField(true);
01464   for(int i=0;i<12;i++)
01465     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-12);
01466   
01467   const double expected2[]={0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414};
01468   DataArrayDouble *f2=g->getBarycenterAndOwner();
01469   for(int i=0;i<24;i++)
01470     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-12);
01471   //
01472   f1->decrRef();
01473   f2->decrRef();
01474   g->decrRef();
01475   f->decrRef();
01476   e->decrRef();
01477   d->decrRef();
01478   d2->decrRef();
01479   c->decrRef();
01480   b->decrRef();
01481   a->decrRef();
01482 }
01483 
01487 void MEDCouplingBasicsTest3::testExtrudedMesh7()
01488 {
01489   const double coo1[4]={0.,1.,2.,3.5};
01490   DataArrayDouble *a=DataArrayDouble::New();
01491   a->alloc(4,1);
01492   std::copy(coo1,coo1+4,a->getPointer());
01493   MEDCouplingCMesh *b=MEDCouplingCMesh::New();
01494   b->setCoordsAt(0,a);
01495   MEDCouplingUMesh *c=b->buildUnstructured();
01496   CPPUNIT_ASSERT_EQUAL(1,c->getSpaceDimension());
01497   c->changeSpaceDimension(2);
01498   //
01499   DataArrayDouble *d=DataArrayDouble::New();
01500   d->alloc(13,1);
01501   d->iota();
01502   MEDCouplingCMesh *e=MEDCouplingCMesh::New();
01503   e->setCoordsAt(0,d);
01504   MEDCouplingUMesh *f=e->buildUnstructured();
01505   DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
01506   DataArrayDouble *h=g->fromPolarToCart();
01507   f->setCoords(h);
01508   MEDCouplingUMesh *i=c->buildExtrudedMesh(f,1);
01509   CPPUNIT_ASSERT_EQUAL(52,i->getNumberOfNodes());
01510   bool tmp2;
01511   int tmp3;
01512   DataArrayInt *tmp=i->mergeNodes(1e-9,tmp2,tmp3);
01513   CPPUNIT_ASSERT(tmp2);
01514   CPPUNIT_ASSERT_EQUAL(37,tmp3);
01515   tmp->decrRef();
01516   i->convertDegeneratedCells();
01517   const double vec1[3]={10.,0.,0.};
01518   i->translate(vec1);
01519   DataArrayDouble *g2=h->applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
01520   f->setCoords(g2);
01521   i->changeSpaceDimension(3);
01522   MEDCouplingUMesh *i3=i->buildExtrudedMesh(f,1);
01523   MEDCouplingFieldDouble *f2=i3->getMeasureField(true);
01524   tmp=i->mergeNodes(1e-9,tmp2,tmp3);
01525   CPPUNIT_ASSERT(tmp2);
01526   CPPUNIT_ASSERT_EQUAL(444,tmp3);
01527   tmp->decrRef();
01528   const double expected1[36]={1.327751058489274, 4.2942574094314701, 13.024068164857139, 1.3069177251569044, 4.1484240761012954, 12.297505664866796, 1.270833333332571, 3.8958333333309674, 11.039062499993179, 1.2291666666659207, 3.6041666666644425, 9.585937499993932, 1.1930822748415895, 3.3515759238941376, 8.3274943351204556, 1.1722489415082769, 3.2057425905609289, 7.6009318351210622, 1.1722489415082862, 3.2057425905609884, 7.6009318351213713, 1.1930822748416161, 3.3515759238943001, 8.3274943351212727, 1.2291666666659564, 3.6041666666646734, 9.5859374999950777, 1.2708333333326081, 3.8958333333311868, 11.039062499994293, 1.3069177251569224, 4.1484240761014384, 12.297505664867627, 1.3277510584902354, 4.2942574094346071, 13.024068164866796};
01529   int kk=0;
01530   for(int ii=0;ii<12;ii++)
01531     for(int jj=0;jj<36;jj++,kk++)
01532       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[jj],f2->getIJ(0,kk),1e-9);
01533   //
01534   f2->decrRef();
01535   i3->decrRef();
01536   g2->decrRef();
01537   i->decrRef();
01538   h->decrRef();
01539   g->decrRef();
01540   f->decrRef();
01541   e->decrRef();
01542   d->decrRef();
01543   c->decrRef();
01544   b->decrRef();
01545   a->decrRef();
01546 }
01547 
01548 void MEDCouplingBasicsTest3::testSimplexize1()
01549 {
01550   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
01551   std::vector<int> v(1);
01552   v[0]=3;
01553   m->convertToPolyTypes(&v[0],&v[0]+v.size());
01554   DataArrayInt *da=m->simplexize(0);
01555   CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
01556   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
01557   const int expected2[7]={0,0,1,2,3,4,4};
01558   for(int i=0;i<7;i++)
01559     CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
01560   m->checkCoherency();
01561   CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
01562   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
01563   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
01564   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
01565   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
01566   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
01567   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
01568   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
01569   const double expected1[7]={0.125,0.125,0.125,0.125,0.25,0.125,0.125};
01570   MEDCouplingFieldDouble *f=m->getMeasureField(false);
01571   for(int i=0;i<7;i++)
01572     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
01573   std::set<INTERP_KERNEL::NormalizedCellType> types=m->getAllTypes();
01574   CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
01575   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
01576   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
01577   f->decrRef();
01578   da->decrRef();
01579   m->decrRef();
01580   //
01581   m=build3DSurfTargetMesh_1();
01582   v[0]=3;
01583   m->convertToPolyTypes(&v[0],&v[0]+v.size());
01584   da=m->simplexize(1);
01585   CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples());
01586   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
01587   for(int i=0;i<7;i++)
01588     CPPUNIT_ASSERT_EQUAL(expected2[i],da->getIJ(i,0));
01589   m->checkCoherency();
01590   types=m->getAllTypes();
01591   CPPUNIT_ASSERT_EQUAL(2,(int)types.size());
01592   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,*(types.begin()));
01593   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,*(++(types.begin())));
01594   CPPUNIT_ASSERT_EQUAL(7,m->getNumberOfCells());
01595   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(0));
01596   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(1));
01597   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(2));
01598   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(3));
01599   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POLYGON,m->getTypeOfCell(4));
01600   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(5));
01601   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_TRI3,m->getTypeOfCell(6));
01602   f=m->getMeasureField(false);
01603   for(int i=0;i<7;i++)
01604     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i]*sqrt(2.),f->getIJ(i,0),1e-10);
01605   f->decrRef();
01606   da->decrRef();
01607   m->decrRef();
01608 }
01609 
01610 void MEDCouplingBasicsTest3::testSimplexize2()
01611 {
01612   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
01613   std::vector<int> v(1);
01614   v[0]=3;
01615   m->convertToPolyTypes(&v[0],&v[0]+v.size());
01616   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01617   f1->setMesh(m);
01618   DataArrayDouble *arr=DataArrayDouble::New();
01619   const double arr1[10]={10.,110.,20.,120.,30.,130.,40.,140.,50.,150.};
01620   arr->alloc(5,2);
01621   std::copy(arr1,arr1+10,arr->getPointer());
01622   f1->setArray(arr);
01623   arr->decrRef();
01624   //
01625   f1->checkCoherency();
01626   CPPUNIT_ASSERT(f1->simplexize(0));
01627   f1->checkCoherency();
01628   const double expected1[14]={10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.};
01629   for(int i=0;i<14;i++)
01630     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
01631   CPPUNIT_ASSERT(!f1->simplexize(0));
01632   for(int i=0;i<14;i++)
01633     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-10);
01634   //
01635   f1->decrRef();
01636   m->decrRef();
01637 }
01638 
01639 void MEDCouplingBasicsTest3::testDAMeld1()
01640 {
01641   DataArrayDouble *da1=DataArrayDouble::New();
01642   da1->alloc(7,2);
01643   DataArrayDouble *da2=DataArrayDouble::New();
01644   da2->alloc(7,1);
01645   //
01646   da1->fillWithValue(7.);
01647   da2->iota(0.);
01648   DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
01649   //
01650   da1->setInfoOnComponent(0,"c0da1");
01651   da1->setInfoOnComponent(1,"c1da1");
01652   da3->setInfoOnComponent(0,"c0da3");
01653   da3->setInfoOnComponent(1,"c1da3");
01654   da3->setInfoOnComponent(2,"c2da3");
01655   //
01656   DataArrayDouble *da1C=da1->deepCpy();
01657   da1->meldWith(da3);
01658   CPPUNIT_ASSERT_EQUAL(5,da1->getNumberOfComponents());
01659   CPPUNIT_ASSERT_EQUAL(7,da1->getNumberOfTuples());
01660   CPPUNIT_ASSERT(da1->getInfoOnComponent(0)=="c0da1");
01661   CPPUNIT_ASSERT(da1->getInfoOnComponent(1)=="c1da1");
01662   CPPUNIT_ASSERT(da1->getInfoOnComponent(2)=="c0da3");
01663   CPPUNIT_ASSERT(da1->getInfoOnComponent(3)=="c1da3");
01664   CPPUNIT_ASSERT(da1->getInfoOnComponent(4)=="c2da3");
01665   //
01666   const double expected1[35]={7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.};
01667   for(int i=0;i<35;i++)
01668     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10);
01669   //
01670   DataArrayInt *dai1=da1C->convertToIntArr();
01671   DataArrayInt *dai3=da3->convertToIntArr();
01672   dai1->meldWith(dai3);
01673   CPPUNIT_ASSERT_EQUAL(5,dai1->getNumberOfComponents());
01674   CPPUNIT_ASSERT_EQUAL(7,dai1->getNumberOfTuples());
01675   CPPUNIT_ASSERT(dai1->getInfoOnComponent(0)=="c0da1");
01676   CPPUNIT_ASSERT(dai1->getInfoOnComponent(1)=="c1da1");
01677   CPPUNIT_ASSERT(dai1->getInfoOnComponent(2)=="c0da3");
01678   CPPUNIT_ASSERT(dai1->getInfoOnComponent(3)=="c1da3");
01679   CPPUNIT_ASSERT(dai1->getInfoOnComponent(4)=="c2da3");
01680   for(int i=0;i<35;i++)
01681     CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai1->getIJ(0,i));
01682   // test of static method DataArrayDouble::meld
01683   DataArrayDouble *da4=DataArrayDouble::Meld(da1C,da3);
01684   CPPUNIT_ASSERT_EQUAL(5,da4->getNumberOfComponents());
01685   CPPUNIT_ASSERT_EQUAL(7,da4->getNumberOfTuples());
01686   CPPUNIT_ASSERT(da4->getInfoOnComponent(0)=="c0da1");
01687   CPPUNIT_ASSERT(da4->getInfoOnComponent(1)=="c1da1");
01688   CPPUNIT_ASSERT(da4->getInfoOnComponent(2)=="c0da3");
01689   CPPUNIT_ASSERT(da4->getInfoOnComponent(3)=="c1da3");
01690   CPPUNIT_ASSERT(da4->getInfoOnComponent(4)=="c2da3");
01691   for(int i=0;i<35;i++)
01692     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10);
01693   // test of static method DataArrayInt::meld
01694   dai1->decrRef();
01695   dai1=da1C->convertToIntArr();
01696   DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3);
01697   CPPUNIT_ASSERT_EQUAL(5,dai4->getNumberOfComponents());
01698   CPPUNIT_ASSERT_EQUAL(7,dai4->getNumberOfTuples());
01699   CPPUNIT_ASSERT(dai4->getInfoOnComponent(0)=="c0da1");
01700   CPPUNIT_ASSERT(dai4->getInfoOnComponent(1)=="c1da1");
01701   CPPUNIT_ASSERT(dai4->getInfoOnComponent(2)=="c0da3");
01702   CPPUNIT_ASSERT(dai4->getInfoOnComponent(3)=="c1da3");
01703   CPPUNIT_ASSERT(dai4->getInfoOnComponent(4)=="c2da3");
01704   for(int i=0;i<35;i++)
01705     CPPUNIT_ASSERT_EQUAL((int)expected1[i],dai4->getIJ(0,i));
01706   //
01707   dai4->decrRef();
01708   da4->decrRef();
01709   dai3->decrRef();
01710   dai1->decrRef();
01711   da1C->decrRef();
01712   da1->decrRef();
01713   da2->decrRef();
01714   da3->decrRef();
01715 }
01716 
01717 void MEDCouplingBasicsTest3::testFieldMeld1()
01718 {
01719   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
01720   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01721   f1->setMesh(m);
01722   DataArrayDouble *da1=DataArrayDouble::New();
01723   const double arr1[5]={12.,23.,34.,45.,56.};
01724   da1->alloc(5,1);
01725   std::copy(arr1,arr1+5,da1->getPointer());
01726   da1->setInfoOnComponent(0,"aaa");
01727   f1->setArray(da1);
01728   f1->setTime(3.4,2,1);
01729   f1->checkCoherency();
01730   //
01731   MEDCouplingFieldDouble *f2=f1->deepCpy();
01732   f2->setMesh(f1->getMesh());
01733   f2->checkCoherency();
01734   f2->changeNbOfComponents(2,5.);
01735   (*f2)=5.;
01736   f2->getArray()->setInfoOnComponent(0,"bbb");
01737   f2->getArray()->setInfoOnComponent(1,"ccc");
01738   f2->checkCoherency();
01739   //
01740   MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::MeldFields(f2,f1);
01741   f3->checkCoherency();
01742   CPPUNIT_ASSERT_EQUAL(5,f3->getNumberOfTuples());
01743   CPPUNIT_ASSERT_EQUAL(3,f3->getNumberOfComponents());
01744   CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(0)=="bbb");
01745   CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(1)=="ccc");
01746   CPPUNIT_ASSERT(f3->getArray()->getInfoOnComponent(2)=="aaa");
01747   const double expected1[15]={5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.};
01748   for(int i=0;i<15;i++)
01749     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-12);
01750   int dt,it;
01751   double time=f3->getTime(dt,it);
01752   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4,time,1e-14);
01753   CPPUNIT_ASSERT_EQUAL(2,dt);
01754   CPPUNIT_ASSERT_EQUAL(1,it);
01755   //
01756   MEDCouplingFieldDouble *f4=f2->buildNewTimeReprFromThis(NO_TIME,false);
01757   MEDCouplingFieldDouble *f5=f1->buildNewTimeReprFromThis(NO_TIME,false);
01758   MEDCouplingFieldDouble *f6=MEDCouplingFieldDouble::MeldFields(f4,f5);
01759   f6->checkCoherency();
01760   CPPUNIT_ASSERT_EQUAL(5,f6->getNumberOfTuples());
01761   CPPUNIT_ASSERT_EQUAL(3,f6->getNumberOfComponents());
01762   CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(0)=="bbb");
01763   CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(1)=="ccc");
01764   CPPUNIT_ASSERT(f6->getArray()->getInfoOnComponent(2)=="aaa");
01765   for(int i=0;i<15;i++)
01766     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f6->getIJ(0,i),1e-12);
01767   //
01768   f6->decrRef();
01769   f4->decrRef();
01770   f5->decrRef();
01771   f3->decrRef();
01772   da1->decrRef();
01773   f2->decrRef();
01774   f1->decrRef();
01775   m->decrRef();
01776 }
01777 
01778 void MEDCouplingBasicsTest3::testMergeNodes2()
01779 {
01780   MEDCouplingUMesh *m1=build2DTargetMesh_1();
01781   MEDCouplingUMesh *m2=build2DTargetMesh_1();
01782   const double vec[2]={0.002,0.};
01783   m2->translate(vec);
01784   //
01785   std::vector<const MEDCouplingUMesh *> tmp(2);
01786   tmp[0]=m1;
01787   tmp[1]=m2;
01788   MEDCouplingUMesh *m3=MEDCouplingUMesh::MergeUMeshes(tmp);
01789   bool b;
01790   int newNbOfNodes;
01791   DataArrayInt *da=m3->mergeNodes2(0.01,b,newNbOfNodes);
01792   CPPUNIT_ASSERT_EQUAL(9,m3->getNumberOfNodes());
01793   const double expected1[18]={-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7};
01794   for(int i=0;i<18;i++)
01795     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],m3->getCoords()->getIJ(0,i),1e-13);
01796   //
01797   da->decrRef();
01798   m3->decrRef();
01799   m1->decrRef();
01800   m2->decrRef();
01801 }
01802 
01803 void MEDCouplingBasicsTest3::testMergeField2()
01804 {
01805   MEDCouplingUMesh *m=build2DTargetMesh_1();
01806   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01807   f1->setMesh(m);
01808   DataArrayDouble *arr=DataArrayDouble::New();
01809   arr->alloc(5,2);
01810   arr->fillWithValue(2.);
01811   f1->setArray(arr);
01812   arr->decrRef();
01813   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01814   f2->setMesh(m);
01815   arr=DataArrayDouble::New();
01816   arr->alloc(5,2);
01817   arr->fillWithValue(5.);
01818   f2->setArray(arr);
01819   arr->decrRef();
01820   MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01821   f3->setMesh(m);
01822   arr=DataArrayDouble::New();
01823   arr->alloc(5,2);
01824   arr->fillWithValue(7.);
01825   f3->setArray(arr);
01826   arr->decrRef();
01827   //
01828   std::vector<const MEDCouplingFieldDouble *> tmp(3);
01829   tmp[0]=f1; tmp[1]=f2; tmp[2]=f3;
01830   MEDCouplingFieldDouble *f4=MEDCouplingFieldDouble::MergeFields(tmp);
01831   CPPUNIT_ASSERT_EQUAL(15,f4->getMesh()->getNumberOfCells());
01832   const double expected1[30]={2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.};
01833   for(int i=0;i<30;i++)
01834     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f4->getIJ(0,i),1.e-13);
01835   //
01836   f4->decrRef();
01837   f1->decrRef();
01838   f2->decrRef();
01839   f3->decrRef();
01840   m->decrRef();
01841 }
01842 
01843 void MEDCouplingBasicsTest3::testDAIBuildComplement1()
01844 {
01845   DataArrayInt *a=DataArrayInt::New();
01846   const int tab[4]={3,1,7,8};
01847   a->alloc(4,1);
01848   std::copy(tab,tab+4,a->getPointer());
01849   DataArrayInt *b=a->buildComplement(12);
01850   CPPUNIT_ASSERT_EQUAL(8,b->getNumberOfTuples());
01851   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
01852   const int expected1[8]={0,2,4,5,6,9,10,11};
01853   for(int i=0;i<8;i++)
01854     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
01855   b->decrRef();
01856   a->decrRef();
01857 }
01858 
01859 void MEDCouplingBasicsTest3::testDAIBuildUnion1()
01860 {
01861   DataArrayInt *a=DataArrayInt::New();
01862   const int tab1[4]={3,1,7,8};
01863   a->alloc(4,1);
01864   std::copy(tab1,tab1+4,a->getPointer());
01865   DataArrayInt *c=DataArrayInt::New();
01866   const int tab2[5]={5,3,0,18,8};
01867   c->alloc(5,1);
01868   std::copy(tab2,tab2+5,c->getPointer());
01869   DataArrayInt *b=a->buildUnion(c);
01870   CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
01871   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
01872   const int expected1[7]={0,1,3,5,7,8,18};
01873   for(int i=0;i<7;i++)
01874     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
01875   c->decrRef();
01876   b->decrRef();
01877   a->decrRef();
01878 }
01879 
01880 void MEDCouplingBasicsTest3::testDAIBuildIntersection1()
01881 {
01882   DataArrayInt *a=DataArrayInt::New();
01883   const int tab1[4]={3,1,7,8};
01884   a->alloc(4,1);
01885   std::copy(tab1,tab1+4,a->getPointer());
01886   DataArrayInt *c=DataArrayInt::New();
01887   const int tab2[5]={5,3,0,18,8};
01888   c->alloc(5,1);
01889   std::copy(tab2,tab2+5,c->getPointer());
01890   DataArrayInt *b=a->buildIntersection(c);
01891   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfTuples());
01892   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
01893   const int expected1[2]={3,8};
01894   for(int i=0;i<2;i++)
01895     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
01896   c->decrRef();
01897   b->decrRef();
01898   a->decrRef();
01899 }
01900 
01901 void MEDCouplingBasicsTest3::testDAIDeltaShiftIndex1()
01902 {
01903   DataArrayInt *a=DataArrayInt::New();
01904   const int tab[7]={1,3,6,7,7,9,15};
01905   a->alloc(7,1);
01906   std::copy(tab,tab+7,a->getPointer());
01907   DataArrayInt *b=a->deltaShiftIndex();
01908   CPPUNIT_ASSERT_EQUAL(6,b->getNumberOfTuples());
01909   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
01910   const int expected1[6]={2,3,1,0,2,6};
01911   for(int i=0;i<6;i++)
01912     CPPUNIT_ASSERT_EQUAL(expected1[i],b->getIJ(0,i));
01913   b->decrRef();
01914   a->decrRef();
01915 }
01916 
01917 void MEDCouplingBasicsTest3::testDaDoubleSelectByTupleIdSafe1()
01918 {
01919   DataArrayDouble *a=DataArrayDouble::New();
01920   a->alloc(7,2);
01921   a->setInfoOnComponent(0,"toto");
01922   a->setInfoOnComponent(1,"tata");
01923   const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
01924   std::copy(arr1,arr1+14,a->getPointer());
01925   //
01926   const int arr2[7]={4,2,0,6,5};
01927   DataArrayDouble *b=a->selectByTupleIdSafe(arr2,arr2+5);
01928   CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
01929   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
01930   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
01931   CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
01932   const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
01933   for(int i=0;i<10;i++)
01934     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
01935   const int arr4[5]={4,-1,0,6,5};
01936   CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
01937   const int arr5[5]={4,2,0,6,7};
01938   CPPUNIT_ASSERT_THROW(a->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
01939   b->decrRef();
01940   a->decrRef();
01941   //
01942   DataArrayInt *c=DataArrayInt::New();
01943   c->alloc(7,2);
01944   c->setInfoOnComponent(0,"toto");
01945   c->setInfoOnComponent(1,"tata");
01946   const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
01947   std::copy(arr3,arr3+14,c->getPointer());
01948   DataArrayInt *d=c->selectByTupleIdSafe(arr2,arr2+5);
01949   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
01950   CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
01951   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
01952   CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
01953   const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
01954   for(int i=0;i<10;i++)
01955     CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
01956   CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr4,arr4+5),INTERP_KERNEL::Exception);
01957   CPPUNIT_ASSERT_THROW(c->selectByTupleIdSafe(arr5,arr5+5),INTERP_KERNEL::Exception);
01958   c->decrRef();
01959   d->decrRef();
01960 }
01961 
01962 void MEDCouplingBasicsTest3::testAreCellsIncludedIn1()
01963 {
01964   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
01965   const int pt[2]={1,3};
01966   MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(pt,pt+2,true);
01967   DataArrayInt *tmp;
01968   CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
01969   CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfTuples());
01970   CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
01971   CPPUNIT_ASSERT_EQUAL(pt[0],tmp->getIJ(0,0));
01972   CPPUNIT_ASSERT_EQUAL(pt[1],tmp->getIJ(0,1));
01973   tmp->decrRef();
01974   CPPUNIT_ASSERT(!m2->areCellsIncludedIn(m,0,tmp));
01975   tmp->decrRef();
01976   m2->decrRef();
01977   m->decrRef();
01978 }
01979 
01980 void MEDCouplingBasicsTest3::testDAIBuildSubstraction1()
01981 {
01982   DataArrayInt *a=DataArrayInt::New();
01983   const int aa[]={2,3,6,8,9};
01984   a->alloc(5,1);
01985   std::copy(aa,aa+5,a->getPointer());
01986   DataArrayInt *b=DataArrayInt::New();
01987   const int bb[]={1,3,5,9,11};
01988   b->alloc(5,1);
01989   std::copy(bb,bb+5,b->getPointer());
01990   //
01991   DataArrayInt *c=a->buildSubstraction(b);
01992   CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples());
01993   CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
01994   const int expected1[3]={2,6,8};
01995   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer()));
01996   //
01997   c->decrRef();
01998   b->decrRef();
01999   a->decrRef();
02000 }
02001 
02002 void MEDCouplingBasicsTest3::testBuildOrthogonalField2()
02003 {
02004   MEDCouplingUMesh *m=build2DTargetMesh_1();
02005   DataArrayInt *d1=DataArrayInt::New();
02006   DataArrayInt *d2=DataArrayInt::New();
02007   DataArrayInt *d3=DataArrayInt::New();
02008   DataArrayInt *d4=DataArrayInt::New();
02009   MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
02010   //
02011   MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
02012   DataArrayDouble *da1=f1->getArray();
02013   CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfComponents());
02014   CPPUNIT_ASSERT_EQUAL(13,da1->getNumberOfTuples());
02015   //
02016   const double expected1[26]={-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.};
02017   for(int i=0;i<26;i++)
02018     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-14);
02019   //
02020   f1->decrRef();
02021   m1->decrRef();
02022   d1->decrRef();
02023   d2->decrRef();
02024   d3->decrRef();
02025   d4->decrRef();
02026   m->decrRef();
02027 }
02028 
02029 void MEDCouplingBasicsTest3::testUMInsertNextCell1()
02030 {
02031   double targetCoords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
02032   int targetConn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
02033   MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
02034   targetMesh->allocateCells(5);
02035   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn),INTERP_KERNEL::Exception);
02036   targetMesh->setMeshDimension(2);
02037   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
02038   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,targetConn),INTERP_KERNEL::Exception);
02039   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn),INTERP_KERNEL::Exception);
02040   CPPUNIT_ASSERT_THROW(targetMesh->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,targetConn),INTERP_KERNEL::Exception);
02041   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
02042   targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
02043   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
02044   targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
02045   targetMesh->finishInsertingCells();
02046   DataArrayDouble *myCoords=DataArrayDouble::New();
02047   myCoords->alloc(9,2);
02048   std::copy(targetCoords,targetCoords+18,myCoords->getPointer());
02049   targetMesh->setCoords(myCoords);
02050   myCoords->decrRef();
02051   targetMesh->checkCoherency();
02052   targetMesh->decrRef();
02053 }
02054 
02055 void MEDCouplingBasicsTest3::testFieldOperatorDivDiffComp1()
02056 {
02057   MEDCouplingUMesh *m=build2DTargetMesh_1();
02058   DataArrayInt *d1=DataArrayInt::New();
02059   DataArrayInt *d2=DataArrayInt::New();
02060   DataArrayInt *d3=DataArrayInt::New();
02061   DataArrayInt *d4=DataArrayInt::New();
02062   MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
02063   //
02064   MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
02065   const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
02066   DataArrayDouble *arr=DataArrayDouble::New();
02067   arr->alloc(13,1);
02068   std::copy(arr1,arr1+13,arr->getPointer());
02069   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
02070   f2->setArray(arr);
02071   f2->setMesh(m1);
02072   f2->checkCoherency();
02073   //
02074   MEDCouplingFieldDouble *f3=(*f1)/(*f2);
02075   CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
02076   f3->checkCoherency();
02077   (*f1)/=(*f2);
02078   CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
02079   CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
02080   const double expected1[26]={-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0};
02081   for(int i=0;i<26;i++)
02082     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
02083   //
02084   f3->decrRef();
02085   f2->decrRef();
02086   arr->decrRef();
02087   f1->decrRef();
02088   m1->decrRef();
02089   d1->decrRef();
02090   d2->decrRef();
02091   d3->decrRef();
02092   d4->decrRef();
02093   m->decrRef();
02094 }
02095 
02096 void MEDCouplingBasicsTest3::testDARearrange1()
02097 {
02098   DataArrayInt *da1=DataArrayInt::New();
02099   da1->alloc(12,1);
02100   da1->iota(0);
02101   const int *ptr=da1->getConstPointer();
02102   //
02103   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
02104   CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents());
02105   CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfTuples());
02106   da1->rearrange(4);
02107   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
02108   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
02109   CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfComponents());
02110   CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfTuples());
02111   for(int i=0;i<12;i++)
02112     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
02113   //
02114   da1->rearrange(6);
02115   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
02116   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
02117   CPPUNIT_ASSERT_EQUAL(6,da1->getNumberOfComponents());
02118   CPPUNIT_ASSERT_EQUAL(2,da1->getNumberOfTuples());
02119   for(int i=0;i<12;i++)
02120     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
02121   //
02122   CPPUNIT_ASSERT_THROW(da1->rearrange(7),INTERP_KERNEL::Exception);
02123   //
02124   da1->rearrange(12);
02125   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
02126   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
02127   CPPUNIT_ASSERT_EQUAL(12,da1->getNumberOfComponents());
02128   CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfTuples());
02129   for(int i=0;i<12;i++)
02130     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
02131   //
02132   da1->rearrange(3);
02133   CPPUNIT_ASSERT(ptr==da1->getConstPointer());
02134   CPPUNIT_ASSERT_EQUAL(12,da1->getNbOfElems());
02135   CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents());
02136   CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples());
02137   for(int i=0;i<12;i++)
02138     CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i));
02139   //double
02140   DataArrayDouble *da2=da1->convertToDblArr();
02141   da1->decrRef();
02142   const double *ptr2=da2->getConstPointer();
02143   //
02144   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
02145   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
02146   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
02147   da2->rearrange(4);
02148   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
02149   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
02150   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfComponents());
02151   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfTuples());
02152   for(int i=0;i<12;i++)
02153     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
02154   //
02155   da2->rearrange(6);
02156   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
02157   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
02158   CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfComponents());
02159   CPPUNIT_ASSERT_EQUAL(2,da2->getNumberOfTuples());
02160   for(int i=0;i<12;i++)
02161     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
02162   //
02163   CPPUNIT_ASSERT_THROW(da2->rearrange(7),INTERP_KERNEL::Exception);
02164   //
02165   da2->rearrange(1);
02166   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
02167   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
02168   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
02169   CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples());
02170   for(int i=0;i<12;i++)
02171     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
02172   //
02173   da2->rearrange(3);
02174   CPPUNIT_ASSERT(ptr2==da2->getConstPointer());
02175   CPPUNIT_ASSERT_EQUAL(12,da2->getNbOfElems());
02176   CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents());
02177   CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples());
02178   for(int i=0;i<12;i++)
02179     CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14);
02180   da2->decrRef();
02181 }
02182 
02183 void MEDCouplingBasicsTest3::testGetDifferentValues1()
02184 {
02185   DataArrayInt *da1=DataArrayInt::New();
02186   const int arr[12]={1,2,3,2,2,3,5,1,5,5,2,2};
02187   da1->alloc(4,3);
02188   std::copy(arr,arr+12,da1->getPointer());
02189   std::set<int> s=da1->getDifferentValues();
02190   const int expected1[4]={1,2,3,5};
02191   CPPUNIT_ASSERT_EQUAL(4,(int)s.size());
02192   CPPUNIT_ASSERT(std::equal(expected1,expected1+4,s.begin()));
02193   da1->decrRef();
02194 }
02195 
02196 void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1()
02197 {
02198   DataArrayInt *a=DataArrayInt::New();
02199   const int vala[5]={4,5,6,7,8};
02200   a->alloc(5,1);
02201   std::copy(vala,vala+5,a->getPointer());
02202   DataArrayInt *b=DataArrayInt::New();
02203   const int valb[5]={5,4,8,6,7};
02204   b->alloc(5,1);
02205   std::copy(valb,valb+5,b->getPointer());
02206   DataArrayInt *c=a->buildPermutationArr(*b);
02207   const int expect1[5]={1,0,4,2,3};
02208   CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
02209   CPPUNIT_ASSERT_EQUAL(1,c->getNumberOfComponents());
02210   CPPUNIT_ASSERT(std::equal(expect1,expect1+5,c->getConstPointer()));
02211   CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
02212   b->setIJ(0,0,9);
02213   CPPUNIT_ASSERT(!a->isEqualWithoutConsideringStrAndOrder(*b));
02214   CPPUNIT_ASSERT_THROW(a->buildPermutationArr(*b),INTERP_KERNEL::Exception);
02215   a->setIJ(3,0,4);
02216   b->setIJ(0,0,5);
02217   b->setIJ(4,0,4);//;a==[4,5,6,4,8] and b==[5,4,8,6,4]
02218   CPPUNIT_ASSERT(a->isEqualWithoutConsideringStrAndOrder(*b));
02219   c->decrRef();
02220   c=a->buildPermutationArr(*b);
02221   const int expect2[5]={1,3,4,2,3};
02222   CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer()));
02223   DataArrayDouble *d=b->convertToDblArr();
02224   b->sort();
02225   const int expect3[5]={4,4,5,6,8};
02226   CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer()));
02227   d->sort();
02228   CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
02229   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
02230   for(int i=0;i<5;i++)
02231     CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14);
02232   //
02233   d->decrRef();
02234   c->decrRef();
02235   a->decrRef();
02236   b->decrRef();
02237 }
02238 
02239 void MEDCouplingBasicsTest3::testAreCellsIncludedIn2()
02240 {
02241   const char myName[]="Vitoo";
02242   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
02243   MEDCouplingUMesh *m2=(MEDCouplingUMesh *)m->buildPartOfMySelf(0,0,true);
02244   CPPUNIT_ASSERT_EQUAL(0,m2->getNumberOfCells());
02245   CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
02246   CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
02247   m2->setName(myName);
02248   DataArrayInt *tmp;
02249   CPPUNIT_ASSERT(m->areCellsIncludedIn(m2,0,tmp));
02250   CPPUNIT_ASSERT(std::string(myName)==tmp->getName());
02251   CPPUNIT_ASSERT_EQUAL(0,tmp->getNumberOfTuples());
02252   CPPUNIT_ASSERT_EQUAL(1,tmp->getNumberOfComponents());
02253   m->decrRef();
02254   m2->decrRef();
02255   tmp->decrRef();
02256 }
02257 
02258 void MEDCouplingBasicsTest3::testUMeshGetPartBarycenterAndOwner1()
02259 {
02260   MEDCouplingUMesh *m1=build2DTargetMesh_1();
02261   const int part[3]={1,0,4};
02262   DataArrayDouble *b=m1->getPartBarycenterAndOwner(part,part+3);
02263   CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
02264   CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
02265   const double expected1[6]={0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45};
02266   for(int i=0;i<6;i++)
02267     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
02268   b->decrRef();
02269   m1->decrRef();
02270 }
02271 
02272 void MEDCouplingBasicsTest3::testUMeshGetPartMeasureField1()
02273 {
02274   MEDCouplingUMesh *m1=build2DTargetMesh_1();
02275   const int part[3]={1,0,4};
02276   DataArrayDouble *b=m1->getPartMeasureField(true,part,part+3);
02277   CPPUNIT_ASSERT_EQUAL(1,b->getNumberOfComponents());
02278   CPPUNIT_ASSERT_EQUAL(3,b->getNumberOfTuples());
02279   const double expected1[3]={0.125,0.25,0.25};
02280   for(int i=0;i<3;i++)
02281     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
02282   b->decrRef();
02283   m1->decrRef();
02284 }
02285 
02286 void MEDCouplingBasicsTest3::testUMeshBuildPartOrthogonalField1()
02287 {
02288   MEDCouplingUMesh *m1=build2DTargetMesh_1();
02289   m1->changeSpaceDimension(3);
02290   const int part[3]={1,0,4};
02291   MEDCouplingFieldDouble *b=m1->buildPartOrthogonalField(part,part+3);
02292   CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfComponents());
02293   CPPUNIT_ASSERT_EQUAL(3,b->getArray()->getNumberOfTuples());
02294   const double expected1[9]={0.,0.,-1.,0.,0.,-1.,0.,0.,-1.};
02295   for(int i=0;i<9;i++)
02296     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getArray()->getIJ(0,i),1e-14);
02297   b->decrRef();
02298   m1->decrRef();
02299 }
02300 
02301 void MEDCouplingBasicsTest3::testUMeshGetTypesOfPart1()
02302 {
02303   MEDCouplingUMesh *m1=build2DTargetMesh_1();
02304   const int part1[]={0,3,4};
02305   std::set<INTERP_KERNEL::NormalizedCellType> s;
02306   s=m1->getTypesOfPart(part1,part1+3);
02307   CPPUNIT_ASSERT(s.size()==1);
02308   CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_QUAD4);
02309   const int part2[]={2,2,2,1};
02310   s=m1->getTypesOfPart(part2,part2+4);
02311   CPPUNIT_ASSERT(s.size()==1);
02312   CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
02313   const int part3[]={3,2,1};
02314   s=m1->getTypesOfPart(part3,part3+3);
02315   CPPUNIT_ASSERT(s.size()==2);
02316   CPPUNIT_ASSERT(*s.begin()==INTERP_KERNEL::NORM_TRI3);
02317   CPPUNIT_ASSERT(*(++s.begin())==INTERP_KERNEL::NORM_QUAD4);
02318   m1->decrRef();
02319 }
02320 
02321 void MEDCouplingBasicsTest3::testUMeshKeepCellIdsByType1()
02322 {
02323   MEDCouplingUMesh *m1=build2DTargetMesh_1();
02324   const int part1[3]={0,3,4};
02325   DataArrayInt *a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part1,part1+3);
02326   CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
02327   CPPUNIT_ASSERT_EQUAL(0,a->getNumberOfTuples());
02328   a->decrRef();
02329   //
02330   const int part2[5]={3,2,0,2,4};
02331   a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_TRI3,part2,part2+5);
02332   CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
02333   CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfTuples());
02334   CPPUNIT_ASSERT_EQUAL(2,a->getIJ(0,0));
02335   CPPUNIT_ASSERT_EQUAL(2,a->getIJ(1,0));
02336   a->decrRef();
02337   //
02338   a=m1->keepCellIdsByType(INTERP_KERNEL::NORM_QUAD4,part2,part2+5);
02339   CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents());
02340   CPPUNIT_ASSERT_EQUAL(3,a->getNumberOfTuples());
02341   CPPUNIT_ASSERT_EQUAL(3,a->getIJ(0,0));
02342   CPPUNIT_ASSERT_EQUAL(0,a->getIJ(1,0));
02343   CPPUNIT_ASSERT_EQUAL(4,a->getIJ(2,0));
02344   //
02345   a->decrRef();
02346   m1->decrRef();
02347 }
02348 
02349 void MEDCouplingBasicsTest3::testDAIAggregateMulti1()
02350 {
02351   DataArrayInt *a=DataArrayInt::New();
02352   a->setName("aa");
02353   a->alloc(4,1);
02354   a->iota(0);
02355   a->rearrange(2);
02356   DataArrayInt *b=DataArrayInt::New();
02357   b->setName("bb");
02358   b->alloc(6,1);
02359   b->iota(0);
02360   b->rearrange(2);
02361   //
02362   std::vector<const DataArrayInt *> v(2);
02363   v[0]=a; v[1]=b;
02364   DataArrayInt *c=DataArrayInt::Aggregate(v);
02365   CPPUNIT_ASSERT_EQUAL(5,c->getNumberOfTuples());
02366   CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
02367   CPPUNIT_ASSERT(c->getName()=="aa");
02368   const int expect1[10]={0,1,2,3,0,1,2,3,4,5};
02369   for(int i=0;i<10;i++)
02370     CPPUNIT_ASSERT_EQUAL(expect1[i],c->getIJ(0,i));
02371   //
02372   c->decrRef();
02373   a->decrRef();
02374   b->decrRef();
02375 }
02376 
02377 void MEDCouplingBasicsTest3::testMergeUMeshes2()
02378 {
02379   MEDCouplingUMesh *m1=build3DSurfTargetMesh_1();
02380   MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
02381   MEDCouplingUMesh *m3=build3DSurfTargetMesh_1();
02382   //
02383   const int vec1[3]={0,2,3};
02384   MEDCouplingUMesh *m2_2=(MEDCouplingUMesh *)m2->buildPartOfMySelf(vec1,vec1+3,false);
02385   const int vec2[2]={1,1};
02386   MEDCouplingUMesh *m3_2=(MEDCouplingUMesh *)m3->buildPartOfMySelf(vec2,vec2+2,false);
02387   //
02388   std::vector<const MEDCouplingUMesh *> ms(3);
02389   std::vector<const MEDCouplingMesh *> ms2(3);
02390   ms[0]=m1; ms[1]=m2_2; ms[2]=m3_2;
02391   ms2[0]=m1; ms2[1]=m2_2; ms2[2]=m3_2;
02392   //
02393   MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(ms);
02394   m4->checkCoherency();
02395   CPPUNIT_ASSERT_EQUAL(10,m4->getNumberOfCells());
02396   CPPUNIT_ASSERT_EQUAL(20,m4->getNumberOfNodes());
02397   CPPUNIT_ASSERT_EQUAL(45,m4->getMeshLength());
02398   //
02399   MEDCouplingMesh *m4bis=MEDCouplingMesh::MergeMeshes(ms2);
02400   CPPUNIT_ASSERT(m4->isEqual(m4bis,1e-12));
02401   m4bis->decrRef();
02402   //
02403   const int vec3[5]={0,1,2,3,4};
02404   MEDCouplingUMesh *m4_1=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec3,vec3+5,false);
02405   m4_1->setName(m1->getName());
02406   CPPUNIT_ASSERT(m4_1->isEqual(m1,1e-12));
02407   m4_1->decrRef();
02408   //
02409   const int vec4[3]={5,6,7};
02410   MEDCouplingUMesh *m4_2=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec4,vec4+3,false);
02411   DataArrayInt *cellCor=0;
02412   DataArrayInt *nodeCor=0;
02413   m4_2->checkGeoEquivalWith(m2_2,10,1e-12,cellCor,nodeCor);
02414   CPPUNIT_ASSERT(cellCor==0);
02415   CPPUNIT_ASSERT(nodeCor==0);
02416   m4_2->decrRef();
02417   //
02418   const int vec5[2]={8,9};
02419   MEDCouplingUMesh *m4_3=(MEDCouplingUMesh *)m4->buildPartOfMySelf(vec5,vec5+2,false);
02420   CPPUNIT_ASSERT_EQUAL(2,m4_3->getNumberOfCells());
02421   CPPUNIT_ASSERT_EQUAL(3,m4_3->getNumberOfNodes());
02422   m3_2->zipCoords();
02423   m4_3->setName(m3_2->getName());
02424   CPPUNIT_ASSERT(m4_3->isEqual(m3_2,1e-12));
02425   m4_3->decrRef();
02426   //
02427   m4->decrRef();
02428   m1->decrRef();
02429   m2->decrRef();
02430   m2_2->decrRef();
02431   m3->decrRef();
02432   m3_2->decrRef();
02433 }
02434 
02435 void MEDCouplingBasicsTest3::testBuild0DMeshFromCoords1()
02436 {
02437   const double sourceCoords[12]={-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.};
02438   DataArrayDouble *coo=DataArrayDouble::New();
02439   coo->alloc(4,3);
02440   coo->setName("My0D");
02441   std::copy(sourceCoords,sourceCoords+12,coo->getPointer());
02442   MEDCouplingUMesh *m=MEDCouplingUMesh::Build0DMeshFromCoords(coo);
02443   m->checkCoherency();
02444   CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
02445   CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfCells());
02446   CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
02447   CPPUNIT_ASSERT_EQUAL(0,m->getMeshDimension());
02448   const std::set<INTERP_KERNEL::NormalizedCellType>& types=m->getAllTypes();
02449   CPPUNIT_ASSERT_EQUAL(1,(int)types.size());
02450   CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_POINT1,*types.begin());
02451   for(int i=0;i<4;i++)
02452     {
02453       std::vector<int> conn;
02454       m->getNodeIdsOfCell(i,conn);
02455       CPPUNIT_ASSERT_EQUAL(1,(int)conn.size());
02456       CPPUNIT_ASSERT_EQUAL(i,conn[0]);
02457       CPPUNIT_ASSERT(INTERP_KERNEL::NORM_POINT1==m->getTypeOfCell(i));
02458     }
02459   CPPUNIT_ASSERT(std::string(m->getName())=="My0D");
02460   m->decrRef();
02461   coo->decrRef();
02462 }
02463