From 527710825f300def98d4ea354ecca35d07ffcff5 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Tue, 28 Jan 2014 15:11:25 +0000 Subject: [PATCH] write vtu files in subdirectories --- AMDiS/src/io/FileWriter.cc | 24 +++++++++++++++++++----- AMDiS/src/io/FileWriter.h | 3 +++ AMDiS/src/io/FileWriter.hh | 1 + AMDiS/src/io/detail/VtkWriter.cc | 31 ++++++++++++++++++++++++++++--- AMDiS/src/io/detail/VtkWriter.h | 2 ++ 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/AMDiS/src/io/FileWriter.cc b/AMDiS/src/io/FileWriter.cc index 8f2d7c98..7c016bd0 100644 --- a/AMDiS/src/io/FileWriter.cc +++ b/AMDiS/src/io/FileWriter.cc @@ -19,7 +19,9 @@ ******************************************************************************/ -#include "boost/lexical_cast.hpp" +#include +#include + #include "FileWriter.h" #include "Initfile.h" #include "ValueWriter.h" @@ -119,12 +121,23 @@ namespace AMDiS } std::string fn = filename; + + if (createParaViewSubDir) { + using namespace boost::filesystem; + path vtu_path = fn; + path vtu_filename = vtu_path.filename(); + vtu_path.remove_filename() /= vtu_filename.stem(); + create_directory(vtu_path); + vtu_path /= vtu_filename; + fn = vtu_path.string(); + } #if HAVE_PARALLEL_DOMAIN_AMDIS std::string paraFilename = fn; fn += "-p" + boost::lexical_cast(MPI::COMM_WORLD.Get_rank()) + "-"; std::string postfix = ""; #endif + if (appendIndex) { TEST_EXIT(indexLength <= 99)("index lenght > 99\n"); @@ -174,10 +187,11 @@ namespace AMDiS } if (writeParaViewFormat) { + std::string vtu_file = fn + paraviewFileExt; VtkWriter::Aux vtkWriter(&dataCollectors, solutionNames, VtkWriter::Vtuformat(paraViewMode), (paraViewPrecision == 1), writeParaViewVectorFormat); - vtkWriter.writeFile(fn + paraviewFileExt); + vtkWriter.writeFile(vtu_file); #if HAVE_PARALLEL_DOMAIN_AMDIS if (MPI::COMM_WORLD.Get_rank() == 0) { @@ -206,14 +220,14 @@ namespace AMDiS } if (writeParaViewAnimation) { - std::string fn_2 = fn_ + paraviewFileExt; + std::string pvd_file = fn_ + paraviewFileExt; #if HAVE_PARALLEL_DOMAIN_AMDIS - fn_2 = fn_ + paraviewParallelFileExt; + pvd_file = fn_ + paraviewParallelFileExt; if (MPI::COMM_WORLD.Get_rank() == 0) #endif { VtkWriter::detail::updateAnimationFile(adaptInfo, - fn_2, + pvd_file, ¶viewAnimationFrames, filename + ".pvd"); } diff --git a/AMDiS/src/io/FileWriter.h b/AMDiS/src/io/FileWriter.h index 940ed815..e5497574 100644 --- a/AMDiS/src/io/FileWriter.h +++ b/AMDiS/src/io/FileWriter.h @@ -175,6 +175,9 @@ namespace AMDiS { /// 1: extend number of component to 3, so that paraview can display the std::vector as worldstd::vector bool writeAs3dVector; + + /// create a subdirectory where to put the vtu file + bool createParaViewSubDir; /// 0: Don't write ParaView animation file; 1: Write ParaView animation file. int writeParaViewAnimation; diff --git a/AMDiS/src/io/FileWriter.hh b/AMDiS/src/io/FileWriter.hh index e787625e..898b529b 100644 --- a/AMDiS/src/io/FileWriter.hh +++ b/AMDiS/src/io/FileWriter.hh @@ -165,6 +165,7 @@ namespace AMDiS Parameters::get(name + "->ParaView vector format", writeParaViewVectorFormat); Parameters::get(name + "->write vector as 3d vector", writeAs3dVector); Parameters::get(name + "->ParaView animation", writeParaViewAnimation); + Parameters::get(name + "->ParaView create subdirectory", createParaViewSubDir); Parameters::get(name + "->ParaView ext", paraviewFileExt); Parameters::get(name + "->Periodic format", writePeriodicFormat); Parameters::get(name + "->Periodic ext", periodicFileExt); diff --git a/AMDiS/src/io/detail/VtkWriter.cc b/AMDiS/src/io/detail/VtkWriter.cc index cd058bcd..d617bb2c 100644 --- a/AMDiS/src/io/detail/VtkWriter.cc +++ b/AMDiS/src/io/detail/VtkWriter.cc @@ -131,6 +131,32 @@ namespace AMDiS { namespace io { base64.append(writePaddChars,'='); return base64; } + + std::string extract_relative_path(std::string valueFilename, std::string animationFilename) + { + using namespace boost::filesystem; + path vtu_path = valueFilename; + path pvd_path = animationFilename; + + path::iterator it_vtu, it_pvd; + path vtu_path0 = absolute(vtu_path); vtu_path0.remove_filename(); + path pvd_path0 = absolute(pvd_path); pvd_path0.remove_filename(); + + // find matching root directories + for (it_vtu = vtu_path0.begin(), it_pvd = pvd_path0.begin(); + it_vtu != vtu_path0.end() && it_pvd != pvd_path0.end() && *it_vtu == *it_pvd; + it_vtu++, it_pvd++) {} + + // create relative path + path new_vtu_path; + for (; it_pvd != pvd_path0.end(); it_pvd++) + new_vtu_path /= ".."; + for (; it_vtu != vtu_path0.end(); it_vtu++) + new_vtu_path /= *it_vtu; + new_vtu_path /= vtu_path.filename(); + + return new_vtu_path.string(); + } int updateAnimationFile(AdaptInfo *adaptInfo, string valueFilename, @@ -139,9 +165,8 @@ namespace AMDiS { namespace io { { FUNCNAME("updateAnimationFile()"); - size_t found = valueFilename.find_last_of("/\\"); - paraViewAnimationFrames->push_back(make_pair(adaptInfo->getTime(), - valueFilename.substr(found + 1))); + paraViewAnimationFrames->push_back( + make_pair(adaptInfo->getTime(), extract_relative_path(valueFilename, animationFilename))); boost::iostreams::filtering_ostream file; { diff --git a/AMDiS/src/io/detail/VtkWriter.h b/AMDiS/src/io/detail/VtkWriter.h index 062ffd2d..f31a3b2b 100644 --- a/AMDiS/src/io/detail/VtkWriter.h +++ b/AMDiS/src/io/detail/VtkWriter.h @@ -281,6 +281,8 @@ namespace AMDiS { namespace io { std::string base64Encode(std::string text); + std::string extract_relative_path(std::string valueFilename, std::string animationFilename); + /// Adds a new entry to a ParaView animation file. int updateAnimationFile(AdaptInfo *adaptInfo, std::string valueFilename, -- GitLab