Back to index

salome-med  6.5.0
MEDCouplingBasicsTest2.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 "MEDCouplingBasicsTest2.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 <algorithm>
00030 #include <functional>
00031 #include <iterator>
00032 
00033 using namespace ParaMEDMEM;
00034 
00035 void MEDCouplingBasicsTest2::testGaussPointField1()
00036 {
00037   const double _a=0.446948490915965;
00038   const double _b=0.091576213509771;
00039   const double _p1=0.11169079483905;
00040   const double _p2=0.0549758718227661;
00041   const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
00042   const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
00043                             2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
00044   const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
00045   std::vector<double> _refCoo1(refCoo1,refCoo1+6);
00046   std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
00047   std::vector<double> _wg1(wg1,wg1+6);
00048   //
00049   MEDCouplingUMesh *m=build2DTargetMesh_1();
00050   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME);
00051   f->setMesh(m);
00052   CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected());
00053   CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization());
00054   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
00055   CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo1,_gsCoo1,_wg1),INTERP_KERNEL::Exception);
00056   CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization());
00057   const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
00058   std::vector<double> _refCoo2(refCoo2,refCoo2+8);
00059   _gsCoo1.resize(4); _wg1.resize(2);
00060   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
00061   CPPUNIT_ASSERT_EQUAL(2,f->getNbOfGaussLocalization());
00062   DataArrayDouble *array=DataArrayDouble::New();
00063   array->alloc(18,2);
00064   double *ptr=array->getPointer();
00065   for(int i=0;i<18*2;i++)
00066     ptr[i]=(double)(i+1);
00067   f->setArray(array);
00068   f->setName("MyFirstFieldOnGaussPoint");
00069   array->decrRef();
00070   f->checkCoherency();
00071   CPPUNIT_ASSERT_DOUBLES_EQUAL(27.,f->getIJK(2,5,0),1e-14);
00072   CPPUNIT_ASSERT_DOUBLES_EQUAL(16.,f->getIJK(1,5,1),1e-14);
00073   //
00074   f->clearGaussLocalizations();
00075   CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization());
00076   CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);
00077   int ids1[4]={0,1,3,4};
00078   CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnCells(ids1,ids1+4,_refCoo2,_gsCoo1,_wg1),INTERP_KERNEL::Exception);
00079   CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization());
00080   int ids2[2]={0,4};
00081   f->setGaussLocalizationOnCells(ids2,ids2+2,_refCoo2,_gsCoo1,_wg1);
00082   CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization());
00083   CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0));
00084   CPPUNIT_ASSERT_THROW(f->getGaussLocalizationIdOfOneCell(1),INTERP_KERNEL::Exception);
00085   int ids3[2]={1,2};
00086   f->setGaussLocalizationOnCells(ids3,ids3+2,_refCoo1,_gsCoo1,_wg1);
00087   CPPUNIT_ASSERT_EQUAL(2,f->getNbOfGaussLocalization());
00088   CPPUNIT_ASSERT_EQUAL(0,f->getGaussLocalizationIdOfOneCell(0));
00089   CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(1));
00090   CPPUNIT_ASSERT_EQUAL(1,f->getGaussLocalizationIdOfOneCell(2));
00091   CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);//<- cell 3 has no localization
00092   int ids4[1]={3};
00093   std::vector<double> _gsCoo2(_gsCoo1);
00094   std::vector<double> _wg2(_wg1);
00095   _gsCoo2[0]=0.8888777776666; _wg2[0]=0.1234567892377;
00096   f->setGaussLocalizationOnCells(ids4,ids4+1,_refCoo2,_gsCoo2,_wg2);
00097   CPPUNIT_ASSERT_EQUAL(3,f->getNbOfGaussLocalization());
00098   std::vector<int> tmpIds;
00099   f->getCellIdsHavingGaussLocalization(0,tmpIds);
00100   CPPUNIT_ASSERT_EQUAL(2,(int)tmpIds.size());
00101   CPPUNIT_ASSERT(std::equal(ids2,ids2+2,tmpIds.begin()));
00102   CPPUNIT_ASSERT_THROW(f->checkCoherency(),INTERP_KERNEL::Exception);//<- it's always not ok because undelying array not with the good size.
00103   DataArrayDouble *array2=f->getArray()->substr(0,10);
00104   f->setArray(array2);
00105   array2->decrRef();
00106   f->checkCoherency();//<- here it is OK
00107   MEDCouplingFieldDouble *f2=f->clone(true);
00108   CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
00109   MEDCouplingGaussLocalization& gl1=f2->getGaussLocalization(0);
00110   double tmp=gl1.getGaussCoord(1,1);
00111   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.07*_b-1,tmp,1e-14);
00112   gl1.setGaussCoord(1,1,0.07);
00113   CPPUNIT_ASSERT(!f->isEqual(f2,1e-14,1e-14));
00114   gl1.setGaussCoord(1,1,tmp);
00115   CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
00116   f->decrRef();
00117   f2->checkCoherency();
00118   //
00119   f2->decrRef();
00120   m->decrRef();
00121 }
00122 
00123 void MEDCouplingBasicsTest2::testGaussPointNEField1()
00124 {
00125   MEDCouplingUMesh *m=build2DTargetMesh_1();
00126   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
00127   f->setMesh(m);
00128   CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected());
00129   f->setName("MyFirstFieldOnNE");
00130   f->setDescription("MyDescriptionNE");
00131   DataArrayDouble *array=DataArrayDouble::New();
00132   array->alloc(18,2);
00133   double *ptr=array->getPointer();
00134   for(int i=0;i<18*2;i++)
00135     ptr[i]=(double)(i+7);
00136   f->setArray(array);
00137   array->decrRef();
00138   //
00139   f->checkCoherency();
00140   MEDCouplingFieldDouble *f2=f->clone(true);
00141   CPPUNIT_ASSERT(f->isEqual(f2,1e-14,1e-14));
00142   CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,f->getIJK(2,0,0),1e-14);
00143   CPPUNIT_ASSERT_DOUBLES_EQUAL(18.,f->getIJK(1,1,1),1e-14);
00144   f2->decrRef();
00145   //
00146   f->decrRef();
00147   m->decrRef();
00148 }
00149 
00150 void MEDCouplingBasicsTest2::testCellOrientation1()
00151 {
00152   MEDCouplingUMesh *m=build2DTargetMesh_1();
00153   double vec[3]={0.,0.,-1.};
00154   std::vector<int> res1;
00155   CPPUNIT_ASSERT_THROW(m->are2DCellsNotCorrectlyOriented(vec,false,res1),INTERP_KERNEL::Exception);
00156   m->changeSpaceDimension(3);
00157   res1.clear();
00158   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
00159   CPPUNIT_ASSERT(res1.empty());
00160   vec[2]=1;
00161   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
00162   CPPUNIT_ASSERT_EQUAL(5,(int)res1.size());
00163   res1.clear();
00164   //
00165   vec[2]=-1.;
00166   // connectivity inversion
00167   int *conn=m->getNodalConnectivity()->getPointer();
00168   int tmp=conn[11];
00169   conn[11]=conn[12];
00170   conn[12]=tmp;
00171   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
00172   CPPUNIT_ASSERT_EQUAL(1,(int)res1.size());
00173   CPPUNIT_ASSERT_EQUAL(2,res1[0]);
00174   res1.clear();
00175   m->orientCorrectly2DCells(vec,false);
00176   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
00177   CPPUNIT_ASSERT(res1.empty());
00178   MEDCouplingUMesh *m2=build2DTargetMesh_1();
00179   m2->changeSpaceDimension(3);
00180   CPPUNIT_ASSERT(m->isEqual(m2,1e-12));
00181   m2->decrRef();
00182   //
00183   m->decrRef();
00184 }
00185 
00186 void MEDCouplingBasicsTest2::testCellOrientation2()
00187 {
00188   MEDCouplingUMesh *m1=0;
00189   MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
00190   m1->decrRef();
00191   std::vector<int> res1;
00192   m2->arePolyhedronsNotCorrectlyOriented(res1);
00193   CPPUNIT_ASSERT_EQUAL(6,(int)res1.size());
00194   m2->orientCorrectlyPolyhedrons();
00195   res1.clear();
00196   m2->arePolyhedronsNotCorrectlyOriented(res1);
00197   CPPUNIT_ASSERT(res1.empty());
00198   m2->checkCoherency();
00199   CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
00200   int cellIds[3]={0,6,12};
00201   std::vector<int> cellIds2(cellIds,cellIds+3);
00202   m2->convertToPolyTypes(&cellIds2[0],&cellIds2[0]+cellIds2.size());
00203   m2->orientCorrectlyPolyhedrons();
00204   res1.clear();
00205   m2->arePolyhedronsNotCorrectlyOriented(res1);
00206   CPPUNIT_ASSERT(res1.empty());
00207   MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
00208   //Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation
00209   MEDCouplingUMesh *m3=build2DTargetMesh_1();
00210   double vec[3]={0.,0.,1.};
00211   m3->changeSpaceDimension(3);
00212   const int ids1[5]={0,1,2,3,4};
00213   std::vector<int> ids2(ids1,ids1+5);
00214   m3->convertToPolyTypes(&ids2[0],&ids2[0]+ids2.size());
00215   m3->orientCorrectly2DCells(vec,false);
00216   MEDCouplingUMesh *m4=buildCU1DMesh_U();
00217   m4->changeSpaceDimension(3);
00218   double center[3]={0.,0.,0.};
00219   double vector[3]={0.,1.,0.};
00220   m4->rotate(center,vector,-M_PI/2.);
00221   MEDCouplingUMesh *m5=m3->buildExtrudedMesh(m4,0);
00222   res1.clear();
00223   m5->arePolyhedronsNotCorrectlyOriented(res1);
00224   CPPUNIT_ASSERT_EQUAL(15,(int)res1.size());
00225   m5->orientCorrectlyPolyhedrons();
00226   res1.clear();
00227   m5->arePolyhedronsNotCorrectlyOriented(res1);
00228   CPPUNIT_ASSERT(res1.empty());
00229   MEDCouplingFieldDouble *f3=m5->getMeasureField(false);
00230   CPPUNIT_ASSERT_EQUAL(15,f3->getArray()->getNumberOfTuples());
00231   CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
00232   const double *f3Ptr=f3->getArray()->getConstPointer();
00233   const double expected1[15]={
00234     0.075,0.0375,0.0375,0.075,0.075,
00235     0.1125,0.05625,0.05625,0.1125,0.1125,
00236     0.0625,0.03125,0.03125,0.0625,0.0625
00237   };
00238   for(int i=0;i<15;i++)
00239     CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),f3Ptr[i],1e-12);
00240   f3->decrRef();
00241   DataArrayDouble *f4=m5->getBarycenterAndOwner();
00242   CPPUNIT_ASSERT_EQUAL(15,f4->getNumberOfTuples());
00243   CPPUNIT_ASSERT_EQUAL(3,f4->getNumberOfComponents());
00244   const double *f4Ptr=f4->getConstPointer();
00245   const double expected2[45]={
00246     -0.05,-0.05,0.15, 0.3666666666666667,-0.13333333333333333,0.15, 0.53333333333333333,0.033333333333333333,0.15, -0.05,0.45,0.15, 0.45,0.45,0.15,
00247     -0.05,-0.05,0.525, 0.3666666666666667,-0.13333333333333333,0.525, 0.53333333333333333,0.033333333333333333,0.525, -0.05,0.45,0.525, 0.45,0.45,0.525,
00248     -0.05,-0.05,0.875, 0.3666666666666667,-0.13333333333333333,0.875, 0.53333333333333333,0.033333333333333333,0.875, -0.05,0.45,0.875, 0.45,0.45,0.875
00249   };
00250   for(int i=0;i<45;i++)
00251     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4Ptr[i],1e-12);
00252   f4->decrRef();
00253   m5->decrRef();
00254   m3->decrRef();
00255   m4->decrRef();
00256   //
00257   f2->decrRef();
00258   m2->decrRef();
00259 }
00260 
00264 void MEDCouplingBasicsTest2::testPolyhedronBarycenter()
00265 {
00266   int connN[]={0,3,2,1, -1, 4,5,6,7, -1, 0,4,7,3, -1, 3,7,6,2, -1, 2,6,5,1, -1, 1,5,4,0};
00267   double coords[]={0.,0.,0., 1.,0.,0., 1.,1.,0., 0.,1.,0., 0.,0.,1., 1.,0.,1., 1.,1.,1., 0.,1.,1., 0.5, 0.5, 0.5};
00268   MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
00269   meshN->setName("ForBary");
00270   meshN->setMeshDimension(3);
00271   meshN->allocateCells(4);
00272   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,29,connN);
00273   meshN->finishInsertingCells();
00274   DataArrayDouble *myCoords=DataArrayDouble::New();
00275   myCoords->alloc(9,3);
00276   std::copy(coords,coords+27,myCoords->getPointer());
00277   meshN->setCoords(myCoords);
00278   myCoords->decrRef();
00279   meshN->checkCoherency();
00280   //
00281   std::vector<int> res1;
00282   meshN->arePolyhedronsNotCorrectlyOriented(res1);
00283   meshN->orientCorrectlyPolyhedrons();
00284   CPPUNIT_ASSERT(res1.empty());
00285   const double *ref,*daPtr;
00286   DataArrayDouble *da=meshN->getBarycenterAndOwner();
00287   CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfTuples());
00288   CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents());
00289   daPtr=da->getConstPointer();
00290   ref=meshN->getCoords()->getConstPointer()+24;
00291   for(int i=0;i<3;i++)
00292     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
00293   da->decrRef();
00294   //
00295   const double center[]={0.,0.,0.};
00296   const double vec[]={0.,2.78,0.};
00297   da=meshN->getBarycenterAndOwner();
00298   daPtr=da->getConstPointer();
00299   ref=meshN->getCoords()->getConstPointer()+24;
00300   for(int i=0;i<3;i++)
00301     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
00302   da->decrRef();
00303   //
00304   meshN->rotate(center,vec,M_PI/7.);
00305   meshN->translate(vec);
00306   da=meshN->getBarycenterAndOwner();
00307   daPtr=da->getConstPointer();
00308   ref=meshN->getCoords()->getConstPointer()+24;
00309   for(int i=0;i<3;i++)
00310     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-12);
00311   da->decrRef();
00312   //
00313   const double center2[]={1.12,3.45,6.78};
00314   const double vec2[]={4.5,9.3,2.8};
00315   meshN->rotate(center2,vec2,M_E);
00316   meshN->translate(vec2);
00317   da=meshN->getBarycenterAndOwner();
00318   daPtr=da->getConstPointer();
00319   ref=meshN->getCoords()->getConstPointer()+24;
00320   for(int i=0;i<3;i++)
00321     CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i],daPtr[i],1e-10);
00322   da->decrRef();
00323   //
00324   meshN->decrRef();
00325 }
00326 
00327 void MEDCouplingBasicsTest2::testNormL12Integ1D()
00328 {
00329   MEDCouplingUMesh *m1=build1DTargetMesh_3();
00330   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00331   f1->setMesh(m1);
00332   DataArrayDouble *array=DataArrayDouble::New();
00333   array->alloc(m1->getNumberOfCells(),3);
00334   const double arr[12]={-5.23,15.45,-25.56,6.67,-16.78,26.89,-7.91,17.23,-27.43,8.21,-18.63,28.72};
00335   std::copy(arr,arr+12,array->getPointer());
00336   f1->setArray(array);
00337   array->decrRef();
00338   //
00339   const double *ptr;
00340   DataArrayDouble *f3=m1->getBarycenterAndOwner();
00341   CPPUNIT_ASSERT_EQUAL(4,f3->getNumberOfTuples());
00342   CPPUNIT_ASSERT_EQUAL(1,f3->getNumberOfComponents());
00343   double expected9[4]={0.75,5.105,0.8,5.155};
00344   ptr=f3->getConstPointer();
00345    for(int i=0;i<4;i++)
00346     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected9[i],ptr[i],1e-12);
00347   f3->decrRef();
00348   //
00349   MEDCouplingFieldDouble *f2=m1->getMeasureField(false);
00350   CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
00351   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
00352   double expected1[4]={0.5,0.21,-0.6,-0.31};
00353   ptr=f2->getArray()->getConstPointer();
00354   for(int i=0;i<4;i++)
00355     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
00356   f2->decrRef();
00357   double expected2[4]={0.5,0.21,0.6,0.31};
00358   f2=m1->getMeasureField(true);
00359   ptr=f2->getArray()->getConstPointer();
00360   for(int i=0;i<4;i++)
00361     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
00362   f2->decrRef();
00363   //integral
00364   double res[3];
00365   f1->integral(false,res);
00366   double expected3[3]={0.9866,-0.3615,0.4217};
00367   for(int i=0;i<3;i++)
00368     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],res[i],1e-12);
00369   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f1->integral(0,false),1e-12);
00370   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f1->integral(1,false),1e-12);
00371   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f1->integral(2,false),1e-12);
00372   f1->integral(true,res);
00373   double expected4[3]={-3.4152,8.7639,-14.6879};
00374   for(int i=0;i<3;i++)
00375     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],res[i],1e-12);
00376   //normL1
00377   f1->normL1(res);
00378   double expected5[3]={6.979506172839505, 16.89018518518518, 27.02969135802469};
00379   for(int i=0;i<3;i++)
00380     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
00381   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[0],f1->normL1(0),1e-12);
00382   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[1],f1->normL1(1),1e-12);
00383   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[2],f1->normL1(2),1e-12);
00384   //normL2
00385   f1->normL2(res);
00386   double expected7[3]={7.090910979452395, 16.9275542960123, 27.053271464160858};
00387   for(int i=0;i<3;i++)
00388     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-9);
00389   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[0],f1->normL2(0),1e-9);
00390   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[1],f1->normL2(1),1e-9);
00391   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[2],f1->normL2(2),1e-9);
00392   //buildMeasureField
00393   MEDCouplingFieldDouble *f4=f1->buildMeasureField(false);
00394   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.2,f4->accumulate(0),1e-12);
00395   f4->decrRef();
00396   f4=f1->buildMeasureField(true);
00397   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.62,f4->accumulate(0),1e-12);
00398   f4->decrRef();
00399   //
00400   f1->decrRef();
00401   m1->decrRef();
00402   // Testing with 2D Curve
00403   m1=build2DCurveTargetMesh_3();
00404   f2=m1->getMeasureField(false);
00405   CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
00406   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
00407   ptr=f2->getArray()->getConstPointer();
00408   for(int i=0;i<4;i++)
00409     CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected2[i],ptr[i],1e-12);
00410   f2->decrRef();
00411   f2=m1->getMeasureField(true);
00412   CPPUNIT_ASSERT_EQUAL(4,f2->getArray()->getNumberOfTuples());
00413   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
00414   ptr=f2->getArray()->getConstPointer();
00415   for(int i=0;i<4;i++)
00416     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i]*sqrt(2.),ptr[i],1e-12);
00417   f2->decrRef();
00418   //bary
00419   f3=m1->getBarycenterAndOwner();
00420   CPPUNIT_ASSERT_EQUAL(4,f3->getNumberOfTuples());
00421   CPPUNIT_ASSERT_EQUAL(2,f3->getNumberOfComponents());
00422   double expected10[8]={0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155};
00423   ptr=f3->getConstPointer();
00424    for(int i=0;i<8;i++)
00425      CPPUNIT_ASSERT_DOUBLES_EQUAL(expected10[i],ptr[i],1e-12);
00426   f3->decrRef();
00427   //
00428   f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00429   f1->setMesh(m1);
00430   array=DataArrayDouble::New();
00431   array->alloc(m1->getNumberOfCells(),3);
00432   std::copy(arr,arr+12,array->getPointer());
00433   f1->setArray(array);
00434   array->decrRef();
00435   f1->integral(false,res);
00436   for(int i=0;i<3;i++)
00437     CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
00438   f1->integral(true,res);
00439   for(int i=0;i<3;i++)
00440     CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.)*expected4[i],res[i],1e-12);
00441   f1->normL1(res);
00442   for(int i=0;i<3;i++)
00443     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],res[i],1e-12);
00444   f1->normL2(res);
00445   for(int i=0;i<3;i++)
00446     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],res[i],1e-12);
00447   //
00448   f1->decrRef();
00449   m1->decrRef();
00450 }
00451 
00452 void MEDCouplingBasicsTest2::testAreaBary2D()
00453 {
00454   MEDCouplingUMesh *m1=build2DTargetMesh_3();
00455   MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
00456   CPPUNIT_ASSERT_EQUAL(10,f1->getArray()->getNumberOfTuples());
00457   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
00458   double expected1[10]={-0.5,-1,-1.5,-0.5,-1,  0.5,1,1.5,0.5,1};
00459   const double *ptr=f1->getArray()->getConstPointer();
00460   for(int i=0;i<10;i++)
00461     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
00462   f1->decrRef();
00463   f1=m1->getMeasureField(true);
00464   ptr=f1->getArray()->getConstPointer();
00465   for(int i=0;i<10;i++)
00466     CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
00467   f1->decrRef();
00468   DataArrayDouble *f2=m1->getBarycenterAndOwner();
00469   CPPUNIT_ASSERT_EQUAL(10,f2->getNumberOfTuples());
00470   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
00471   double expected2[20]={
00472     0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
00473     0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,
00474   };
00475   ptr=f2->getConstPointer();
00476   for(int i=0;i<20;i++)
00477     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
00478   f2->decrRef();
00479   m1->changeSpaceDimension(3);
00480   f1=m1->getMeasureField(false);
00481   CPPUNIT_ASSERT_EQUAL(10,f1->getArray()->getNumberOfTuples());
00482   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
00483   ptr=f1->getArray()->getConstPointer();
00484   for(int i=0;i<10;i++)
00485     CPPUNIT_ASSERT_DOUBLES_EQUAL(std::abs(expected1[i]),ptr[i],1e-12);
00486   f1->decrRef();
00487   f2=m1->getBarycenterAndOwner();
00488   CPPUNIT_ASSERT_EQUAL(10,f2->getNumberOfTuples());
00489   CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfComponents());
00490   ptr=f2->getConstPointer();
00491   double expected3[30]={
00492     0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.,
00493     0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.
00494   };
00495   for(int i=0;i<30;i++)
00496     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
00497   f2->decrRef();
00498   m1->decrRef();
00499 }
00500 
00504 void MEDCouplingBasicsTest2::testAreaBary3D()
00505 {
00506   double coords [] = { 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
00507                        0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
00508                        0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
00509                        0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
00510                        -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
00511                        -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
00512                        0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
00513                        0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
00514                        -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
00515                        0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
00516                        -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
00517                        -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
00518                        -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
00519                        -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
00520                        -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
00521                        -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
00522                        0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
00523                        0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
00524                        0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
00525                        -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
00526                        -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
00527                        -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
00528                        -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
00529                        0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
00530                        0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
00531                        0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
00532                        -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
00533                        -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
00534                        0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
00535                        0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
00536                        -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
00537                        0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
00538                        0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
00539                        0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
00540                        -0.0372812069535 , -0.286740286332 , 0.00963701291166 };
00541 
00542   int connN [] = { /*polyhedron 0*/
00543     0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
00544     , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
00545     , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
00546     , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
00547     /* polyhedron 1*/
00548     0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
00549     , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
00550     , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
00551     , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
00552     /* polyhedron 2*/
00553     6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
00554     , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
00555     /*polyhedron 3*/
00556     35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
00557     , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
00558     , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
00559     , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65};
00560 
00561   double barys[]={ -0.0165220465527 , -0.0190922868195 , 0.158882733414 ,
00562                    0.0287618656076 , 0.135874379934 , -0.14601588119 ,
00563                    -0.147128055553 , 0.0465995097041 , -0.049391174453 ,
00564                    -0.00142506732317 , -0.0996953090351 , -0.115159183132 };
00565   MEDCouplingUMesh *meshN=MEDCouplingUMesh::New();
00566   meshN->setName("ForBary");
00567   meshN->setMeshDimension(3);
00568   meshN->allocateCells(4);
00569   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,113,connN);
00570   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,99,connN+113);
00571   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,43,connN+212);
00572   meshN->insertNextCell(INTERP_KERNEL::NORM_POLYHED,92,connN+255);
00573   meshN->finishInsertingCells();
00574   DataArrayDouble *myCoords=DataArrayDouble::New();
00575   myCoords->alloc(69,3);
00576   std::copy(coords,coords+207,myCoords->getPointer());
00577   meshN->setCoords(myCoords);
00578   myCoords->decrRef();
00579   meshN->checkCoherency();
00580   std::vector<int> res1;
00581   meshN->arePolyhedronsNotCorrectlyOriented(res1);
00582   meshN->orientCorrectlyPolyhedrons();
00583   res1.clear();
00584   meshN->arePolyhedronsNotCorrectlyOriented(res1);
00585   CPPUNIT_ASSERT(res1.empty());
00586   //
00587   DataArrayDouble *da=meshN->getBarycenterAndOwner();
00588   CPPUNIT_ASSERT_EQUAL(4,da->getNumberOfTuples());
00589   CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents());
00590   const double *daPtr=da->getConstPointer();
00591   for(int i=0;i<12;i++)
00592     CPPUNIT_ASSERT_DOUBLES_EQUAL(barys[i],daPtr[i],1e-12);
00593   da->decrRef();
00594   //
00595   meshN->decrRef();
00596 }
00597 
00598 void MEDCouplingBasicsTest2::testRenumberCellsForFields()
00599 {
00600   MEDCouplingUMesh *m=build2DTargetMesh_1();
00601   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
00602   f->setMesh(m);
00603   DataArrayDouble *arr=DataArrayDouble::New();
00604   int nbOfCells=m->getNumberOfCells();
00605   arr->alloc(nbOfCells,3);
00606   f->setArray(arr);
00607   arr->decrRef();
00608   const double values1[15]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.};
00609   std::copy(values1,values1+15,arr->getPointer());
00610   const int renumber1[5]={3,1,0,4,2};
00611   double res[3];
00612   const double loc[]={-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45};
00613   for(int j=0;j<5;j++)
00614     {
00615       f->getValueOn(loc+2*j,res);
00616       for(int i=0;i<3;i++)
00617         CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
00618     }
00619   f->renumberCells(renumber1,false);
00620   const double *ptr=f->getArray()->getConstPointer();
00621   const double expected1[15]={9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.};
00622   for(int i=0;i<15;i++)
00623     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],ptr[i],1e-12);
00624   //check that fields remains the same geometrically
00625   for(int j=0;j<5;j++)
00626     {
00627       f->getValueOn(loc+2*j,res);
00628       for(int i=0;i<3;i++)
00629         CPPUNIT_ASSERT_DOUBLES_EQUAL(values1[i+3*j],res[i],1e-12);
00630     }
00631   f->decrRef();
00632   //On gauss
00633   f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,NO_TIME);
00634   f->setMesh(m);
00635   const double _a=0.446948490915965;
00636   const double _b=0.091576213509771;
00637   const double _p1=0.11169079483905;
00638   const double _p2=0.0549758718227661;
00639   const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. };
00640   const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
00641                             2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 };
00642   const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 };
00643   std::vector<double> _refCoo1(refCoo1,refCoo1+6);
00644   std::vector<double> _gsCoo1(gsCoo1,gsCoo1+12);
00645   std::vector<double> _wg1(wg1,wg1+6);
00646   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
00647   const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. };
00648   std::vector<double> _refCoo2(refCoo2,refCoo2+8);
00649   _gsCoo1.resize(4); _wg1.resize(2);
00650   f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
00651   arr=DataArrayDouble::New();
00652   arr->alloc(18,2);
00653   const double values2[36]={1.,1001.,2.,1002., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 31.,1031.,32.,1032., 41.,1041.,42.,1042.};
00654   std::copy(values2,values2+36,arr->getPointer());
00655   f->setArray(arr);
00656   arr->decrRef();
00657   f->checkCoherency();
00658   MEDCouplingFieldDouble *fCpy=f->clone(true);
00659   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
00660   f->renumberCells(renumber1,false);
00661   CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
00662   double expected2[36]={21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 41.,1041.,42.,1042., 1.,1001.,2.,1002., 31.,1031.,32.,1032.};
00663   ptr=f->getArray()->getConstPointer();
00664   for(int i=0;i<36;i++)
00665     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],ptr[i],1e-12);
00666   const int renumber2[5]={2,1,4,0,3};//reverse renumber1
00667   f->renumberCells(renumber2,false);
00668   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
00669   fCpy->decrRef();
00670   f->decrRef();
00671   //GaussNE
00672   f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,NO_TIME);
00673   f->setMesh(m);
00674   arr=DataArrayDouble::New();
00675   arr->alloc(18,2);
00676   const double values3[36]={1.,1001.,2.,1002.,3.,1003.,4.,1004., 11.,1011.,12.,1012.,13.,1013., 21.,1021.,22.,1022.,23.,1023., 31.,1031.,32.,1032.,33.,1033.,34.,1034., 41.,1041.,42.,1042.,43.,1043.,44.,1044.};
00677   std::copy(values3,values3+36,arr->getPointer());
00678   f->setArray(arr);
00679   arr->decrRef();
00680   f->checkCoherency();
00681   fCpy=f->clone(true);
00682   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
00683   f->renumberCells(renumber1,false);
00684   CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
00685   double expected3[36]={21.,1021.,22.,1022.,23.,1023.,11.,1011.,12.,1012.,13.,1013.,41.,1041.,42.,1042.,43.,1043.,44.,1044.,1.,1001.,2.,1002.,3.,1003.,4.,1004.,31.,1031.,32.,1032.,33.,1033.,34.,1034.};
00686   ptr=f->getArray()->getConstPointer();
00687   for(int i=0;i<36;i++)
00688     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ptr[i],1e-12);
00689   f->renumberCells(renumber2,false);//perform reverse operation of renumbering to check that the resulting field is equal.
00690   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
00691   fCpy->decrRef();
00692   f->decrRef();
00693   //
00694   m->decrRef();
00695 }
00696 
00697 void MEDCouplingBasicsTest2::testRenumberNodesForFields()
00698 {
00699   MEDCouplingUMesh *m=build2DTargetMesh_1();
00700   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
00701   f->setMesh(m);
00702   CPPUNIT_ASSERT_EQUAL(9,f->getNumberOfMeshPlacesExpected());
00703   DataArrayDouble *arr=DataArrayDouble::New();
00704   int nbOfNodes=m->getNumberOfNodes();
00705   arr->alloc(nbOfNodes,3);
00706   f->setArray(arr);
00707   arr->decrRef();
00708   const double values1[27]={7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.};
00709   std::copy(values1,values1+27,arr->getPointer());
00710   f->checkCoherency();
00711   const int renumber1[9]={0,4,1,3,5,2,6,7,8};
00712   double res[3];
00713   const double loc[]={0.5432,-0.2432, 0.5478,0.1528};
00714   const double expected1[6]={9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124};
00715   for(int j=0;j<2;j++)
00716     {
00717       f->getValueOn(loc+2*j,res);
00718       for(int i=0;i<3;i++)
00719         CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
00720     }
00721   MEDCouplingFieldDouble *fCpy=f->clone(true);
00722   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
00723   f->renumberNodes(renumber1);
00724   CPPUNIT_ASSERT(!f->isEqual(fCpy,1e-12,1e-12));
00725   for(int j=0;j<2;j++)
00726     {
00727       f->getValueOn(loc+2*j,res);
00728       for(int i=0;i<3;i++)
00729         CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i+3*j],res[i],1e-12);
00730     }
00731   const double expected2[27]={7.,107.,10007.,9.,109.,10009.,12.,112.,10012.,10.,110.,10010.,8.,108.,10008.,11.,111.,10011.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.};
00732   for(int i=0;i<27;i++)
00733     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getArray()->getConstPointer()[i],1e-12);
00734   const int renumber2[9]={0,2,5,3,1,4,6,7,8};//reverse of renumber2
00735   f->renumberNodes(renumber2);
00736   CPPUNIT_ASSERT(f->isEqual(fCpy,1e-12,1e-12));
00737   fCpy->decrRef();
00738   //
00739   m->decrRef();
00740   f->decrRef();
00741 }
00742 
00743 void MEDCouplingBasicsTest2::testConvertQuadraticCellsToLinear()
00744 {
00745   MEDCouplingUMesh *mesh=build2DTargetMesh_3();
00746   mesh->checkCoherency();
00747   const std::set<INTERP_KERNEL::NormalizedCellType>& types=mesh->getAllTypes();
00748   CPPUNIT_ASSERT_EQUAL(5,(int)types.size());
00749   INTERP_KERNEL::NormalizedCellType expected1[5]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QUAD8};
00750   std::set<INTERP_KERNEL::NormalizedCellType> expected1Bis(expected1,expected1+5);
00751   CPPUNIT_ASSERT(expected1Bis==types);
00752   CPPUNIT_ASSERT(mesh->isPresenceOfQuadratic());
00753   CPPUNIT_ASSERT_EQUAL(62,mesh->getMeshLength());
00754   MEDCouplingFieldDouble *f1=mesh->getMeasureField(false);
00755   //
00756   mesh->convertQuadraticCellsToLinear();
00757   CPPUNIT_ASSERT(!mesh->isPresenceOfQuadratic());
00758   //
00759   mesh->checkCoherency();
00760   MEDCouplingFieldDouble *f2=mesh->getMeasureField(false);
00761   CPPUNIT_ASSERT(f1->getArray()->isEqual(*f2->getArray(),1e-12));
00762   CPPUNIT_ASSERT_EQUAL(48,mesh->getMeshLength());
00763   const std::set<INTERP_KERNEL::NormalizedCellType>& types2=mesh->getAllTypes();
00764   CPPUNIT_ASSERT_EQUAL(3,(int)types.size());
00765   INTERP_KERNEL::NormalizedCellType expected2[3]={INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4};
00766   std::set<INTERP_KERNEL::NormalizedCellType> expected2Bis(expected2,expected2+3);
00767   CPPUNIT_ASSERT(expected2Bis==types2);
00768   //
00769   f1->decrRef();
00770   f2->decrRef();
00771   mesh->decrRef();
00772 }
00773 
00774 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith()
00775 {
00776   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
00777   MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
00778   DataArrayInt *cellCor,*nodeCor;
00779   //First test mesh1
00780   mesh1->checkGeoEquivalWith(mesh1,0,1e-12,cellCor,nodeCor);//deepEqual
00781   CPPUNIT_ASSERT(cellCor==0);
00782   CPPUNIT_ASSERT(nodeCor==0);
00783   mesh1->checkGeoEquivalWith(mesh1,1,1e-12,cellCor,nodeCor);//fastEqual
00784   CPPUNIT_ASSERT(cellCor==0);
00785   CPPUNIT_ASSERT(nodeCor==0);
00786   mesh1->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
00787   CPPUNIT_ASSERT(cellCor==0);
00788   CPPUNIT_ASSERT(nodeCor==0);
00789   //Second test mesh1 and mesh2 are 2 different meshes instance
00790   mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual
00791   CPPUNIT_ASSERT(cellCor==0);
00792   CPPUNIT_ASSERT(nodeCor==0);
00793   mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual
00794   CPPUNIT_ASSERT(cellCor==0);
00795   CPPUNIT_ASSERT(nodeCor==0);
00796   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
00797   CPPUNIT_ASSERT(cellCor==0);
00798   CPPUNIT_ASSERT(nodeCor==0);
00799   //Third test : cell permutation by keeping the first the middle and the last as it is.
00800   const int renum[]={0,2,1,3,4,5,6,8,7,9};
00801   mesh2->renumberCells(renum,false);
00802   CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
00803   CPPUNIT_ASSERT(cellCor==0);
00804   CPPUNIT_ASSERT(nodeCor==0);
00805   mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
00806   CPPUNIT_ASSERT(cellCor==0);
00807   CPPUNIT_ASSERT(nodeCor==0);
00808   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
00809   CPPUNIT_ASSERT(cellCor);
00810   CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
00811   CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
00812   CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
00813   CPPUNIT_ASSERT(nodeCor==0);
00814   cellCor->decrRef();
00815   cellCor=0;
00816   CPPUNIT_ASSERT(nodeCor==0);
00817   //4th test : cell and node permutation by keeping the first the middle and the last as it is.
00818   mesh2->decrRef();
00819   mesh2=build2DTargetMesh_3();
00820   const int renum2[]={0,2,1,3,4,5,6,8,7,9,10};
00821   mesh2->renumberCells(renum,false);
00822   mesh2->renumberNodes(renum2,11);
00823   CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
00824   CPPUNIT_ASSERT(cellCor==0);
00825   CPPUNIT_ASSERT(nodeCor==0);
00826   mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
00827   CPPUNIT_ASSERT(cellCor==0);
00828   CPPUNIT_ASSERT(nodeCor==0);
00829   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
00830   CPPUNIT_ASSERT(cellCor);
00831   CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
00832   CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
00833   CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
00834   CPPUNIT_ASSERT(nodeCor);
00835   CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
00836   CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
00837   CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
00838   cellCor->decrRef();
00839   cellCor=0;
00840   nodeCor->decrRef();
00841   nodeCor=0;
00842   //5th test : modification of the last cell to check fastCheck detection.
00843   mesh2->decrRef();
00844   mesh2=build2DTargetMesh_3();
00845   const int renum3[]={0,2,1,3,4,5,6,8,9,7};
00846   mesh2->renumberCells(renum3,false);
00847   mesh2->renumberNodes(renum2,11);
00848   bool isExcep=false;
00849   try { mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual fails
00850   }
00851   catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
00852   CPPUNIT_ASSERT(isExcep); isExcep=false;
00853   CPPUNIT_ASSERT(cellCor==0);
00854   CPPUNIT_ASSERT(nodeCor==0);
00855   try { mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual has detected something
00856   }
00857   catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
00858   CPPUNIT_ASSERT(isExcep); isExcep=false;
00859   CPPUNIT_ASSERT(cellCor==0);
00860   CPPUNIT_ASSERT(nodeCor==0);
00861   mesh2->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
00862   CPPUNIT_ASSERT(cellCor);
00863   CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
00864   CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
00865   CPPUNIT_ASSERT(std::equal(renum3,renum3+10,cellCor->getConstPointer()));
00866   CPPUNIT_ASSERT(nodeCor);
00867   CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
00868   CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
00869   CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
00870   cellCor->decrRef();
00871   cellCor=0;
00872   nodeCor->decrRef();
00873   nodeCor=0;
00874   //
00875   mesh1->decrRef();
00876   mesh2->decrRef();
00877 }
00878 
00879 void MEDCouplingBasicsTest2::testCheckGeoEquivalWith2()
00880 {
00881   MEDCouplingUMesh *mesh1=build2DTargetMesh_4();
00882   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
00883   DataArrayInt *cellCor,*nodeCor;
00884   mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);
00885   CPPUNIT_ASSERT(cellCor==0);
00886   CPPUNIT_ASSERT(nodeCor!=0);
00887   const int expected1[9]={0, 1, 3, 4, 5, 6, 7, 8, 9};
00888   for(int i=0;i<9;i++)
00889     CPPUNIT_ASSERT_EQUAL(expected1[i],nodeCor->getIJ(i,0));
00890   nodeCor->decrRef();
00891   //
00892   mesh1->decrRef();
00893   mesh2->decrRef();
00894 }
00895 
00896 void MEDCouplingBasicsTest2::testCopyTinyStringsFromOnFields()
00897 {
00898   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
00899   int nbOfCells=m->getNumberOfCells();
00900   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
00901   f->setMesh(m);
00902   CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected());
00903   f->setName("a");
00904   f->setDescription("b");
00905   DataArrayDouble *a1=DataArrayDouble::New();
00906   a1->alloc(nbOfCells,2);
00907   a1->fillWithZero();
00908   a1->setInfoOnComponent(0,"c");
00909   a1->setInfoOnComponent(1,"d");
00910   DataArrayDouble *a2=a1->deepCpy();
00911   a2->setInfoOnComponent(0,"e");
00912   a2->setInfoOnComponent(1,"f");
00913   f->setArray(a1);
00914   f->setEndArray(a2);
00915   f->setEndTime(3.,3,4);
00916   a2->decrRef();
00917   a1->decrRef();
00918   m->setName("g");
00919   m->getCoords()->setInfoOnComponent(0,"h");
00920   m->getCoords()->setInfoOnComponent(1,"i");
00921   m->getCoords()->setInfoOnComponent(2,"j");
00922   //
00923   f->checkCoherency();
00924   MEDCouplingFieldDouble *f2=f->clone(true);
00925   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
00926   f2->setName("smth");
00927   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
00928   f2->copyTinyStringsFrom(f);
00929   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
00930   f2->setDescription("GGG");
00931   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
00932   f2->copyTinyStringsFrom(f);
00933   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
00934   f2->getArray()->setInfoOnComponent(0,"mmmm");
00935   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
00936   f2->copyTinyStringsFrom(f);
00937   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
00938   f2->getEndArray()->setInfoOnComponent(1,"mmmm");
00939   CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
00940   f2->copyTinyStringsFrom(f);
00941   CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
00942   f2->decrRef();
00943   MEDCouplingUMesh *m2=m->clone(true);
00944   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
00945   m2->setName("123");
00946   CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
00947   m2->copyTinyStringsFrom(m);
00948   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
00949   m2->getCoords()->setInfoOnComponent(1,"eee");
00950   CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
00951   m2->copyTinyStringsFrom(m);
00952   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
00953   m2->decrRef();
00954   //
00955   f->decrRef();
00956   m->decrRef();
00957 }
00958 
00959 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute()
00960 {
00961   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
00962   MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
00963   CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
00964   m->tryToShareSameCoordsPermute(*m2,1e-12);
00965   CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
00966   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
00967   const int renum1[9]={1,2,0,5,8,7,4,3,6};
00968   m->renumberNodes(renum1,9);
00969   CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
00970   CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
00971   m->tryToShareSameCoordsPermute(*m2,1e-12);
00972   CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
00973   CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
00974   m2->decrRef();
00975   m->decrRef();
00976 }
00977 
00978 void MEDCouplingBasicsTest2::testTryToShareSameCoordsPermute2()
00979 {
00980   MEDCouplingUMesh *m1=build2DTargetMesh_4();
00981   double targetCoords[8]={-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 };
00982   int targetConn[4]={0,2,3,1};
00983   MEDCouplingUMesh *m2=MEDCouplingUMesh::New();
00984   m2->setMeshDimension(2);
00985   m2->allocateCells(1);
00986   m2->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
00987   m2->finishInsertingCells();
00988   DataArrayDouble *myCoords=DataArrayDouble::New();
00989   myCoords->alloc(4,2);
00990   std::copy(targetCoords,targetCoords+8,myCoords->getPointer());
00991   m2->setCoords(myCoords);
00992   myCoords->decrRef();
00993   m2->checkCoherency();
00994   m1->checkCoherency();
00995   //
00996   const double expected1[5]={0.25,0.125,0.125,0.25,0.25};
00997   MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
00998   MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
00999   CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
01000   CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
01001   for(int i=0;i<5;i++)
01002     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
01003   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
01004   f2->decrRef();
01005   f1->decrRef();
01006   CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoordsPermute(*m2,1e-12),INTERP_KERNEL::Exception);// <- here in this order the sharing is impossible.
01007   // Let's go for deeper test of tryToShareSameCoordsPermute
01008   m2->tryToShareSameCoordsPermute(*m1,1e-12);
01009   f1=m1->getMeasureField(false);
01010   f2=m2->getMeasureField(false);
01011   CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
01012   CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
01013   for(int i=0;i<5;i++)
01014     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
01015   CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
01016   //
01017   f2->decrRef();
01018   f1->decrRef();
01019   //
01020   m1->decrRef();
01021   m2->decrRef();
01022 }
01023 
01024 void MEDCouplingBasicsTest2::testChangeUnderlyingMesh1()
01025 {
01026   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
01027   MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
01028   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01029   f1->setMesh(mesh1);
01030   DataArrayDouble *array=DataArrayDouble::New();
01031   array->alloc(mesh1->getNumberOfCells(),2);
01032   const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
01033   std::copy(arr,arr+20,array->getPointer());
01034   f1->setArray(array);
01035   array->decrRef();
01036   //
01037   const int renum[]={0,2,1,3,4,5,6,8,7,9};
01038   mesh2->renumberCells(renum,false);
01039   CPPUNIT_ASSERT(f1->getMesh()==mesh1);
01040   f1->changeUnderlyingMesh(mesh1,10,1e-12);// nothing done only to check that nothing done.
01041   CPPUNIT_ASSERT(f1->getMesh()==mesh1);
01042   f1->changeUnderlyingMesh(mesh2,10,1e-12);
01043   CPPUNIT_ASSERT(f1->getMesh()==mesh2);
01044   const double expected1[20]={7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.};
01045   for(int i=0;i<20;i++)
01046     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getArray()->getIJ(0,i),1e-12);
01047   f1->decrRef();
01048   //
01049   f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
01050   f1->setMesh(mesh1);
01051   array=DataArrayDouble::New();
01052   array->alloc(mesh1->getNumberOfNodes(),2);
01053   const double arr2[22]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.,17.,117.};
01054   std::copy(arr2,arr2+22,array->getPointer());
01055   f1->setArray(array);
01056   array->decrRef();
01057   //
01058   const int renum2[]={0,2,10,3,4,5,6,8,7,9,1};
01059   mesh2->renumberNodes(renum2,11);
01060   CPPUNIT_ASSERT(f1->getMesh()==mesh1);
01061   f1->changeUnderlyingMesh(mesh2,10,1e-12);
01062   CPPUNIT_ASSERT(f1->getMesh()==mesh2);
01063   const double expected2[22]={7.,107.,17.,117.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,9.,109.};
01064   for(int i=0;i<22;i++)
01065     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getArray()->getIJ(0,i),1e-12);
01066   f1->decrRef();
01067   //
01068   mesh1->decrRef();
01069   mesh2->decrRef();
01070 }
01071 
01072 void MEDCouplingBasicsTest2::testGetMaxValue1()
01073 {
01074   MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
01075   int nbOfCells=m->getNumberOfCells();
01076   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
01077   f->setMesh(m);
01078   DataArrayDouble *a1=DataArrayDouble::New();
01079   a1->alloc(nbOfCells,1);
01080   const double val1[5]={3.,4.,5.,6.,7.};
01081   std::copy(val1,val1+5,a1->getPointer());
01082   DataArrayDouble *a2=DataArrayDouble::New();
01083   a2->alloc(nbOfCells,1);
01084   const double val2[5]={0.,1.,2.,8.,7.};
01085   std::copy(val2,val2+5,a2->getPointer());
01086   f->setArray(a1);
01087   f->setEndArray(a2);
01088   f->setEndTime(3.,3,4);
01089   f->checkCoherency();
01090   //
01091   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.,f->getMaxValue(),1e-14);
01092   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
01093   CPPUNIT_ASSERT_DOUBLES_EQUAL(5.,f->getAverageValue(),1e-14);
01094   CPPUNIT_ASSERT_DOUBLES_EQUAL(5.125,f->getWeightedAverageValue(),1e-14);
01095   a1->setIJ(0,2,9.5);
01096   CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
01097   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f->getMinValue(),1e-14);
01098   a2->setIJ(0,0,9.);
01099   CPPUNIT_ASSERT_DOUBLES_EQUAL(9.5,f->getMaxValue(),1e-14);
01100   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,f->getMinValue(),1e-14);
01101   //
01102   a2->decrRef();
01103   a1->decrRef();
01104   m->decrRef();
01105   f->decrRef();
01106 }
01107 
01108 void MEDCouplingBasicsTest2::testSubstractInPlaceDM1()
01109 {
01110   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
01111   MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
01112   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01113   f1->setMesh(mesh1);
01114   DataArrayDouble *array=DataArrayDouble::New();
01115   array->alloc(mesh1->getNumberOfCells(),2);
01116   const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
01117   std::copy(arr,arr+20,array->getPointer());
01118   f1->setArray(array);
01119   array->decrRef();
01120   //
01121   CPPUNIT_ASSERT_EQUAL(10,f1->getNumberOfTuples());
01122   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
01123   CPPUNIT_ASSERT_EQUAL(20,f1->getNumberOfValues());
01124   //
01125   const int renum[]={0,2,3,1,4,5,6,8,7,9};
01126   mesh2->renumberCells(renum,false);
01127   //
01128   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01129   f2->setMesh(mesh2);
01130   array=DataArrayDouble::New();
01131   array->alloc(mesh2->getNumberOfCells(),2);
01132   const double arr2[20]={7.1,107.1,10.1,110.1,8.1,108.1,9.1,109.1,11.1,111.1,12.1,112.1,13.1,113.1,15.1,115.1,14.1,114.1,16.1,116.1};
01133   std::copy(arr2,arr2+20,array->getPointer());
01134   f2->setArray(array);
01135   array->decrRef();
01136   //
01137   f1->substractInPlaceDM(f2,10,1e-12);
01138   f1->applyFunc(1,"abs(x+y+0.2)");
01139   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,f1->getMaxValue(),1e-14);
01140   //
01141   f1->decrRef();
01142   f2->decrRef();
01143   mesh1->decrRef();
01144   mesh2->decrRef();
01145 }
01146 
01147 void MEDCouplingBasicsTest2::testDotCrossProduct1()
01148 {
01149   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
01150   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01151   f1->setTime(2.3,5,6);
01152   f1->setMesh(mesh1);
01153   DataArrayDouble *array=DataArrayDouble::New();
01154   array->alloc(mesh1->getNumberOfCells(),3);
01155   const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.};
01156   std::copy(arr1,arr1+30,array->getPointer());
01157   f1->setArray(array);
01158   array->decrRef();
01159   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01160   f2->setTime(7.8,4,5);
01161   f2->setMesh(mesh1);
01162   array=DataArrayDouble::New();
01163   array->alloc(mesh1->getNumberOfCells(),3);
01164   const double arr2[30]={1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.};
01165   std::copy(arr2,arr2+30,array->getPointer());
01166   f2->setArray(array);
01167   array->decrRef();
01168   //
01169   MEDCouplingFieldDouble *f3=f1->dot(*f2);
01170   const double expected1[10]={842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.};
01171   for(int i=0;i<10;i++)
01172     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(i,0),1e-9);
01173   f3->decrRef();
01174   //
01175   MEDCouplingFieldDouble *f4=f1->crossProduct(*f2);
01176   const double expected2[30]={-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.};
01177   for(int i=0;i<30;i++)
01178     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
01179   f4->decrRef();
01180   //
01181   f2->decrRef();
01182   f1->decrRef();
01183   mesh1->decrRef();
01184 }
01185 
01186 void MEDCouplingBasicsTest2::testMinMaxFields1()
01187 {
01188   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
01189   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01190   f1->setTime(2.3,5,6);
01191   f1->setMesh(mesh1);
01192   DataArrayDouble *array=DataArrayDouble::New();
01193   array->alloc(mesh1->getNumberOfCells(),3);
01194   const double arr1[30]={7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.};
01195   std::copy(arr1,arr1+30,array->getPointer());
01196   f1->setArray(array);
01197   array->decrRef();
01198   MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01199   f2->setTime(7.8,4,5);
01200   f2->setMesh(mesh1);
01201   array=DataArrayDouble::New();
01202   array->alloc(mesh1->getNumberOfCells(),3);
01203   const double arr2[30]={6.,108.,206.,9.,107.,209.,8.,110.,208.,11.,109.,211.,10.,112.,210.,13.,111.,213.,12.,114.,212.,15.,113.,215.,14.,116.,214.,17.,115.,217.};
01204   std::copy(arr2,arr2+30,array->getPointer());
01205   f2->setArray(array);
01206   array->decrRef();
01207   //
01208   MEDCouplingFieldDouble *f3=f1->max(*f2);
01209   const double expected1[30]={7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.};
01210   for(int i=0;i<30;i++)
01211     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-9);
01212   f3->decrRef();
01213   //
01214   MEDCouplingFieldDouble *f4=f1->min(*f2);
01215   const double expected2[30]={6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.};
01216   for(int i=0;i<30;i++)
01217     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f4->getIJ(0,i),1e-9);
01218   f4->decrRef();
01219   //
01220   f2->decrRef();
01221   f1->decrRef();
01222   mesh1->decrRef();
01223 }
01224 
01225 void MEDCouplingBasicsTest2::testApplyLin1()
01226 {
01227   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
01228   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
01229   f1->setMesh(mesh1);
01230   DataArrayDouble *array=DataArrayDouble::New();
01231   array->alloc(mesh1->getNumberOfCells(),2);
01232   const double arr[20]={7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.};
01233   std::copy(arr,arr+20,array->getPointer());
01234   f1->setArray(array);
01235   array->decrRef();
01236   //
01237   f1->applyLin(2.,3.,0);
01238   const double expected1[20]={17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.};
01239   for(int i=0;i<20;i++)
01240     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-9);
01241   //
01242   const double arr2[20]={2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
01243   array=DataArrayDouble::New();
01244   array->alloc(mesh1->getNumberOfCells(),2);
01245   std::copy(arr2,arr2+20,array->getPointer());
01246   f1->setEndArray(array);
01247   array->decrRef();
01248   //
01249   f1->applyLin(4.,5.,1);
01250   //
01251   const double expected2[20]={17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.};
01252   for(int i=0;i<20;i++)
01253     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-9);
01254   const double expected3[20]={2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.};
01255   for(int i=0;i<20;i++)
01256     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f1->getEndArray()->getIJ(0,i),1e-9);
01257   //
01258   mesh1->decrRef();
01259   f1->decrRef();
01260 }
01261 
01262 void MEDCouplingBasicsTest2::testGetIdsInRange1()
01263 {
01264   MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
01265   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01266   f1->setTime(2.3,5,6);
01267   f1->setMesh(mesh1);
01268   DataArrayDouble *array=DataArrayDouble::New();
01269   array->alloc(mesh1->getNumberOfCells(),1);
01270   const double arr1[10]={2.,8.,6.,5.,11.,7.,9.,3.,10.,4.};
01271   std::copy(arr1,arr1+10,array->getPointer());
01272   f1->setArray(array);
01273   array->decrRef();
01274   //
01275   f1->checkCoherency();
01276   DataArrayInt *da=f1->getIdsInRange(2.9,7.1);
01277   CPPUNIT_ASSERT_EQUAL(5,da->getNbOfElems());
01278   const int expected1[5]={2,3,5,7,9};
01279   CPPUNIT_ASSERT(std::equal(expected1,expected1+5,da->getConstPointer()));
01280   da->decrRef();
01281   da=f1->getIdsInRange(8.,12.);
01282   CPPUNIT_ASSERT_EQUAL(4,da->getNbOfElems());
01283   const int expected2[4]={1,4,6,8};
01284   CPPUNIT_ASSERT(std::equal(expected2,expected2+4,da->getConstPointer()));
01285   da->decrRef();
01286   //
01287   f1->decrRef();
01288   mesh1->decrRef();
01289 }
01290 
01291 void MEDCouplingBasicsTest2::testBuildSubPart1()
01292 {
01293   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01294   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01295   f1->setTime(2.3,5,6);
01296   f1->setMesh(mesh1);
01297   DataArrayDouble *array=DataArrayDouble::New();
01298   array->alloc(mesh1->getNumberOfCells(),2);
01299   const double arr1[10]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.};
01300   std::copy(arr1,arr1+10,array->getPointer());
01301   f1->setArray(array);
01302   array->decrRef();
01303   //
01304   const int part1[3]={2,1,4};
01305   MEDCouplingFieldDouble *f2=f1->buildSubPart(part1,part1+3);
01306   f2->zipCoords();
01307   CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfTuples());
01308   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
01309   const double expected1[6]={5.,105.,4.,104.,7.,107.};
01310   for(int i=0;i<6;i++)
01311     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected1[i],1e-12);
01312   CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
01313   CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
01314   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
01315   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
01316   MEDCouplingUMesh *m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
01317   CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
01318   const double expected2[12]={0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7};
01319   for(int i=0;i<12;i++)
01320     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
01321   const double expected3[13]={3,2,3,1,3,0,2,1,4,4,5,3,2};
01322   CPPUNIT_ASSERT(std::equal(expected3,expected3+13,m2C->getNodalConnectivity()->getConstPointer()));
01323   const double expected4[4]={0,4,8,13};
01324   CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
01325   f2->decrRef();
01326   f1->decrRef();
01327   // Test with field on nodes.
01328   f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
01329   f1->setTime(2.3,5,6);
01330   f1->setMesh(mesh1);
01331   array=DataArrayDouble::New();
01332   array->alloc(mesh1->getNumberOfNodes(),2);
01333   const double arr2[18]={3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.};
01334   std::copy(arr2,arr2+18,array->getPointer());  
01335   f1->setArray(array);
01336   array->decrRef();
01337   const int part2[2]={1,2};
01338   f2=f1->buildSubPart(part2,part2+2);
01339   CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfTuples());
01340   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
01341   const double expected5[8]={4.,104.,5.,105.,7.,107.,8.,108.};
01342   for(int i=0;i<8;i++)
01343     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
01344   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getNumberOfCells());
01345   CPPUNIT_ASSERT_EQUAL(4,f2->getMesh()->getNumberOfNodes());
01346   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
01347   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
01348   m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
01349   CPPUNIT_ASSERT_EQUAL(8,m2C->getMeshLength());
01350   for(int i=0;i<8;i++)//8 is not an error
01351     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
01352   CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
01353   CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
01354   CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
01355   f2->decrRef();
01356   //idem previous because nodes of cell#4 are not fully present in part3 
01357   const int part3[2]={1,2};
01358   DataArrayInt *arrr=DataArrayInt::New();
01359   arrr->alloc(2,1);
01360   std::copy(part3,part3+2,arrr->getPointer());
01361   f2=f1->buildSubPart(arrr);
01362   arrr->decrRef();
01363   CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfTuples());
01364   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
01365   for(int i=0;i<8;i++)
01366     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected5[i],1e-12);
01367   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getNumberOfCells());
01368   CPPUNIT_ASSERT_EQUAL(4,f2->getMesh()->getNumberOfNodes());
01369   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
01370   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
01371   m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
01372   CPPUNIT_ASSERT_EQUAL(8,m2C->getMeshLength());
01373   for(int i=0;i<8;i++)//8 is not an error
01374     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
01375   CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
01376   CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
01377   CPPUNIT_ASSERT(std::equal(expected4,expected4+3,m2C->getNodalConnectivityIndex()->getConstPointer()));
01378   f2->decrRef();
01379   //
01380   const int part4[3]={1,2,4};
01381   f2=f1->buildSubPart(part4,part4+3);
01382   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfTuples());
01383   CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
01384   const double expected6[12]={4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.};
01385   for(int i=0;i<12;i++)
01386     CPPUNIT_ASSERT_DOUBLES_EQUAL(f2->getIJ(0,i),expected6[i],1e-12);
01387   CPPUNIT_ASSERT_EQUAL(3,f2->getMesh()->getNumberOfCells());
01388   CPPUNIT_ASSERT_EQUAL(6,f2->getMesh()->getNumberOfNodes());
01389   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getSpaceDimension());
01390   CPPUNIT_ASSERT_EQUAL(2,f2->getMesh()->getMeshDimension());
01391   m2C=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
01392   CPPUNIT_ASSERT_EQUAL(13,m2C->getMeshLength());
01393   for(int i=0;i<12;i++)
01394     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],m2C->getCoords()->getIJ(0,i),1.e-12);
01395   CPPUNIT_ASSERT(std::equal(expected3,expected3+4,m2C->getNodalConnectivity()->getConstPointer()+4));
01396   CPPUNIT_ASSERT(std::equal(expected3+4,expected3+8,m2C->getNodalConnectivity()->getConstPointer()));
01397   CPPUNIT_ASSERT(std::equal(expected3+8,expected3+13,m2C->getNodalConnectivity()->getConstPointer()+8));
01398   CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m2C->getNodalConnectivityIndex()->getConstPointer()));
01399   f2->decrRef();
01400   //
01401   f1->decrRef();
01402   mesh1->decrRef();
01403 }
01404 
01405 void MEDCouplingBasicsTest2::testDoublyContractedProduct1()
01406 {
01407   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01408   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01409   f1->setMesh(mesh1);
01410   DataArrayDouble *array=DataArrayDouble::New();
01411   array->alloc(mesh1->getNumberOfCells(),6);
01412   const double arr1[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
01413   std::copy(arr1,arr1+30,array->getPointer());
01414   f1->setArray(array);
01415   array->decrRef();
01416   f1->checkCoherency();
01417   //
01418   MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
01419   f2->checkCoherency();
01420   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01421   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01422   for(int i=0;i<5;i++)
01423     CPPUNIT_ASSERT_DOUBLES_EQUAL(3906.56,f2->getIJ(i,0),1e-9);
01424   f2->decrRef();
01425   //
01426   mesh1->decrRef();
01427   f1->decrRef();
01428 }
01429 
01430 void MEDCouplingBasicsTest2::testDeterminant1()
01431 {
01432   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01433   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,CONST_ON_TIME_INTERVAL);
01434   f1->setTime(2.3,5,6);
01435   f1->setEndTime(3.8,7,3);
01436   f1->setMesh(mesh1);
01437   DataArrayDouble *array=DataArrayDouble::New();
01438   array->alloc(mesh1->getNumberOfCells(),4);
01439   const double arr1[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
01440   std::copy(arr1,arr1+20,array->getPointer());
01441   f1->setArray(array);
01442   array->decrRef();
01443   //4 components
01444   f1->checkCoherency();
01445   MEDCouplingFieldDouble *f2=f1->determinant();
01446   f2->checkCoherency();
01447   CPPUNIT_ASSERT_EQUAL(CONST_ON_TIME_INTERVAL,f2->getTimeDiscretization());
01448   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01449   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfValues());
01450   for(int i=0;i<5;i++)
01451     CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.42,f2->getIJ(i,0),1e-13);
01452   f2->decrRef();
01453   f1->decrRef();
01454   //6 components multi arrays with end array not defined
01455   f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
01456   f1->setTime(2.3,5,6);
01457   f1->setEndTime(3.8,7,3);
01458   f1->setMesh(mesh1);
01459   array=DataArrayDouble::New();
01460   array->alloc(mesh1->getNumberOfNodes(),6);
01461   const double arr2[54]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7,
01462                          1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
01463   std::copy(arr2,arr2+54,array->getPointer());
01464   f1->setArray(array);
01465   array->decrRef();
01466   CPPUNIT_ASSERT_THROW(f1->checkCoherency(),INTERP_KERNEL::Exception);//no end array specified !
01467   //
01468   f2=f1->determinant();
01469   CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
01470   CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfComponents());
01471   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
01472   for(int i=0;i<9;i++)
01473     CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
01474   f2->decrRef();
01475   //6 components multi arrays with end array defined
01476   array=DataArrayDouble::New();
01477   array->alloc(mesh1->getNumberOfNodes(),6);
01478   const double arr3[54]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5,
01479                          7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
01480   std::copy(arr3,arr3+54,array->getPointer());
01481   f1->setEndArray(array);
01482   array->decrRef();
01483   f1->checkCoherency();
01484   f2=f1->determinant();
01485   f2->checkCoherency();
01486   CPPUNIT_ASSERT_EQUAL(LINEAR_TIME,f2->getTimeDiscretization());
01487   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01488   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
01489   int it,order;
01490   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(it,order),1e-12);
01491   CPPUNIT_ASSERT_EQUAL(5,it); CPPUNIT_ASSERT_EQUAL(6,order);
01492   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.8,f2->getEndTime(it,order),1e-12);
01493   CPPUNIT_ASSERT_EQUAL(7,it); CPPUNIT_ASSERT_EQUAL(3,order);
01494   for(int i=0;i<9;i++)
01495     {
01496       CPPUNIT_ASSERT_DOUBLES_EQUAL(137.335,f2->getIJ(i,0),1e-10);
01497       CPPUNIT_ASSERT_DOUBLES_EQUAL(1289.685,f2->getEndArray()->getIJ(i,0),1e-9);
01498     }
01499   f2->decrRef();
01500   f1->decrRef();
01501   //9 components
01502   f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
01503   f1->setTime(7.8,10,2);
01504   f1->setMesh(mesh1);
01505   array=DataArrayDouble::New();
01506   array->alloc(mesh1->getNumberOfCells(),9);
01507   const double arr4[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
01508   std::copy(arr4,arr4+45,array->getPointer());
01509   f1->setArray(array);
01510   array->decrRef();
01511   //
01512   f1->checkCoherency();
01513   f2=f1->determinant();
01514   f2->checkCoherency();
01515   CPPUNIT_ASSERT_EQUAL(ONE_TIME,f2->getTimeDiscretization());
01516   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01517   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01518   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8,f2->getTime(it,order),1e-12);
01519   CPPUNIT_ASSERT_EQUAL(10,it); CPPUNIT_ASSERT_EQUAL(2,order);
01520   for(int i=0;i<5;i++)
01521     CPPUNIT_ASSERT_DOUBLES_EQUAL(3.267,f2->getIJ(i,0),1e-13);
01522   f2->decrRef();
01523   //
01524   mesh1->decrRef();
01525   f1->decrRef();
01526 }
01527 
01528 void MEDCouplingBasicsTest2::testEigenValues1()
01529 {
01530   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01531   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01532   f1->setMesh(mesh1);
01533   DataArrayDouble *array=DataArrayDouble::New();
01534   array->alloc(mesh1->getNumberOfCells(),6);
01535   const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
01536   std::copy(arr1,arr1+30,array->getPointer());
01537   f1->setArray(array);
01538   array->decrRef();
01539   f1->checkCoherency();
01540   //
01541   MEDCouplingFieldDouble *f2=f1->eigenValues();
01542   f2->checkCoherency();
01543   CPPUNIT_ASSERT_EQUAL(3,f2->getNumberOfComponents());
01544   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01545   const double expected1[3]={13.638813677891717,-4.502313844635971,-2.2364998332557486};
01546   for(int i=0;i<5;i++)
01547     {
01548       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
01549       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
01550       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
01551     }
01552   f2->decrRef();
01553   //
01554   mesh1->decrRef();
01555   f1->decrRef();
01556 }
01557 
01558 void MEDCouplingBasicsTest2::testEigenVectors1()
01559 {
01560   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01561   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01562   f1->setMesh(mesh1);
01563   DataArrayDouble *array=DataArrayDouble::New();
01564   array->alloc(mesh1->getNumberOfCells(),6);
01565   const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
01566   std::copy(arr1,arr1+30,array->getPointer());
01567   f1->setArray(array);
01568   array->decrRef();
01569   f1->checkCoherency();
01570   //
01571   MEDCouplingFieldDouble *f2=f1->eigenVectors();
01572   f2->checkCoherency();
01573   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents());
01574   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01575   const double expected1[9]={
01576     0.5424262364180696, 0.5351201064614425, 0.6476266283176001,//eigenvect 0
01577     0.7381111277307373, 0.06458838384003074, -0.6715804522117897,//eigenvect 1
01578     -0.4012053603397987, 0.8423032781211455, -0.3599436712889738//eigenvect 2
01579   };
01580   for(int i=0;i<5;i++)
01581     {
01582       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
01583       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
01584       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
01585       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
01586       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
01587       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
01588       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
01589       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
01590       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
01591     }
01592   f2->decrRef();
01593   //
01594   mesh1->decrRef();
01595   f1->decrRef();
01596 }
01597 
01598 void MEDCouplingBasicsTest2::testInverse1()
01599 {
01600   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01601   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01602   f1->setMesh(mesh1);
01603   DataArrayDouble *array=DataArrayDouble::New();
01604   array->alloc(mesh1->getNumberOfCells(),9);
01605   const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
01606   std::copy(arr1,arr1+45,array->getPointer());
01607   f1->setArray(array);
01608   array->decrRef();
01609   f1->checkCoherency();
01610   //
01611   MEDCouplingFieldDouble *f2=f1->inverse();
01612   f2->checkCoherency();
01613   CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfComponents());
01614   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01615   const double expected1[9]={-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072};
01616   for(int i=0;i<5;i++)
01617     {
01618       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
01619       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
01620       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
01621       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
01622       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
01623       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
01624       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[6],f2->getIJ(i,6),1e-13);
01625       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[7],f2->getIJ(i,7),1e-13);
01626       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[8],f2->getIJ(i,8),1e-13);
01627     }
01628   f2->decrRef();
01629   //
01630   array=DataArrayDouble::New();
01631   array->alloc(mesh1->getNumberOfCells(),6);
01632   const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
01633   std::copy(arr3,arr3+30,array->getPointer());
01634   f1->setArray(array);
01635   array->decrRef();
01636   f1->checkCoherency();
01637   //
01638   f2=f1->inverse();
01639   f2->checkCoherency();
01640   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
01641   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01642   const double expected3[6]={-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887};
01643   for(int i=0;i<5;i++)
01644     {
01645       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[0],f2->getIJ(i,0),1e-13);
01646       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[1],f2->getIJ(i,1),1e-13);
01647       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[2],f2->getIJ(i,2),1e-13);
01648       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[3],f2->getIJ(i,3),1e-13);
01649       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[4],f2->getIJ(i,4),1e-13);
01650       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[5],f2->getIJ(i,5),1e-13);
01651     }
01652   f2->decrRef();
01653   //
01654   array=DataArrayDouble::New();
01655   array->alloc(mesh1->getNumberOfCells(),4);
01656   const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
01657   std::copy(arr2,arr2+20,array->getPointer());
01658   f1->setArray(array);
01659   array->decrRef();
01660   f1->checkCoherency();
01661   //
01662   f2=f1->inverse();
01663   f2->checkCoherency();
01664   CPPUNIT_ASSERT_EQUAL(4,f2->getNumberOfComponents());
01665   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01666   const double expected2[4]={-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156};
01667   for(int i=0;i<5;i++)
01668     {
01669       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[0],f2->getIJ(i,0),1e-13);
01670       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[1],f2->getIJ(i,1),1e-13);
01671       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[2],f2->getIJ(i,2),1e-13);
01672       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[3],f2->getIJ(i,3),1e-13);
01673     }
01674   f2->decrRef();
01675   //
01676   mesh1->decrRef();
01677   f1->decrRef();
01678 }
01679 
01680 void MEDCouplingBasicsTest2::testTrace1()
01681 {
01682   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01683   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01684   f1->setMesh(mesh1);
01685   DataArrayDouble *array=DataArrayDouble::New();
01686   array->alloc(mesh1->getNumberOfCells(),9);
01687   const double arr1[45]={1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1};
01688   std::copy(arr1,arr1+45,array->getPointer());
01689   f1->setArray(array);
01690   array->decrRef();
01691   f1->checkCoherency();
01692   //
01693   MEDCouplingFieldDouble *f2=f1->trace();
01694   f2->checkCoherency();
01695   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01696   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01697   for(int i=0;i<5;i++)
01698     CPPUNIT_ASSERT_DOUBLES_EQUAL(15.9,f2->getIJ(i,0),1e-13);
01699   f2->decrRef();
01700   //
01701   array=DataArrayDouble::New();
01702   array->alloc(mesh1->getNumberOfCells(),6);
01703   const double arr3[30]={7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5};
01704   std::copy(arr3,arr3+30,array->getPointer());
01705   f1->setArray(array);
01706   array->decrRef();
01707   f1->checkCoherency();
01708   //
01709   f2=f1->trace();
01710   f2->checkCoherency();
01711   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01712   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01713   for(int i=0;i<5;i++)
01714     CPPUNIT_ASSERT_DOUBLES_EQUAL(25.8,f2->getIJ(i,0),1e-13);
01715   f2->decrRef();
01716   //
01717   array=DataArrayDouble::New();
01718   array->alloc(mesh1->getNumberOfCells(),4);
01719   const double arr2[20]={1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5};
01720   std::copy(arr2,arr2+20,array->getPointer());
01721   f1->setArray(array);
01722   array->decrRef();
01723   f1->checkCoherency();
01724   //
01725   f2=f1->trace();
01726   f2->checkCoherency();
01727   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01728   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01729   for(int i=0;i<5;i++)
01730     CPPUNIT_ASSERT_DOUBLES_EQUAL(5.7,f2->getIJ(i,0),1e-13);
01731   f2->decrRef();
01732   //
01733   mesh1->decrRef();
01734   f1->decrRef();
01735 }
01736 
01737 void MEDCouplingBasicsTest2::testDeviator1()
01738 {
01739   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01740   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01741   f1->setMesh(mesh1);
01742   DataArrayDouble *array=DataArrayDouble::New();
01743   array->alloc(mesh1->getNumberOfCells(),6);
01744   const double arr1[30]={1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7};
01745   std::copy(arr1,arr1+30,array->getPointer());
01746   f1->setArray(array);
01747   array->decrRef();
01748   f1->checkCoherency();
01749   //
01750   MEDCouplingFieldDouble *f2=f1->deviator();
01751   f2->checkCoherency();
01752   CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents());
01753   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01754   const double expected1[6]={-1.1,0.,1.1,4.5,5.6,6.7};
01755   for(int i=0;i<5;i++)
01756     {
01757       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(i,0),1e-13);
01758       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[1],f2->getIJ(i,1),1e-13);
01759       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[2],f2->getIJ(i,2),1e-13);
01760       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[3],f2->getIJ(i,3),1e-13);
01761       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[4],f2->getIJ(i,4),1e-13);
01762       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[5],f2->getIJ(i,5),1e-13);
01763     }
01764   f2->decrRef();
01765   //
01766   mesh1->decrRef();
01767   f1->decrRef();
01768 }
01769 
01770 void MEDCouplingBasicsTest2::testMagnitude1()
01771 {
01772   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01773   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01774   f1->setMesh(mesh1);
01775   DataArrayDouble *array=DataArrayDouble::New();
01776   array->alloc(mesh1->getNumberOfCells(),5);
01777   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6};
01778   std::copy(arr1,arr1+25,array->getPointer());
01779   f1->setArray(array);
01780   array->decrRef();
01781   f1->checkCoherency();
01782   //
01783   MEDCouplingFieldDouble *f2=f1->magnitude();
01784   f2->checkCoherency();
01785   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01786   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01787   for(int i=0;i<5;i++)
01788     CPPUNIT_ASSERT_DOUBLES_EQUAL(8.3606219864313918,f2->getIJ(i,0),1e-13);
01789   f2->decrRef();
01790   //
01791   mesh1->decrRef();
01792   f1->decrRef();
01793 }
01794 
01795 void MEDCouplingBasicsTest2::testMaxPerTuple1()
01796 {
01797   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01798   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01799   f1->setMesh(mesh1);
01800   DataArrayDouble *array=DataArrayDouble::New();
01801   array->alloc(mesh1->getNumberOfCells(),5);
01802   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
01803   std::copy(arr1,arr1+25,array->getPointer());
01804   f1->setArray(array);
01805   array->decrRef();
01806   f1->checkCoherency();
01807   //
01808   MEDCouplingFieldDouble *f2=f1->maxPerTuple();
01809   f2->checkCoherency();
01810   CPPUNIT_ASSERT_EQUAL(1,f2->getNumberOfComponents());
01811   CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples());
01812   for(int i=0;i<5;i++)
01813     CPPUNIT_ASSERT_DOUBLES_EQUAL(5.6,f2->getIJ(i,0),1e-13);
01814   f2->decrRef();
01815   //
01816   mesh1->decrRef();
01817   f1->decrRef();
01818 }
01819 
01820 void MEDCouplingBasicsTest2::testChangeNbOfComponents()
01821 {
01822   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01823   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01824   f1->setMesh(mesh1);
01825   DataArrayDouble *array=DataArrayDouble::New();
01826   array->alloc(mesh1->getNumberOfCells(),5);
01827   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
01828   std::copy(arr1,arr1+25,array->getPointer());
01829   f1->setArray(array);
01830   array->decrRef();
01831   f1->checkCoherency();
01832   //
01833   f1->changeNbOfComponents(3,7.77);
01834   f1->checkCoherency();
01835   CPPUNIT_ASSERT_EQUAL(3,f1->getNumberOfComponents());
01836   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
01837   const double expected1[15]={1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2};
01838   for(int i=0;i<15;i++)
01839     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(0,i),1e-13);
01840   f1->changeNbOfComponents(4,7.77);
01841   f1->checkCoherency();
01842   CPPUNIT_ASSERT_EQUAL(4,f1->getNumberOfComponents());
01843   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
01844   const double expected2[20]={1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77};
01845   for(int i=0;i<20;i++)
01846     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(0,i),1e-13);
01847   //
01848   mesh1->decrRef();
01849   f1->decrRef();
01850 }
01851 
01852 void MEDCouplingBasicsTest2::testSortPerTuple1()
01853 {
01854   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01855   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
01856   f1->setMesh(mesh1);
01857   DataArrayDouble *array=DataArrayDouble::New();
01858   array->alloc(mesh1->getNumberOfCells(),5);
01859   const double arr1[25]={1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4};
01860   std::copy(arr1,arr1+25,array->getPointer());
01861   f1->setArray(array);
01862   array->decrRef();
01863   f1->checkCoherency();
01864   //
01865   f1->sortPerTuple(true);
01866   f1->checkCoherency();
01867   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents());
01868   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
01869   for(int i=0;i<5;i++)
01870     {
01871       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,0),1e-13);
01872       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,1),1e-13);
01873       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
01874       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,3),1e-13);
01875       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,4),1e-13);
01876     }
01877   //
01878   f1->sortPerTuple(false);
01879   f1->checkCoherency();
01880   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfComponents());
01881   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
01882   for(int i=0;i<5;i++)
01883     {
01884       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[4],f1->getIJ(i,0),1e-13);
01885       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[3],f1->getIJ(i,1),1e-13);
01886       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[2],f1->getIJ(i,2),1e-13);
01887       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[1],f1->getIJ(i,3),1e-13);
01888       CPPUNIT_ASSERT_DOUBLES_EQUAL(arr1[0],f1->getIJ(i,4),1e-13);
01889     }
01890   //
01891   mesh1->decrRef();
01892   f1->decrRef();
01893 }
01894 
01895 void MEDCouplingBasicsTest2::testIsEqualWithoutConsideringStr1()
01896 {
01897   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01898   MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
01899   DataArrayInt *da1,*da2;
01900   //
01901   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
01902   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01903   mesh2->setName("rr");
01904   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
01905   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01906   mesh1->checkDeepEquivalWith(mesh2,2,1e-12,da1,da2);
01907   CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,da1,da2),INTERP_KERNEL::Exception);
01908   mesh2->setName("");
01909   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
01910   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01911   mesh2->getCoords()->setInfoOnComponent(0,"tty");
01912   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
01913   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01914   mesh2->getCoords()->setInfoOnComponent(0,"");
01915   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
01916   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01917   mesh2->getCoords()->setInfoOnComponent(1,"tty");
01918   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
01919   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01920   mesh2->getCoords()->setInfoOnComponent(1,"");
01921   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
01922   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01923   double tmp=mesh2->getCoords()->getIJ(0,3);
01924   mesh2->getCoords()->setIJ(0,3,9999.);
01925   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
01926   CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01927   mesh2->getCoords()->setIJ(0,3,tmp);
01928   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
01929   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01930   int tmp2=mesh2->getNodalConnectivity()->getIJ(0,4);
01931   mesh2->getNodalConnectivity()->setIJ(0,4,0);
01932   CPPUNIT_ASSERT(!mesh1->isEqual(mesh2,1e-12));
01933   CPPUNIT_ASSERT(!mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01934   mesh2->getNodalConnectivity()->setIJ(0,4,tmp2);
01935   CPPUNIT_ASSERT(mesh1->isEqual(mesh2,1e-12));
01936   CPPUNIT_ASSERT(mesh1->isEqualWithoutConsideringStr(mesh2,1e-12));
01937   //
01938   MEDCouplingFieldDouble *f1=mesh1->getMeasureField(true);
01939   MEDCouplingFieldDouble *f2=mesh2->getMeasureField(true);
01940   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
01941   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
01942   f2->setName("ftest");
01943   CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
01944   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
01945   f1->setName("ftest");
01946   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
01947   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
01948   //
01949   f2->getArray()->setInfoOnComponent(0,"eee");
01950   CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
01951   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
01952   f2->getArray()->setInfoOnComponent(0,"");
01953   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
01954   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
01955   //
01956   f2->getArray()->setIJ(1,0,0.123);
01957   CPPUNIT_ASSERT(!f1->isEqual(f2,1e-12,1e-12));
01958   CPPUNIT_ASSERT(!f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
01959   f2->getArray()->setIJ(1,0,0.125);
01960   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
01961   CPPUNIT_ASSERT(f1->isEqualWithoutConsideringStr(f2,1e-12,1e-12));
01962   //
01963   f1->decrRef();
01964   f2->decrRef();
01965   //
01966   mesh1->decrRef();
01967   mesh2->decrRef();
01968 }
01969 
01970 void MEDCouplingBasicsTest2::testGetNodeIdsOfCell1()
01971 {
01972   MEDCouplingUMesh *mesh1=build2DTargetMesh_1();
01973   std::vector<int> nodeIds;
01974   mesh1->getNodeIdsOfCell(1,nodeIds);
01975   CPPUNIT_ASSERT_EQUAL(3,(int)nodeIds.size());
01976   CPPUNIT_ASSERT_EQUAL(1,nodeIds[0]);
01977   CPPUNIT_ASSERT_EQUAL(4,nodeIds[1]);
01978   CPPUNIT_ASSERT_EQUAL(2,nodeIds[2]);
01979   std::vector<double> coords;
01980   mesh1->getCoordinatesOfNode(4,coords);
01981   CPPUNIT_ASSERT_EQUAL(2,(int)coords.size());
01982   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[0],1e-13);
01983   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2,coords[1],1e-13);
01984   mesh1->decrRef();
01985 }
01986 
01987 void MEDCouplingBasicsTest2::testGetEdgeRatioField1()
01988 {
01989   MEDCouplingUMesh *m1=build2DTargetMesh_1();
01990   MEDCouplingFieldDouble *f1=m1->getEdgeRatioField();
01991   CPPUNIT_ASSERT_EQUAL(m1->getNumberOfCells(),f1->getNumberOfTuples());
01992   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
01993   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
01994   const double expected1[5]={1.,1.4142135623730951, 1.4142135623730951,1.,1.};
01995   for(int i=0;i<5;i++)
01996     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-14);
01997   f1->decrRef();
01998   m1->decrRef();
01999   //
02000   m1=build3DSurfTargetMesh_1();
02001   f1=m1->getEdgeRatioField();
02002   CPPUNIT_ASSERT_EQUAL(m1->getNumberOfCells(),f1->getNumberOfTuples());
02003   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
02004   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
02005   const double expected2[5]={1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951};
02006   for(int i=0;i<5;i++)
02007     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f1->getIJ(i,0),1e-14);
02008   f1->decrRef();
02009   m1->decrRef();
02010 }
02011 
02012 void MEDCouplingBasicsTest2::testFillFromAnalytic3()
02013 {
02014   MEDCouplingUMesh *m=build2DTargetMesh_1();
02015   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
02016   CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"y+x"),INTERP_KERNEL::Exception);
02017   f1->setMesh(m);
02018   f1->setName("myField");
02019   f1->fillFromAnalytic(1,"y+x");
02020   f1->checkCoherency();
02021   CPPUNIT_ASSERT(std::string(f1->getName())=="myField");
02022   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
02023   CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
02024   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
02025   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
02026   double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
02027   const double *tmp=f1->getArray()->getConstPointer();
02028   std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
02029   std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
02030   double max=*std::max_element(values1,values1+5);
02031   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
02032   f1->decrRef();
02033   //
02034   f1=MEDCouplingFieldDouble::New(ON_NODES,CONST_ON_TIME_INTERVAL);
02035   f1->setMesh(m);
02036   f1->setEndTime(1.2,3,4);
02037   f1->fillFromAnalytic(1,"y+2*x");
02038   f1->checkCoherency();
02039   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
02040   CPPUNIT_ASSERT(f1->getTimeDiscretization()==CONST_ON_TIME_INTERVAL);
02041   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
02042   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
02043   double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
02044   tmp=f1->getArray()->getConstPointer();
02045   std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
02046   std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
02047   max=*std::max_element(values2,values2+9);
02048   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
02049   f1->decrRef();
02050   f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
02051   f1->setMesh(m);
02052   f1->setEndTime(1.2,3,4);
02053   f1->fillFromAnalytic(1,"2.*x+y");
02054   f1->checkCoherency();
02055   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
02056   CPPUNIT_ASSERT(f1->getTimeDiscretization()==LINEAR_TIME);
02057   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
02058   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
02059   tmp=f1->getArray()->getConstPointer();
02060   double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
02061   double values2BisBis[9];
02062   std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
02063   std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
02064   max=*std::max_element(values2BisBis,values2BisBis+9);
02065   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
02066   tmp=f1->getEndArray()->getConstPointer();
02067   std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
02068   std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
02069   max=*std::max_element(values2BisBis,values2BisBis+9);
02070   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
02071   f1->decrRef();
02072   //
02073   f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
02074   f1->setMesh(m);
02075   f1->fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
02076   f1->checkCoherency();
02077   CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
02078   CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
02079   CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
02080   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
02081   double values3[18]={-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8};
02082   tmp=f1->getArray()->getConstPointer();
02083   std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
02084   std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
02085   max=*std::max_element(values3,values3+18);
02086   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
02087   double values4[2];
02088   f1->accumulate(values4);
02089   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
02090   CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
02091   f1->integral(true,values4);
02092   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
02093   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
02094   f1->decrRef();
02095   //
02096   f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
02097   f1->setMesh(m);
02098   CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
02099   //
02100   m->decrRef();
02101   f1->decrRef();
02102 }
02103 
02104 void MEDCouplingBasicsTest2::testFieldDoubleOpEqual1()
02105 {
02106   MEDCouplingUMesh *m=build2DTargetMesh_1();
02107   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
02108   CPPUNIT_ASSERT_THROW((*f1)=0.07,INTERP_KERNEL::Exception);
02109   f1->setMesh(m);
02110   (*f1)=0.07;
02111   f1->checkCoherency();
02112   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
02113   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
02114   for(int i=0;i<5;i++)
02115     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.07,f1->getIJ(i,0),1e-16);
02116   (*f1)=0.09;
02117   f1->checkCoherency();
02118   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
02119   CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
02120   for(int i=0;i<5;i++)
02121     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.09,f1->getIJ(i,0),1e-16);
02122   f1->decrRef();
02123   //
02124   f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
02125   f1->setEndTime(4.5,2,3);
02126   f1->setMesh(m);
02127   (*f1)=0.08;
02128   f1->checkCoherency();
02129   CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
02130   CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
02131   for(int i=0;i<9;i++)
02132     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getIJ(i,0),1e-16);
02133   CPPUNIT_ASSERT_EQUAL(1,f1->getEndArray()->getNumberOfComponents());
02134   CPPUNIT_ASSERT_EQUAL(9,f1->getEndArray()->getNumberOfTuples());
02135   for(int i=0;i<9;i++)
02136     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getEndArray()->getIJ(i,0),1e-16);
02137   f1->decrRef();
02138   //
02139   m->decrRef();
02140 }
02141 
02142 void MEDCouplingBasicsTest2::testAreaBary3D2()
02143 {
02144   const double coordsForHexa8[24]={
02145     -75.45749305371, 180.95495078401, 39.515472018008,
02146     -9.755591679144, 23.394927935279, 5.108794294848,
02147     14.337630157832, 61.705351002702, 160.42422501908,
02148     -27.273893776752, 167.567731083961, 192.830034145464,
02149     //
02150     99.857193154796,264.499264735586,-8.287335493412,
02151     144.939882761126,156.38626563134,-31.896173894226,
02152     161.34096835726,182.4654895809,73.832387065572,
02153     132.680430393685,255.37973247196,96.15235602819
02154   };
02155   const double volHexa8=3258520.29637466;
02156   const double baryHexa8[3]={43.925705821778, 155.31893955289, 65.874418109644};
02157 
02158   const double coordsForPenta6[18]={
02159     -68.199829618726,178.938498373416,62.608505919588,
02160     8.461744647847,76.653979804423,165.00018874933,
02161     -27.273893776752,167.567731083961,192.830034145464,
02162     //
02163     106.586501038965,262.629609408327,13.124533008813,
02164     155.465082847275,197.414118382622,78.408350795821,
02165     132.680430393685,255.37973247196,96.15235602819
02166   };
02167   const double volPenta6=944849.868507338;
02168   const double baryPenta6[3]={39.631002313543,182.692711783428,106.98540473964};
02169   
02170   const double coordsForPyra5[15]={
02171     132.680430393685,255.37973247196,96.15235602819,
02172     -27.273893776752,167.567731083961,192.830034145464,
02173     8.461744647847,76.653979804423,165.00018874933,
02174     155.465082847275,197.414118382622,78.408350795821,
02175     //
02176     -68.199829618726,178.938498373416,62.608505919588
02177   };
02178   const double volPyra5=756943.92980254;
02179   const double baryPyra5[3]={29.204294116618,172.540129749156,118.01035951483};
02180   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Bary3D2",3);
02181   DataArrayDouble *coo=DataArrayDouble::New();
02182   coo->alloc(19,3);
02183   double *tmp=std::copy(coordsForHexa8,coordsForHexa8+24,coo->getPointer());
02184   tmp=std::copy(coordsForPenta6,coordsForPenta6+18,tmp);
02185   std::copy(coordsForPyra5,coordsForPyra5+15,tmp);
02186   mesh->setCoords(coo);
02187   coo->decrRef();
02188   //
02189   int tmpConn[8]={0,1,2,3,4,5,6,7};
02190   mesh->allocateCells(3);
02191   mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,tmpConn);
02192   std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),8));
02193   mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,tmpConn);
02194   std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),6));
02195   mesh->insertNextCell(INTERP_KERNEL::NORM_PYRA5,5,tmpConn);
02196   mesh->finishInsertingCells();
02197   mesh->checkCoherency();
02198   bool isMerged;
02199   int newNebOfNodes;
02200   DataArrayInt *da=mesh->mergeNodes(1e-7,isMerged,newNebOfNodes);
02201   da->decrRef();
02202   CPPUNIT_ASSERT_EQUAL(12,newNebOfNodes);
02203   MEDCouplingFieldDouble *vols=mesh->getMeasureField(true);
02204   CPPUNIT_ASSERT_EQUAL(3,vols->getNumberOfTuples());
02205   CPPUNIT_ASSERT_EQUAL(1,vols->getNumberOfComponents());
02206   CPPUNIT_ASSERT_DOUBLES_EQUAL(volHexa8,vols->getIJ(0,0),1e-6);
02207   CPPUNIT_ASSERT_DOUBLES_EQUAL(volPenta6,vols->getIJ(1,0),1e-7);
02208   CPPUNIT_ASSERT_DOUBLES_EQUAL(volPyra5,vols->getIJ(2,0),1e-7);
02209   vols->decrRef();
02210   DataArrayDouble *bary=mesh->getBarycenterAndOwner();
02211   CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfTuples());
02212   CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfComponents());
02213   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[0],bary->getIJ(0,0),1e-11);
02214   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[1],bary->getIJ(0,1),1e-11);
02215   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[2],bary->getIJ(0,2),1e-11);
02216   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[0],bary->getIJ(1,0),1e-11);
02217   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[1],bary->getIJ(1,1),1e-11);
02218   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[2],bary->getIJ(1,2),1e-11);
02219   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[0],bary->getIJ(2,0),1e-11);
02220   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[1],bary->getIJ(2,1),1e-11);
02221   CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[2],bary->getIJ(2,2),1e-11);
02222   bary->decrRef();
02223   //
02224   mesh->decrRef();
02225 }