10#include <dune/grid/io/file/vtk/common.hh>
11#include <dune/common/path.hh>
13#include <dune/grid/io/file/vtk/vtkwriter.hh>
15#include <amdis/Environment.hpp>
26 template <
class Gr
idView>
29 using VTKWriter = Dune::VTKWriter<GridView>;
45 template <
class... Args>
47 :
VTKSequenceWriter<GridView>(std::make_shared<VTKWriter>(gridView, FWD(args)...))
59 template <
class... Args>
62 vtkWriter_->addCellData(FWD(args)...);
66 template <
class... Args>
69 vtkWriter_->addVertexData(FWD(args)...);
78 virtual void write(
double time, std::string
const& name, Dune::VTK::OutputType type = Dune::VTK::ascii)
80 pwrite(time, name,
".",
"", type);
91 virtual void pwrite(
double time, std::string
const& name, std::string
const& path, std::string
const& extendpath,
92 Dune::VTK::OutputType type = Dune::VTK::ascii)
95 unsigned int count = timesteps_.size();
96 timesteps_.push_back(time);
99 vtkWriter_->pwrite(seqName(name, count), Dune::concatPaths(path, extendpath),
"", type);
103 std::ofstream pvdFile;
104 pvdFile.exceptions(std::ios_base::badbit | std::ios_base::failbit |
105 std::ios_base::eofbit);
106 std::string pvdname = path +
"/" + name +
".pvd";
107 pvdFile.open(pvdname.c_str());
108 pvdFile <<
"<?xml version=\"1.0\"?>\n"
109 <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << Dune::VTK::getEndiannessString() <<
"\">\n"
111 for (
unsigned int i = 0; i <= count; ++i) {
112 std::string piecepath = extendpath;
113 std::string fullname = getParallelHeaderName(seqName(name,i), piecepath,
Environment::mpiSize());
114 pvdFile <<
"<DataSet timestep=\"" << timesteps_[i]
115 <<
"\" part=\"0\" file=\""
116 << fullname <<
"\"/>\n";
118 pvdFile <<
"</Collection>\n"
119 <<
"</VTKFile>\n" << std::flush;
126 static std::string seqName(std::string
const& name,
unsigned int count)
130 n << name <<
"-" << std::setw(5) << count;
134 static std::string getParallelHeaderName(std::string
const& name, std::string
const& path,
int commSize)
136 std::ostringstream s;
137 if (path.size() > 0) {
139 if (path[path.size()-1] !=
'/')
142 s <<
's' << std::setw(4) << std::setfill(
'0') << commSize <<
'-';
144 if (GridView::dimension > 1)
152 std::shared_ptr<VTKWriter> vtkWriter_;
153 std::vector<double> timesteps_;
static int mpiSize()
Return the MPI_Size of the group created by Dune::MPIHelper.
Definition: Environment.hpp:74
static int mpiRank()
Return the MPI_Rank of the current processor.
Definition: Environment.hpp:68
class to write pvd-files which contains a list of all collected vtk-files
Definition: VTKSequenceWriter.hpp:28
void addVertexData(Args &&... args)
Adds a field of vertex data to the VTK file.
Definition: VTKSequenceWriter.hpp:67
std::shared_ptr< VTKWriter > const & vtkWriter() const
accessor for the underlying VTKWriter instance
Definition: VTKSequenceWriter.hpp:53
void addCellData(Args &&... args)
Adds a field of cell data to the VTK file.
Definition: VTKSequenceWriter.hpp:60
VTKSequenceWriter(GridView const &gridView, Args &&... args)
Set up the VTKSequenceWriter class by creating a timestep writer of type VTKWriter.
Definition: VTKSequenceWriter.hpp:46
virtual void pwrite(double time, std::string const &name, std::string const &path, std::string const &extendpath, Dune::VTK::OutputType type=Dune::VTK::ascii)
Writes VTK data for the given time,.
Definition: VTKSequenceWriter.hpp:91
VTKSequenceWriter(std::shared_ptr< VTKWriter > vtkWriter)
Set up the VTKSequenceWriter class.
Definition: VTKSequenceWriter.hpp:36
virtual void write(double time, std::string const &name, Dune::VTK::OutputType type=Dune::VTK::ascii)
Writes VTK data for the given time,.
Definition: VTKSequenceWriter.hpp:78