-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2020 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
#include "MEDLoader.hxx"
#include "MEDLoaderBase.hxx"
#include "MEDCouplingUMesh.hxx"
-#include "MEDCouplingExtrudedMesh.hxx"
+#include "MEDCouplingMappedExtrudedMesh.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingMultiFields.hxx"
#include <cstdlib>
#include <vector>
+#include <unistd.h> // get_current_dir_name()
+
#include <mpi.h>
using namespace std;
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
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");
+ execName+="/bin/medpartitioner_para";
+ std::ifstream my_file(execName.c_str());
+ if (my_file.good())
+ return execName;
+ }
+ 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);
-
+
+ MEDCoupling::MEDFileUMesh* initialMesh=MEDCoupling::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
+ MEDCoupling::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
+ MEDCoupling::MEDCouplingUMesh* faceMesh=initialMesh->getLevelM1Mesh(false);
+
cmd="mpirun -np 5 "+execName+" --ndomains=5 --split-method=metis"; //on same proc
sourceName=fileName;
targetName=fileName;
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());
- std::vector<ParaMEDMEM::MEDCouplingUMesh*>cellMeshes=collection.getMesh();
+ std::vector<MEDCoupling::MEDCouplingUMesh*>cellMeshes=collection.getMesh();
CPPUNIT_ASSERT_EQUAL(5, (int) cellMeshes.size());
int nbcells=0;
for (std::size_t i = 0; i < cellMeshes.size(); i++)
nbcells+=cellMeshes[i]->getNumberOfCells();
CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), nbcells);
-
- std::vector<ParaMEDMEM::MEDCouplingUMesh*>faceMeshes=collection.getFaceMesh();
+
+ std::vector<MEDCoupling::MEDCouplingUMesh*>faceMeshes=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";
if (_verbose) cout<<endl<<cmd<<endl;
res=system(cmd.c_str());
CPPUNIT_ASSERT_EQUAL(0, res);
-
+
string refusedName=targetName+"1.med";
- ParaMEDMEM::MEDFileUMesh* refusedMesh=ParaMEDMEM::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
- ParaMEDMEM::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
- ParaMEDMEM::MEDCouplingUMesh* refusedFaceMesh=refusedMesh->getLevelM1Mesh(false);
-
+ MEDCoupling::MEDFileUMesh* refusedMesh=MEDCoupling::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
+ MEDCoupling::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
+ MEDCoupling::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);
+ MEDCoupling::MEDCouplingMesh* mergeCell=cellMesh->mergeMyselfWith(refusedCellMesh);
CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), mergeCell->getNumberOfCells());
-
- ParaMEDMEM::MEDCouplingMesh* mergeFace=faceMesh->mergeMyselfWith(refusedFaceMesh);
+
+ MEDCoupling::MEDCouplingMesh* mergeFace=faceMesh->mergeMyselfWith(refusedFaceMesh);
CPPUNIT_ASSERT_EQUAL(faceMesh->getNumberOfCells(), mergeFace->getNumberOfCells());
-
+
CPPUNIT_ASSERT(faceMesh->isEqual(refusedFaceMesh,1e-12));
*/
-
+
std::vector<const MEDCouplingUMesh *> meshes;
std::vector<DataArrayInt *> corr;
meshes.push_back(cellMesh);
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();
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();
{
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);
-
+
+ MEDCoupling::MEDFileUMesh* initialMesh=MEDCoupling::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
+ MEDCoupling::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
+
cmd="mpirun -np 5 "+execName+" --ndomains=5 --split-method=metis"; //on same proc
sourceName=fileName;
targetName=fileName;
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";
if (_verbose) cout<<endl<<cmd<<endl;
res=system(cmd.c_str());
CPPUNIT_ASSERT_EQUAL(0, res);
-
+
string refusedName=targetName+"1.med";
- ParaMEDMEM::MEDFileUMesh* refusedMesh=ParaMEDMEM::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
- ParaMEDMEM::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
-
+ MEDCoupling::MEDFileUMesh* refusedMesh=MEDCoupling::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
+ MEDCoupling::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
+
CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
-
+
std::vector<const MEDCouplingUMesh *> meshes;
std::vector<DataArrayInt *> corr;
meshes.push_back(cellMesh);
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);
-
+
+ MCAuto<MEDCouplingFieldDouble> field1=dynamic_cast<MEDCouplingFieldDouble*>(ReadFieldCell(fileName.c_str(),initialMesh->getName().c_str(),0,"VectorFieldOnCells",0,1));
+ MCAuto<MEDCouplingFieldDouble> field2=dynamic_cast<MEDCouplingFieldDouble*>(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 : "<<f1->reprZip();
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 nbcomp=field1->getNumberOfComponents();
}
}
CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp, nbequal);
-
+
for (std::size_t i = 0; i < corr.size(); i++)
corr[i]->decrRef();
- field1->decrRef();
- field2->decrRef();
fusedCell->decrRef();
refusedCellMesh->decrRef();
cellMesh->decrRef();
{
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);
-
+
+ MEDCoupling::MEDFileUMesh* initialMesh=MEDCoupling::MEDFileUMesh::New(fileName.c_str(),_mesh_name.c_str());
+ MEDCoupling::MEDCouplingUMesh* cellMesh=initialMesh->getLevel0Mesh(false);
+
cmd="mpirun -np 5 "+execName+" --ndomains=5 --split-method=metis"; //on same proc
sourceName=fileName;
targetName=fileName;
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";
if (_verbose) cout<<endl<<cmd<<endl;
res=system(cmd.c_str());
CPPUNIT_ASSERT_EQUAL(0, res);
-
+
string refusedName=targetName+"1.med";
- ParaMEDMEM::MEDFileUMesh* refusedMesh=ParaMEDMEM::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
- ParaMEDMEM::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
-
+ MEDCoupling::MEDFileUMesh* refusedMesh=MEDCoupling::MEDFileUMesh::New(refusedName.c_str(),_mesh_name.c_str());
+ MEDCoupling::MEDCouplingUMesh* refusedCellMesh=refusedMesh->getLevel0Mesh(false);
+
CPPUNIT_ASSERT_EQUAL(cellMesh->getNumberOfCells(), refusedCellMesh->getNumberOfCells());
-
+
std::vector<const MEDCouplingUMesh *> meshes;
std::vector<DataArrayInt *> corr;
meshes.push_back(cellMesh);
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);
-
+
+ MEDCouplingField* ff1=ReadField(ON_GAUSS_NE,fileName.c_str(),initialMesh->getName().c_str(),0,"MyFieldOnGaussNE",5,6);
+ MEDCouplingField* ff2=ReadField(ON_GAUSS_NE,refusedName.c_str(),refusedCellMesh->getName().c_str(),0,"MyFieldOnGaussNE",5,6);
+ MCAuto<MEDCouplingFieldDouble> field1 = dynamic_cast<MEDCouplingFieldDouble *>(ff1);
+ MCAuto<MEDCouplingFieldDouble> field2 = dynamic_cast<MEDCouplingFieldDouble *>(ff2);
+
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;
}
}
CPPUNIT_ASSERT_EQUAL(nbcells*nbcomp*nbptgauss, nbequal);
-
+
for (std::size_t i = 0; i < corr.size(); i++)
corr[i]->decrRef();
- field1->decrRef();
- field2->decrRef();
fusedCell->decrRef();
refusedCellMesh->decrRef();
cellMesh->decrRef();
void MEDPARTITIONERTest::launchMedpartitionerOnTestMeshes()
{
-
- /* examples
+
+ /* examples
export INFI=/home/vb144235/resources/blade.med
//no need export MESH=Fuse_1
export INFI=tmp_testMeshxxx.med
*/
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;
if (_verbose) cout<<endl<<cmd<<endl;
res=system(cmd.c_str());
CPPUNIT_ASSERT_EQUAL(0, res);
-
+
cmd="mpirun -np 3 "+execName+" --ndomains=5 --split-method=metis"; //on less proc
sourceName=_file_name;
targetName=_file_name;
if (_verbose) cout<<endl<<cmd<<endl;
res=system(cmd.c_str());
CPPUNIT_ASSERT_EQUAL(0, res);
-
+
cmd="mpirun -np 1 "+execName+" --ndomains=1 --split-method=metis"; //on 1 proc
sourceName=targetName+".xml";
targetName=_file_name;
if (_verbose) cout<<endl<<cmd<<endl;
res=system(cmd.c_str());
CPPUNIT_ASSERT_EQUAL(0, res);
-}
+}
void MEDPARTITIONERTest::launchMedpartitionerOnHugeTestMeshes()
{
int res=0;
string cmd,execName,sourceName,targetName;
- execName=getenv("MED_ROOT_DIR"); //.../INSTALL/MED
- execName+="/bin/salome/medpartitioner_para";
+ execName=getPartitionerParaExe();
string snbTarget=IntToStr(_nb_target_huge);
cmd="mpirun -np "+snbTarget+" "+execName+" --ndomains="+snbTarget+" --split-method=metis"; //on same proc
if (_verbose) cout<<endl<<cmd<<endl;
res=system(cmd.c_str());
CPPUNIT_ASSERT_EQUAL(0, res);
-}
+}
void MEDPARTITIONERTest::testMpirunSmallSize()
{