diff --git a/Common/Context.h b/Common/Context.h index 36f6da7ba8c22f952ffc367926f73c0058f7d27f..7fdf57ce184c856b2aa17ac3233549fd03baf066 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -245,7 +245,7 @@ class CTX { struct{ int draw, link, horizontalScales; int smooth, animCycle, animStep, combineTime, combineRemoveOrig; - int fileFormat, plugins, forceNodeData; + int fileFormat, plugins, forceNodeData, forceElementData; double animDelay; std::string graphPointCommand; double graphPointX, graphPointY; diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index af580608d61a1506637bbdb6696a7cdf3c0ad5f3..7e2273b512660e42f191c56a6e72bb6a374545e1 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -1278,6 +1278,8 @@ StringXNumber PostProcessingOptions_Number[] = { { F|O, "CombineRemoveOriginal" , opt_post_combine_remove_orig , 1. , "Remove original views after a Combine operation" }, + { F|O, "ForceElementData" , opt_post_force_element_data , 0. , + "Try to force saving datasets as ElementData" }, { F|O, "ForceNodeData" , opt_post_force_node_data , 0. , "Try to force saving datasets as NodeData" }, { F|O, "Format" , opt_post_file_format , 10. , diff --git a/Common/Options.cpp b/Common/Options.cpp index 818d95368ed24fc8b781c9589e76f55efd1575e9..05253ea7518f5c4254a6aa52314f957ff9c0b3bb 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -6516,6 +6516,13 @@ double opt_post_force_node_data(OPT_ARGS_NUM) return CTX::instance()->post.forceNodeData; } +double opt_post_force_element_data(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX::instance()->post.forceElementData = (int)val; + return CTX::instance()->post.forceElementData; +} + double opt_post_graph_point_x(OPT_ARGS_NUM) { if(action & GMSH_SET) diff --git a/Common/Options.h b/Common/Options.h index 0725eac18441baeeda0055b9ce17dfa9f52583bc..f5d175c128b2afb7824901a971ca285f687432b6 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -542,6 +542,7 @@ double opt_post_plugins(OPT_ARGS_NUM); double opt_post_nb_views(OPT_ARGS_NUM); double opt_post_file_format(OPT_ARGS_NUM); double opt_post_force_node_data(OPT_ARGS_NUM); +double opt_post_force_element_data(OPT_ARGS_NUM); double opt_post_graph_point_x(OPT_ARGS_NUM); double opt_post_graph_point_y(OPT_ARGS_NUM); double opt_view_nb_timestep(OPT_ARGS_NUM); diff --git a/Post/PViewData.h b/Post/PViewData.h index 3bcef8cfea41b96b319e1d3f23d1370faf7165ad..e9e8a45a052da6102ee025c197fef303c6dd9719 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -279,7 +279,7 @@ class PViewData { virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false, bool saveMesh=true, bool multipleView=false, int partitionNum=0, bool saveInterpolationMatrices=true, - bool forceNodeData=false); + bool forceNodeData=false, bool forceElementData=false); virtual bool writeMED(const std::string &fileName); virtual bool toVector(std::vector<std::vector<double> > &vec); virtual bool fromVector(const std::vector<std::vector<double> > &vec); diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index 04965f28adc5e33a9a8c8a3809662463cebcf3cb..3e4e8dfab55eb6ab1892ca6456681849f294c68c 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -254,7 +254,7 @@ class PViewDataGModel : public PViewData { virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false, bool savemesh=true, bool multipleView=false, int partitionNum=0, bool saveInterpolationMatrices=true, - bool forceNodeData=false); + bool forceNodeData=false, bool forceElementData=false); bool readMED(const std::string &fileName, int fileIndex); bool writeMED(const std::string &fileName); void importLists(int N[24], std::vector<double> *V[24]); diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index 1d9f2e29d8a57fda175461f85fda771aa7ff535a..134411cc284f9044c413a0ac93e91a05862762ed 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -135,7 +135,8 @@ bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fi bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool binary, bool saveMesh, bool multipleView, int partitionNum, - bool saveInterpolationMatrices, bool forceNodeData) + bool saveInterpolationMatrices, bool forceNodeData, + bool forceElementData) { if(_steps.empty()) return true; @@ -148,6 +149,10 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool Msg::Warning("Cannot force NodeData for this dataset: saving native data"); } + if(forceElementData && _type != ElementData){ + Msg::Warning("Cannot force ElementData for this dataset: saving native data"); + } + GModel *model = _steps[0]->getModel(); FILE *fp; diff --git a/Post/PViewDataIO.cpp b/Post/PViewDataIO.cpp index 6dda3e731cd9200c8f32defb66e72616c30d8c11..b0ee584571967aaacb8f89a29174fc6e0376518b 100644 --- a/Post/PViewDataIO.cpp +++ b/Post/PViewDataIO.cpp @@ -180,7 +180,8 @@ bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed, bool PViewData::writeMSH(const std::string &fileName, double version, bool binary, bool saveMesh, bool multipleView, int partitionNum, - bool saveInterpolationMatrices, bool forceNodeData) + bool saveInterpolationMatrices, bool forceNodeData, + bool forceElementData) { Msg::Error("MSH export not implemented for this view type"); return false; diff --git a/Post/PViewDataList.h b/Post/PViewDataList.h index b76f8a620f8e0ad68f81ae51cc849dc3de36484b..97c1f74881c71d44b0f7615c0d191388331e71ba 100644 --- a/Post/PViewDataList.h +++ b/Post/PViewDataList.h @@ -129,7 +129,7 @@ class PViewDataList : public PViewData { virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false, bool savemesh=true, bool multipleView=false, int partitionNum=0, bool saveInterpolationMatrices=true, - bool forceNodeData=false); + bool forceNodeData=false, bool forceElementData=false); virtual void importLists(int N[24], std::vector<double> *V[24]); virtual void getListPointers(int N[24], std::vector<double> *V[24]); }; diff --git a/Post/PViewDataListIO.cpp b/Post/PViewDataListIO.cpp index 75ee8bb1fc9d60dadb3705fe4d8409517221f930..2c781b54a7af10462cfbd87a5ba883a205527de6 100644 --- a/Post/PViewDataListIO.cpp +++ b/Post/PViewDataListIO.cpp @@ -544,7 +544,7 @@ static void createElements(std::vector<double> &list, int nbelm, int nbnod, bool PViewDataList::writeMSH(const std::string &fileName, double version, bool binary, bool saveMesh, bool multipleView, int partitionNum, bool saveInterpolationMatrices, - bool forceNodeData) + bool forceNodeData, bool forceElementData) { if(_adaptive){ Msg::Warning("Writing adapted dataset (will only export current time step)"); @@ -615,7 +615,8 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b fprintf(fp, "$EndElements\n"); } - if(saveInterpolationMatrices && haveInterpolationMatrices() && !forceNodeData){ + if(saveInterpolationMatrices && haveInterpolationMatrices() && + !forceNodeData && !forceElementData){ fprintf(fp, "$InterpolationScheme\n"); fprintf(fp, "\"INTERPOLATION_SCHEME\"\n"); fprintf(fp, "%d\n", (int)_interpolation.size()); @@ -640,9 +641,12 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b for(int ts = 0; ts < NbTimeStep; ts++){ if(forceNodeData) fprintf(fp, "$NodeData\n"); + else if(forceElementData) + fprintf(fp, "$ElementData\n"); else fprintf(fp, "$ElementNodeData\n"); - if(saveInterpolationMatrices && haveInterpolationMatrices() && !forceNodeData) + if(saveInterpolationMatrices && haveInterpolationMatrices() && + !forceNodeData && !forceElementData) fprintf(fp, "2\n\"%s\"\n\"INTERPOLATION_SCHEME\"\n", getName().c_str()); else fprintf(fp, "1\n\"%s\"\n", getName().c_str()); @@ -681,14 +685,24 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b int nb = list->size() / *numEle; for(unsigned int i = 0; i < list->size(); i += nb){ double *v = &(*list)[i + 3 * numNodes]; - fprintf(fp, "%d %d", ++n, mult); - for(int j = 0; j < numComponents * mult; j++) - fprintf(fp, " %.16g", v[numComponents * mult * ts + j]); + if(forceElementData){ // just keep first vertex value + fprintf(fp, "%d", ++n); + for(int j = 0; j < numComponents; j++) + fprintf(fp, " %.16g", v[numComponents * mult * ts + j]); + } + else{ + fprintf(fp, "%d %d", ++n, mult); + for(int j = 0; j < numComponents * mult; j++) + fprintf(fp, " %.16g", v[numComponents * mult * ts + j]); + } fprintf(fp, "\n"); } } } - fprintf(fp, "$EndElementNodeData\n"); + if(forceElementData) + fprintf(fp, "$EndElementData\n"); + else + fprintf(fp, "$EndElementNodeData\n"); } } diff --git a/Post/PViewIO.cpp b/Post/PViewIO.cpp index ae0db3543522ce7036709bc96e0f704c62e02de4..96194fbf78b5d8c43ab43a548b8f14f1d0062192 100644 --- a/Post/PViewIO.cpp +++ b/Post/PViewIO.cpp @@ -299,7 +299,8 @@ bool PView::write(const std::string &fileName, int format, bool append) case 4: ret = _data->writeTXT(fileName); break; case 5: ret = _data->writeMSH(fileName, CTX::instance()->mesh.mshFileVersion, CTX::instance()->mesh.binary, true, false, - 0, true, CTX::instance()->post.forceNodeData); break; + 0, true, CTX::instance()->post.forceNodeData, + CTX::instance()->post.forceElementData); break; case 6: ret = _data->writeMED(fileName); break; case 10: { @@ -311,7 +312,8 @@ bool PView::write(const std::string &fileName, int format, bool append) else if(ext == ".msh") ret = _data->writeMSH(fileName, CTX::instance()->mesh.mshFileVersion, CTX::instance()->mesh.binary, true, false, - 0, true, CTX::instance()->post.forceNodeData); + 0, true, CTX::instance()->post.forceNodeData, + CTX::instance()->post.forceElementData); else if(ext == ".med") ret = _data->writeMED(fileName); else