Back to index

salome-med  6.5.0
MEDCouplingBasicsTest5.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 "MEDCouplingBasicsTest5.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 #include "MEDCouplingMultiFields.hxx"
00028 #include "MEDCouplingFieldOverTime.hxx"
00029 
00030 #include <cmath>
00031 #include <functional>
00032 #include <iterator>
00033 
00034 using namespace ParaMEDMEM;
00035 
00036 void MEDCouplingBasicsTest5::testUMeshTessellate2D1()
00037 {
00038   double m1Coords[50]={0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214};
00039   int m1Conn[56]={0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23};
00040   MEDCouplingUMesh *m1=MEDCouplingUMesh::New();
00041   m1->setMeshDimension(2);
00042   m1->allocateCells(8);
00043   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn);
00044   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+6);
00045   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+14);
00046   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+20);
00047   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+28);
00048   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+34);
00049   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+42);
00050   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+48);
00051   m1->finishInsertingCells();
00052   DataArrayDouble *myCoords1=DataArrayDouble::New();
00053   myCoords1->alloc(25,2);
00054   std::copy(m1Coords,m1Coords+50,myCoords1->getPointer());
00055   m1->setCoords(myCoords1);
00056   myCoords1->decrRef();
00057   //
00058   MEDCouplingUMesh *m11=static_cast<MEDCouplingUMesh *>(m1->deepCpy());
00059   m11->tessellate2D(1.);
00060   CPPUNIT_ASSERT(m11->getCoords()->isEqual(*m11->getCoords(),1e-12));
00061   const int expected1[48]={5,0,3,11,1,5,3,4,12,2,1,11,5,5,15,3,0,5,6,16,4,3,15,5,5,5,0,7,19,5,6,5,19,7,8,20,5,0,1,23,7,5,1,2,24,8,7,23};
00062   const int expected2[9]={0,5,12,17,24,29,36,41,48};
00063   CPPUNIT_ASSERT_EQUAL(48,m11->getNodalConnectivity()->getNumberOfTuples());
00064   CPPUNIT_ASSERT_EQUAL(9,m11->getNodalConnectivityIndex()->getNumberOfTuples());
00065   CPPUNIT_ASSERT(std::equal(expected1,expected1+48,m11->getNodalConnectivity()->getConstPointer()));
00066   CPPUNIT_ASSERT(std::equal(expected2,expected2+9,m11->getNodalConnectivityIndex()->getConstPointer()));
00067   m11->decrRef();
00068   //
00069   MEDCouplingUMesh *m12=static_cast<MEDCouplingUMesh *>(m1->deepCpy());
00070   m12->tessellate2D(0.5);
00071   CPPUNIT_ASSERT_EQUAL(41,m12->getNumberOfNodes());
00072   const int expected3[60]={5,0,3,25,26,1,5,3,4,27,28,2,1,26,25,5,5,29,30,3,0,5,6,31,32,4,3,30,29,5,5,5,0,7,33,34,5,6,5,34,33,7,8,35,36,5,0,1,37,38,7,5,1,2,39,40,8,7,38,37};
00073   const int expected4[9]={0,6,15,21,30,36,45,51,60};
00074   const double expected5[82]={0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.479425538604203,0.8775825618903728,0.8414709848078964,0.54030230586814,0.7191383079063044,1.3163738428355591,1.2622064772118446,0.8104534588022099,-0.877582561890373,0.4794255386042027,-0.5403023058681399,0.8414709848078964,-1.3163738428355596,0.7191383079063038,-0.8104534588022098,1.2622064772118446,-0.4794255386042031,-0.8775825618903728,-0.8414709848078965,-0.5403023058681399,-0.7191383079063045,-1.3163738428355591,-1.2622064772118449,-0.8104534588022098,0.8775825618903729,-0.47942553860420295,0.54030230586814,-0.8414709848078964,1.3163738428355594,-0.7191383079063043,0.8104534588022099,-1.2622064772118446};
00075   for(int i=0;i<82;i++)
00076     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m12->getCoords()->getIJ(0,i),1e-12);
00077   CPPUNIT_ASSERT_EQUAL(60,m12->getNodalConnectivity()->getNumberOfTuples());
00078   CPPUNIT_ASSERT_EQUAL(9,m12->getNodalConnectivityIndex()->getNumberOfTuples());
00079   CPPUNIT_ASSERT(std::equal(expected3,expected3+60,m12->getNodalConnectivity()->getConstPointer()));
00080   CPPUNIT_ASSERT(std::equal(expected4,expected4+9,m12->getNodalConnectivityIndex()->getConstPointer()));
00081   m12->decrRef();
00082   //
00083   m1->decrRef();
00084 }
00085 
00089 void MEDCouplingBasicsTest5::testIntersect2DMeshesTmp4()
00090 {
00091   double m1Coords[50]={0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214};
00092   int m1Conn[56]={0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23};
00093   MEDCouplingUMesh *m1=MEDCouplingUMesh::New();
00094   m1->setMeshDimension(2);
00095   m1->allocateCells(8);
00096   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn);
00097   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+6);
00098   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+14);
00099   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+20);
00100   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+28);
00101   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+34);
00102   m1->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,m1Conn+42);
00103   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8,m1Conn+48);
00104   m1->finishInsertingCells();
00105   DataArrayDouble *myCoords1=DataArrayDouble::New();
00106   myCoords1->alloc(25,2);
00107   std::copy(m1Coords,m1Coords+50,myCoords1->getPointer());
00108   m1->setCoords(myCoords1);
00109   myCoords1->decrRef();
00110   //
00111   double m2Coords[30]={0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.};
00112   int m2Conn[32]={0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13};
00113   MEDCouplingUMesh *m2=MEDCouplingUMesh::New();
00114   m2->setMeshDimension(2);
00115   m2->allocateCells(8);
00116   for(int i=0;i<8;i++)
00117     m2->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,m2Conn+4*i);
00118   m2->finishInsertingCells();
00119   DataArrayDouble *myCoords2=DataArrayDouble::New();
00120   myCoords2->alloc(15,2);
00121   std::copy(m2Coords,m2Coords+30,myCoords2->getPointer());
00122   m2->setCoords(myCoords2);
00123   myCoords2->decrRef();
00124   //
00125   DataArrayInt *d1=0,*d2=0;
00126   MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m2,m1,1e-10,d1,d2);
00127   m3->unPolyze();
00128   const int expected1[12]={0,0,1,2,2,3,4,4,5,6,6,7};
00129   const int expected2[12]={0,1,1,2,3,3,4,5,5,6,7,7};
00130   CPPUNIT_ASSERT_EQUAL(12,d1->getNumberOfTuples());
00131   CPPUNIT_ASSERT_EQUAL(12,d2->getNumberOfTuples());
00132   CPPUNIT_ASSERT_EQUAL(12,m3->getNumberOfCells());
00133   CPPUNIT_ASSERT_EQUAL(88,m3->getNumberOfNodes());
00134   CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension());
00135   CPPUNIT_ASSERT(std::equal(expected1,expected1+12,d1->getConstPointer()));
00136   CPPUNIT_ASSERT(std::equal(expected2,expected2+12,d2->getConstPointer()));
00137   const int expected3[100]={6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,6,18,15,20,55,56,57,8,20,7,6,18,58,59,60,61,8,41,6,7,21,62,63,64,65,6,20,15,22,66,67,68,8,22,11,7,20,69,70,71,72,8,21,7,11,42,73,74,75,76,6,22,15,16,77,78,79,8,16,1,13,22,80,81,82,83,8,43,13,1,17,84,85,86,87};
00138   const int expected4[13]={0,7,16,25,32,41,50,57,66,75,82,91,100};
00139   const double expected5[176]={0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865477,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865477,0.7071067811865477,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865479,-0.7071067811865476,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865477,-0.7071067811865476,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635};
00140   CPPUNIT_ASSERT_EQUAL(100,m3->getNodalConnectivity()->getNumberOfTuples());
00141   CPPUNIT_ASSERT_EQUAL(13,m3->getNodalConnectivityIndex()->getNumberOfTuples());
00142   CPPUNIT_ASSERT(std::equal(expected3,expected3+100,m3->getNodalConnectivity()->getConstPointer()));
00143   CPPUNIT_ASSERT(std::equal(expected4,expected4+13,m3->getNodalConnectivityIndex()->getConstPointer()));
00144   for(int i=0;i<176;i++)
00145     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12);
00146   d1->decrRef();
00147   d2->decrRef();
00148   m3->decrRef();
00149   //
00150   m1->decrRef();
00151   m2->decrRef();
00152 }
00153 
00154 void MEDCouplingBasicsTest5::testGetCellIdsCrossingPlane1()
00155 {
00156   MEDCouplingUMesh *mesh2D=0;
00157   MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
00158   const double vec[3]={-0.07,1.,0.07};
00159   const double origin[3]={1.524,1.4552,1.74768};
00160   DataArrayInt *ids1=mesh3D->getCellIdsCrossingPlane(origin,vec,1e-10);
00161   CPPUNIT_ASSERT_EQUAL(9,ids1->getNumberOfTuples());
00162   const int expected1[9]={1,3,4,7,9,10,13,15,16};
00163   CPPUNIT_ASSERT(std::equal(expected1,expected1+9,ids1->getConstPointer()));
00164   const double vec2[3]={0.,0.,1.};
00165   DataArrayInt *ids2=mesh3D->getCellIdsCrossingPlane(origin,vec2,1e-10);
00166   const int expected2[6]={6,7,8,9,10,11};
00167   CPPUNIT_ASSERT_EQUAL(6,ids2->getNumberOfTuples());
00168   CPPUNIT_ASSERT(std::equal(expected2,expected2+6,ids2->getConstPointer()));
00169   ids1->decrRef();
00170   ids2->decrRef();
00171   mesh3D->decrRef();
00172   mesh2D->decrRef();
00173 }
00174 
00175 void MEDCouplingBasicsTest5::testBuildSlice3D1()
00176 {
00177   MEDCouplingUMesh *mesh2D=0;
00178   MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
00179   mesh2D->decrRef();
00180   // First slice in the middle of 3D cells
00181   const double vec1[3]={-0.07,1.,0.07};
00182   const double origin1[3]={1.524,1.4552,1.74768};
00183   DataArrayInt *ids=0;
00184   MEDCouplingUMesh *slice1=mesh3D->buildSlice3D(origin1,vec1,1e-10,ids);
00185   const int expected1[9]={1,3,4,7,9,10,13,15,16};
00186   const int expected2[47]={5,42,41,40,43,44,5,42,46,45,41,5,44,43,40,47,48,5,49,42,44,50,5,49,51,46,42,5,50,44,48,52,5,53,49,50,54,5,53,55,51,49,5,54,50,52,56};
00187   const int expected3[10]={0,6,11,17,22,27,32,37,42,47};
00188   const double expected4[171]={1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,2.,2.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,2.,2.,1.,1.,1.,2.,1.,1.25,2.,1.,1.5,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,1.,1.,3.,1.,1.25,3.,1.,1.5,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,1.,1.5408576,0.,2.,1.6108576000000001,0.,2.,1.5408576,1.,1.,1.5,0.5836800000000008,1.,1.4708576,1.,3.,1.6808576,0.,3.,1.6108576000000001,1.,0.,1.4708576,0.,0.,1.4008576,1.,2.,1.4708576,2.,1.,1.4008576000000001,2.,3.,1.5408575999999998,2.,0.,1.3308575999999999,2.,2.,1.4008576,3.,1.,1.3308576,3.,3.,1.4708576,3.,0.,1.2608576,3.};
00189   CPPUNIT_ASSERT_EQUAL(2,slice1->getMeshDimension());
00190   CPPUNIT_ASSERT_EQUAL(3,slice1->getSpaceDimension());
00191   CPPUNIT_ASSERT_EQUAL(57,slice1->getNumberOfNodes());
00192   CPPUNIT_ASSERT_EQUAL(9,slice1->getNumberOfCells());
00193   CPPUNIT_ASSERT_EQUAL(9,ids->getNumberOfTuples());
00194   CPPUNIT_ASSERT_EQUAL(47,slice1->getNodalConnectivity()->getNumberOfTuples());
00195   CPPUNIT_ASSERT_EQUAL(10,slice1->getNodalConnectivityIndex()->getNumberOfTuples());
00196   CPPUNIT_ASSERT(std::equal(expected1,expected1+9,ids->getConstPointer()));
00197   CPPUNIT_ASSERT(std::equal(expected2,expected2+47,slice1->getNodalConnectivity()->getConstPointer()));
00198   CPPUNIT_ASSERT(std::equal(expected3,expected3+10,slice1->getNodalConnectivityIndex()->getConstPointer()));
00199   for(int i=0;i<171;i++)
00200     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],slice1->getCoords()->getIJ(0,i),1e-12);
00201   ids->decrRef();
00202   slice1->decrRef();
00203   // 2nd slice based on already existing nodes of mesh3D.
00204   const double vec2[3]={0.,3.,1.};
00205   const double origin2[3]={2.5,1.,3.};
00206   slice1=mesh3D->buildSlice3D(origin2,vec2,1e-10,ids);
00207   const int expected5[49]={5,50,10,4,51,5,50,52,7,10,5,51,4,5,53,5,54,50,51,55,56,5,54,57,52,50,5,56,55,51,53,58,5,38,59,56,54,43,5,54,57,46,43,5,38,59,56,58,48};
00208   const int expected6[10]={0,5,10,15,21,26,32,38,43,49};
00209   const double expected7[180]={1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,1.,3.,0.,2.,2.,0.,2.,3.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25,2.,1.,0.,2.,1.,1.5,2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,0.,0.,3.,1.,1.,3.,1.,1.25,3.,1.,0.,3.,1.,1.5,3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,2.,1.6666666666666667,1.,1.,1.6666666666666667,1.,3.,1.6666666666666667,1.,0.,1.6666666666666667,1.,2.,1.3333333333333335,2.,1.,1.5,1.5,1.,1.3333333333333333,2.,3.,1.3333333333333335,2.,0.,1.3333333333333335,2.,1.,1.25,2.25};
00210   CPPUNIT_ASSERT_EQUAL(2,slice1->getMeshDimension());
00211   CPPUNIT_ASSERT_EQUAL(3,slice1->getSpaceDimension());
00212   CPPUNIT_ASSERT_EQUAL(60,slice1->getNumberOfNodes());
00213   CPPUNIT_ASSERT_EQUAL(9,slice1->getNumberOfCells());
00214   CPPUNIT_ASSERT_EQUAL(9,ids->getNumberOfTuples());
00215   CPPUNIT_ASSERT_EQUAL(49,slice1->getNodalConnectivity()->getNumberOfTuples());
00216   CPPUNIT_ASSERT_EQUAL(10,slice1->getNodalConnectivityIndex()->getNumberOfTuples());
00217   CPPUNIT_ASSERT(std::equal(expected1,expected1+9,ids->getConstPointer()));
00218   CPPUNIT_ASSERT(std::equal(expected5,expected5+49,slice1->getNodalConnectivity()->getConstPointer()));
00219   CPPUNIT_ASSERT(std::equal(expected6,expected6+10,slice1->getNodalConnectivityIndex()->getConstPointer()));
00220   for(int i=0;i<180;i++)
00221     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected7[i],slice1->getCoords()->getIJ(0,i),1e-12);
00222   ids->decrRef();
00223   slice1->decrRef();
00224   // 3rd slice based on shared face of mesh3D.
00225   const double vec3[3]={0.,0.,1.};
00226   const double origin3[3]={2.5,1.,2.};
00227   slice1=mesh3D->buildSlice3D(origin3,vec3,1e-10,ids);
00228   const int expected8[12]={6,7,8,9,10,11,12,13,14,15,16,17};
00229   const int expected9[68]={5,15,26,16,18,5,16,21,28,22,19,17,5,18,20,21,16,5,21,24,25,28,5,26,16,17,19,22,23,5,22,27,29,28,5,15,26,16,18,5,16,21,28,22,19,17,5,18,20,21,16,5,21,24,25,28,5,26,16,17,19,22,23,5,22,27,29,28};
00230   const int expected10[13]={0,5,12,17,22,29,34,39,46,51,56,63,68};
00231   const double expected11[135]={0.,0.,1.,1.,1.,1.,1.,1.25, 1.,1.,0.,1.,1.,1.5, 1.,2.,0.,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25, 2.,1.,0.,2.,1.,1.5, 2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,1.,3.,2.,2.,2.,2.,2.,3.,2.,0.,0.,3.,1.,1.,3.,1.,1.25, 3.,1.,0.,3.,1.,1.5, 3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,1.,3.,3.,2.,2.,3.,2.,3.,3.};
00232   CPPUNIT_ASSERT_EQUAL(2,slice1->getMeshDimension());
00233   CPPUNIT_ASSERT_EQUAL(3,slice1->getSpaceDimension());
00234   CPPUNIT_ASSERT_EQUAL(45,slice1->getNumberOfNodes());
00235   CPPUNIT_ASSERT_EQUAL(12,slice1->getNumberOfCells());
00236   CPPUNIT_ASSERT_EQUAL(12,ids->getNumberOfTuples());
00237   CPPUNIT_ASSERT_EQUAL(68,slice1->getNodalConnectivity()->getNumberOfTuples());
00238   CPPUNIT_ASSERT_EQUAL(13,slice1->getNodalConnectivityIndex()->getNumberOfTuples());
00239   CPPUNIT_ASSERT(std::equal(expected8,expected8+12,ids->getConstPointer()));
00240   CPPUNIT_ASSERT(std::equal(expected9,expected9+68,slice1->getNodalConnectivity()->getConstPointer()));
00241   CPPUNIT_ASSERT(std::equal(expected10,expected10+13,slice1->getNodalConnectivityIndex()->getConstPointer()));
00242   for(int i=0;i<135;i++)
00243     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected11[i],slice1->getCoords()->getIJ(0,i),1e-12);
00244   ids->decrRef();
00245   slice1->decrRef();
00246   //
00247   mesh3D->decrRef();
00248 }
00249 
00250 void MEDCouplingBasicsTest5::testBuildSlice3DSurf1()
00251 {
00252   MEDCouplingUMesh *mesh2D=0;
00253   MEDCouplingUMesh *mesh3D=build3DExtrudedUMesh_1(mesh2D);
00254   mesh2D->decrRef();
00255   DataArrayInt *a=DataArrayInt::New(),*b=DataArrayInt::New(),*c=DataArrayInt::New(),*d=DataArrayInt::New();
00256   mesh2D=mesh3D->buildDescendingConnectivity(a,b,c,d);
00257   a->decrRef(); b->decrRef(); c->decrRef(); d->decrRef();
00258   mesh3D->decrRef();
00259   //
00260   const double vec1[3]={-0.07,1.,0.07};
00261   const double origin1[3]={1.524,1.4552,1.74768};
00262   DataArrayInt *ids=0;
00263   MEDCouplingUMesh *slice1=mesh2D->buildSlice3DSurf(origin1,vec1,1e-10,ids);
00264   const int expected1[25]={6,8,10,11,13,18,19,21,23,25,26,38,41,43,47,49,52,53,64,67,69,73,75,78,79};
00265   const int expected2[75]={1,40,41,1,42,41,1,40,43,1,44,43,1,42,44,1,45,41,1,42,46,1,46,45,1,47,40,1,47,48,1,44,48,1,49,42,1,44,50,1,49,50,1,49,51,1,51,46,1,48,52,1,50,52,1,53,49,1,50,54,1,53,54,1,53,55,1,55,51,1,52,56,1,54,56};
00266   const int expected3[26]={0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75};
00267   const double expected4[171]={1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,2.,2.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,2.,2.,1.,1.,1.,2.,1.,1.25,2.,1.,1.5,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,1.,1.,3.,1.,1.25,3.,1.,1.5,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,1.,1.5408576,0.,2.,1.6108576000000001,0.,2.,1.5408576,1.,1.,1.5,0.5836800000000008,1.,1.4708576,1.,3.,1.6808576,0.,3.,1.6108576000000001,1.,0.,1.4708576,0.,0.,1.4008576,1.,2.,1.4708576,2.,1.,1.4008576000000001,2.,3.,1.5408575999999998,2.,0.,1.3308575999999999,2.,2.,1.4008576,3.,1.,1.3308576,3.,3.,1.4708576,3.,0.,1.2608576,3.};
00268   CPPUNIT_ASSERT_EQUAL(1,slice1->getMeshDimension());
00269   CPPUNIT_ASSERT_EQUAL(3,slice1->getSpaceDimension());
00270   CPPUNIT_ASSERT_EQUAL(57,slice1->getNumberOfNodes());
00271   CPPUNIT_ASSERT_EQUAL(25,slice1->getNumberOfCells());
00272   CPPUNIT_ASSERT_EQUAL(25,ids->getNumberOfTuples());
00273   CPPUNIT_ASSERT_EQUAL(75,slice1->getNodalConnectivity()->getNumberOfTuples());
00274   CPPUNIT_ASSERT_EQUAL(26,slice1->getNodalConnectivityIndex()->getNumberOfTuples());
00275   CPPUNIT_ASSERT(std::equal(expected1,expected1+25,ids->getConstPointer()));
00276   CPPUNIT_ASSERT(std::equal(expected2,expected2+47,slice1->getNodalConnectivity()->getConstPointer()));
00277   CPPUNIT_ASSERT(std::equal(expected3,expected3+26,slice1->getNodalConnectivityIndex()->getConstPointer()));
00278   for(int i=0;i<171;i++)
00279     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],slice1->getCoords()->getIJ(0,i),1e-12);
00280   ids->decrRef();
00281   slice1->decrRef();
00282   //
00283   const double vec2[3]={0.,0.,1.};
00284   const double origin2[3]={2.5,1.,2.};
00285   slice1=mesh2D->buildSlice3DSurf(origin2,vec2,1e-10,ids);
00286   const int expected5[68]={32,32,32,32,33,34,35,36,37,38,39,40,41,42,43,43,43,43,43,43,44,44,44,44,45,46,47,47,47,47,48,49,50,51,52,53,53,53,53,53,53,54,54,54,54,55,56,57,59,60,61,62,63,64,65,66,67,68,71,72,74,75,76,77,78,81,82,83};
00287   const int expected6[204]={1,15,18,1,18,16,1,16,26,1,26,15,1,26,15,1,16,26,1,18,16,1,15,18,1,16,21,1,21,28,1,22,28,1,19,22,1,17,19,1,16,17,1,16,21,1,21,28,1,28,22,1,22,19,1,19,17,1,17,16,1,16,18,1,18,20,1,20,21,1,21,16,1,20,21,1,18,20,1,28,21,1,21,24,1,24,25,1,25,28,1,25,28,1,24,25,1,21,24,1,23,22,1,26,23,1,26,16,1,16,17,1,17,19,1,19,22,1,22,23,1,23,26,1,22,28,1,28,29,1,29,27,1,27,22,1,27,22,1,29,27,1,28,29,1,26,15,1,16,26,1,18,16,1,15,18,1,16,21,1,21,28,1,22,28,1,19,22,1,17,19,1,16,17,1,20,21,1,18,20,1,25,28,1,24,25,1,21,24,1,23,22,1,26,23,1,27,22,1,29,27,1,28,29};
00288   const int expected7[69]={0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204};
00289   const double expected8[135]={0.,0.,1.,1.,1.,1.,1.,1.25, 1.,1.,0.,1.,1.,1.5, 1.,2.,0.,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25, 2.,1.,0.,2.,1.,1.5, 2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,1.,3.,2.,2.,2.,2.,2.,3.,2.,0.,0.,3.,1.,1.,3.,1.,1.25, 3.,1.,0.,3.,1.,1.5, 3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,1.,3.,3.,2.,2.,3.,2.,3.,3.};
00290   CPPUNIT_ASSERT_EQUAL(1,slice1->getMeshDimension());
00291   CPPUNIT_ASSERT_EQUAL(3,slice1->getSpaceDimension());
00292   CPPUNIT_ASSERT_EQUAL(45,slice1->getNumberOfNodes());
00293   CPPUNIT_ASSERT_EQUAL(68,slice1->getNumberOfCells());
00294   CPPUNIT_ASSERT_EQUAL(68,ids->getNumberOfTuples());
00295   CPPUNIT_ASSERT_EQUAL(204,slice1->getNodalConnectivity()->getNumberOfTuples());
00296   CPPUNIT_ASSERT_EQUAL(69,slice1->getNodalConnectivityIndex()->getNumberOfTuples());
00297   CPPUNIT_ASSERT(std::equal(expected5,expected5+68,ids->getConstPointer()));
00298   CPPUNIT_ASSERT(std::equal(expected6,expected6+171,slice1->getNodalConnectivity()->getConstPointer()));
00299   CPPUNIT_ASSERT(std::equal(expected7,expected7+69,slice1->getNodalConnectivityIndex()->getConstPointer()));
00300   for(int i=0;i<135;i++)
00301     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected8[i],slice1->getCoords()->getIJ(0,i),1e-12);
00302   ids->decrRef();
00303   slice1->decrRef();
00304   //
00305   mesh2D->decrRef();
00306 }
00307 
00308 void MEDCouplingBasicsTest5::testDataArrayDoubleAdvSetting1()
00309 {
00310   const double data1[14]={1.,11.,2.,12.,3.,13.,4.,14.,5.,15.,6.,16.,7.,17.};
00311   const double data2[10]={8.,38.,9.,39.,0.,30.,11.,41.,12.,42.};
00312   const char *comps[2]={"comp1","comp2"};
00313   std::vector<std::string> compsCpp(comps,comps+2);
00314   DataArrayDouble *da=DataArrayDouble::New();
00315   DataArrayDouble *tmp=0;
00316   da->setInfoAndChangeNbOfCompo(compsCpp);
00317   da->setName("da");
00318   da->alloc(7,2);
00319   compsCpp.pop_back();
00320   CPPUNIT_ASSERT_THROW(da->setInfoAndChangeNbOfCompo(compsCpp),INTERP_KERNEL::Exception);
00321   std::copy(data1,data1+14,da->getPointer());
00322   //
00323   std::vector<std::pair<int,int> > p(3);
00324   p[0].first=0; p[0].second=3; p[1].first=3; p[1].second=5; p[2].first=5; p[2].second=7;
00325   tmp=da->selectByTupleRanges(p);
00326   CPPUNIT_ASSERT(tmp->isEqual(*da,1e-14));
00327   tmp->decrRef();
00328   p[0].first=0; p[0].second=2; p[1].first=3; p[1].second=4; p[2].first=5; p[2].second=7;
00329   tmp=da->selectByTupleRanges(p);
00330   const double expected1[10]={1.,11.,2.,12.,4.,14.,6.,16.,7.,17.};
00331   CPPUNIT_ASSERT_EQUAL(5,tmp->getNumberOfTuples());
00332   CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfComponents());
00333   for(int i=0;i<10;i++)
00334     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],tmp->getIJ(0,i),1e-14);
00335   tmp->decrRef();
00336   p[0].first=0; p[0].second=2; p[1].first=0; p[1].second=2; p[2].first=5; p[2].second=6;
00337   tmp=da->selectByTupleRanges(p);
00338   const double expected2[10]={1.,11.,2.,12.,1.,11.,2.,12.,6.,16.};
00339   CPPUNIT_ASSERT_EQUAL(5,tmp->getNumberOfTuples());
00340   CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfComponents());
00341   for(int i=0;i<10;i++)
00342     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],tmp->getIJ(0,i),1e-14);
00343   tmp->decrRef();
00344   p[0].first=0; p[0].second=2; p[1].first=-1; p[1].second=2; p[2].first=5; p[2].second=6;
00345   CPPUNIT_ASSERT_THROW(da->selectByTupleRanges(p),INTERP_KERNEL::Exception);
00346   p[0].first=0; p[0].second=2; p[1].first=0; p[1].second=2; p[2].first=5; p[2].second=8;
00347   CPPUNIT_ASSERT_THROW(da->selectByTupleRanges(p),INTERP_KERNEL::Exception);
00348   //
00349   DataArrayDouble *da2=DataArrayDouble::New();
00350   da2->alloc(5,2);
00351   std::copy(data2,data2+10,da2->getPointer());
00352   //
00353   DataArrayDouble *dac=da->deepCpy();
00354   dac->setContigPartOfSelectedValues2(1,da2,2,4,1);
00355   const double expected3[14]={1.,11.,0.,30.,11.,41.,4.,14.,5.,15.,6.,16.,7.,17.};
00356   for(int i=0;i<14;i++)
00357     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],dac->getIJ(0,i),1e-14);
00358   dac->decrRef();
00359   //
00360   dac=da->deepCpy();
00361   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues2(3,da2,0,5,1),INTERP_KERNEL::Exception);
00362   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues2(0,da2,4,6,1),INTERP_KERNEL::Exception);
00363   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues2(3,da2,5,0,1),INTERP_KERNEL::Exception);
00364   dac->setContigPartOfSelectedValues2(3,da2,1,5,1);
00365   const double expected4[14]={1.,11.,2.,12.,3.,13.,9.,39.,0.,30.,11.,41.,12.,42.};
00366   for(int i=0;i<14;i++)
00367     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],dac->getIJ(0,i),1e-14);
00368   dac->decrRef();
00369   //
00370   DataArrayInt *ids=DataArrayInt::New();
00371   ids->alloc(3,1);
00372   dac=da->deepCpy();
00373   ids->setIJ(0,0,2); ids->setIJ(1,0,0); ids->setIJ(2,0,4);
00374   dac->setContigPartOfSelectedValues(2,da2,ids);
00375   const double expected5[14]={1.,11.,2.,12.,0.,30.,8.,38.,12.,42.,6.,16.,7.,17.};
00376   for(int i=0;i<14;i++)
00377     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],dac->getIJ(0,i),1e-14);
00378   dac->decrRef();
00379   //
00380   dac=da->deepCpy();
00381   ids->setIJ(0,0,2); ids->setIJ(1,0,5); ids->setIJ(2,0,4);
00382   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues(1,da2,ids),INTERP_KERNEL::Exception);
00383   ids->setIJ(0,0,2); ids->setIJ(1,0,2); ids->setIJ(2,0,-1);
00384   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues(1,da2,ids),INTERP_KERNEL::Exception);
00385   ids->setIJ(0,0,2); ids->setIJ(1,0,2); ids->setIJ(2,0,1);
00386   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues(5,da2,ids),INTERP_KERNEL::Exception);
00387   dac->decrRef();
00388   //
00389   ids->setIJ(0,0,2); ids->setIJ(1,0,2); ids->setIJ(2,0,1);
00390   dac=da->deepCpy();
00391   dac->setContigPartOfSelectedValues(4,da2,ids);
00392   const double expected6[14]={1.,11.,2.,12.,3.,13.,4.,14.,0.,30.,0.,30.,9.,39.};
00393   for(int i=0;i<14;i++)
00394     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected6[i],dac->getIJ(0,i),1e-14);
00395   dac->decrRef();
00396   ids->decrRef();
00397   //
00398   da2->decrRef();
00399   da->decrRef();
00400 }
00401 
00402 void MEDCouplingBasicsTest5::testDataArrayIntAdvSetting1()
00403 {
00404   const int data1[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
00405   const int data2[10]={8,38,9,39,0,30,11,41,12,42};
00406   const char *comps[2]={"comp1","comp2"};
00407   std::vector<std::string> compsCpp(comps,comps+2);
00408   DataArrayInt *da=DataArrayInt::New();
00409   DataArrayInt *tmp=0;
00410   da->setInfoAndChangeNbOfCompo(compsCpp);
00411   da->setName("da");
00412   da->alloc(7,2);
00413   compsCpp.pop_back();
00414   CPPUNIT_ASSERT_THROW(da->setInfoAndChangeNbOfCompo(compsCpp),INTERP_KERNEL::Exception);
00415   std::copy(data1,data1+14,da->getPointer());
00416   //
00417   std::vector<std::pair<int,int> > p(3);
00418   p[0].first=0; p[0].second=3; p[1].first=3; p[1].second=5; p[2].first=5; p[2].second=7;
00419   tmp=da->selectByTupleRanges(p);
00420   CPPUNIT_ASSERT(tmp->isEqual(*da));
00421   tmp->decrRef();
00422   p[0].first=0; p[0].second=2; p[1].first=3; p[1].second=4; p[2].first=5; p[2].second=7;
00423   tmp=da->selectByTupleRanges(p);
00424   const int expected1[10]={1,11,2,12,4,14,6,16,7,17};
00425   CPPUNIT_ASSERT_EQUAL(5,tmp->getNumberOfTuples());
00426   CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfComponents());
00427   for(int i=0;i<10;i++)
00428     CPPUNIT_ASSERT_EQUAL(expected1[i],tmp->getIJ(0,i));
00429   tmp->decrRef();
00430   p[0].first=0; p[0].second=2; p[1].first=0; p[1].second=2; p[2].first=5; p[2].second=6;
00431   tmp=da->selectByTupleRanges(p);
00432   const int expected2[10]={1,11,2,12,1,11,2,12,6,16};
00433   CPPUNIT_ASSERT_EQUAL(5,tmp->getNumberOfTuples());
00434   CPPUNIT_ASSERT_EQUAL(2,tmp->getNumberOfComponents());
00435   for(int i=0;i<10;i++)
00436     CPPUNIT_ASSERT_EQUAL(expected2[i],tmp->getIJ(0,i));
00437   tmp->decrRef();
00438   p[0].first=0; p[0].second=2; p[1].first=-1; p[1].second=2; p[2].first=5; p[2].second=6;
00439   CPPUNIT_ASSERT_THROW(da->selectByTupleRanges(p),INTERP_KERNEL::Exception);
00440   p[0].first=0; p[0].second=2; p[1].first=0; p[1].second=2; p[2].first=5; p[2].second=8;
00441   CPPUNIT_ASSERT_THROW(da->selectByTupleRanges(p),INTERP_KERNEL::Exception);
00442   //
00443   DataArrayInt *da2=DataArrayInt::New();
00444   da2->alloc(5,2);
00445   std::copy(data2,data2+10,da2->getPointer());
00446   //
00447   DataArrayInt *dac=da->deepCpy();
00448   dac->setContigPartOfSelectedValues2(1,da2,2,4,1);
00449   const int expected3[14]={1,11,0,30,11,41,4,14,5,15,6,16,7,17};
00450   for(int i=0;i<14;i++)
00451     CPPUNIT_ASSERT_EQUAL(expected3[i],dac->getIJ(0,i));
00452   dac->decrRef();
00453   //
00454   dac=da->deepCpy();
00455   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues2(3,da2,0,5,1),INTERP_KERNEL::Exception);
00456   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues2(0,da2,4,6,1),INTERP_KERNEL::Exception);
00457   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues2(3,da2,5,0,1),INTERP_KERNEL::Exception);
00458   dac->setContigPartOfSelectedValues2(3,da2,1,5,1);
00459   const int expected4[14]={1,11,2,12,3,13,9,39,0,30,11,41,12,42};
00460   for(int i=0;i<14;i++)
00461     CPPUNIT_ASSERT_EQUAL(expected4[i],dac->getIJ(0,i));
00462   dac->decrRef();
00463   //
00464   DataArrayInt *ids=DataArrayInt::New();
00465   ids->alloc(3,1);
00466   dac=da->deepCpy();
00467   ids->setIJ(0,0,2); ids->setIJ(1,0,0); ids->setIJ(2,0,4);
00468   dac->setContigPartOfSelectedValues(2,da2,ids);
00469   const int expected5[14]={1,11,2,12,0,30,8,38,12,42,6,16,7,17};
00470   for(int i=0;i<14;i++)
00471     CPPUNIT_ASSERT_EQUAL(expected5[i],dac->getIJ(0,i));
00472   dac->decrRef();
00473   //
00474   dac=da->deepCpy();
00475   ids->setIJ(0,0,2); ids->setIJ(1,0,5); ids->setIJ(2,0,4);
00476   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues(1,da2,ids),INTERP_KERNEL::Exception);
00477   ids->setIJ(0,0,2); ids->setIJ(1,0,2); ids->setIJ(2,0,-1);
00478   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues(1,da2,ids),INTERP_KERNEL::Exception);
00479   ids->setIJ(0,0,2); ids->setIJ(1,0,2); ids->setIJ(2,0,1);
00480   CPPUNIT_ASSERT_THROW(dac->setContigPartOfSelectedValues(5,da2,ids),INTERP_KERNEL::Exception);
00481   dac->decrRef();
00482   //
00483   ids->setIJ(0,0,2); ids->setIJ(1,0,2); ids->setIJ(2,0,1);
00484   dac=da->deepCpy();
00485   dac->setContigPartOfSelectedValues(4,da2,ids);
00486   const int expected6[14]={1,11,2,12,3,13,4,14,0,30,0,30,9,39};
00487   for(int i=0;i<14;i++)
00488     CPPUNIT_ASSERT_EQUAL(expected6[i],dac->getIJ(0,i));
00489   dac->decrRef();
00490   ids->decrRef();
00491   //
00492   da2->decrRef();
00493   da->decrRef();
00494 }
00495 
00496 void MEDCouplingBasicsTest5::testBuildDescendingConnec2Of3DMesh1()
00497 {
00498   MEDCouplingUMesh *mesh=build3DSourceMesh_1();
00499   DataArrayInt *desc=DataArrayInt::New();
00500   DataArrayInt *descIndx=DataArrayInt::New();
00501   DataArrayInt *revDesc=DataArrayInt::New();
00502   DataArrayInt *revDescIndx=DataArrayInt::New();
00503   //
00504   MEDCouplingUMesh *mesh2=mesh->buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx);
00505   mesh2->checkCoherency();
00506   CPPUNIT_ASSERT_EQUAL(2,mesh2->getMeshDimension());
00507   CPPUNIT_ASSERT_EQUAL(30,mesh2->getNumberOfCells());
00508   CPPUNIT_ASSERT_EQUAL(31,revDescIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(31,revDescIndx->getNumberOfTuples());
00509   CPPUNIT_ASSERT_EQUAL(13,descIndx->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(13,descIndx->getNumberOfTuples());
00510   CPPUNIT_ASSERT_EQUAL(48,desc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,desc->getNumberOfTuples());
00511   CPPUNIT_ASSERT_EQUAL(48,revDesc->getNbOfElems()); CPPUNIT_ASSERT_EQUAL(48,revDesc->getNumberOfTuples());
00512   const int expected1[48]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,-10,15,-5,-13,16,17,-14,18,-4,19,-2,20,21,22,23,24,25,-11,26,-1,-12,-25,-22,27,28,-7,-20,-24,29,-16,-18,30,-8,-28};
00513   CPPUNIT_ASSERT(std::equal(expected1,expected1+48,desc->getConstPointer()));
00514   const int expected2[13]={0,4,8,12,16,20,24,28,32,36,40,44,48};
00515   CPPUNIT_ASSERT(std::equal(expected2,expected2+13,descIndx->getConstPointer()));
00516   const int expected3[31]={0,2,4,5,7,9,10,12,14,15,17,19,21,23,25,26,28,29,31,32,34,35,37,38,40,42,43,44,46,47,48};
00517   CPPUNIT_ASSERT(std::equal(expected3,expected3+31,revDescIndx->getConstPointer()));
00518   const int expected4[48]={0,8,0,6,0,0,5,1,4,1,1,9,1,11,2,2,3,2,7,2,8,3,4,3,5,3,4,10,4,5,11,5,6,10,6,6,9,7,7,10,7,8,8,9,9,11,10,11};
00519   CPPUNIT_ASSERT(std::equal(expected4,expected4+48,revDesc->getConstPointer()));
00520   DataArrayInt *conn=mesh2->getNodalConnectivity();
00521   DataArrayInt *connIndex=mesh2->getNodalConnectivityIndex();
00522   const int expected5[31]={0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120};
00523   CPPUNIT_ASSERT(std::equal(expected5,expected5+31,connIndex->getConstPointer()));
00524   const int expected6[120]={3,8,1,7,3,8,3,1,3,1,3,7,3,7,3,8,3,6,0,8,3,6,2,0,3,0,2,8,3,8,2,6,3,7,4,5,3,7,8,4,3,4,8,5,3,5,8,7,3,6,8,4,3,6,7,8,3,4,7,6,3,8,4,0,3,0,4,6,3,6,3,8,3,7,3,6,3,8,0,1,3,1,0,3,3,3,0,8,3,4,1,5,3,4,8,1,3,1,8,5,3,1,7,5,3,0,2,3,3,3,2,8,3,1,4,0,3,3,2,6};
00525   CPPUNIT_ASSERT(std::equal(expected6,expected6+120,conn->getConstPointer()));
00526   //
00527   desc->decrRef();
00528   descIndx->decrRef();
00529   revDesc->decrRef();
00530   revDescIndx->decrRef();
00531   mesh2->decrRef();
00532   mesh->decrRef();
00533 }
00534 
00535 void MEDCouplingBasicsTest5::testAre2DCellsNotCorrectlyOriented1()
00536 {
00537   double m1Coords[8]={1.,1.,-1.,-1.,-1.,-1.,1.,-1.};
00538   int m1Conn[4]={0,3,1,2};
00539   MEDCouplingUMesh *m1=MEDCouplingUMesh::New();
00540   m1->setMeshDimension(2);
00541   m1->allocateCells(1);
00542   m1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,m1Conn);
00543   m1->finishInsertingCells();
00544   DataArrayDouble *myCoords1=DataArrayDouble::New();
00545   myCoords1->alloc(4,2);
00546   std::copy(m1Coords,m1Coords+8,myCoords1->getPointer());
00547   m1->setCoords(myCoords1);
00548   myCoords1->decrRef();
00549   //
00550   double vec1[3]={0.,0.,1.};
00551   double *vec2=new double[2];
00552   for(int i=0;i<18;i++)
00553     {
00554       vec2[0]=3.*cos(M_PI/9.*i);
00555       vec2[1]=3.*sin(M_PI/9.*i);
00556       MEDCouplingUMesh *m1Cpy=static_cast<MEDCouplingUMesh *>(m1->deepCpy());
00557       m1Cpy->translate(vec2);
00558       std::vector<int> res;
00559       CPPUNIT_ASSERT_THROW(m1Cpy->are2DCellsNotCorrectlyOriented(vec1,false,res),INTERP_KERNEL::Exception);
00560       res.clear();
00561       m1Cpy->changeSpaceDimension(3);
00562       m1Cpy->are2DCellsNotCorrectlyOriented(vec1,false,res);
00563       CPPUNIT_ASSERT_EQUAL(1,(int)res.size());
00564       CPPUNIT_ASSERT_EQUAL(0,res[0]);
00565       m1Cpy->decrRef();
00566     }
00567   delete [] vec2;
00568   //
00569   m1->decrRef();
00570 }
00571 
00572 void MEDCouplingBasicsTest5::testDataArrayAbs1()
00573 {
00574   DataArrayDouble *d1=DataArrayDouble::New();
00575   const double val1[12]={2.,-3.,-5.,6.,-7.,-8.,9.,10.,-11.,-12.,-13.,-15.};
00576   const double expected1[12]={2.,3.,5.,6.,7.,8.,9.,10.,11.,12.,13.,15.};
00577   d1->alloc(6,2);
00578   std::copy(val1,val1+12,d1->getPointer());
00579   DataArrayInt *d2=d1->convertToIntArr();
00580   //
00581   d1->abs();
00582   for(int i=0;i<12;i++)
00583     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],d1->getIJ(0,i),1e-14);
00584   //
00585   const int expected2[12]={2,3,5,6,7,8,9,10,11,12,13,15};
00586   d2->abs();
00587   for(int i=0;i<12;i++)
00588     CPPUNIT_ASSERT_EQUAL(expected2[i],d2->getIJ(0,i));
00589   //
00590   d2->decrRef();
00591   d1->decrRef();
00592 }
00593 
00594 void MEDCouplingBasicsTest5::testGetValueOn3()
00595 {
00596   const double v[4]={0.,1.,1.5,2.};
00597   const double v2[5]={0.7,1.25,0.,2.,1.5};
00598   const double disp[12]={5.,50.,500.,6.,60.,600.,7.,70.,700.,8.,80.,800.};
00599   MEDCouplingUMesh *m=MEDCouplingUMesh::New("myMesh",1);
00600   const int nbNodes=4;
00601   const int nbCells=nbNodes-1;
00602   m->allocateCells(nbCells);
00603   DataArrayDouble *coords=DataArrayDouble::New();
00604   coords->alloc(nbNodes,1);
00605   std::copy(v,v+nbNodes,coords->getPointer());
00606   m->setCoords(coords);
00607   coords->decrRef();
00608   const int conn[6]={0,1,2,1,2,3};
00609   m->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn);
00610   m->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+2);
00611   m->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,conn+4);
00612   m->finishInsertingCells();
00613   MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_NODES);
00614   f->setMesh(m);
00615   DataArrayDouble *array=DataArrayDouble::New();
00616   array->alloc(m->getNumberOfNodes(),3);
00617   std::copy(disp,disp+12,array->getPointer());
00618   f->setArray(array);
00619   array->decrRef();
00620   DataArrayDouble *arr1=f->getValueOnMulti(v2,5);
00621   CPPUNIT_ASSERT_EQUAL(5,arr1->getNumberOfTuples());
00622   CPPUNIT_ASSERT_EQUAL(3,arr1->getNumberOfComponents());
00623   const double expected1[15]={5.7,57.,570.,6.5,65.,650.,5.,50.,500.,8.,80.,800.,7.,70.,700.};
00624   for(int i=0;i<15;i++)
00625     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],arr1->getIJ(0,i),1e-14);
00626   arr1->decrRef();
00627   f->decrRef();
00628   m->decrRef();
00629 }
00630 
00631 void MEDCouplingBasicsTest5::testGetNodeIdsOfCell2()
00632 {
00633   MEDCouplingCMesh *m1c=MEDCouplingCMesh::New();
00634   DataArrayDouble *coordsX=DataArrayDouble::New();
00635   double arrX[5] = { -1., 1., 2., 4., 4.5 };
00636   coordsX->useArray(arrX,false, CPP_DEALLOC,5,1);
00637   DataArrayDouble *coordsY=DataArrayDouble::New();
00638   double arrY[4] = { -2., 2., 4., 8. };
00639   coordsY->useArray(arrY,false, CPP_DEALLOC,4,1);
00640   DataArrayDouble *coordsZ=DataArrayDouble::New();
00641   double arrZ[3] = { -2., 2., 4. };
00642   coordsZ->useArray(arrZ,false, CPP_DEALLOC,3,1);  
00643   // test in 1D
00644   m1c->setCoordsAt(0,coordsX);
00645   CPPUNIT_ASSERT_EQUAL(4,m1c->getNumberOfCells());
00646   const int expected1[4][2]={{0,1},{1,2},{2,3},{3,4}};
00647   for(int i=0;i<4;i++)
00648     {
00649       std::vector<int> v;
00650       m1c->getNodeIdsOfCell(i,v);
00651       CPPUNIT_ASSERT((int)v.size()==2);
00652       std::equal(v.begin(),v.end(),expected1[i]);
00653     }
00654   // test in 2D
00655   m1c->setCoordsAt(1,coordsY);
00656   CPPUNIT_ASSERT_EQUAL(12,m1c->getNumberOfCells());
00657   const int expected2[12][4]={{0,1,6,5},{1,2,7,6},{2,3,8,7},{3,4,9,8},{4,5,11,10},{5,6,12,11},{6,7,13,12},{7,8,14,13},{8,9,16,15},{9,10,17,16},{10,11,18,17},{11,12,19,18}};
00658   for(int i=0;i<12;i++)
00659     {
00660       std::vector<int> v;
00661       m1c->getNodeIdsOfCell(i,v);
00662       CPPUNIT_ASSERT((int)v.size()==4);
00663       std::equal(v.begin(),v.end(),expected2[i]);
00664     }
00665   // test in 3D
00666   m1c->setCoordsAt(2,coordsZ);
00667   CPPUNIT_ASSERT_EQUAL(24,m1c->getNumberOfCells());
00668   const int expected3[24][8]={{0,1,6,5,20,21,26,25},{1,2,7,6,21,22,27,26},{2,3,8,7,22,23,28,27},{3,4,9,8,23,24,29,28},{4,5,11,10,24,25,31,30},{5,6,12,11,25,26,32,31},{6,7,13,12,26,27,33,32},{7,8,14,13,27,28,34,33},{8,9,16,15,28,29,36,35},{9,10,17,16,29,30,37,36},{10,11,18,17,30,31,38,37},{11,12,19,18,31,32,39,38},{20,21,26,25,40,41,46,45},{21,22,27,26,41,42,47,46},{22,23,28,27,42,43,48,47},{23,24,29,28,43,44,49,48},{24,25,31,30,44,45,51,50},{25,26,32,31,45,46,52,51},{26,27,33,32,46,47,53,52},{27,28,34,33,47,48,54,53},{28,29,36,35,48,49,56,55},{29,30,37,36,49,50,57,56},{30,31,38,37,50,51,58,57},{31,32,39,38,51,52,59,58}};
00669   for(int i=0;i<12;i++)
00670     {
00671       std::vector<int> v;
00672       m1c->getNodeIdsOfCell(i,v);
00673       CPPUNIT_ASSERT((int)v.size()==8);
00674       std::equal(v.begin(),v.end(),expected3[i]);
00675     }
00676   //
00677   coordsX->decrRef();
00678   coordsY->decrRef();
00679   coordsZ->decrRef();
00680   m1c->decrRef();
00681 }
00682 
00683 void MEDCouplingBasicsTest5::testRenumberNodesInConn1()
00684 {
00685   double mesh2DCoords[27]={-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. };
00686   int mesh2DConn[18]={1,4,2, 4,5,2, 0,3,4,1, 6,7,4,3, 7,8,5,4};
00687   MEDCouplingUMesh *mesh2D=MEDCouplingUMesh::New("mesh",2);
00688   mesh2D->allocateCells(5);
00689   mesh2D->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,mesh2DConn);
00690   mesh2D->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,mesh2DConn+3);
00691   mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,mesh2DConn+6);
00692   mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,mesh2DConn+10);
00693   mesh2D->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,mesh2DConn+14);
00694   mesh2D->finishInsertingCells();
00695   DataArrayDouble *myCoords=DataArrayDouble::New();
00696   myCoords->alloc(9,3);
00697   std::copy(mesh2DCoords,mesh2DCoords+27,myCoords->getPointer());
00698   mesh2D->setCoords(myCoords);
00699   myCoords->decrRef();
00700   mesh2D->checkCoherency();
00701   //
00702   double mesh3DCoords[24]={-0.3,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.2,-0.3,0., -0.3,-0.3,1., -0.3,0.2,1., 0.2,0.2,1., 0.2,-0.3,1. };
00703   int mesh3DConn[8]={0,1,2,3,4,5,6,7};
00704   MEDCouplingUMesh *mesh3D=MEDCouplingUMesh::New("mesh",3);
00705   mesh3D->allocateCells(1);
00706   mesh3D->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,mesh3DConn);
00707   mesh3D->finishInsertingCells();
00708   DataArrayDouble *myCoords3D=DataArrayDouble::New();
00709   myCoords3D->alloc(8,3);
00710   std::copy(mesh3DCoords,mesh3DCoords+24,myCoords3D->getPointer());
00711   mesh3D->setCoords(myCoords3D);
00712   myCoords3D->decrRef();
00713   mesh3D->checkCoherency();
00714   //
00715   MEDCouplingUMesh *mesh3D_2=dynamic_cast<MEDCouplingUMesh *>(mesh3D->deepCpy());
00716   MEDCouplingUMesh *mesh2D_2=dynamic_cast<MEDCouplingUMesh *>(mesh2D->deepCpy());
00717   MEDCouplingUMesh *mesh3D_4=dynamic_cast<MEDCouplingUMesh *>(mesh3D->deepCpy());
00718   MEDCouplingUMesh *mesh2D_4=dynamic_cast<MEDCouplingUMesh *>(mesh2D->deepCpy());
00719   DataArrayInt *renumNodes=DataArrayInt::New();
00720   int oldNbOf3DNodes=mesh3D->getNumberOfNodes();
00721   renumNodes->alloc(mesh2D->getNumberOfNodes(),1);
00722   renumNodes->iota(oldNbOf3DNodes);
00723   DataArrayDouble *coo=DataArrayDouble::Aggregate(mesh3D->getCoords(),mesh2D->getCoords());
00724   mesh3D->setCoords(coo);
00725   mesh2D->setCoords(coo);
00726   coo->decrRef();
00727   MEDCouplingUMesh *mesh2D_3=dynamic_cast<MEDCouplingUMesh *>(mesh2D->deepCpy());
00728   mesh2D_3->shiftNodeNumbersInConn(oldNbOf3DNodes);
00729   mesh2D->renumberNodesInConn(renumNodes->getConstPointer());
00730   renumNodes->decrRef();
00731   CPPUNIT_ASSERT(mesh2D_3->isEqual(mesh2D,1e-12));
00732   mesh2D_3->decrRef();
00733   //
00734   DataArrayInt *da1,*da2;
00735   mesh3D->checkGeoEquivalWith(mesh3D_2,10,1e-12,da1,da2);
00736   CPPUNIT_ASSERT(da1==0);
00737   CPPUNIT_ASSERT_EQUAL(8,da2->getNumberOfTuples());
00738   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
00739   const int expected1[8]={8,11,12,9,4,5,6,7};
00740   for(int i=0;i<8;i++)
00741     CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
00742   da2->decrRef();
00743   //
00744   mesh2D->checkGeoEquivalWith(mesh2D_2,10,1e-12,da1,da2);
00745   CPPUNIT_ASSERT(da1==0);
00746   CPPUNIT_ASSERT_EQUAL(9,da2->getNumberOfTuples());
00747   CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
00748   for(int i=0;i<9;i++)
00749     CPPUNIT_ASSERT_EQUAL(8+i,da2->getIJ(i,0));
00750   da2->decrRef();
00751   //
00752   const double vect[3]={1.,0.,0.};
00753   MEDCouplingUMesh *mesh2D_5=dynamic_cast<MEDCouplingUMesh *>(mesh2D_4->deepCpy());
00754   mesh2D_5->translate(vect);
00755   std::vector<MEDCouplingUMesh *> meshes(3);
00756   meshes[0]=mesh3D_4; meshes[1]=mesh2D_4; meshes[2]=mesh2D_5;
00757   MEDCouplingUMesh::PutUMeshesOnSameAggregatedCoords(meshes);
00758   CPPUNIT_ASSERT(mesh3D_4->getCoords()==mesh2D_4->getCoords());
00759   CPPUNIT_ASSERT(mesh2D_4->getCoords()==mesh2D_5->getCoords());
00760   mesh3D_4->checkCoherency(); mesh2D_4->checkCoherency(); mesh2D_5->checkCoherency();
00761   CPPUNIT_ASSERT_EQUAL(26,mesh3D_4->getNumberOfNodes());
00762   CPPUNIT_ASSERT_EQUAL(3,mesh3D_4->getSpaceDimension());
00763   CPPUNIT_ASSERT_EQUAL(9,mesh3D_4->getNodalConnectivity()->getNumberOfTuples());
00764   CPPUNIT_ASSERT_EQUAL(23,mesh2D_4->getNodalConnectivity()->getNumberOfTuples());
00765   CPPUNIT_ASSERT_EQUAL(23,mesh2D_5->getNodalConnectivity()->getNumberOfTuples());
00766   const int expected2[9]={18,0,1,2,3,4,5,6,7};
00767   const int expected3[23]={3,9,12,10, 3,12,13,10, 4,8,11,12,9, 4,14,15,12,11, 4,15,16,13,12};
00768   const int expected4[23]={3,18,21,19, 3,21,22,19, 4,17,20,21,18, 4,23,24,21,20, 4,24,25,22,21};
00769   const double expected5[78]={-0.3,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.2,-0.3,0., -0.3,-0.3,1., -0.3,0.2,1., 0.2,0.2,1., 0.2,-0.3,1., -0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0., 0.7, -0.3, 0.0, 1.2, -0.3, 0.0, 1.7, -0.3, 0.0, 0.7, 0.2, 0.0, 1.2, 0.2, 0.0, 1.7, 0.2, 0.0, 0.7, 0.7, 0.0, 1.2, 0.7, 0.0, 1.7, 0.7, 0.0};
00770   CPPUNIT_ASSERT(std::equal(expected2,expected2+9,mesh3D_4->getNodalConnectivity()->getConstPointer()));
00771   CPPUNIT_ASSERT(std::equal(expected3,expected3+23,mesh2D_4->getNodalConnectivity()->getConstPointer()));
00772   CPPUNIT_ASSERT(std::equal(expected4,expected4+23,mesh2D_5->getNodalConnectivity()->getConstPointer()));
00773   for(int i=0;i<78;i++)
00774     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],mesh3D_4->getCoords()->getIJ(0,i),1e-12);
00775   //
00776   MEDCouplingUMesh::MergeNodesOnUMeshesSharingSameCoords(meshes,1e-12);
00777   mesh3D_4->checkCoherency(); mesh2D_4->checkCoherency(); mesh2D_5->checkCoherency();
00778   CPPUNIT_ASSERT(mesh3D_4->getCoords()==mesh2D_4->getCoords());
00779   CPPUNIT_ASSERT(mesh2D_4->getCoords()==mesh2D_5->getCoords());
00780   CPPUNIT_ASSERT_EQUAL(19,mesh3D_4->getNumberOfNodes());
00781   CPPUNIT_ASSERT_EQUAL(3,mesh3D_4->getSpaceDimension());
00782   CPPUNIT_ASSERT_EQUAL(9,mesh3D_4->getNodalConnectivity()->getNumberOfTuples());
00783   CPPUNIT_ASSERT_EQUAL(23,mesh2D_4->getNodalConnectivity()->getNumberOfTuples());
00784   CPPUNIT_ASSERT_EQUAL(23,mesh2D_5->getNodalConnectivity()->getNumberOfTuples());
00785   const int expected6[9]={18,0,1,2,3,4,5,6,7};
00786   const int expected7[23]={3,3,2,8, 3,2,9,8, 4,0,1,2,3, 4,10,11,2,1, 4,11,12,9,2};
00787   const int expected8[23]={3,13,15,14, 3,15,16,14, 4,8,9,15,13, 4,12,17,15,9, 4,17,18,16,15};
00788   const double expected9[57]={-0.3, -0.3, 0., -0.3, 0.2, 0., 0.2, 0.2, 0., 0.2, -0.3, 0., -0.3, -0.3, 1., -0.3, 0.2, 1., 
00789                               0.2, 0.2, 1., 0.2, -0.3, 1., 0.7, -0.3, 0., 0.7, 0.2, 0., -0.3, 0.7, 0., 0.2, 0.7, 0., 
00790                               0.7, 0.7, 0., 1.2, -0.3, 0., 1.7, -0.3, 0., 1.2, 0.2, 0., 1.7, 0.2, 0., 1.2, 0.7, 0., 1.7, 0.7, 0.};
00791   CPPUNIT_ASSERT(std::equal(expected6,expected6+9,mesh3D_4->getNodalConnectivity()->getConstPointer()));
00792   CPPUNIT_ASSERT(std::equal(expected7,expected7+23,mesh2D_4->getNodalConnectivity()->getConstPointer()));
00793   CPPUNIT_ASSERT(std::equal(expected8,expected8+23,mesh2D_5->getNodalConnectivity()->getConstPointer()));
00794   for(int i=0;i<57;i++)
00795     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected9[i],mesh3D_4->getCoords()->getIJ(0,i),1e-12);
00796   mesh2D_5->decrRef();
00797   //
00798   mesh3D_4->decrRef();
00799   mesh2D_4->decrRef();
00800   mesh3D_2->decrRef();
00801   mesh2D_2->decrRef();
00802   //
00803   mesh3D->decrRef();
00804   mesh2D->decrRef();
00805 }
00806 
00807 void MEDCouplingBasicsTest5::testComputeNeighborsOfCells1()
00808 {
00809   MEDCouplingUMesh *m=build2DTargetMesh_1();
00810   DataArrayInt *d1=0,*d2=0;
00811   m->computeNeighborsOfCells(d1,d2);
00812   CPPUNIT_ASSERT_EQUAL(6,d2->getNumberOfTuples());
00813   CPPUNIT_ASSERT_EQUAL(10,d1->getNumberOfTuples());
00814   const int expected1[6]={0,2,4,6,8,10};
00815   const int expected2[10]={3,1,0,2,4,1,4,0,2,3};
00816   CPPUNIT_ASSERT(std::equal(expected1,expected1+6,d2->getConstPointer()));
00817   CPPUNIT_ASSERT(std::equal(expected2,expected2+10,d1->getConstPointer()));
00818   d1->decrRef();
00819   d2->decrRef();
00820   m->decrRef();
00821 }
00822 
00823 void MEDCouplingBasicsTest5::testCheckButterflyCellsBug1()
00824 {
00825   double mesh2DCoords[10]={323.85,120.983748908684,317.5,131.982271536747,336.55,120.983748908686,330.2,131.982271536751,323.85,142.98079416481};
00826   int mesh2DConn[5]={4,1,0,2,3};
00827   MEDCouplingUMesh *mesh2D=MEDCouplingUMesh::New("mesh",2);
00828   mesh2D->allocateCells(1);
00829   mesh2D->insertNextCell(INTERP_KERNEL::NORM_POLYGON,5,mesh2DConn);
00830   mesh2D->finishInsertingCells();
00831   DataArrayDouble *myCoords=DataArrayDouble::New();
00832   myCoords->alloc(5,2);
00833   std::copy(mesh2DCoords,mesh2DCoords+10,myCoords->getPointer());
00834   mesh2D->setCoords(myCoords);
00835   myCoords->decrRef();
00836   mesh2D->checkCoherency();
00837   //
00838   std::vector<int> v;
00839   mesh2D->checkButterflyCells(v);
00840   CPPUNIT_ASSERT_EQUAL(0,(int)v.size());
00841   //
00842   mesh2D->decrRef();
00843 }
00844 
00845 void MEDCouplingBasicsTest5::testDataArrayIntRange1()
00846 {
00847   DataArrayInt *d=DataArrayInt::Range(2,17,7);
00848   const int expected1[3]={2,9,16};
00849   CPPUNIT_ASSERT_EQUAL(3,d->getNumberOfTuples());
00850   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00851   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,d->getConstPointer()));
00852   d->decrRef();
00853   //
00854   d=DataArrayInt::Range(2,23,7);
00855   CPPUNIT_ASSERT_EQUAL(3,d->getNumberOfTuples());
00856   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00857   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,d->getConstPointer()));
00858   d->decrRef();
00859   //
00860   d=DataArrayInt::Range(2,24,7);
00861   const int expected2[4]={2,9,16,23};
00862   CPPUNIT_ASSERT_EQUAL(4,d->getNumberOfTuples());
00863   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00864   CPPUNIT_ASSERT(std::equal(expected2,expected2+4,d->getConstPointer()));
00865   d->decrRef();
00866   //
00867   d=DataArrayInt::Range(24,2,-7);
00868   const int expected3[4]={24,17,10,3};
00869   CPPUNIT_ASSERT_EQUAL(4,d->getNumberOfTuples());
00870   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00871   CPPUNIT_ASSERT(std::equal(expected3,expected3+4,d->getConstPointer()));
00872   d->decrRef();
00873   //
00874   d=DataArrayInt::Range(23,2,-7);
00875   const int expected4[3]={23,16,9};
00876   CPPUNIT_ASSERT_EQUAL(3,d->getNumberOfTuples());
00877   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00878   CPPUNIT_ASSERT(std::equal(expected4,expected4+3,d->getConstPointer()));
00879   d->decrRef();
00880   //
00881   d=DataArrayInt::Range(23,22,-7);
00882   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfTuples());
00883   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00884   CPPUNIT_ASSERT_EQUAL(23,d->getIJ(0,0));
00885   d->decrRef();
00886   //
00887   d=DataArrayInt::Range(22,23,7);
00888   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfTuples());
00889   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00890   CPPUNIT_ASSERT_EQUAL(22,d->getIJ(0,0));
00891   d->decrRef();
00892   //
00893   d=DataArrayInt::Range(22,22,7);
00894   CPPUNIT_ASSERT_EQUAL(0,d->getNumberOfTuples());
00895   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00896   d->decrRef();
00897   //
00898   d=DataArrayInt::Range(22,22,-7);
00899   CPPUNIT_ASSERT_EQUAL(0,d->getNumberOfTuples());
00900   CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents());
00901   d->decrRef();
00902   //
00903   CPPUNIT_ASSERT_THROW(DataArrayInt::Range(22,23,-7),INTERP_KERNEL::Exception);
00904   CPPUNIT_ASSERT_THROW(DataArrayInt::Range(23,22,7),INTERP_KERNEL::Exception);
00905   CPPUNIT_ASSERT_THROW(DataArrayInt::Range(23,22,0),INTERP_KERNEL::Exception);
00906   CPPUNIT_ASSERT_THROW(DataArrayInt::Range(22,23,0),INTERP_KERNEL::Exception);
00907 }
00908 
00909 void MEDCouplingBasicsTest5::testDataArrayDoubleGetMinMaxPerComponent1()
00910 {
00911   const double values1[12]={1.,2.,3.,-0.9,2.1,3.,1.3,1.7,3.,1.,1.8,3.};
00912   DataArrayDouble *d1=DataArrayDouble::New();
00913   double *res=new double[2*3];
00914   CPPUNIT_ASSERT_THROW(d1->getMinMaxPerComponent(res),INTERP_KERNEL::Exception);
00915   d1->alloc(4,3);
00916   std::copy(values1,values1+12,d1->getPointer());
00917   d1->getMinMaxPerComponent(res);
00918   const double expected1[6]={-0.9,1.3,1.7,2.1,3.,3.};
00919   for(int i=0;i<6;i++)
00920     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],res[i],1e-14);
00921   delete [] res;
00922   //
00923   d1->rearrange(2);
00924   res=new double[2*2];
00925   d1->getMinMaxPerComponent(res);
00926   const double expected2[4]={1.,3.,-0.9,3.};
00927   for(int i=0;i<4;i++)
00928     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],res[i],1e-14);
00929   delete [] res;
00930   //
00931   d1->rearrange(1);
00932   res=new double[2*1];
00933   d1->getMinMaxPerComponent(res);
00934   const double expected3[2]={-0.9,3.};
00935   for(int i=0;i<2;i++)
00936     CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],res[i],1e-14);
00937   delete [] res;
00938   d1->decrRef();
00939 }
00940 
00941 void MEDCouplingBasicsTest5::testDataArrayIntGetHashCode1()
00942 {
00943   DataArrayInt *d1=DataArrayInt::New(); d1->alloc(3545,1); d1->iota(0);
00944   DataArrayInt *d2=DataArrayInt::New(); d2->alloc(3545,1); d2->iota(0);
00945   //
00946   CPPUNIT_ASSERT_EQUAL(d1->getHashCode(),d2->getHashCode());
00947   CPPUNIT_ASSERT_EQUAL(232341068,d1->getHashCode());
00948   d1->setIJ(886,0,6);
00949   CPPUNIT_ASSERT_EQUAL(232340188,d1->getHashCode());
00950   //
00951   d1->decrRef();
00952   d2->decrRef();
00953 }
00954 
00955 void MEDCouplingBasicsTest5::testZipConnectivityPol1()
00956 {
00957   MEDCouplingUMesh *m1=build2DTargetMesh_1();
00958   const int cells1[3]={2,3,4};
00959   MEDCouplingPointSet *m2_1=m1->buildPartOfMySelf(cells1,cells1+3,true);
00960   MEDCouplingUMesh *m2=dynamic_cast<MEDCouplingUMesh *>(m2_1);
00961   DataArrayInt *arr=0;
00962   CPPUNIT_ASSERT(m2);
00963   // no permutation policy 0
00964   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,0,arr));
00965   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
00966   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
00967   CPPUNIT_ASSERT(std::equal(cells1,cells1+3,arr->getConstPointer()));
00968   arr->decrRef();
00969   // no permutation policy 1
00970   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,1,arr));
00971   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
00972   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
00973   CPPUNIT_ASSERT(std::equal(cells1,cells1+3,arr->getConstPointer()));
00974   arr->decrRef();
00975   // no permutation policy 2
00976   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,2,arr));
00977   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
00978   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
00979   CPPUNIT_ASSERT(std::equal(cells1,cells1+3,arr->getConstPointer()));
00980   arr->decrRef();
00981   // some modification into m2
00982   const int modif1[3]={2,4,5};
00983   std::copy(modif1,modif1+3,m2->getNodalConnectivity()->getPointer()+1);
00984   //policy 0 fails because cell0 in m2 has same orientation be not same connectivity
00985   const int expected1[3]={5,3,4};
00986   CPPUNIT_ASSERT(!m1->areCellsIncludedIn(m2,0,arr));
00987   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
00988   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
00989   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,arr->getConstPointer()));
00990   arr->decrRef();
00991   //policy 1 succeeds because cell0 in m2 has not exactly the same conn
00992   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,1,arr));
00993   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
00994   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
00995   CPPUNIT_ASSERT(std::equal(cells1,cells1+3,arr->getConstPointer()));
00996   arr->decrRef();
00997   //policy 2 succeeds because cell0 in m2 has same nodes in connectivity
00998   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,2,arr));
00999   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
01000   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01001   CPPUNIT_ASSERT(std::equal(cells1,cells1+3,arr->getConstPointer()));
01002   arr->decrRef();
01003   //some new modification into m2
01004   const int modif2[3]={2,5,4};
01005   std::copy(modif2,modif2+3,m2->getNodalConnectivity()->getPointer()+1);
01006   //policy 0 fails because cell0 in m2 has not exactly the same conn
01007   CPPUNIT_ASSERT(!m1->areCellsIncludedIn(m2,0,arr));
01008   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
01009   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01010   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,arr->getConstPointer()));
01011   arr->decrRef();
01012   //policy 1 fails too because cell0 in m2 has not same orientation
01013   CPPUNIT_ASSERT(!m1->areCellsIncludedIn(m2,1,arr));
01014   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
01015   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01016   CPPUNIT_ASSERT(std::equal(expected1,expected1+3,arr->getConstPointer()));
01017   arr->decrRef();
01018   //policy 2 succeeds because cell0 in m2 has same nodes in connectivity
01019   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,2,arr));
01020   CPPUNIT_ASSERT_EQUAL(3,arr->getNumberOfTuples());
01021   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01022   CPPUNIT_ASSERT(std::equal(cells1,cells1+3,arr->getConstPointer()));
01023   arr->decrRef();
01024   m1->decrRef();
01025   m2->decrRef();
01026   // Now 1D
01027   const int cells2[2]={3,2};
01028   m1=build1DSourceMesh_2();
01029   m2_1=m1->buildPartOfMySelf(cells2,cells2+2,true);
01030   m2=dynamic_cast<MEDCouplingUMesh *>(m2_1);
01031   CPPUNIT_ASSERT(m2);
01032   arr=0;
01033   // no permutation policy 0
01034   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,0,arr));
01035   CPPUNIT_ASSERT_EQUAL(2,arr->getNumberOfTuples());
01036   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01037   CPPUNIT_ASSERT(std::equal(cells2,cells2+2,arr->getConstPointer()));
01038   arr->decrRef();
01039   // no permutation policy 1
01040   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,1,arr));
01041   CPPUNIT_ASSERT_EQUAL(2,arr->getNumberOfTuples());
01042   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01043   CPPUNIT_ASSERT(std::equal(cells2,cells2+2,arr->getConstPointer()));
01044   arr->decrRef();
01045   // no permutation policy 2
01046   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,2,arr));
01047   CPPUNIT_ASSERT_EQUAL(2,arr->getNumberOfTuples());
01048   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01049   CPPUNIT_ASSERT(std::equal(cells2,cells2+2,arr->getConstPointer()));
01050   arr->decrRef();
01051   // some modification into m2
01052   const int modif3[2]={4,3};
01053   std::copy(modif3,modif3+2,m2->getNodalConnectivity()->getPointer()+1);
01054   //policy 0 fails because cell0 in m2 has not exactly the same conn
01055   const int expected2[2]={4,2};
01056   CPPUNIT_ASSERT(!m1->areCellsIncludedIn(m2,0,arr));
01057   CPPUNIT_ASSERT_EQUAL(2,arr->getNumberOfTuples());
01058   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01059   CPPUNIT_ASSERT(std::equal(expected2,expected2+2,arr->getConstPointer()));
01060   arr->decrRef();
01061   //policy 1 fails too because cell0 in m2 has not same orientation
01062   CPPUNIT_ASSERT(!m1->areCellsIncludedIn(m2,1,arr));
01063   CPPUNIT_ASSERT_EQUAL(2,arr->getNumberOfTuples());
01064   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01065   CPPUNIT_ASSERT(std::equal(expected2,expected2+2,arr->getConstPointer()));
01066   arr->decrRef();
01067   //policy 2 succeeds because cell0 in m2 has same nodes in connectivity
01068   CPPUNIT_ASSERT(m1->areCellsIncludedIn(m2,2,arr));
01069   CPPUNIT_ASSERT_EQUAL(2,arr->getNumberOfTuples());
01070   CPPUNIT_ASSERT_EQUAL(1,arr->getNumberOfComponents());
01071   CPPUNIT_ASSERT(std::equal(cells2,cells2+2,arr->getConstPointer()));
01072   arr->decrRef();
01073   m1->decrRef();
01074   m2->decrRef();
01075 }