Commit 52771082 authored by Praetorius, Simon's avatar Praetorius, Simon

write vtu files in subdirectories

parent fed1a0df
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
******************************************************************************/ ******************************************************************************/
#include "boost/lexical_cast.hpp" #include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include "FileWriter.h" #include "FileWriter.h"
#include "Initfile.h" #include "Initfile.h"
#include "ValueWriter.h" #include "ValueWriter.h"
...@@ -119,12 +121,23 @@ namespace AMDiS ...@@ -119,12 +121,23 @@ namespace AMDiS
} }
std::string fn = filename; 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 #if HAVE_PARALLEL_DOMAIN_AMDIS
std::string paraFilename = fn; std::string paraFilename = fn;
fn += "-p" + boost::lexical_cast<std::string>(MPI::COMM_WORLD.Get_rank()) + "-"; fn += "-p" + boost::lexical_cast<std::string>(MPI::COMM_WORLD.Get_rank()) + "-";
std::string postfix = ""; std::string postfix = "";
#endif #endif
if (appendIndex) { if (appendIndex) {
TEST_EXIT(indexLength <= 99)("index lenght > 99\n"); TEST_EXIT(indexLength <= 99)("index lenght > 99\n");
...@@ -174,10 +187,11 @@ namespace AMDiS ...@@ -174,10 +187,11 @@ namespace AMDiS
} }
if (writeParaViewFormat) { if (writeParaViewFormat) {
std::string vtu_file = fn + paraviewFileExt;
VtkWriter::Aux vtkWriter(&dataCollectors, VtkWriter::Aux vtkWriter(&dataCollectors,
solutionNames, solutionNames,
VtkWriter::Vtuformat(paraViewMode), (paraViewPrecision == 1), writeParaViewVectorFormat); VtkWriter::Vtuformat(paraViewMode), (paraViewPrecision == 1), writeParaViewVectorFormat);
vtkWriter.writeFile(fn + paraviewFileExt); vtkWriter.writeFile(vtu_file);
#if HAVE_PARALLEL_DOMAIN_AMDIS #if HAVE_PARALLEL_DOMAIN_AMDIS
if (MPI::COMM_WORLD.Get_rank() == 0) { if (MPI::COMM_WORLD.Get_rank() == 0) {
...@@ -206,14 +220,14 @@ namespace AMDiS ...@@ -206,14 +220,14 @@ namespace AMDiS
} }
if (writeParaViewAnimation) { if (writeParaViewAnimation) {
std::string fn_2 = fn_ + paraviewFileExt; std::string pvd_file = fn_ + paraviewFileExt;
#if HAVE_PARALLEL_DOMAIN_AMDIS #if HAVE_PARALLEL_DOMAIN_AMDIS
fn_2 = fn_ + paraviewParallelFileExt; pvd_file = fn_ + paraviewParallelFileExt;
if (MPI::COMM_WORLD.Get_rank() == 0) if (MPI::COMM_WORLD.Get_rank() == 0)
#endif #endif
{ {
VtkWriter::detail::updateAnimationFile(adaptInfo, VtkWriter::detail::updateAnimationFile(adaptInfo,
fn_2, pvd_file,
&paraviewAnimationFrames, &paraviewAnimationFrames,
filename + ".pvd"); filename + ".pvd");
} }
......
...@@ -175,6 +175,9 @@ namespace AMDiS { ...@@ -175,6 +175,9 @@ namespace AMDiS {
/// 1: extend number of component to 3, so that paraview can display the std::vector as worldstd::vector /// 1: extend number of component to 3, so that paraview can display the std::vector as worldstd::vector
bool writeAs3dVector; 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. /// 0: Don't write ParaView animation file; 1: Write ParaView animation file.
int writeParaViewAnimation; int writeParaViewAnimation;
......
...@@ -165,6 +165,7 @@ namespace AMDiS ...@@ -165,6 +165,7 @@ namespace AMDiS
Parameters::get(name + "->ParaView vector format", writeParaViewVectorFormat); Parameters::get(name + "->ParaView vector format", writeParaViewVectorFormat);
Parameters::get(name + "->write vector as 3d vector", writeAs3dVector); Parameters::get(name + "->write vector as 3d vector", writeAs3dVector);
Parameters::get(name + "->ParaView animation", writeParaViewAnimation); Parameters::get(name + "->ParaView animation", writeParaViewAnimation);
Parameters::get(name + "->ParaView create subdirectory", createParaViewSubDir);
Parameters::get(name + "->ParaView ext", paraviewFileExt); Parameters::get(name + "->ParaView ext", paraviewFileExt);
Parameters::get(name + "->Periodic format", writePeriodicFormat); Parameters::get(name + "->Periodic format", writePeriodicFormat);
Parameters::get(name + "->Periodic ext", periodicFileExt); Parameters::get(name + "->Periodic ext", periodicFileExt);
......
...@@ -131,6 +131,32 @@ namespace AMDiS { namespace io { ...@@ -131,6 +131,32 @@ namespace AMDiS { namespace io {
base64.append(writePaddChars,'='); base64.append(writePaddChars,'=');
return base64; 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, int updateAnimationFile(AdaptInfo *adaptInfo,
string valueFilename, string valueFilename,
...@@ -139,9 +165,8 @@ namespace AMDiS { namespace io { ...@@ -139,9 +165,8 @@ namespace AMDiS { namespace io {
{ {
FUNCNAME("updateAnimationFile()"); FUNCNAME("updateAnimationFile()");
size_t found = valueFilename.find_last_of("/\\"); paraViewAnimationFrames->push_back(
paraViewAnimationFrames->push_back(make_pair(adaptInfo->getTime(), make_pair(adaptInfo->getTime(), extract_relative_path(valueFilename, animationFilename)));
valueFilename.substr(found + 1)));
boost::iostreams::filtering_ostream file; boost::iostreams::filtering_ostream file;
{ {
......
...@@ -281,6 +281,8 @@ namespace AMDiS { namespace io { ...@@ -281,6 +281,8 @@ namespace AMDiS { namespace io {
std::string base64Encode(std::string text); 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. /// Adds a new entry to a ParaView animation file.
int updateAnimationFile(AdaptInfo *adaptInfo, int updateAnimationFile(AdaptInfo *adaptInfo,
std::string valueFilename, std::string valueFilename,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment