6#ifndef DUNE_GRID_IO_FILE_VTK_VTKSEQUENCEWRITERBASE_HH
7#define DUNE_GRID_IO_FILE_VTK_VTKSEQUENCEWRITERBASE_HH
17#include <dune/common/path.hh>
32 template<
class Gr
idView>
35 std::shared_ptr<VTKWriter<GridView> > vtkWriter_;
36 std::vector<double> timesteps_;
37 std::string name_,path_,extendpath_;
48 const std::string& name,
49 const std::string& path,
50 const std::string& extendpath,
54 name_(name), path_(path),
55 extendpath_(extendpath),
63 const std::shared_ptr< VTKWriter<GridView> >&
vtkWriter()
const
71 vtkWriter_->addCellData(p);
80 void addCellData (
const V &v,
const std::string &name,
int ncomps=1)
82 vtkWriter_->addCellData(v, name, ncomps);
88 vtkWriter_->addVertexData(p);
99 vtkWriter_->addVertexData(v, name, ncomps);
111 unsigned int count = timesteps_.size();
112 timesteps_.push_back(time);
116 vtkWriter_->write(concatPaths(path_,seqName(count)),type);
118 vtkWriter_->pwrite(seqName(count), path_,extendpath_,type);
122 std::ofstream pvdFile;
123 pvdFile.exceptions(std::ios_base::badbit | std::ios_base::failbit |
124 std::ios_base::eofbit);
125 std::string pvdname = name_ +
".pvd";
126 pvdFile.open(pvdname.c_str());
127 pvdFile <<
"<?xml version=\"1.0\"?> \n"
129 <<
"<Collection> \n";
130 for (
unsigned int i=0; i<=count; i++)
133 std::string piecepath;
134 std::string fullname;
137 fullname = vtkWriter_->getSerialPieceName(seqName(i), piecepath);
140 piecepath = concatPaths(path_, extendpath_);
141 fullname = vtkWriter_->getParallelHeaderName(seqName(i), piecepath, size_);
143 pvdFile <<
"<DataSet timestep=\"" << timesteps_[i]
144 <<
"\" group=\"\" part=\"0\" name=\"\" file=\""
145 << fullname <<
"\"/> \n";
147 pvdFile <<
"</Collection> \n"
148 <<
"</VTKFile> \n" << std::flush;
176 timesteps_ = timesteps;
182 std::string seqName(
unsigned int count)
const
186 n << name_ <<
"-" << std::setw(5) << count;
Provides file i/o for the visualization toolkit.
Common stuff for the VTKWriter.
Include standard header files.
Definition: agrid.hh:60
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:43
@ ascii
Output to the file is in ascii.
Definition: common.hh:45
std::string getEndiannessString()
determine endianness of this C++ implementation
Definition: common.hh:232
A base class for grid functions with any return type and dimension.
Definition: function.hh:42
Base class to write pvd-files which contains a list of all collected vtk-files.
Definition: vtksequencewriterbase.hh:34
void addVertexData(const V &v, const std::string &name, int ncomps=1)
Adds a field of vertex data to the VTK file.
Definition: vtksequencewriterbase.hh:97
const std::vector< double > & getTimeSteps() const
Retrieve the current list of time steps.
Definition: vtksequencewriterbase.hh:164
const std::shared_ptr< VTKWriter< GridView > > & vtkWriter() const
Definition: vtksequencewriterbase.hh:63
void write(double time, VTK::OutputType type=VTK::ascii)
Writes VTK data for the given time,.
Definition: vtksequencewriterbase.hh:108
void addVertexData(const std::shared_ptr< const typename VTKWriter< GridView >::VTKFunction > &p)
Adds a field of vertex data to the VTK file.
Definition: vtksequencewriterbase.hh:86
void addCellData(const V &v, const std::string &name, int ncomps=1)
Adds a field of cell data to the VTK file.
Definition: vtksequencewriterbase.hh:80
VTKSequenceWriterBase(std::shared_ptr< VTKWriter< GridView > > vtkWriter, const std::string &name, const std::string &path, const std::string &extendpath, int rank, int size)
Set up the VTKSequenceWriterBase class.
Definition: vtksequencewriterbase.hh:47
void addCellData(const std::shared_ptr< const typename VTKWriter< GridView >::VTKFunction > &p)
Adds a field of cell data to the VTK file.
Definition: vtksequencewriterbase.hh:69
void setTimeSteps(const std::vector< double > ×teps)
Set the current list of time steps.
Definition: vtksequencewriterbase.hh:174
void clear()
Clears all VTK data added to the VTK writer.
Definition: vtksequencewriterbase.hh:156
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:95