Back to index

salome-med  6.5.0
MEDPARTITIONERTest.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 "MEDPARTITIONERTest.hxx"
00021 
00022 #include "MEDPARTITIONER_MeshCollection.hxx"
00023 #include "MEDPARTITIONER_ParallelTopology.hxx"
00024 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
00025 #include "MEDPARTITIONER_Utils.hxx"
00026 
00027 #include "CellModel.hxx"
00028 #include "MEDFileMesh.hxx"
00029 #include "MEDLoader.hxx"
00030 #include "MEDLoaderBase.hxx"
00031 #include "MEDCouplingUMesh.hxx"
00032 #include "MEDCouplingExtrudedMesh.hxx"
00033 #include "MEDCouplingFieldDouble.hxx"
00034 #include "MEDCouplingMemArray.hxx"
00035 #include "MEDCouplingMultiFields.hxx"
00036 
00037 #include <cppunit/TestAssert.h>
00038 
00039 #include <sstream>
00040 #include <cmath>
00041 #include <list>
00042 #include <stdexcept>
00043 #include <cstdlib>
00044 #include <vector>
00045 
00046 #ifdef HAVE_MPI2
00047 #include <mpi.h>
00048 #endif
00049 
00050 using namespace std;
00051 using namespace ParaMEDMEM;
00052 using namespace MEDPARTITIONER;
00053 
00054 void MEDPARTITIONERTest::setSize(int ni, int nj, int nk)
00055 {
00056   this->_ni=ni;  //nb of hexa9
00057   this->_nj=nj;
00058   this->_nk=nk;
00059   this->_ntot=_ni*_nj*_nk;
00060   string ijk=IntToStr(ni)+"x"+IntToStr(nj)+"x"+IntToStr(nk);
00061   this->_file_name="tmp_testMesh_"+ijk+".med";
00062   this->_file_name_with_faces="tmp_testMeshWithFaces_"+ijk+".med";
00063   string ij=IntToStr(ni)+"x"+IntToStr(nj);
00064   this->_file_name2="tmp_testMesh_"+ij+".med";
00065   this->_mesh_name="testMesh";
00066 }
00067 
00068 void MEDPARTITIONERTest::setSmallSize()
00069 {
00070   setSize(2,3,5); //nb of hexa9
00071 }
00072 
00073 void MEDPARTITIONERTest::setMedianSize()
00074 {
00075   setSize(20,30,50); //nb of hexa9
00076 }
00077 
00078 void MEDPARTITIONERTest::setbigSize()
00079 {
00080   setSize(200,300,500); //nb of hexa9
00081 }
00082 
00083 std::string MEDPARTITIONERTest::getPartitionerExe() const
00084 {
00085   std::string execName;
00086   if ( getenv("top_builddir")) // make distcheck
00087     {
00088       execName = getenv("top_builddir");
00089       execName += "/src/MEDPartitioner/medpartitioner";
00090     }
00091   else if ( getenv("MED_ROOT_DIR") )
00092     {
00093       execName=getenv("MED_ROOT_DIR");  //.../INSTALL/MED
00094       execName+="/bin/salome/medpartitioner";
00095     }
00096   else
00097     {
00098       CPPUNIT_FAIL("Can't find medpartitioner, neither MED_ROOT_DIR nor top_builddir is set");
00099     }
00100   return execName;
00101 }
00102 
00103 // ============================================================================
00107 // ============================================================================
00108 void MEDPARTITIONERTest::setUp()
00109 {
00110   this->_verbose=0;
00111 #if defined(HAVE_MPI2)
00112   if (MyGlobals::_Rank==-1)  //do once only
00113     {
00114       MPI_Init(0,0);
00115       MPI_Comm_size(MPI_COMM_WORLD, &MyGlobals::_World_Size);
00116       MPI_Comm_rank(MPI_COMM_WORLD, &MyGlobals::_Rank);
00117     }
00118 #else
00119   //sequential : no MPI
00120   MyGlobals::_World_Size=1;
00121   MyGlobals::_Rank=0;
00122 #endif
00123 
00124   if (_verbose>10)
00125     {
00126 #if defined(HAVE_MPI2)
00127       cout<<"\ndefined(HAVE_MPI2)"<<endl;
00128 #else
00129       cout<<"\nNOT defined(HAVE_MPI2)"<<endl;
00130 #endif
00131 #if defined(MED_ENABLE_PARMETIS)
00132       cout<<"defined(MED_ENABLE_PARMETIS)"<<endl;
00133 #else
00134       cout<<"NOT defined(MED_ENABLE_PARMETIS)"<<endl;
00135 #endif
00136 #if defined(MED_ENABLE_METIS)
00137       cout<<"defined(MED_ENABLE_METIS)"<<endl;
00138 #else
00139       cout<<"NOT defined(MED_ENABLE_METIS)"<<endl;
00140 #endif
00141 #if defined(MED_ENABLE_SCOTCH)
00142       cout<<"defined(MED_ENABLE_SCOTCH)"<<endl;
00143 #else
00144       cout<<"NOT defined(MED_ENABLE_SCOTCH)"<<endl;
00145 #endif
00146     }
00147 }
00148 
00149 // ============================================================================
00153 // ============================================================================
00154 void MEDPARTITIONERTest::tearDown()
00155 {
00156 }
00157 
00158 ParaMEDMEM::MEDCouplingUMesh * MEDPARTITIONERTest::buildCUBE3DMesh()
00159 //only hexa8
00160 {
00161   vector<int> conn;
00162   vector<double> coor;
00163   for (int k=0; k<=_nk; k++)
00164     for (int j=0; j<=_nj; j++)
00165       for (int i=0; i<=_ni; i++)
00166         {
00167           coor.push_back(i+.1);
00168           coor.push_back(j+.2);
00169           coor.push_back(k+.3);
00170         }
00171   int ii;
00172   for (int k=0; k<_nk; k++)
00173     for (int j=0; j<_nj; j++)
00174       for (int i=0; i<_ni; i++)
00175         {
00176           ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1);
00177           conn.push_back(ii);
00178           conn.push_back(ii+1);
00179           ii=ii + _ni + 2 ;
00180           conn.push_back(ii);
00181           conn.push_back(ii-1);
00182     
00183           ii=i + j*(_ni+1) + (k+1)*(_ni+1)*(_nj+1);
00184           conn.push_back(ii);
00185           conn.push_back(ii+1);
00186           ii=ii + _ni + 2 ;
00187           conn.push_back(ii);
00188           conn.push_back(ii-1);
00189         }
00190 
00191   /*
00192   if (_verbose)  //only for debug
00193     {
00194       cout<< "\nnb coor " << (_ni+1)*(_nj+1)*(_nk+1)*3 << " " << coor.size() << endl;
00195       for (int i=0; i<(int)coor.size(); i++)
00196         cout << coor[i] << " ";
00197       cout << endl;
00198       cout << "\nnb conn " << (_ni)*(_nj)*(_nk)*8 << " " << conn.size() << endl;
00199       for (int i=0; i<(int)conn.size(); i=i+8)
00200         { 
00201           for (int j=0; j<8; j++)
00202             cout << conn[i+j] << " ";
00203           cout << endl;
00204         }
00205       cout << endl;
00206     }
00207   */
00208   
00209   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
00210   mesh->setMeshDimension(3);
00211   int nbc=conn.size()/8; //nb of cells
00212   int nbv=coor.size()/3; //nb of vertices
00213   mesh->allocateCells(nbc);
00214   for(int i=0; i<nbc; i++)
00215     {
00216       int onehexa[8];
00217       std::copy(conn.begin()+i*8,conn.begin()+(i+1)*8,onehexa);
00218       if (false) //(_verbose)
00219         {
00220           for (int j=0; j<8; j++) cout<<onehexa[j]<<" ";
00221           cout<<endl;
00222         }
00223       mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,onehexa);
00224     }
00225   mesh->finishInsertingCells();
00226   DataArrayDouble *myCoords=DataArrayDouble::New();
00227   myCoords->alloc(nbv,3);
00228   std::copy(coor.begin(),coor.end(),myCoords->getPointer());
00229   mesh->setCoords(myCoords);
00230   mesh->setName(_mesh_name.c_str());
00231   myCoords->decrRef();
00232   mesh->checkCoherency();
00233   return mesh;
00234 }
00235 
00236 ParaMEDMEM::MEDCouplingUMesh * MEDPARTITIONERTest::buildCARRE3DMesh()
00237 //only quad4 in oblique (k=j)
00238 {
00239   vector<int> conn;
00240   vector<double> coor;
00241   for (int j=0; j<=_nj; j++)
00242     for (int i=0; i<=_ni; i++)
00243       {
00244         int k=j;
00245         coor.push_back(i+.1);
00246         coor.push_back(j+.2);
00247         coor.push_back(k+.3);
00248       }
00249   int ii;
00250   int k=0;
00251   for (int j=0; j<_nj; j++)
00252     for (int i=0; i<_ni; i++)
00253       {
00254         ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1);
00255         conn.push_back(ii);
00256         conn.push_back(ii+1);
00257         ii=ii + _ni + 2 ;
00258         conn.push_back(ii);
00259         conn.push_back(ii-1);
00260       }
00261 
00262   if (false) //(_verbose)
00263     {
00264       cout<<"\nnb coor "<<(_ni+1)*(_nj+1)*3<<" "<<coor.size()<<endl;
00265       for (int i=0; i<(int)coor.size(); i++)
00266         cout << coor[i] << " ";
00267       cout<<endl;
00268       cout<<"\nnb conn "<<(_ni)*(_nj)*4<<" "<<conn.size()<<endl;
00269       for (int i=0; i<(int)conn.size(); i=i+4)
00270         { 
00271           for (int j=0; j<4; j++) cout<<conn[i+j]<<" ";
00272           cout<<endl;
00273         }
00274       cout<<endl;
00275     }
00276   
00277   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
00278   mesh->setMeshDimension(2);
00279   int nbc=conn.size()/4; //nb of cells
00280   int nbv=coor.size()/3; //nb of vertices
00281   mesh->allocateCells(nbc);
00282   for(int i=0; i<nbc; i++)
00283     {
00284       int onequa[4];
00285       std::copy(conn.begin()+i*4,conn.begin()+(i+1)*4,onequa);
00286       if (false) //(_verbose)
00287         {
00288           for (int j=0; j<4; j++) cout<<onequa[j]<<" ";
00289           cout<<endl;
00290         }
00291       mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,onequa);
00292     }
00293   mesh->finishInsertingCells();
00294   DataArrayDouble *myCoords=DataArrayDouble::New();
00295   myCoords->alloc(nbv,3);
00296   std::copy(coor.begin(),coor.end(),myCoords->getPointer());
00297   mesh->setCoords(myCoords);
00298   mesh->setName(_mesh_name.c_str());
00299   myCoords->decrRef();
00300   mesh->checkCoherency();
00301   return mesh;
00302 }
00303 
00304 ParaMEDMEM::MEDCouplingUMesh * MEDPARTITIONERTest::buildFACE3DMesh()
00305 //only quad4 on a global face of the CUBE3D (k=0)
00306 {
00307   vector<int> conn;
00308   vector<double> coor;
00309   for (int j=0; j<=_nj; j++)
00310     for (int i=0; i<=_ni; i++)
00311       {
00312         int k=0;
00313         coor.push_back(i+.1);
00314         coor.push_back(j+.2);
00315         coor.push_back(k+.3);
00316       }
00317   int ii;
00318   int k=0;
00319   for (int j=0; j<_nj; j++)
00320     for (int i=0; i<_ni; i++)
00321       {
00322         ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1);
00323         conn.push_back(ii);
00324         conn.push_back(ii+1);
00325         ii=ii + _ni + 2 ;
00326         conn.push_back(ii);
00327         conn.push_back(ii-1);
00328       }
00329 
00330   if (false) //(_verbose)
00331     {
00332       cout<<"\nnb coor "<<(_ni+1)*(_nj+1)*3<<" "<<coor.size()<<endl;
00333       for (int i=0; i<(int)coor.size(); i++)
00334         cout << coor[i] << " ";
00335       cout<<endl;
00336       cout<<"\nnb conn "<<(_ni)*(_nj)*4<<" "<<conn.size()<<endl;
00337       for (int i=0; i<(int)conn.size(); i=i+4)
00338         { 
00339           for (int j=0; j<4; j++)
00340             cout << conn[i+j] << " ";
00341           cout << endl;
00342         }
00343       cout << endl;
00344     }
00345   
00346   MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
00347   mesh->setMeshDimension(2);
00348   int nbc=conn.size()/4; //nb of cells
00349   int nbv=coor.size()/3; //nb of vertices
00350   mesh->allocateCells(nbc);
00351   for(int i=0; i<nbc; i++)
00352     {
00353       int onequa[4];
00354       std::copy(conn.begin()+i*4,conn.begin()+(i+1)*4,onequa);
00355       if (false) //(_verbose)
00356         {
00357           for (int j=0; j<4; j++) cout<<onequa[j]<<" ";
00358           cout<<endl;
00359         }
00360       mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,onequa);
00361     }
00362   mesh->finishInsertingCells();
00363   DataArrayDouble *myCoords=DataArrayDouble::New();
00364   myCoords->alloc(nbv,3);
00365   std::copy(coor.begin(),coor.end(),myCoords->getPointer());
00366   mesh->setCoords(myCoords);
00367   mesh->setName(_mesh_name.c_str());
00368   myCoords->decrRef();
00369   mesh->checkCoherency();
00370   return mesh;
00371 }
00372 
00373 MEDCouplingFieldDouble * MEDPARTITIONERTest::buildVecFieldOnCells(string myfileName)
00374 {
00375   //int ni=2,nj=3,nk=5; //nb of hexa9
00376   vector<double> field;
00377   for (int k=0; k<_nk; k++)
00378     for (int j=0; j<_nj; j++)
00379       for (int i=0; i<_ni; i++)
00380         {
00381           field.push_back(i+.1);
00382           field.push_back(j+.2);
00383           field.push_back(k+.3);
00384         }
00385 
00386   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(myfileName.c_str(),_mesh_name.c_str(),0);
00387   int nbOfCells=mesh->getNumberOfCells();
00388   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
00389   f1->setName("VectorFieldOnCells");
00390   f1->setDescription("DescriptionOfFieldOnCells"); //not saved in file?
00391   f1->setMesh(mesh);
00392   DataArrayDouble *myField=DataArrayDouble::New();
00393   myField->alloc(nbOfCells,3);
00394   std::copy(field.begin(),field.end(),myField->getPointer());
00395   f1->setArray(myField);
00396   myField->setInfoOnComponent(0,"vx");
00397   myField->setInfoOnComponent(1,"vy");
00398   myField->setInfoOnComponent(2,"vz");
00399   myField->decrRef();
00400   f1->setTime(2.,0,1);
00401   f1->checkCoherency();
00402   mesh->decrRef();
00403   return f1;
00404 }
00405 
00406 MEDCouplingFieldDouble * MEDPARTITIONERTest::buildVecFieldOnNodes()
00407 {
00408   //int ni=2,nj=3,nk=5; //nb of hexa9
00409   vector<double> field;
00410   for (int k=0; k<=_nk; k++)
00411     for (int j=0; j<=_nj; j++)
00412       for (int i=0; i<=_ni; i++)
00413         {
00414           field.push_back(i+.1);
00415           field.push_back(j+.2);
00416           field.push_back(k+.3);
00417         }
00418   
00419   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(_file_name.c_str(),_mesh_name.c_str(),0);
00420   int nbOfNodes=mesh->getNumberOfNodes();
00421   MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
00422   f1->setName("VectorFieldOnNodes");
00423   f1->setDescription("DescriptionOfFieldOnNodes"); //not saved in file?
00424   f1->setMesh(mesh);
00425   DataArrayDouble *myField=DataArrayDouble::New();
00426   myField->alloc(nbOfNodes,3);
00427   std::copy(field.begin(),field.end(),myField->getPointer());
00428   f1->setArray(myField);
00429   myField->setInfoOnComponent(0,"vx");
00430   myField->setInfoOnComponent(1,"vy");
00431   myField->setInfoOnComponent(2,"vz");
00432   myField->decrRef();
00433   f1->setTime(2.,0,1);
00434   f1->checkCoherency();
00435   mesh->decrRef();
00436   return f1;
00437 }
00438 
00439 
00440 void MEDPARTITIONERTest::createTestMeshWithoutField()
00441 {
00442   {
00443     MEDCouplingUMesh * mesh = buildCUBE3DMesh();
00444     MEDLoader::WriteUMesh(_file_name.c_str(),mesh,true);
00445     if (_verbose) cout<<endl<<_file_name<<" created"<<endl;
00446     if (_ntot<1000000) //too long
00447       {
00448         MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(_file_name.c_str(),mesh->getName(),0);
00449         if (_verbose) cout<<_file_name<<" reread"<<endl;
00450         CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00451         mesh_rw->decrRef();
00452       }
00453     mesh->decrRef();
00454   }
00455   
00456   {
00457     vector<const ParaMEDMEM::MEDCouplingUMesh*> meshes;
00458     MEDCouplingUMesh * mesh1 = buildCUBE3DMesh();
00459     MEDCouplingUMesh * mesh2 = buildFACE3DMesh();
00460     mesh1->setName("testMesh");
00461     mesh2->setName("theFaces");
00462     mesh2->tryToShareSameCoordsPermute(*mesh1, 1e-9);
00463     mesh2->checkCoherency();
00464     mesh1->checkCoherency();
00465     meshes.push_back(mesh1);
00466     meshes.push_back(mesh2);
00467     MEDLoader::WriteUMeshes(_file_name_with_faces.c_str(), meshes, true);
00468   
00469     ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(_file_name_with_faces.c_str(), mesh1->getName());
00470     DataArrayInt* FacesFam=DataArrayInt::New();
00471     FacesFam->alloc(mfm->getSizeAtLevel(-1),1);
00472     FacesFam->fillWithValue(-1);
00473     DataArrayInt* CellsFam=DataArrayInt::New();
00474     CellsFam->alloc(mfm->getSizeAtLevel(0),1);
00475     CellsFam->fillWithValue(1);
00476     mfm->setFamilyFieldArr(-1,FacesFam);
00477     mfm->setFamilyFieldArr(0,CellsFam);
00478     map<string,int> theFamilies;
00479     theFamilies["FAMILLE_ZERO"]=0;
00480     theFamilies["FamilyFaces"]=-1;
00481     theFamilies["FamilyCells"]=1;
00482     map<string, vector<string> > theGroups;
00483     theGroups["GroupFaces"].push_back("FamilyFaces");
00484     theGroups["GroupCells"].push_back("FamilyCells");
00485     mfm->setFamilyInfo(theFamilies);
00486     mfm->setGroupInfo(theGroups);
00487     mfm->write(_file_name_with_faces.c_str(),0);
00488     FacesFam->decrRef();
00489     CellsFam->decrRef();
00490   
00491     /*ce truc marche pas!
00492       ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(_file_name_with_faces.c_str(), mesh1->getName());
00493       vector<const ParaMEDMEM::MEDCouplingUMesh*> ms;
00494       ms.push_back(mesh2);
00495       mfm->setGroupsFromScratch(-1, ms);
00496       mfm->write(_file_name_with_faces.c_str(),0);
00497     */
00498   
00499     if (_verbose) cout<<endl<<_file_name_with_faces<<" created"<<endl;
00500     if (_ntot<1000000) //too long
00501       {
00502         MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(_file_name_with_faces.c_str(),mesh1->getName(),0);
00503         if (_verbose) cout<<_file_name_with_faces<<" reread"<<endl;
00504         CPPUNIT_ASSERT(mesh1->isEqual(mesh_rw,1e-12));
00505         mesh_rw->decrRef();
00506       }
00507     mesh1->decrRef();
00508     mesh2->decrRef();
00509   }
00510    
00511   {
00512     MEDCouplingUMesh * mesh = buildCARRE3DMesh();
00513     MEDLoader::WriteUMesh(_file_name2.c_str(),mesh,true);
00514     if (_verbose) cout<<endl<<_file_name2<<" created"<<endl;
00515     MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(_file_name2.c_str(),mesh->getName(),0);
00516     if (_verbose) cout<<_file_name2<<" reread"<<endl;
00517     CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12));
00518     mesh_rw->decrRef();
00519     mesh->decrRef();
00520   }
00521 }
00522 
00523 /*
00524 create a set of nbx*nby*nbz files mesh of ni*ny*nz cells
00525 */
00526 void MEDPARTITIONERTest::createHugeTestMesh(int ni, int nj, int nk, int nbx, int nby, int nbz, int nbTarget)
00527 {
00528   setSize(ni,nj,nk);
00529   _nb_target_huge=nbTarget;
00530   MEDCouplingUMesh * mesh = buildCUBE3DMesh();
00531   //int nbx=1, nby=1, nbz=2;
00532   std::vector< double > cooDep,cooFin;
00533   mesh->getCoordinatesOfNode(0, cooDep);
00534   mesh->getCoordinatesOfNode(mesh->getNumberOfNodes()-1, cooFin);
00535   //cout<<endl<<cooDep[0]<<" "<<cooDep[1]<<" "<<cooDep[2]<<endl;
00536   //cout<<cooFin[0]<<" "<<cooFin[1]<<" "<<cooFin[2]<<endl;
00537 
00538   string tagXml="\
00539 <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n \
00540 <root>\n \
00541   <version maj=\"2\" min=\"3\" ver=\"1\"/>\n \
00542   <description what=\"\" when=\"YYMMDDHHmm\"/>\n \
00543   <content>\n \
00544     <mesh name=\"testMesh\"/>\n \
00545   </content>\n \
00546   <splitting>\n \
00547     <subdomain number=\"$subdomainNumber\"/>\n \
00548     <global_numbering present=\"no\"/>\n \
00549   </splitting>\n \
00550   <files>\n$tagSubfile \
00551   </files>\n \
00552   <mapping>\n$tagMesh \
00553   </mapping>\n \
00554 </root>\n";
00555   
00556   string tagSubfiles, tagSubfile="\
00557     <subfile id=\"$xyz\">\n \
00558       <name>$fileName</name>\n \
00559       <machine>localhost</machine>\n \
00560     </subfile>\n";
00561   string tagMeshes, tagMesh="\
00562     <mesh name=\"testMesh\">\n \
00563       <chunk subdomain=\"$xyz\">\n \
00564         <name>testMesh</name>\n \
00565       </chunk>\n \
00566     </mesh>\n";
00567   
00568   int xyz=1;
00569   string sxyz;
00570   DataArrayDouble* coordsInit=mesh->getCoords()->deepCpy();
00571   double* ptrInit=coordsInit->getPointer();
00572   double deltax=cooFin[0]-cooDep[0];
00573   double deltay=cooFin[1]-cooDep[1];
00574   double deltaz=cooFin[2]-cooDep[2];
00575   
00576   double dz=0.;
00577   for (int z=0; z<nbz; z++)
00578     {
00579       double dy=0.;
00580       for (int y=0; y<nby; y++)
00581         {
00582           double dx=0.;
00583           for (int x=0; x<nbx; x++)
00584             {
00585               string fileName;
00586               sxyz=IntToStr(xyz);
00587               fileName="tmp_testMeshHuge_"+IntToStr(_ni)+"x"+IntToStr(_nj)+"x"+IntToStr(_nk)+"_"+sxyz+".med";
00588         
00589               DataArrayDouble* coords=mesh->getCoords();
00590               //int nbOfComp=coords->getNumberOfComponents();  //be 3D
00591               int nbOfTuple=coords->getNumberOfTuples();
00592               double* ptr=coords->getPointer();
00593               double* ptrini=ptrInit;
00594               for (int i=0; i<nbOfTuple; i++)
00595                 {
00596                   *ptr=(*ptrini)+dx; ptr++; ptrini++; //be 3D
00597                   *ptr=(*ptrini)+dy; ptr++; ptrini++;
00598                   *ptr=(*ptrini)+dz; ptr++; ptrini++;
00599                 }
00600 
00601               MEDLoader::WriteUMesh(fileName.c_str(),mesh,true);
00602         
00603               tagSubfiles+=tagSubfile;
00604               tagSubfiles.replace(tagSubfiles.find("$xyz"),4,sxyz);
00605               tagSubfiles.replace(tagSubfiles.find("$fileName"),9,fileName);
00606         
00607               tagMeshes+=tagMesh;
00608               tagMeshes.replace(tagMeshes.find("$xyz"),4,sxyz);
00609               xyz++;
00610               dx+=deltax;
00611             }
00612           dy+=deltay;
00613         }
00614       dz+=deltaz;
00615     }
00616   coordsInit->decrRef();
00617   
00618   tagXml.replace(tagXml.find("$subdomainNumber"),16,sxyz);
00619   tagXml.replace(tagXml.find("$tagSubfile"),11,tagSubfiles);
00620   tagXml.replace(tagXml.find("$tagMesh"),8,tagMeshes);
00621 
00622   string nameFileXml;
00623   _file_name_huge_xml="tmp_testMeshHuge_"+IntToStr(_ni)+"x"+IntToStr(_nj)+"x"+IntToStr(_nk)+"_"+sxyz+".xml";
00624   std::ofstream f(_file_name_huge_xml.c_str());
00625   f<<tagXml;
00626   f.close();
00627   //cout<<"\n"<<tagXml<<endl;
00628   if (_verbose) 
00629     cout<<endl<<nameFileXml<<" created"<<endl;
00630 }
00631 
00632 void MEDPARTITIONERTest::createTestMeshWithVecFieldOnCells()
00633 {
00634   {
00635     string name=_file_name;
00636     MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name);
00637     name.replace(name.find(".med"),4,"_WithVecFieldOnCells.med");
00638     MEDLoader::WriteField(name.c_str(),f1,true);
00639     f1->setTime(3.,1,1);  //time,it,order
00640     f1->applyFunc("x/2.");
00641     MEDLoader::WriteField(name.c_str(),f1,false);
00642     if (_verbose) cout<<endl<<name<<" created"<<endl;
00643     if (_ntot<1000000) //too long
00644       {
00645         MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(name.c_str(),f1->getMesh()->getName(),0,f1->getName(),0,1);
00646         //DataArrayDouble *res=f2->getArray();
00647         if (_verbose) cout<<name<<" reread"<<endl;
00648         //CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
00649         f2->decrRef();
00650       }
00651     f1->decrRef();
00652   }
00653   {
00654     string name=_file_name;
00655     MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name);
00656     name.replace(name.find(".med"),4,"_WithVecFieldOnGaussNe.med");
00657     MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME);
00658     f3->setMesh(f1->getMesh());
00659     //cout<<"\nNumberOfMeshPlacesExpected "<<f3->getNumberOfMeshPlacesExpected()<<" "
00660     //                                     /*<<getNumberOfTuples(f1->getMesh())<<" "*/
00661     //                                     <<f3->getMesh()->getNumberOfNodes()<<" "
00662     //                                     <<f3->getMesh()->getNumberOfCells()<<endl;
00663     f3->setName("MyFieldOnGaussNE");
00664     f3->setDescription("MyDescriptionNE");
00665     DataArrayDouble *array=DataArrayDouble::New();
00666     //int nb=f1->getMesh()->getNumberOfNodes();
00667   
00668     /*8 pt de gauss by cell
00669       int nb=f3->getMesh()->getNumberOfCells()*8;
00670       array->alloc(nb,2);
00671       double *ptr=array->getPointer();
00672       for (int i=0; i<nb*2; i=i+2) {ptr[i]=(double)(i/8) ; ptr[i]=2.*(double)(i/8);}
00673     */
00674   
00675     //more nbptgauss=8 by default needs set MEDCouplingFieldDiscretizationPerCell
00676     //theory: (may be) http://www.code-aster.org/V2/doc/v9/fr/man_r/r3/r3.06.03.pdf
00677     int nbptgauss=8; //nb pt de gauss by cell 
00678     int nbcell=f3->getMesh()->getNumberOfCells();
00679     int nb=nbcell*nbptgauss;
00680     int nbcomp=2;
00681     array->alloc(nb,nbcomp);
00682     double *ptr=array->getPointer();
00683     int ii=0;
00684     for (int i=0; i<nbcell; i++)
00685       for (int j=0; j<nbptgauss; j++)
00686         for (int k=0; k<nbcomp; k++)
00687           {
00688             //123.4 for 12th cell,3rd component, 4th gausspoint
00689             ptr[ii]=(double)((i+1)*10+(k+1))+((double)(j+1))/10.;
00690             ii++;
00691           }
00692     array->setInfoOnComponent(0,"vGx");
00693     array->setInfoOnComponent(1,"vGy");
00694     f3->setTime(4.,5,6);
00695     f3->setArray(array);
00696     array->decrRef();
00697     MEDLoader::WriteField(name.c_str(),f3,true);
00698     if (_verbose) cout<<endl<<name<<" created"<<endl;
00699     f3->checkCoherency();
00700     f1->decrRef();
00701     if (_ntot<1000000) //too long
00702       {
00703         MEDCouplingFieldDouble* f4=MEDLoader::ReadField(ON_GAUSS_NE,
00704                                                         name.c_str(), f3->getMesh()->getName(), 0, "MyFieldOnGaussNE", 5, 6);
00705         if (_verbose) cout<<"MyFieldOnGaussNE reread"<<endl;
00706         f4->decrRef();
00707       }
00708     f3->decrRef();
00709   }
00710   {
00711     string name=_file_name_with_faces;
00712     MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name);
00713     name.replace(name.find(".med"),4,"_WithVecFieldOnCells.med");
00714     MEDLoader::WriteField(name.c_str(),f1,true);
00715     if (_verbose) cout<<endl<<name<<" created"<<endl;
00716     if (_ntot<1000000) //too long
00717       {
00718         MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldCell(name.c_str(),f1->getMesh()->getName(),0,f1->getName(),0,1);
00719         if (_verbose) cout<<name<<" reread"<<endl;
00720         //CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); assertion failed!!
00721         f2->decrRef();
00722       }
00723     f1->decrRef();
00724   }
00725 }
00726 
00727 void MEDPARTITIONERTest::createTestMeshWithVecFieldOnNodes()
00728 {
00729   MEDCouplingFieldDouble *f1=buildVecFieldOnNodes();
00730   string name=_file_name;
00731   name.replace(name.find(".med"),4,"_WithVecFieldOnNodes.med");
00732   MEDLoader::WriteField(name.c_str(),f1,true);
00733   if (_verbose) cout<<endl<<name<<" created"<<endl;
00734   if (_ntot<1000000) //too long
00735     {
00736       MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldNode(name.c_str(),f1->getMesh()->getName(),0,f1->getName(),0,1);
00737       if (_verbose) cout<<name<<" reread"<<endl;
00738       //CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); assertion failed!!
00739       f2->decrRef();
00740     }
00741   f1->decrRef();
00742 }
00743 
00744 void MEDPARTITIONERTest::verifyTestMeshWithVecFieldOnNodes()
00745 {
00746   string name=_file_name;
00747   name.replace(name.find(".med"),4,"_WithVecFieldOnNodes.med");
00748   MEDCouplingUMesh * m=MEDLoader::ReadUMeshFromFile(name.c_str(),_mesh_name.c_str(),0);
00749   const std::set<INTERP_KERNEL::NormalizedCellType>& types=m->getAllTypes();
00750   if (_verbose)
00751     {
00752       cout<<"\n types in "<<name<<" : ";
00753       //for (std::set<INTERP_KERNEL::NormalizedCellType>::iterator t=types.begin(); t!=types.end(); ++t) cout<<" "<<*t;
00754       for (std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator t=types.begin(); t!=types.end(); ++t) 
00755         {
00756           //INTERP_KERNEL::CellModel essai=INTERP_KERNEL::CellModel::GetCellModel(*t);
00757           cout<<" "<<(INTERP_KERNEL::CellModel::GetCellModel(*t)).getRepr();
00758         }
00759       cout<<endl;
00760     }
00761   m->decrRef();
00762   
00763   MEDFileUMesh * mf = MEDFileUMesh::New(_file_name.c_str(),_mesh_name.c_str(),-1,-1);
00764   vector<int> lev;
00765   lev=mf->getNonEmptyLevels();
00766   if (_verbose)
00767     {
00768       cout<<" levels in "<<name<<" : ";
00769       for (vector<int>::iterator l=lev.begin(); l!=lev.end(); ++l) cout<<" "<<*l;
00770       cout<<endl;
00771     }
00772   mf->decrRef();
00773 }
00774 
00775 void MEDPARTITIONERTest::createTestMeshes()
00776 {
00777   createTestMeshWithoutField();
00778   createTestMeshWithVecFieldOnCells();
00779   createTestMeshWithVecFieldOnNodes();
00780 }
00781 
00782 void MEDPARTITIONERTest::deleteTestMeshes()
00783 {
00784   string cmd="rm *tmp_testMesh*";
00785   if (_verbose) cout<<endl<<cmd<<endl;
00786   system(cmd.c_str());  //may be not if debug
00787 }
00788 
00789 void MEDPARTITIONERTest::testMeshCollectionSingle()
00790 {
00791   setSmallSize();
00792   createTestMeshes();
00793   MyGlobals::_World_Size=1;
00794   MyGlobals::_Rank=0;
00795   string fileName=_file_name_with_faces;
00796   MEDPARTITIONER::ParaDomainSelector parallelizer(false);
00797   MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
00798   CPPUNIT_ASSERT(collection.isParallelMode());
00799   CPPUNIT_ASSERT_EQUAL(3, collection.getMeshDimension());
00800   CPPUNIT_ASSERT(collection.getName()=="testMesh");
00801   CPPUNIT_ASSERT_EQUAL(1,collection.getNbOfLocalMeshes());
00802   CPPUNIT_ASSERT_EQUAL(1,collection.getNbOfGlobalMeshes());
00803   CPPUNIT_ASSERT_EQUAL(_ni*_nj*_nk,collection.getNbOfLocalCells());
00804   CPPUNIT_ASSERT_EQUAL(_ni*_nj,collection.getNbOfLocalFaces());
00805 }
00806 
00807 void MEDPARTITIONERTest::testMeshCollectionXml()
00808 {
00809   setSmallSize();
00810   createHugeTestMesh(_ni, _nj, _nk, 2, 2, 2, 32); //xml but not so huge
00811   string fileName=_file_name_huge_xml;
00812   MEDPARTITIONER::ParaDomainSelector parallelizer(false);
00813   MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
00814   CPPUNIT_ASSERT(collection.isParallelMode());
00815   CPPUNIT_ASSERT_EQUAL(3, collection.getMeshDimension());
00816   CPPUNIT_ASSERT(collection.getName()=="testMesh");
00817   CPPUNIT_ASSERT_EQUAL(8,collection.getNbOfLocalMeshes());
00818   CPPUNIT_ASSERT_EQUAL(8,collection.getNbOfGlobalMeshes());
00819   CPPUNIT_ASSERT_EQUAL(_ni*_nj*_nk*8,collection.getNbOfLocalCells());
00820   CPPUNIT_ASSERT_EQUAL(0,collection.getNbOfLocalFaces());
00821 }
00822 
00823 
00824 //#################for metis
00825 
00826 
00827 
00828 #if defined(MED_ENABLE_METIS)
00829 void MEDPARTITIONERTest::testMeshCollectionSinglePartitionMetis()
00830 {
00831   setSmallSize();
00832   createTestMeshes();
00833   //MyGlobals::_Verbose=500;
00834   string fileName=_file_name_with_faces;
00835   int ndomains=2;
00836   bool split_family=false;
00837   bool empty_groups=false;
00838   MEDPARTITIONER::ParaDomainSelector parallelizer(false);
00839   MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
00840   
00841   MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
00842   aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
00843   //Creating the graph and partitioning it
00844   auto_ptr< MEDPARTITIONER::Topology > new_topo;
00845   new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS) );
00846   //Creating a new mesh collection from the partitioning
00847   MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
00848   
00849   //example to create files
00850   //MyGlobals::_General_Informations.clear();
00851   //MyGlobals::_General_Informations.push_back(SerializeFromString("finalMeshName=Merge"));
00852   //if (MyGlobals::_Verbose>100) cout << "generalInformations : \n"<<ReprVectorOfString(MyGlobals::_General_Informations);
00853   //new_collection.write("ttmp")
00854   
00855   CPPUNIT_ASSERT(new_collection.isParallelMode());
00856   CPPUNIT_ASSERT_EQUAL(3, new_collection.getMeshDimension());
00857   CPPUNIT_ASSERT(new_collection.getName()==collection.getName());
00858   CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
00859   CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
00860   CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
00861   CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
00862 }
00863 
00864 void MEDPARTITIONERTest::testMeshCollectionComplexPartitionMetis()
00865 {
00866   setSmallSize();
00867   createHugeTestMesh(_ni, _nj, _nk, 2, 2, 2, 32); //xml on 2*2*2 meshes but not so huge
00868   string fileName=_file_name_huge_xml;
00869   bool split_family=false;
00870   bool empty_groups=false;
00871   MEDPARTITIONER::ParaDomainSelector parallelizer(false);
00872   MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
00873   
00874   MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
00875   aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
00876   
00877   for (int ndomains=2 ; ndomains<=16 ; ndomains++)
00878     {
00879       //Creating the graph and partitioning it
00880       auto_ptr< MEDPARTITIONER::Topology > new_topo;
00881       new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS) );
00882       //Creating a new mesh collection from the partitioning
00883       MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
00884       
00885       CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
00886       CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
00887       CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
00888       CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
00889     }
00890 }
00891 
00892 void MEDPARTITIONERTest::testMetisSmallSize()
00893 {
00894 #if !defined(HAVE_MPI2)
00895   setSmallSize();
00896   createTestMeshes();
00897   std::string MetisOrScotch("metis");
00898   launchMetisOrScotchMedpartitionerOnTestMeshes(MetisOrScotch);
00899   verifyMetisOrScotchMedpartitionerOnSmallSizeForMesh(MetisOrScotch);
00900   verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnCells(MetisOrScotch);
00901   verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnGaussNe(MetisOrScotch);
00902 #endif
00903 }
00904 #endif
00905 
00906 
00907 //#################for scotch
00908 
00909 
00910 #if defined(MED_ENABLE_SCOTCH)
00911 void MEDPARTITIONERTest::testMeshCollectionSinglePartitionScotch()
00912 {
00913   setSmallSize();
00914   createTestMeshes();
00915   //MyGlobals::_Verbose=500;
00916   string fileName=_file_name_with_faces;
00917   int ndomains=2;
00918   bool split_family=false;
00919   bool empty_groups=false;
00920   MEDPARTITIONER::ParaDomainSelector parallelizer(false);
00921   MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
00922   
00923   MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
00924   aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
00925   //Creating the graph and partitioning it
00926   auto_ptr< MEDPARTITIONER::Topology > new_topo;
00927   new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH) );
00928   //Creating a new mesh collection from the partitioning
00929   MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
00930   
00931   //example to create files
00932   //MyGlobals::_General_Informations.clear();
00933   //MyGlobals::_General_Informations.push_back(SerializeFromString("finalMeshName=Merge"));
00934   //if (MyGlobals::_Verbose>100) cout << "generalInformations : \n"<<ReprVectorOfString(MyGlobals::_General_Informations);
00935   //new_collection.write("ttmp")
00936   
00937   CPPUNIT_ASSERT(new_collection.isParallelMode());
00938   CPPUNIT_ASSERT_EQUAL(3, new_collection.getMeshDimension());
00939   CPPUNIT_ASSERT(new_collection.getName()==collection.getName());
00940   CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
00941   CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
00942   CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
00943   CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
00944 }
00945 
00946 void MEDPARTITIONERTest::testMeshCollectionComplexPartitionScotch()
00947 {
00948   setSmallSize();
00949   createHugeTestMesh(_ni, _nj, _nk, 2, 2, 2, 32); //xml on 2*2*2 meshes but not so huge
00950   string fileName=_file_name_huge_xml;
00951   bool split_family=false;
00952   bool empty_groups=false;
00953   MEDPARTITIONER::ParaDomainSelector parallelizer(false);
00954   MEDPARTITIONER::MeshCollection collection(fileName,parallelizer);
00955   
00956   MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
00957   aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
00958   
00959   for (int ndomains=2 ; ndomains<=16 ; ndomains++)
00960     {
00961       //Creating the graph and partitioning it
00962       auto_ptr< MEDPARTITIONER::Topology > new_topo;
00963       new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH) );
00964       //Creating a new mesh collection from the partitioning
00965       MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
00966       
00967       CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfLocalMeshes());
00968       CPPUNIT_ASSERT_EQUAL(ndomains,new_collection.getNbOfGlobalMeshes());
00969       CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalCells(),new_collection.getNbOfLocalCells());
00970       CPPUNIT_ASSERT_EQUAL(collection.getNbOfLocalFaces(),new_collection.getNbOfLocalFaces());
00971     }
00972 }
00973 
00974 void MEDPARTITIONERTest::testScotchSmallSize()
00975 {
00976 #if !defined(HAVE_MPI2)
00977   setSmallSize();
00978   createTestMeshes();
00979   std::string MetisOrScotch("scotch");
00980   launchMetisOrScotchMedpartitionerOnTestMeshes(MetisOrScotch);
00981   verifyMetisOrScotchMedpartitionerOnSmallSizeForMesh(MetisOrScotch);
00982   verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnCells(MetisOrScotch);
00983   verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnGaussNe(MetisOrScotch);
00984 #endif
00985 }
00986 #endif
00987 
00988 void MEDPARTITIONERTest::launchMetisOrScotchMedpartitionerOnTestMeshes(std::string MetisOrScotch)
00989 {
00990   int res;
00991   string cmd,execName,sourceName,targetName;
00992   
00993   execName=getPartitionerExe();
00994   
00995   cmd="which "+execName+" 2>/dev/null 1>/dev/null";  //no trace
00996   res=system(cmd.c_str());
00997   CPPUNIT_ASSERT_EQUAL_MESSAGE(execName + " - INVALID PATH TO medpartitioner", 0, res);
00998   
00999   cmd=execName+" --ndomains=2 --split-method="+MetisOrScotch;  //on same proc
01000   sourceName=_file_name;
01001   targetName=_file_name;
01002   targetName.replace(targetName.find(".med"),4,"_partitionedTo2_");
01003   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01004   if (_verbose) cout<<endl<<cmd<<endl;
01005   res=system(cmd.c_str());
01006   CPPUNIT_ASSERT_EQUAL(0, res);
01007   
01008   cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch; //on less proc
01009   sourceName=_file_name;
01010   targetName=_file_name;
01011   targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
01012   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01013   if (_verbose) cout<<endl<<cmd<<endl;
01014   res=system(cmd.c_str());
01015   CPPUNIT_ASSERT_EQUAL(0, res);
01016   
01017   cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch;  //on 1 proc
01018   sourceName=targetName+".xml";
01019   targetName=_file_name;
01020   targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
01021   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01022   if (_verbose) cout<<endl<<cmd<<endl;
01023   res=system(cmd.c_str());
01024   CPPUNIT_ASSERT_EQUAL(0, res);
01025 
01026   cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch;  //on more proc
01027   //sourceName=targetName+".xml";
01028   targetName=_file_name;
01029   targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
01030   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01031   if (_verbose) cout<<endl<<cmd<<endl;
01032   res=system(cmd.c_str());
01033   CPPUNIT_ASSERT_EQUAL(0, res);
01034 }  
01035 
01036 void MEDPARTITIONERTest::verifyMetisOrScotchMedpartitionerOnSmallSizeForMesh(std::string MetisOrScotch)
01037 {
01038   int res;
01039   string fileName,cmd,execName,sourceName,targetName,input;
01040   execName=getPartitionerExe();
01041   fileName=_file_name_with_faces;
01042   
01043   ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
01044   ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
01045   ParaMEDMEM::MEDCouplingUMesh* faceMesh=initialMesh->getLevelM1Mesh(false);
01046   
01047   cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch;  //on same proc
01048   sourceName=fileName;
01049   targetName=fileName;
01050   targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
01051   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01052   if (_verbose) cout<<endl<<cmd<<endl;
01053   res=system(cmd.c_str());
01054   CPPUNIT_ASSERT_EQUAL(0, res);
01055   input=targetName+".xml";
01056   
01057   MEDPARTITIONER::ParaDomainSelector parallelizer(false);
01058   MEDPARTITIONER::MeshCollection collection(input,parallelizer);
01059   CPPUNIT_ASSERT_EQUAL(3, collection.getMeshDimension());
01060   std::vector<ParaMEDMEM::MEDCouplingUMesh*>cellMeshes=collection.getMesh();
01061   CPPUNIT_ASSERT_EQUAL(5, (int) cellMeshes.size());
01062   int nbcells=0;
01063   for (std::size_t i = 0; i < cellMeshes.size(); i++)
01064     nbcells+=cellMeshes[i]->getNumberOfCells();
01065   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells);
01066   
01067   std::vector<ParaMEDMEM::MEDCouplingUMesh*>faceMeshes=collection.getFaceMesh();
01068   CPPUNIT_ASSERT_EQUAL(5, (int) faceMeshes.size());
01069   int nbfaces=0;
01070   for (std::size_t i=0; i < faceMeshes.size(); i++)
01071     nbfaces+=faceMeshes[i]->getNumberOfCells();
01072   CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), nbfaces);
01073   
01074   //merge split meshes and test equality
01075   cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch;  //on same proc
01076   sourceName=targetName+".xml";
01077   targetName=fileName;
01078   targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
01079   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01080   if (_verbose) cout<<endl<<cmd<<endl;
01081   res=system(cmd.c_str());
01082   CPPUNIT_ASSERT_EQUAL(0, res);
01083   
01084   string refusedName=targetName+"1.med";
01085   ParaMEDMEM::MEDFileUMesh* refusedMesh=ParaMEDMEM::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
01086   ParaMEDMEM::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
01087   ParaMEDMEM::MEDCouplingUMesh* refusedFaceMesh=refusedMesh->getLevelM1Mesh(false);
01088   
01089   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
01090   CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), refusedFaceMesh->getNumberOfCells());
01091   
01092   /*not the good job
01093     ParaMEDMEM::MEDCouplingMesh* mergeCell=cellMesh->mergeMyselfWith(refusedCellMesh);
01094     CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), mergeCell->getNumberOfCells());
01095   
01096     ParaMEDMEM::MEDCouplingMesh* mergeFace=faceMesh->mergeMyselfWith(refusedFaceMesh);
01097     CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), mergeFace->getNumberOfCells());
01098   
01099     CPPUNIT_ASSERT(faceMesh->isEqual(refusedFaceMesh,1e-12));
01100   */
01101   
01102   std::vector<const MEDCouplingUMesh *> meshes;
01103   std::vector<DataArrayInt *> corr;
01104   meshes.push_back(cellMesh);
01105   refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9);
01106   meshes.push_back(refusedCellMesh);
01107   MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
01108   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells());
01109   
01110   meshes.resize(0);
01111   for (std::size_t i = 0; i < corr.size(); i++)
01112     corr[i]->decrRef();
01113   corr.resize(0);
01114   meshes.push_back(faceMesh);
01115   refusedFaceMesh->tryToShareSameCoordsPermute(*faceMesh, 1e-9);
01116   meshes.push_back(refusedFaceMesh);
01117   MEDCouplingUMesh* fusedFace=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
01118   CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), fusedFace->getNumberOfCells());
01119   
01120   for (std::size_t i = 0; i < corr.size(); i++)
01121     corr[i]->decrRef();
01122   fusedFace->decrRef();
01123   refusedFaceMesh->decrRef();
01124   faceMesh->decrRef();
01125   fusedCell->decrRef();
01126   refusedCellMesh->decrRef();
01127   cellMesh->decrRef();
01128   //done in ~collection
01129   //for (int i = 0; i < faceMeshes.size(); i++) faceMeshes[i]->decrRef();
01130   //for (int i = 0; i < cellMeshes.size(); i++) cellMeshes[i]->decrRef();
01131 }
01132 
01133 void MEDPARTITIONERTest::verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnCells(std::string MetisOrScotch)
01134 {
01135   int res;
01136   string fileName,cmd,execName,sourceName,targetName,input;
01137   execName=getPartitionerExe();
01138   fileName=_file_name;
01139   fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnCells.med");
01140   
01141   ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
01142   ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
01143   
01144   cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch;  //on same proc
01145   sourceName=fileName;
01146   targetName=fileName;
01147   targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
01148   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01149   if (_verbose) cout<<endl<<cmd<<endl;
01150   res=system(cmd.c_str());
01151   CPPUNIT_ASSERT_EQUAL(0, res);
01152   input=targetName+".xml";
01153   
01154   //merge split meshes and test equality
01155   cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch;  //on same proc
01156   sourceName=targetName+".xml";
01157   targetName=fileName;
01158   targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
01159   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01160   if (_verbose) cout<<endl<<cmd<<endl;
01161   res=system(cmd.c_str());
01162   CPPUNIT_ASSERT_EQUAL(0, res);
01163   
01164   string refusedName=targetName+"1.med";
01165   ParaMEDMEM::MEDFileUMesh* refusedMesh=ParaMEDMEM::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
01166   ParaMEDMEM::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
01167   
01168   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
01169   
01170   std::vector<const MEDCouplingUMesh *> meshes;
01171   std::vector<DataArrayInt *> corr;
01172   meshes.push_back(cellMesh);
01173   refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9);
01174   meshes.push_back(refusedCellMesh);
01175   MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
01176   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells());
01177   
01178   MEDCouplingFieldDouble* field1=MEDLoader::ReadFieldCell(fileName.c_str(),initialMesh->getName(),0,"VectorFieldOnCells",0,1);
01179   MEDCouplingFieldDouble* field2=MEDLoader::ReadFieldCell(refusedName.c_str(),refusedCellMesh->getName(),0,"VectorFieldOnCells",0,1);
01180   
01181   int nbcells=corr[1]->getNumberOfTuples();
01182   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells);
01183   //use corr to test equality of field
01184   DataArrayDouble* f1=field1->getArray();
01185   DataArrayDouble* f2=field2->getArray();
01186   if (_verbose>300) 
01187     {
01188       cout<<"\nf1 : "<<f1->reprZip();
01189       cout<<"\nf2 : "<<f2->reprZip(); //field2->advancedRepradvancedRepr();
01190       for (std::size_t i = 0; i < corr.size(); i++)
01191         cout << "\ncorr " << i << " : " << corr[i]->reprZip();
01192     
01193     }
01194   int nbequal=0;
01195   int nbcomp=field1->getNumberOfComponents();
01196   double* p1=f1->getPointer();
01197   double* p2=f2->getPointer();
01198   int* pc=corr[1]->getPointer();
01199   for (int i = 0; i < nbcells; i++)
01200     {
01201       int i1=pc[i]*nbcomp;
01202       int i2=i*nbcomp;
01203       for (int j = 0; j < nbcomp; j++)
01204         {
01205           if (p1[i1+j]==p2[i2+j]) nbequal++;
01206           //cout<<" "<<p1[i1+j]<<"="<<p2[i2+j];
01207         }
01208     }
01209   CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp, nbequal);
01210   
01211   for (std::size_t i = 0; i < corr.size(); i++)
01212     corr[i]->decrRef();
01213   field1->decrRef();
01214   field2->decrRef();
01215   fusedCell->decrRef();
01216   refusedCellMesh->decrRef();
01217   cellMesh->decrRef();
01218 }
01219 
01220 void MEDPARTITIONERTest::verifyMetisOrScotchMedpartitionerOnSmallSizeForFieldOnGaussNe(std::string MetisOrScotch)
01221 {
01222   int res;
01223   string fileName,cmd,execName,sourceName,targetName,input;
01224   execName=getPartitionerExe();
01225   fileName=_file_name;
01226   fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnGaussNe.med");
01227   
01228   ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
01229   ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
01230   
01231   cmd=execName+" --ndomains=5 --split-method="+MetisOrScotch;  //on same proc
01232   sourceName=fileName;
01233   targetName=fileName;
01234   targetName.replace(targetName.find(".med"),4,"_partitionedTo5_");
01235   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01236   if (_verbose) cout<<endl<<cmd<<endl;
01237   res=system(cmd.c_str());
01238   CPPUNIT_ASSERT_EQUAL(0, res);
01239   input=targetName+".xml";
01240   
01241   //merge split meshes and test equality
01242   cmd=execName+" --ndomains=1 --split-method="+MetisOrScotch;  //on same proc
01243   sourceName=targetName+".xml";
01244   targetName=fileName;
01245   targetName.replace(targetName.find(".med"),4,"_remergedFrom5_");
01246   cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+IntToStr(_verbose);
01247   if (_verbose) cout<<endl<<cmd<<endl;
01248   res=system(cmd.c_str());
01249   CPPUNIT_ASSERT_EQUAL(0, res);
01250   
01251   string refusedName=targetName+"1.med";
01252   ParaMEDMEM::MEDFileUMesh* refusedMesh=ParaMEDMEM::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
01253   ParaMEDMEM::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
01254   
01255   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
01256   
01257   std::vector<const MEDCouplingUMesh *> meshes;
01258   std::vector<DataArrayInt *> corr;
01259   meshes.push_back(cellMesh);
01260   refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9);
01261   meshes.push_back(refusedCellMesh);
01262   MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
01263   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells());
01264   
01265   MEDCouplingFieldDouble* field1=MEDLoader::ReadField(ON_GAUSS_NE,fileName.c_str(),initialMesh->getName(),0,"MyFieldOnGaussNE",5,6);
01266   MEDCouplingFieldDouble* field2=MEDLoader::ReadField(ON_GAUSS_NE,refusedName.c_str(),refusedCellMesh->getName(),0,"MyFieldOnGaussNE",5,6);
01267   
01268   int nbcells=corr[1]->getNumberOfTuples();
01269   CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells);
01270   //use corr to test equality of field
01271   DataArrayDouble* f1=field1->getArray();
01272   DataArrayDouble* f2=field2->getArray();
01273   if (_verbose>300) 
01274     {
01275       cout << "\nf1 : " << f1->reprZip(); //123.4 for 12th cell,3rd component, 4th gausspoint
01276       cout << "\nf2 : " << f2->reprZip(); //field2->advancedRepradvancedRepr();
01277       for (std::size_t i = 0; i < corr.size(); i++)
01278         cout << "\ncorr " << i << " : " << corr[i]->reprZip();
01279     
01280     }
01281   int nbequal=0;
01282   int nbptgauss=8;
01283   int nbcomp=field1->getNumberOfComponents();
01284   double* p1=f1->getPointer();
01285   double* p2=f2->getPointer();
01286   int* pc=corr[1]->getPointer();
01287   for (int i = 0; i < nbcells; i++)
01288     {
01289       int i1=pc[i]*nbcomp*nbptgauss;
01290       int i2=i*nbcomp*nbptgauss;
01291       for (int j = 0; j < nbcomp*nbptgauss; j++)
01292         {
01293           if (p1[i1+j]==p2[i2+j]) nbequal++;
01294           //cout<<" "<<p1[i1+j]<<"="<<p2[i2+j];
01295         }
01296     }
01297   CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp*nbptgauss, nbequal);
01298   
01299   for (std::size_t i = 0; i < corr.size(); i++)
01300     corr[i]->decrRef();
01301   field1->decrRef();
01302   field2->decrRef();
01303   fusedCell->decrRef();
01304   refusedCellMesh->decrRef();
01305   cellMesh->decrRef();
01306 }