From 6f533b86de3559a2303004c071595c42eaeeb1b5 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 19 Oct 2015 14:53:41 +0000 Subject: [PATCH] add support for separate mesh files per partition in MSH3 --- Common/CreateFile.cpp | 5 +++-- Geo/GModel.h | 9 ++++++--- Geo/GModelIO_MSH.cpp | 22 ++++++++++++++++++++++ Geo/GModelIO_MSH2.cpp | 6 +++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Common/CreateFile.cpp b/Common/CreateFile.cpp index 8dffc51634..6e2eebe069 100644 --- a/Common/CreateFile.cpp +++ b/Common/CreateFile.cpp @@ -257,8 +257,9 @@ void CreateOutputFile(const std::string &fileName, int format, if(GModel::current()->getMeshPartitions().size() && CTX::instance()->mesh.mshFilePartitioned == 1) GModel::current()->writePartitionedMSH - (name, CTX::instance()->mesh.binary, CTX::instance()->mesh.saveAll, - CTX::instance()->mesh.saveParametric, CTX::instance()->mesh.scalingFactor); + (name, CTX::instance()->mesh.mshFileVersion, CTX::instance()->mesh.binary, + CTX::instance()->mesh.saveAll, CTX::instance()->mesh.saveParametric, + CTX::instance()->mesh.scalingFactor); else if(GModel::current()->getMeshPartitions().size() && CTX::instance()->mesh.mshFilePartitioned == 2) GModel::current()->writeMSH diff --git a/Geo/GModel.h b/Geo/GModel.h index ac63db4981..dab2d811dc 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -53,6 +53,9 @@ class GModel double scalingFactor=1.0, int elementStartNum=0, int saveSinglePartition=0, bool multipleView=false); + int _writePartitionedMSH2(const std::string &baseName, bool binary=false, + bool saveAll=false, bool saveParametric=false, + double scalingFactor=1.0); // the maximum vertex and element id number in the mesh int _maxVertexNum, _maxElementNum; @@ -617,9 +620,9 @@ class GModel bool saveAll=false, bool saveParametric=false, double scalingFactor=1.0, int elementStartNum=0, int saveSinglePartition=0, bool multipleView=false); - int writePartitionedMSH(const std::string &baseName, bool binary=false, - bool saveAll=false, bool saveParametric=false, - double scalingFactor=1.0); + int writePartitionedMSH(const std::string &baseName, double version=2.2, + bool binary=false, bool saveAll=false, + bool saveParametric=false, double scalingFactor=1.0); // Iridium file format int writeIR3(const std::string &name, int elementTagType, diff --git a/Geo/GModelIO_MSH.cpp b/Geo/GModelIO_MSH.cpp index 34bf1fe3e2..f8e4f8f922 100644 --- a/Geo/GModelIO_MSH.cpp +++ b/Geo/GModelIO_MSH.cpp @@ -3,6 +3,8 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to the public mailing list <gmsh@geuz.org>. +#include <sstream> +#include <iomanip> #include "GModel.h" #include "OS.h" #include "GmshMessage.h" @@ -607,3 +609,23 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, return 1; } + +int GModel::writePartitionedMSH(const std::string &baseName, double version, + bool binary, bool saveAll, bool saveParametric, + double scalingFactor) +{ + if(version < 3) + return _writePartitionedMSH2(baseName, binary, saveAll, saveParametric, + scalingFactor); + + for(std::set<int>::iterator it = meshPartitions.begin(); + it != meshPartitions.end(); it++){ + int partition = *it; + std::ostringstream sstream; + sstream << baseName << "_" << std::setw(6) << std::setfill('0') << partition; + Msg::Info("Writing partition %d in file '%s'", partition, sstream.str().c_str()); + writeMSH(sstream.str(), version, binary, saveAll, saveParametric, + scalingFactor, 0, partition); + } + return 1; +} diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp index efb40fe9f3..a99fd2f459 100644 --- a/Geo/GModelIO_MSH2.cpp +++ b/Geo/GModelIO_MSH2.cpp @@ -1066,9 +1066,9 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary, return 1; } -int GModel::writePartitionedMSH(const std::string &baseName, bool binary, - bool saveAll, bool saveParametric, - double scalingFactor) +int GModel::_writePartitionedMSH2(const std::string &baseName, bool binary, + bool saveAll, bool saveParametric, + double scalingFactor) { int numElements; int startNum = 0; -- GitLab