Back to index

salome-med  6.5.0
ParaMEDLoader.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 "ParaMEDLoader.hxx"
00021 #include "MEDLoader.hxx"
00022 #include "ParaMESH.hxx"
00023 #include "BlockTopology.hxx"
00024 #include "MEDCouplingUMesh.hxx"
00025 
00026 #include <fstream>
00027 
00028 using namespace ParaMEDMEM;
00029 
00030 ParaMEDLoader::ParaMEDLoader()
00031 {
00032 }
00033 
00034 void ParaMEDLoader::WriteParaMesh(const char *fileName, ParaMEDMEM::ParaMESH *mesh)
00035 {
00036   if(!mesh->getBlockTopology()->getProcGroup()->containsMyRank())
00037     return ;
00038   int myRank=mesh->getBlockTopology()->getProcGroup()->myRank();
00039   int nbDomains=mesh->getBlockTopology()->getProcGroup()->size();
00040   std::vector<std::string> fileNames(nbDomains);
00041   for(int i=0;i<nbDomains;i++)
00042     {
00043       std::ostringstream sstr;
00044       sstr << fileName << i+1 << ".med";
00045       fileNames[i]=sstr.str();
00046     }
00047   if(myRank==0)
00048     WriteMasterFile(fileName,fileNames,mesh->getCellMesh()->getName());
00049   MEDLoader::WriteUMesh(fileNames[myRank].c_str(),dynamic_cast<MEDCouplingUMesh *>(mesh->getCellMesh()),true);
00050 }
00051 
00055 void ParaMEDLoader::WriteMasterFile(const char *fileName, const std::vector<std::string>& fileNames, const char *meshName)
00056 {
00057   int nbOfDom=fileNames.size();
00058   std::ofstream fs(fileName);
00059   fs << "#MED Fichier V 2.3" << " " << std::endl;
00060   fs << "#"<<" " << std::endl;
00061   fs << nbOfDom <<" " << std::endl;
00062   for(int i=0;i<nbOfDom;i++)
00063     fs << meshName << " " << i+1 << " " << meshName << "_" << i+1 << " localhost " << fileNames[i] << " " << std::endl;
00064 }