1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "ParaMEDLoader.hxx"
22 #include "MEDLoader.hxx"
23 #include "ParaMESH.hxx"
24 #include "BlockTopology.hxx"
25 #include "MEDCouplingUMesh.hxx"
29 using namespace MEDCoupling;
31 ParaMEDLoader::ParaMEDLoader()
35 void ParaMEDLoader::WriteParaMesh(const char *fileName, MEDCoupling::ParaMESH *mesh)
37 if(!mesh->getBlockTopology()->getProcGroup()->containsMyRank())
39 int myRank=mesh->getBlockTopology()->getProcGroup()->myRank();
40 int nbDomains=mesh->getBlockTopology()->getProcGroup()->size();
41 std::vector<std::string> fileNames(nbDomains);
42 for(int i=0;i<nbDomains;i++)
44 std::ostringstream sstr;
45 sstr << fileName << i+1 << ".med";
46 fileNames[i]=sstr.str();
49 WriteMasterFile(fileName,fileNames,mesh->getCellMesh()->getName().c_str());
50 WriteUMesh(fileNames[myRank].c_str(),dynamic_cast<MEDCouplingUMesh *>(mesh->getCellMesh()),true);
54 * This method builds the master file 'fileName' of a parallel MED file defined in 'fileNames'.
56 void ParaMEDLoader::WriteMasterFile(const char *fileName, const std::vector<std::string>& fileNames, const char *meshName)
58 int nbOfDom=fileNames.size();
59 std::ofstream fs(fileName);
60 fs << "#MED Fichier V 2.3" << " " << std::endl;
61 fs << "#"<<" " << std::endl;
62 fs << nbOfDom <<" " << std::endl;
63 for(int i=0;i<nbOfDom;i++)
64 fs << meshName << " " << i+1 << " " << meshName << "_" << i+1 << " localhost " << fileNames[i] << " " << std::endl;