X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDPartitioner%2FTest%2FMEDPARTITIONERTestPara.cxx;h=866409f0e94aef10d6c5f00f1f106f64d07c067f;hb=56e7b97b6270ad0b2d523070f937e0b8ebae0d30;hp=23fd02c6d96541bc004f7856391be6b504bd3b42;hpb=a430bf38a635445423bb08617ec3a199e254ec3b;p=tools%2Fmedcoupling.git diff --git a/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx b/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx index 23fd02c6d..866409f0e 100644 --- a/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx +++ b/src/MEDPartitioner/Test/MEDPARTITIONERTestPara.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -49,19 +49,36 @@ using namespace std; using namespace ParaMEDMEM; using namespace MEDPARTITIONER; -#if defined(HAVE_MPI2) +#if defined(HAVE_MPI) +std::string MEDPARTITIONERTest::getPartitionerParaExe() const +{ + std::string execName; + if ( getenv("MEDCOUPLING_ROOT_DIR") ) + { + execName=getenv("MEDCOUPLING_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/medpartitioner_para"; + } + else + { + execName = get_current_dir_name(); + execName += "/../../MEDPartitioner/medpartitioner_para"; + if (! std::ifstream(execName.c_str())) + CPPUNIT_FAIL("Can't find medpartitioner_para, please set MEDCOUPLING_ROOT_DIR"); + } + return execName; +} + void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForMesh() { int res; string fileName,cmd,execName,sourceName,targetName,input; - execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED - execName+="/bin/salome/medpartitioner_para"; + execName=getPartitionerParaExe(); fileName=_file_name_with_faces; - + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str()); ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false); ParaMEDMEM::MEDCouplingUMesh* faceMesh=initialMesh->getLevelM1Mesh(false); - + cmd="mpirun -np 5 "+execName+" --ndomains=5 --split-method=metis"; //on same proc sourceName=fileName; targetName=fileName; @@ -71,7 +88,7 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForMesh() res=system(cmd.c_str()); CPPUNIT_ASSERT_EQUAL(0, res); input=targetName+".xml"; - + MEDPARTITIONER::ParaDomainSelector parallelizer(false); MEDPARTITIONER::MeshCollection collection(input,parallelizer); CPPUNIT_ASSERT_EQUAL(3, collection.getMeshDimension()); @@ -81,14 +98,14 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForMesh() for (std::size_t i = 0; i < cellMeshes.size(); i++) nbcells+=cellMeshes[i]->getNumberOfCells(); CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells); - + std::vectorfaceMeshes=collection.getFaceMesh(); CPPUNIT_ASSERT_EQUAL(5, (int) faceMeshes.size()); int nbfaces=0; for (std::size_t i=0; i < faceMeshes.size(); i++) nbfaces+=faceMeshes[i]->getNumberOfCells(); CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), nbfaces); - + //merge split meshes and test equality cmd="mpirun -np 1 "+execName+" --ndomains=1 --split-method=metis"; //on same proc sourceName=targetName+".xml"; @@ -98,25 +115,25 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForMesh() if (_verbose) cout<getLevel0Mesh(false); ParaMEDMEM::MEDCouplingUMesh* refusedFaceMesh=refusedMesh->getLevelM1Mesh(false); - + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), refusedFaceMesh->getNumberOfCells()); - + /*not the good job ParaMEDMEM::MEDCouplingMesh* mergeCell=cellMesh->mergeMyselfWith(refusedCellMesh); CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), mergeCell->getNumberOfCells()); - + ParaMEDMEM::MEDCouplingMesh* mergeFace=faceMesh->mergeMyselfWith(refusedFaceMesh); CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), mergeFace->getNumberOfCells()); - + CPPUNIT_ASSERT(faceMesh->isEqual(refusedFaceMesh,1e-12)); */ - + std::vector meshes; std::vector corr; meshes.push_back(cellMesh); @@ -124,7 +141,7 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForMesh() meshes.push_back(refusedCellMesh); MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells()); - + meshes.resize(0); for (std::size_t i = 0; i < corr.size(); i++) corr[i]->decrRef(); @@ -134,7 +151,7 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForMesh() meshes.push_back(refusedFaceMesh); MEDCouplingUMesh* fusedFace=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), fusedFace->getNumberOfCells()); - + for (std::size_t i = 0; i < corr.size(); i++) corr[i]->decrRef(); fusedFace->decrRef(); @@ -152,14 +169,13 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnCells() { int res; string fileName,cmd,execName,sourceName,targetName,input; - execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED - execName+="/bin/salome/medpartitioner_para"; + execName=getPartitionerParaExe(); fileName=_file_name; fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnCells.med"); - + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str()); ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false); - + cmd="mpirun -np 5 "+execName+" --ndomains=5 --split-method=metis"; //on same proc sourceName=fileName; targetName=fileName; @@ -169,7 +185,7 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnCells() res=system(cmd.c_str()); CPPUNIT_ASSERT_EQUAL(0, res); input=targetName+".xml"; - + //merge split meshes and test equality cmd="mpirun -np 1 "+execName+" --ndomains=1 --split-method=metis"; //on same proc sourceName=targetName+".xml"; @@ -179,13 +195,13 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnCells() if (_verbose) cout<getLevel0Mesh(false); - + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); - + std::vector meshes; std::vector corr; meshes.push_back(cellMesh); @@ -193,22 +209,22 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnCells() meshes.push_back(refusedCellMesh); MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells()); - + MEDCouplingFieldDouble* field1=MEDLoader::ReadFieldCell(fileName.c_str(),initialMesh->getName().c_str(),0,"VectorFieldOnCells",0,1); MEDCouplingFieldDouble* field2=MEDLoader::ReadFieldCell(refusedName.c_str(),refusedCellMesh->getName().c_str(),0,"VectorFieldOnCells",0,1); - + int nbcells=corr[1]->getNumberOfTuples(); CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells); //use corr to test equality of field DataArrayDouble* f1=field1->getArray(); DataArrayDouble* f2=field2->getArray(); - if (_verbose>300) + if (_verbose>300) { cout<<"\nf1 : "<reprZip(); cout<<"\nf2 : "<reprZip(); //field2->advancedRepradvancedRepr(); for (std::size_t i = 0; i < corr.size(); i++) cout << "\ncorr " << i << " : " << corr[i]->reprZip(); - + } int nbequal=0; int nbcomp=field1->getNumberOfComponents(); @@ -226,7 +242,7 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnCells() } } CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp, nbequal); - + for (std::size_t i = 0; i < corr.size(); i++) corr[i]->decrRef(); field1->decrRef(); @@ -240,14 +256,13 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() { int res; string fileName,cmd,execName,sourceName,targetName,input; - execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED - execName+="/bin/salome/medpartitioner_para"; + execName=getPartitionerParaExe(); fileName=_file_name; fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnGaussNe.med"); - + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str()); ParaMEDMEM::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false); - + cmd="mpirun -np 5 "+execName+" --ndomains=5 --split-method=metis"; //on same proc sourceName=fileName; targetName=fileName; @@ -257,7 +272,7 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() res=system(cmd.c_str()); CPPUNIT_ASSERT_EQUAL(0, res); input=targetName+".xml"; - + //merge split meshes and test equality cmd="mpirun -np 1 "+execName+" --ndomains=1 --split-method=metis"; //on same proc sourceName=targetName+".xml"; @@ -267,13 +282,13 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() if (_verbose) cout<getLevel0Mesh(false); - + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); - + std::vector meshes; std::vector corr; meshes.push_back(cellMesh); @@ -281,22 +296,22 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() meshes.push_back(refusedCellMesh); MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells()); - + MEDCouplingFieldDouble* field1=MEDLoader::ReadField(ON_GAUSS_NE,fileName.c_str(),initialMesh->getName().c_str(),0,"MyFieldOnGaussNE",5,6); MEDCouplingFieldDouble* field2=MEDLoader::ReadField(ON_GAUSS_NE,refusedName.c_str(),refusedCellMesh->getName().c_str(),0,"MyFieldOnGaussNE",5,6); - + int nbcells=corr[1]->getNumberOfTuples(); CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells); //use corr to test equality of field DataArrayDouble* f1=field1->getArray(); DataArrayDouble* f2=field2->getArray(); - if (_verbose>300) + if (_verbose>300) { cout << "\nf1 : " << f1->reprZip(); //123.4 for 12th cell,3rd component, 4th gausspoint cout << "\nf2 : " << f2->reprZip(); //field2->advancedRepradvancedRepr(); for (std::size_t i = 0; i < corr.size(); i++) cout << "\ncorr " << i << " : " << corr[i]->reprZip(); - + } int nbequal=0; int nbptgauss=8; @@ -315,7 +330,7 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() } } CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp*nbptgauss, nbequal); - + for (std::size_t i = 0; i < corr.size(); i++) corr[i]->decrRef(); field1->decrRef(); @@ -327,8 +342,8 @@ void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() void MEDPARTITIONERTest::launchMedpartitionerOnTestMeshes() { - - /* examples + + /* examples export INFI=/home/vb144235/resources/blade.med //no need export MESH=Fuse_1 export INFI=tmp_testMeshxxx.med @@ -339,17 +354,16 @@ void MEDPARTITIONERTest::launchMedpartitionerOnTestMeshes() */ int res; string cmd,execName,sourceName,targetName; - + res=system("which mpirun 2>/dev/null 1>/dev/null"); //no trace CPPUNIT_ASSERT_EQUAL(0, res); - - execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED - execName+="/bin/salome/medpartitioner_para"; - + + execName=getPartitionerParaExe(); + cmd="which "+execName+" 2>/dev/null 1>/dev/null"; //no trace res=system(cmd.c_str()); CPPUNIT_ASSERT_EQUAL(0, res); - + cmd="mpirun -np 2 "+execName+" --ndomains=2 --split-method=metis"; //on same proc sourceName=_file_name; targetName=_file_name; @@ -358,7 +372,7 @@ void MEDPARTITIONERTest::launchMedpartitionerOnTestMeshes() if (_verbose) cout<