4#ifndef DUNE_GRID_IO_FILE_VTK_VTKSEQUENCEWRITERBASE_HH
5#define DUNE_GRID_IO_FILE_VTK_VTKSEQUENCEWRITERBASE_HH
15#include <dune/common/path.hh>
30 template<
class Gr
idView>
33 std::shared_ptr<VTKWriter<GridView> > vtkWriter_;
34 std::vector<double> timesteps_;
35 std::string name_,path_,extendpath_;
46 const std::string& name,
47 const std::string& path,
48 const std::string& extendpath,
52 name_(name), path_(path),
53 extendpath_(extendpath),
61 const std::shared_ptr< VTKWriter<GridView> >&
vtkWriter()
const
69 vtkWriter_->addCellData(p);
78 void addCellData (
const V &v,
const std::string &name,
int ncomps=1)
80 vtkWriter_->addCellData(v, name, ncomps);
86 vtkWriter_->addVertexData(p);
97 vtkWriter_->addVertexData(v, name, ncomps);
109 unsigned int count = timesteps_.size();
110 timesteps_.push_back(time);
114 vtkWriter_->write(concatPaths(path_,seqName(count)),type);
116 vtkWriter_->pwrite(seqName(count), path_,extendpath_,type);
120 std::ofstream pvdFile;
121 pvdFile.exceptions(std::ios_base::badbit | std::ios_base::failbit |
122 std::ios_base::eofbit);
123 std::string pvdname = name_ +
".pvd";
124 pvdFile.open(pvdname.c_str());
125 pvdFile <<
"<?xml version=\"1.0\"?> \n"
127 <<
"<Collection> \n";
128 for (
unsigned int i=0; i<=count; i++)
131 std::string piecepath;
132 std::string fullname;
135 fullname = vtkWriter_->getSerialPieceName(seqName(i), piecepath);
138 piecepath = concatPaths(path_, extendpath_);
139 fullname = vtkWriter_->getParallelHeaderName(seqName(i), piecepath, size_);
141 pvdFile <<
"<DataSet timestep=\"" << timesteps_[i]
142 <<
"\" group=\"\" part=\"0\" name=\"\" file=\""
143 << fullname <<
"\"/> \n";
145 pvdFile <<
"</Collection> \n"
146 <<
"</VTKFile> \n" << std::flush;
174 timesteps_ = timesteps;
180 std::string seqName(
unsigned int count)
const
184 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:58
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:41
@ ascii
Output to the file is in ascii.
Definition: common.hh:43
std::string getEndiannessString()
determine endianness of this C++ implementation
Definition: common.hh:230
A base class for grid functions with any return type and dimension.
Definition: function.hh:40
Base class to write pvd-files which contains a list of all collected vtk-files.
Definition: vtksequencewriterbase.hh:32
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:95
const std::vector< double > & getTimeSteps() const
Retrieve the current list of time steps.
Definition: vtksequencewriterbase.hh:162
const std::shared_ptr< VTKWriter< GridView > > & vtkWriter() const
Definition: vtksequencewriterbase.hh:61
void write(double time, VTK::OutputType type=VTK::ascii)
Writes VTK data for the given time,.
Definition: vtksequencewriterbase.hh:106
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:84
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:78
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:45
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:67
void setTimeSteps(const std::vector< double > ×teps)
Set the current list of time steps.
Definition: vtksequencewriterbase.hh:172
void clear()
Clears all VTK data added to the VTK writer.
Definition: vtksequencewriterbase.hh:154
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:93