From: cvw Date: Tue, 3 Jan 2012 15:09:04 +0000 (+0000) Subject: partition of meshes MEDCoupling with MEDCouplingFieldDouble X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a298fa6d8db8e479fdad375aecc29f88dcf7944c;p=tools%2Fmedcoupling.git partition of meshes MEDCoupling with MEDCouplingFieldDouble --- diff --git a/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx b/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx new file mode 100644 index 000000000..7b8bde6cc --- /dev/null +++ b/src/MEDPartitioner/Test/MEDPARTITIONERTest.cxx @@ -0,0 +1,1109 @@ +// Copyright (C) 2007-2011 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +#include +#include +#include +#include +#include +#include + +//#include "MEDPARTITIONERTest.hxx" +#include + +//#include "MEDMEM_STRING.hxx" + +#include "MEDPARTITIONERTest.hxx" + +#include "CellModel.hxx" +#include "MEDFileMesh.hxx" +#include "MEDLoader.hxx" +#include "MEDLoaderBase.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingExtrudedMesh.hxx" +#include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingMultiFields.hxx" + +#include "MEDPARTITIONER_MESHCollection.hxx" +//#include "MEDPARTITIONER_Topology.hxx" +#include "MEDPARTITIONER_ParallelTopology.hxx" +#include "MEDPARTITIONER_ParaDomainSelector.hxx" + +#include "MEDPARTITIONER_utils.hxx" + +#ifdef HAVE_MPI2 +#include +#endif + +using namespace std; +//using namespace MEDPARTITIONER; +using namespace ParaMEDMEM; +using namespace MEDPARTITIONER; + +/*string intToStr(int i) +{ + ostringstream oss; + oss<_ni=ni; //nb of hexa9 + this->_nj=nj; + this->_nk=nk; + this->_ntot=_ni*_nj*_nk; + string ijk=intToStr(ni)+"x"+intToStr(nj)+"x"+intToStr(nk); + this->_fileName="tmp_testMesh_"+ijk+".med"; + this->_fileNameWithFaces="tmp_testMeshWithFaces_"+ijk+".med"; + string ij=intToStr(ni)+"x"+intToStr(nj); + this->_fileName2="tmp_testMesh_"+ij+".med"; + this->_meshName="testMesh"; +} + +void MEDPARTITIONERTest::setSmallSize() +{ + setSize(2,3,5); //nb of hexa9 +} + +void MEDPARTITIONERTest::setMedianSize() +{ + setSize(20,30,50); //nb of hexa9 +} + +void MEDPARTITIONERTest::setbigSize() +{ + setSize(200,300,500); //nb of hexa9 +} + + +// ============================================================================ +/*! + * Set up the environment called at every CPPUNIT_TEST () + */ +// ============================================================================ +void MEDPARTITIONERTest::setUp() +{ + this->_verbose=0; +} + +// ============================================================================ +/*! + * - delete + */ +// ============================================================================ +void MEDPARTITIONERTest::tearDown() +{ +} + +ParaMEDMEM::MEDCouplingUMesh * MEDPARTITIONERTest::buildCUBE3DMesh() +//only hexa8 +{ + vector conn; + vector coor; + for (int k=0; k<=_nk; k++) + for (int j=0; j<=_nj; j++) + for (int i=0; i<=_ni; i++) + { + coor.push_back(i+.1); + coor.push_back(j+.2); + coor.push_back(k+.3); + } + int ii; + for (int k=0; k<_nk; k++) + for (int j=0; j<_nj; j++) + for (int i=0; i<_ni; i++) + { + ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1); + conn.push_back(ii); + conn.push_back(ii+1); + ii=ii + _ni + 2 ; + conn.push_back(ii); + conn.push_back(ii-1); + + ii=i + j*(_ni+1) + (k+1)*(_ni+1)*(_nj+1); + conn.push_back(ii); + conn.push_back(ii+1); + ii=ii + _ni + 2 ; + conn.push_back(ii); + conn.push_back(ii-1); + } + + if (false) //(_verbose) + { + cout<<"\nnb coor "<<(_ni+1)*(_nj+1)*(_nk+1)*3<<" "<setMeshDimension(3); + int nbc=conn.size()/8; //nb of cells + int nbv=coor.size()/3; //nb of vertices + mesh->allocateCells(nbc); + for(int i=0; iinsertNextCell(INTERP_KERNEL::NORM_HEXA8,8,onehexa); + } + mesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(nbv,3); + std::copy(coor.begin(),coor.end(),myCoords->getPointer()); + mesh->setCoords(myCoords); + mesh->setName(_meshName.c_str()); + myCoords->decrRef(); + mesh->checkCoherency(); + return mesh; +} + +ParaMEDMEM::MEDCouplingUMesh * MEDPARTITIONERTest::buildCARRE3DMesh() +//only quad4 in oblique (k=j) +{ + vector conn; + vector coor; + for (int j=0; j<=_nj; j++) + for (int i=0; i<=_ni; i++) + { + int k=j; + coor.push_back(i+.1); + coor.push_back(j+.2); + coor.push_back(k+.3); + } + int ii; + int k=0; + for (int j=0; j<_nj; j++) + for (int i=0; i<_ni; i++) + { + ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1); + conn.push_back(ii); + conn.push_back(ii+1); + ii=ii + _ni + 2 ; + conn.push_back(ii); + conn.push_back(ii-1); + } + + if (false) //(_verbose) + { + cout<<"\nnb coor "<<(_ni+1)*(_nj+1)*3<<" "<setMeshDimension(2); + int nbc=conn.size()/4; //nb of cells + int nbv=coor.size()/3; //nb of vertices + mesh->allocateCells(nbc); + for(int i=0; iinsertNextCell(INTERP_KERNEL::NORM_QUAD4,4,onequa); + } + mesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(nbv,3); + std::copy(coor.begin(),coor.end(),myCoords->getPointer()); + mesh->setCoords(myCoords); + mesh->setName(_meshName.c_str()); + myCoords->decrRef(); + mesh->checkCoherency(); + return mesh; +} + +ParaMEDMEM::MEDCouplingUMesh * MEDPARTITIONERTest::buildFACE3DMesh() +//only quad4 on a global face of the CUBE3D (k=0) +{ + vector conn; + vector coor; + for (int j=0; j<=_nj; j++) + for (int i=0; i<=_ni; i++) + { + int k=0; + coor.push_back(i+.1); + coor.push_back(j+.2); + coor.push_back(k+.3); + } + int ii; + int k=0; + for (int j=0; j<_nj; j++) + for (int i=0; i<_ni; i++) + { + ii=i + j*(_ni+1) + k*(_ni+1)*(_nj+1); + conn.push_back(ii); + conn.push_back(ii+1); + ii=ii + _ni + 2 ; + conn.push_back(ii); + conn.push_back(ii-1); + } + + if (false) //(_verbose) + { + cout<<"\nnb coor "<<(_ni+1)*(_nj+1)*3<<" "<setMeshDimension(2); + int nbc=conn.size()/4; //nb of cells + int nbv=coor.size()/3; //nb of vertices + mesh->allocateCells(nbc); + for(int i=0; iinsertNextCell(INTERP_KERNEL::NORM_QUAD4,4,onequa); + } + mesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(nbv,3); + std::copy(coor.begin(),coor.end(),myCoords->getPointer()); + mesh->setCoords(myCoords); + mesh->setName(_meshName.c_str()); + myCoords->decrRef(); + mesh->checkCoherency(); + return mesh; +} + +MEDCouplingFieldDouble * MEDPARTITIONERTest::buildVecFieldOnCells(string myfileName) +{ + //int ni=2,nj=3,nk=5; //nb of hexa9 + vector field; + for (int k=0; k<_nk; k++) + for (int j=0; j<_nj; j++) + for (int i=0; i<_ni; i++) + { + field.push_back(i+.1); + field.push_back(j+.2); + field.push_back(k+.3); + } + //cvwat + MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(myfileName.c_str(),_meshName.c_str(),0); + int nbOfCells=mesh->getNumberOfCells(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setName("VectorFieldOnCells"); + f1->setDescription("DescriptionOfFieldOnCells"); //not saved in file? + f1->setMesh(mesh); + DataArrayDouble *myField=DataArrayDouble::New(); + myField->alloc(nbOfCells,3); + std::copy(field.begin(),field.end(),myField->getPointer()); + f1->setArray(myField); + myField->setInfoOnComponent(0,"vx"); + myField->setInfoOnComponent(1,"vy"); + myField->setInfoOnComponent(2,"vz"); + myField->decrRef(); + f1->setTime(2.,0,1); + f1->checkCoherency(); + mesh->decrRef(); + return f1; +} + +MEDCouplingFieldDouble * MEDPARTITIONERTest::buildVecFieldOnNodes() +{ + //int ni=2,nj=3,nk=5; //nb of hexa9 + vector field; + for (int k=0; k<=_nk; k++) + for (int j=0; j<=_nj; j++) + for (int i=0; i<=_ni; i++) + { + field.push_back(i+.1); + field.push_back(j+.2); + field.push_back(k+.3); + } + + MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(_fileName.c_str(),_meshName.c_str(),0); + int nbOfNodes=mesh->getNumberOfNodes(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME); + f1->setName("VectorFieldOnNodes"); + f1->setDescription("DescriptionOfFieldOnNodes"); //not saved in file? + f1->setMesh(mesh); + DataArrayDouble *myField=DataArrayDouble::New(); + myField->alloc(nbOfNodes,3); + std::copy(field.begin(),field.end(),myField->getPointer()); + f1->setArray(myField); + myField->setInfoOnComponent(0,"vx"); + myField->setInfoOnComponent(1,"vy"); + myField->setInfoOnComponent(2,"vz"); + myField->decrRef(); + f1->setTime(2.,0,1); + f1->checkCoherency(); + mesh->decrRef(); + return f1; +} + + +void MEDPARTITIONERTest::createTestMeshWithoutField() +{ + { + MEDCouplingUMesh * mesh = buildCUBE3DMesh(); + MEDLoader::WriteUMesh(_fileName.c_str(),mesh,true); + if (_verbose) cout<getName(),0); + if (_verbose) cout<<_fileName<<" reread"<isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + } + mesh->decrRef(); + } + + { + vector meshes; + MEDCouplingUMesh * mesh1 = buildCUBE3DMesh(); + MEDCouplingUMesh * mesh2 = buildFACE3DMesh(); + mesh1->setName("testMesh"); + mesh2->setName("theFaces"); + mesh2->tryToShareSameCoordsPermute(*mesh1, 1e-9); + mesh2->checkCoherency(); + mesh1->checkCoherency(); + meshes.push_back(mesh1); + meshes.push_back(mesh2); + MEDLoader::WriteUMeshes(_fileNameWithFaces.c_str(), meshes, true); + + ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(_fileNameWithFaces.c_str(), mesh1->getName()); + DataArrayInt* FacesFam=DataArrayInt::New(); + FacesFam->alloc(mfm->getSizeAtLevel(-1),1); + FacesFam->fillWithValue(-1); + DataArrayInt* CellsFam=DataArrayInt::New(); + CellsFam->alloc(mfm->getSizeAtLevel(0),1); + CellsFam->fillWithValue(1); + mfm->setFamilyFieldArr(-1,FacesFam); + mfm->setFamilyFieldArr(0,CellsFam); + map theFamilies; + theFamilies["FAMILLE_ZERO"]=0; + theFamilies["FamilyFaces"]=-1; + theFamilies["FamilyCells"]=1; + map > theGroups; + theGroups["GroupFaces"].push_back("FamilyFaces"); + theGroups["GroupCells"].push_back("FamilyCells"); + mfm->setFamilyInfo(theFamilies); + mfm->setGroupInfo(theGroups); + mfm->write(_fileNameWithFaces.c_str(),0); + FacesFam->decrRef(); + CellsFam->decrRef(); + + /*ce truc marche pas! + ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(_fileNameWithFaces.c_str(), mesh1->getName()); + vector ms; + ms.push_back(mesh2); + mfm->setGroupsFromScratch(-1, ms); + mfm->write(_fileNameWithFaces.c_str(),0); + */ + + if (_verbose) cout<getName(),0); + if (_verbose) cout<<_fileNameWithFaces<<" reread"<isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + } + mesh1->decrRef(); + mesh2->decrRef(); + } + + { + MEDCouplingUMesh * mesh = buildCARRE3DMesh(); + MEDLoader::WriteUMesh(_fileName2.c_str(),mesh,true); + if (_verbose) cout<getName(),0); + if (_verbose) cout<<_fileName2<<" reread"<isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + mesh->decrRef(); + } +} + +void MEDPARTITIONERTest::createHugeTestMesh(int ni, int nj, int nk, int nbx, int nby, int nbz, int nbTarget) +{ + setSize(ni,nj,nk); + _nbTargetHuge=nbTarget; + MEDCouplingUMesh * mesh = buildCUBE3DMesh(); + //int nbx=1, nby=1, nbz=2; + std::vector< double > cooDep,cooFin; + mesh->getCoordinatesOfNode(0, cooDep); + mesh->getCoordinatesOfNode(mesh->getNumberOfNodes()-1, cooFin); + //cout<\n \ +\n \ + \n \ + \n \ + \n \ + \n \ + \n \ + \n \ + \n \ + \n \ + \n \ + \n$tagSubfile \ + \n \ + \n$tagMesh \ + \n \ +\n"; + + string tagSubfiles, tagSubfile="\ + \n \ + $fileName\n \ + localhost\n \ + \n"; + string tagMeshes, tagMesh="\ + \n \ + \n \ + testMesh\n \ + \n \ + \n"; + + int xyz=1; + string sxyz; + DataArrayDouble* coordsInit=mesh->getCoords()->deepCpy(); + double* ptrInit=coordsInit->getPointer(); + double deltax=cooFin[0]-cooDep[0]; + double deltay=cooFin[1]-cooDep[1]; + double deltaz=cooFin[2]-cooDep[2]; + + double dz=0.; + for (int z=0; zgetCoords(); + //int nbOfComp=coords->getNumberOfComponents(); //be 3D + int nbOfTuple=coords->getNumberOfTuples(); + double* ptr=coords->getPointer(); + double* ptrini=ptrInit; + for (int i=0; idecrRef(); + + tagXml.replace(tagXml.find("$subdomainNumber"),16,sxyz); + tagXml.replace(tagXml.find("$tagSubfile"),11,tagSubfiles); + tagXml.replace(tagXml.find("$tagMesh"),8,tagMeshes); + + string nameFileXml; + _fileNameHugeXml="tmp_testMeshHuge_"+intToStr(_ni)+"x"+intToStr(_nj)+"x"+intToStr(_nk)+"_"+sxyz+".xml"; + std::ofstream f(_fileNameHugeXml.c_str()); + f<setTime(3.,1,1); //time,it,order + f1->applyFunc("x/2."); + MEDLoader::WriteField(name.c_str(),f1,false); + if (_verbose) cout<getMesh()->getName(),0,f1->getName(),0,1); + //DataArrayDouble *res=f2->getArray(); + if (_verbose) cout<isEqual(f2,1e-12,1e-12)); + f2->decrRef(); + } + f1->decrRef(); + } + { + string name=_fileName; + MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name); + name.replace(name.find(".med"),4,"_WithVecFieldOnGaussNe.med"); + MEDCouplingFieldDouble *f3=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME); + f3->setMesh(f1->getMesh()); + //cout<<"\nNumberOfMeshPlacesExpected "<getNumberOfMeshPlacesExpected()<<" " + // /*<getMesh())<<" "*/ + // <getMesh()->getNumberOfNodes()<<" " + // <getMesh()->getNumberOfCells()<setName("MyFieldOnGaussNE"); + f3->setDescription("MyDescriptionNE"); + DataArrayDouble *array=DataArrayDouble::New(); + //int nb=f1->getMesh()->getNumberOfNodes(); + + /*8 pt de gauss by cell + int nb=f3->getMesh()->getNumberOfCells()*8; + array->alloc(nb,2); + double *ptr=array->getPointer(); + for (int i=0; igetMesh()->getNumberOfCells(); + int nb=nbcell*nbptgauss; + int nbcomp=2; + array->alloc(nb,nbcomp); + double *ptr=array->getPointer(); + int ii=0; + for (int i=0; isetInfoOnComponent(0,"vGx"); + array->setInfoOnComponent(1,"vGy"); + f3->setTime(4.,5,6); + f3->setArray(array); + array->decrRef(); + MEDLoader::WriteField(name.c_str(),f3,true); + if (_verbose) cout<checkCoherency(); + f1->decrRef(); + if (_ntot<1000000) //too long + { + MEDCouplingFieldDouble* f4=MEDLoader::ReadField(ON_GAUSS_NE, + name.c_str(), f3->getMesh()->getName(), 0, "MyFieldOnGaussNE", 5, 6); + if (_verbose) cout<<"MyFieldOnGaussNE reread"<decrRef(); + } + f3->decrRef(); + } + { + string name=_fileNameWithFaces; + MEDCouplingFieldDouble *f1=buildVecFieldOnCells(name); + name.replace(name.find(".med"),4,"_WithVecFieldOnCells.med"); + MEDLoader::WriteField(name.c_str(),f1,true); + if (_verbose) cout<getMesh()->getName(),0,f1->getName(),0,1); + if (_verbose) cout<isEqual(f2,1e-12,1e-12)); assertion failed!! + f2->decrRef(); + } + f1->decrRef(); + } +} + +void MEDPARTITIONERTest::createTestMeshWithVecFieldOnNodes() +{ + MEDCouplingFieldDouble *f1=buildVecFieldOnNodes(); + string name=_fileName; + name.replace(name.find(".med"),4,"_WithVecFieldOnNodes.med"); + MEDLoader::WriteField(name.c_str(),f1,true); + if (_verbose) cout<getMesh()->getName(),0,f1->getName(),0,1); + if (_verbose) cout<isEqual(f2,1e-12,1e-12)); assertion failed!! + f2->decrRef(); + } + f1->decrRef(); +} + +void MEDPARTITIONERTest::verifyTestMeshWithVecFieldOnNodes() +{ + string name=_fileName; + name.replace(name.find(".med"),4,"_WithVecFieldOnNodes.med"); + MEDCouplingUMesh * m=MEDLoader::ReadUMeshFromFile(name.c_str(),_meshName.c_str(),0); + const std::set& types=m->getAllTypes(); + if (_verbose) + { + cout<<"\n types in "<::iterator t=types.begin(); t!=types.end(); ++t) cout<<" "<<*t; + for (std::set::iterator t=types.begin(); t!=types.end(); ++t) + { + //INTERP_KERNEL::CellModel essai=INTERP_KERNEL::CellModel::GetCellModel(*t); + cout<<" "<<(INTERP_KERNEL::CellModel::GetCellModel(*t)).getRepr(); + } + cout<decrRef(); + + MEDFileUMesh * mf; + mf->New(_fileName.c_str(),_meshName.c_str(),-1,-1); + vector lev; + lev=mf->getNonEmptyLevels(); + if (_verbose) + { + cout<<" levels in "<::iterator l=lev.begin(); l!=lev.end(); ++l) cout<<" "<<*l; + cout<decrRef(); +} + +void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForMesh() +{ + int res; + string fileName,cmd,execName,sourceName,targetName,input; + execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/salome/medpartitioner_para"; + fileName=_fileNameWithFaces; + + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_meshName.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; + targetName.replace(targetName.find(".med"),4,"_partitionedTo5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+intToStr(_verbose); + if (_verbose) cout<cellMeshes=collection.getMesh(); + CPPUNIT_ASSERT_EQUAL(5, (int) cellMeshes.size()); + int nbcells=0; + for (int 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 (int 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"; + targetName=fileName; + targetName.replace(targetName.find(".med"),4,"_remergedFrom5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+intToStr(_verbose); + 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); + refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9); + meshes.push_back(refusedCellMesh); + MEDCouplingUMesh* fusedCell=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), fusedCell->getNumberOfCells()); + + meshes.resize(0); + for (int i = 0; i < corr.size(); i++) corr[i]->decrRef(); + corr.resize(0); + meshes.push_back(faceMesh); + refusedFaceMesh->tryToShareSameCoordsPermute(*faceMesh, 1e-9); + meshes.push_back(refusedFaceMesh); + MEDCouplingUMesh* fusedFace=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr); + CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), fusedFace->getNumberOfCells()); + + for (int i = 0; i < corr.size(); i++) corr[i]->decrRef(); + fusedFace->decrRef(); + refusedFaceMesh->decrRef(); + faceMesh->decrRef(); + fusedCell->decrRef(); + refusedCellMesh->decrRef(); + cellMesh->decrRef(); + //done in ~collection + //for (int i = 0; i < faceMeshes.size(); i++) faceMeshes[i]->decrRef(); + //for (int i = 0; i < cellMeshes.size(); i++) cellMeshes[i]->decrRef(); +} + +void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnCells() +{ + int res; + string fileName,cmd,execName,sourceName,targetName,input; + execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/salome/medpartitioner_para"; + fileName=_fileName; + fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnCells.med"); + + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_meshName.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; + targetName.replace(targetName.find(".med"),4,"_partitionedTo5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+intToStr(_verbose); + if (_verbose) cout<getLevel0Mesh(false); + + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); + + std::vector meshes; + std::vector corr; + meshes.push_back(cellMesh); + refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9); + 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(),0,"VectorFieldOnCells",0,1); + MEDCouplingFieldDouble* field2=MEDLoader::ReadFieldCell(refusedName.c_str(),refusedCellMesh->getName(),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) + { + cout<<"\nf1 : "<reprZip(); + cout<<"\nf2 : "<reprZip(); //field2->advancedRepradvancedRepr(); + for (int i = 0; i < corr.size(); i++) cout<<"\ncorr "<reprZip(); + + } + int nbequal=0; + int nbcomp=field1->getNumberOfComponents(); + double* p1=f1->getPointer(); + double* p2=f2->getPointer(); + int* pc=corr[1]->getPointer(); + for (int i = 0; i < nbcells; i++) + { + int i1=pc[i]*nbcomp; + int i2=i*nbcomp; + for (int j = 0; j < nbcomp; j++) + { + if (p1[i1+j]==p2[i2+j]) nbequal++; + //cout<<" "<decrRef(); + field1->decrRef(); + field2->decrRef(); + fusedCell->decrRef(); + refusedCellMesh->decrRef(); + cellMesh->decrRef(); +} + +void MEDPARTITIONERTest::verifyMedpartitionerOnSmallSizeForFieldOnGaussNe() +{ + int res; + string fileName,cmd,execName,sourceName,targetName,input; + execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/salome/medpartitioner_para"; + fileName=_fileName; + fileName.replace(fileName.find(".med"),4,"_WithVecFieldOnGaussNe.med"); + + ParaMEDMEM::MEDFileUMesh* initialMesh=ParaMEDMEM::MEDFileUMesh::New(fileName.c_str(),_meshName.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; + targetName.replace(targetName.find(".med"),4,"_partitionedTo5_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+intToStr(_verbose); + if (_verbose) cout<getLevel0Mesh(false); + + CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells()); + + std::vector meshes; + std::vector corr; + meshes.push_back(cellMesh); + refusedCellMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-9); + 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(),0,"MyFieldOnGaussNE",5,6); + MEDCouplingFieldDouble* field2=MEDLoader::ReadField(ON_GAUSS_NE,refusedName.c_str(),refusedCellMesh->getName(),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) + { + cout<<"\nf1 : "<reprZip(); //123.4 for 12th cell,3rd component, 4th gausspoint + cout<<"\nf2 : "<reprZip(); //field2->advancedRepradvancedRepr(); + for (int i = 0; i < corr.size(); i++) cout<<"\ncorr "<reprZip(); + + } + int nbequal=0; + int nbptgauss=8; + int nbcomp=field1->getNumberOfComponents(); + double* p1=f1->getPointer(); + double* p2=f2->getPointer(); + int* pc=corr[1]->getPointer(); + for (int i = 0; i < nbcells; i++) + { + int i1=pc[i]*nbcomp*nbptgauss; + int i2=i*nbcomp*nbptgauss; + for (int j = 0; j < nbcomp*nbptgauss; j++) + { + if (p1[i1+j]==p2[i2+j]) nbequal++; + //cout<<" "<decrRef(); + field1->decrRef(); + field2->decrRef(); + fusedCell->decrRef(); + refusedCellMesh->decrRef(); + cellMesh->decrRef(); +} + +void MEDPARTITIONERTest::createTestMeshes() +{ + createTestMeshWithoutField(); + createTestMeshWithVecFieldOnCells(); + createTestMeshWithVecFieldOnNodes(); +} + + +void MEDPARTITIONERTest::deleteTestMeshes() +{ + string cmd="rm *tmp_testMesh*"; + if (_verbose) cout</dev/null 1>/dev/null"); //no trace + CPPUNIT_ASSERT_EQUAL(0, res); + + execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED + execName+="/bin/salome/medpartitioner_para"; + + 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=_fileName; + targetName=_fileName; + targetName.replace(targetName.find(".med"),4,"_partitionedTo2_"); + cmd+=" --input-file="+sourceName+" --output-file="+targetName+" --verbose="+intToStr(_verbose); + if (_verbose) cout<