From 48e6a546432a06cae726f873e6e2acc32e9113fb Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Thu, 20 Jun 2019 23:13:33 +0200 Subject: [PATCH 1/5] change output format for vtk files to allow parallel writes --- src/amdis/FileWriter.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/amdis/FileWriter.hpp b/src/amdis/FileWriter.hpp index d45a086e..f2d345a2 100644 --- a/src/amdis/FileWriter.hpp +++ b/src/amdis/FileWriter.hpp @@ -86,9 +86,12 @@ namespace AMDiS vtkWriter_ = std::make_shared>(gridView()); if (animation_) - vtkSeqWriter_ = std::make_shared>(vtkWriter_, filename_, dir_, ""); + vtkSeqWriter_ = std::make_shared>(vtkWriter_, filename_, dir_, "data"); vtkWriter_->addVertexData(discreteFct_, Dune::VTK::FieldInfo(name_, VTKFieldType, VTKFieldSize)); + + test_exit(dir_ == "." || filesystem::exists(dir_), "Output directory '{}' does not exist!",dir_); + filesystem::create_directories(dir_ + "/data"); } void init(std::string const&, tag::unknown) {} @@ -96,12 +99,10 @@ namespace AMDiS /// Implements \ref FileWriterInterface::writeFiles void writeFiles(AdaptInfo& adaptInfo, bool force) override { - test_exit(dir_ == "." || filesystem::exists(dir_), "Output directory '{}' does not exist!",dir_); - if (vtkSeqWriter_) vtkSeqWriter_->write(adaptInfo.time(), mode_); else if (vtkWriter_) - vtkWriter_->write(filesystem::path({dir_, filename_}).string(), mode_); + vtkWriter_->pwrite(filename_, dir_, "data", mode_); } protected: -- GitLab From c526c8b63d8f0653886f02adef2db85d68e4d951 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 24 Jun 2019 12:42:39 +0200 Subject: [PATCH 2/5] add vtk sequence writer and modified the default filewriter settings accordingly --- src/amdis/CMakeLists.txt | 1 + src/amdis/FileWriter.hpp | 13 +-- src/amdis/io/CMakeLists.txt | 3 + src/amdis/io/VTKSequenceWriter.hpp | 154 +++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+), 6 deletions(-) create mode 100644 src/amdis/io/CMakeLists.txt create mode 100644 src/amdis/io/VTKSequenceWriter.hpp diff --git a/src/amdis/CMakeLists.txt b/src/amdis/CMakeLists.txt index 1237bbc9..261e70af 100644 --- a/src/amdis/CMakeLists.txt +++ b/src/amdis/CMakeLists.txt @@ -71,6 +71,7 @@ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/amdis) add_subdirectory("common") add_subdirectory("functions") add_subdirectory("gridfunctions") +add_subdirectory("io") add_subdirectory("linearalgebra") add_subdirectory("localoperators") add_subdirectory("operations") diff --git a/src/amdis/FileWriter.hpp b/src/amdis/FileWriter.hpp index d45a086e..50ee4bb5 100644 --- a/src/amdis/FileWriter.hpp +++ b/src/amdis/FileWriter.hpp @@ -5,8 +5,7 @@ #include #include -#include -//#include +#include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include namespace AMDiS { @@ -86,7 +86,7 @@ namespace AMDiS vtkWriter_ = std::make_shared>(gridView()); if (animation_) - vtkSeqWriter_ = std::make_shared>(vtkWriter_, filename_, dir_, ""); + vtkSeqWriter_ = std::make_shared>(vtkWriter_); vtkWriter_->addVertexData(discreteFct_, Dune::VTK::FieldInfo(name_, VTKFieldType, VTKFieldSize)); } @@ -97,11 +97,12 @@ namespace AMDiS void writeFiles(AdaptInfo& adaptInfo, bool force) override { test_exit(dir_ == "." || filesystem::exists(dir_), "Output directory '{}' does not exist!",dir_); + filesystem::create_directories(dir_ + "/_piecefiles"); if (vtkSeqWriter_) - vtkSeqWriter_->write(adaptInfo.time(), mode_); + vtkSeqWriter_->pwrite(adaptInfo.time(), filename_, dir_, "_piecefiles", mode_); else if (vtkWriter_) - vtkWriter_->write(filesystem::path({dir_, filename_}).string(), mode_); + vtkWriter_->pwrite(filename_, dir_, "_piecefiles", mode_); } protected: @@ -114,7 +115,7 @@ namespace AMDiS DiscreteFunction discreteFct_; std::shared_ptr> vtkWriter_; - std::shared_ptr> vtkSeqWriter_; + std::shared_ptr> vtkSeqWriter_; // write .pvd if animation=true, otherwise write only .vtu bool animation_; diff --git a/src/amdis/io/CMakeLists.txt b/src/amdis/io/CMakeLists.txt new file mode 100644 index 00000000..09203370 --- /dev/null +++ b/src/amdis/io/CMakeLists.txt @@ -0,0 +1,3 @@ +install(FILES + VtkSequenceWriter.hpp +DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/amdis/io) diff --git a/src/amdis/io/VTKSequenceWriter.hpp b/src/amdis/io/VTKSequenceWriter.hpp new file mode 100644 index 00000000..e8be67ce --- /dev/null +++ b/src/amdis/io/VTKSequenceWriter.hpp @@ -0,0 +1,154 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace AMDiS +{ + /// \brief class to write pvd-files which contains a list of all collected vtk-files + /** + * Write pvd-file suitable for easy visualization with + * The Visualization Toolkit (VTK). + * + * \tparam GridView Grid view of the grid we are writing + */ + template + class VTKSequenceWriter + { + using VTKWriter = Dune::VTKWriter; + + public: + /// \brief Set up the VTKSequenceWriter class + /** + * \param vtkWriter Writer object used to write the individual time step data files + */ + VTKSequenceWriter(std::shared_ptr vtkWriter) + : vtkWriter_(std::move(vtkWriter)) + {} + + /// \brief Set up the VTKSequenceWriter class by creating a timestep writer of type \ref VTKWriter + /** + * \param gridView GridView object passed to the constructor of the VTKWriter + * \param args... Additional arguments forwarded to the VTKWriter constructor. + */ + template + VTKSequenceWriter(GridView const& gridView, Args&&... args) + : VTKSequenceWriter(std::make_shared(gridView, FWD(args)...)) + {} + + + /// accessor for the underlying VTKWriter instance + std::shared_ptr const& vtkWriter() const + { + return vtkWriter_; + } + + /// \brief Adds a field of cell data to the VTK file + template + void addCellData(Args&&... args) + { + vtkWriter_->addCellData(FWD(args)...); + } + + /// \brief Adds a field of vertex data to the VTK file + template + void addVertexData (Args&&... args) + { + vtkWriter_->addVertexData(FWD(args)...); + } + + /// \brief Writes VTK data for the given time, + /** + * \param time The time(step) for the data to be written. + * \param name The basename of the .pvd file (without file extension) + * \param type VTK output type. + */ + virtual void write(double time, std::string const& name, Dune::VTK::OutputType type = Dune::VTK::ascii) + { + pwrite(time, name, ".", "", type); + } + + /// \brief Writes VTK data for the given time, + /** + * \param time The time(step) for the data to be written. + * \param name The basename of the .pvd file (without file extension) + * \param path The directory where to put the .pvd file + * \param extendpath The (relative) subdirectory to path, where to put the timestep files + * \param type VTK output type. + */ + virtual void pwrite(double time, std::string const& name, std::string const& path, std::string const& extendpath, + Dune::VTK::OutputType type = Dune::VTK::ascii) + { + // remember current time step + unsigned int count = timesteps_.size(); + timesteps_.push_back(time); + + // write VTK file + vtkWriter_->pwrite(seqName(name, count), Dune::concatPaths(path, extendpath), "", type); + + // write pvd file ... only on rank 0 + if (Environment::mpiRank() == 0) { + std::ofstream pvdFile; + pvdFile.exceptions(std::ios_base::badbit | std::ios_base::failbit | + std::ios_base::eofbit); + std::string pvdname = path + "/" + name + ".pvd"; + pvdFile.open(pvdname.c_str()); + pvdFile << "\n" + << "\n" + << "\n"; + for (unsigned int i = 0; i <= count; ++i) { + std::string piecepath = extendpath; + std::string fullname = getParallelHeaderName(seqName(name,i), piecepath, Environment::mpiSize()); + pvdFile << "\n"; + } + pvdFile << "\n" + << "\n" << std::flush; + pvdFile.close(); + } + } + + protected: + // create sequence name + static std::string seqName(std::string const& name, unsigned int count) + { + std::stringstream n; + n.fill('0'); + n << name << "-" << std::setw(5) << count; + return n.str(); + } + + static std::string getParallelHeaderName(std::string const& name, std::string const& path, int commSize) + { + std::ostringstream s; + if (path.size() > 0) { + s << path; + if (path[path.size()-1] != '/') + s << '/'; + } + s << 's' << std::setw(4) << std::setfill('0') << commSize << '-'; + s << name; + if (GridView::dimension > 1) + s << ".pvtu"; + else + s << ".pvtp"; + return s.str(); + } + + private: + std::shared_ptr vtkWriter_; + std::vector timesteps_; + }; + +} // end namespace AMDiS + -- GitLab From a9ce4406943db7951b8fa6ba42b6b7ad8c4cb258 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 24 Jun 2019 13:14:56 +0200 Subject: [PATCH 3/5] removed initfiles from tests --- test/CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ef3cfe35..6ef4b43b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,8 +28,7 @@ dune_add_test(SOURCES DOFVectorTest.cpp LINK_LIBRARIES amdis) dune_add_test(SOURCES DiscreteFunctionTest.cpp - LINK_LIBRARIES amdis - CMD_ARGS "${CMAKE_SOURCE_DIR}/examples/init/ellipt.dat.2d") + LINK_LIBRARIES amdis) dune_add_test(SOURCES ExpressionsTest.cpp LINK_LIBRARIES amdis) @@ -65,8 +64,7 @@ dune_add_test(SOURCES ISTLCommTest.cpp CMAKE_GUARD "MPI_FOUND AND dune-istl_FOUND") dune_add_test(SOURCES IntegrateTest.cpp - LINK_LIBRARIES amdis - CMD_ARGS "${CMAKE_SOURCE_DIR}/examples/init/ellipt.dat.2d") + LINK_LIBRARIES amdis) dune_add_test(SOURCES MarkerTest.cpp LINK_LIBRARIES amdis) -- GitLab From fb04f146d5c209be57bb5e5ae5f36f81658d29eb Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 24 Jun 2019 13:44:49 +0200 Subject: [PATCH 4/5] correct merge error --- src/amdis/FileWriter.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/amdis/FileWriter.hpp b/src/amdis/FileWriter.hpp index 512f70bb..22ed7404 100644 --- a/src/amdis/FileWriter.hpp +++ b/src/amdis/FileWriter.hpp @@ -91,7 +91,6 @@ namespace AMDiS vtkWriter_->addVertexData(discreteFct_, Dune::VTK::FieldInfo(name_, VTKFieldType, VTKFieldSize)); test_exit(dir_ == "." || filesystem::exists(dir_), "Output directory '{}' does not exist!",dir_); - filesystem::create_directories(dir_ + "/data"); } void init(std::string const&, tag::unknown) {} @@ -99,9 +98,7 @@ namespace AMDiS /// Implements \ref FileWriterInterface::writeFiles void writeFiles(AdaptInfo& adaptInfo, bool force) override { - test_exit(dir_ == "." || filesystem::exists(dir_), "Output directory '{}' does not exist!",dir_); filesystem::create_directories(dir_ + "/_piecefiles"); - if (vtkSeqWriter_) vtkSeqWriter_->pwrite(adaptInfo.time(), filename_, dir_, "_piecefiles", mode_); else if (vtkWriter_) -- GitLab From ac7e15fe4f8672aaeb7dd9d3a84925f3bc00d57b Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Wed, 21 Aug 2019 13:09:21 +0200 Subject: [PATCH 5/5] extracted VTKSequenceWriter from feature/petsc_backend branch --- src/amdis/io/VTKSequenceWriter.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/amdis/io/VTKSequenceWriter.hpp b/src/amdis/io/VTKSequenceWriter.hpp index e8be67ce..3311ecda 100644 --- a/src/amdis/io/VTKSequenceWriter.hpp +++ b/src/amdis/io/VTKSequenceWriter.hpp @@ -45,6 +45,7 @@ namespace AMDiS : VTKSequenceWriter(std::make_shared(gridView, FWD(args)...)) {} + virtual ~VTKSequenceWriter() = default; /// accessor for the underlying VTKWriter instance std::shared_ptr const& vtkWriter() const -- GitLab