dune-grid  2.2.0
vtksequencewriter.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_VTKSEQUENCE_HH
5 #define DUNE_VTKSEQUENCE_HH
6 
8 
9 namespace Dune {
10 
19 template< class GridView >
20 class VTKSequenceWriter : public VTKWriter<GridView> {
23  std::string name_,path_,extendpath_;
24  unsigned int count_;
25  std::ofstream seqFile_;
26  public:
27  explicit VTKSequenceWriter ( const GridView &gridView,
28  const std::string& name,
29  const std::string& path,
30  const std::string& extendpath,
32  : BaseType(gridView,dm),
33  name_(name), path_(path),
34  extendpath_(extendpath),
35  count_(0),
36  seqFile_()
37  {
38  if (gridView.comm().rank()==0) {
39  std::stringstream pvdname;
40  pvdname << name << ".pvd";
41  seqFile_.open(pvdname.str().c_str());
42  seqFile_ << "<?xml version=\"1.0\"?> \n"
43  << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\"> \n"
44  << "<Collection> \n" << std::flush;
45  }
46  }
48  if (seqFile_.is_open()) {
49  seqFile_ << "</Collection> \n"
50  << "</VTKFile> \n" << std::flush;
51  }
52  }
53  void write (double time, VTK::OutputType ot = VTK::ascii)
54  {
55  std::stringstream name;
56  name.fill('0');
57  name << name_ << "-" << std::setw(5) << count_;
58  std::string pvtuName = BaseType::pwrite(name.str().c_str(),
59  path_.c_str(),extendpath_.c_str(),ot);
60  if (seqFile_.is_open()) {
61  seqFile_ << "<DataSet timestep=\"" << time
62  << "\" group=\"\" part=\"0\" name=\"\" file=\""
63  << pvtuName << "\"/> \n" << std::flush;
64  }
65  ++count_;
66  }
67  private:
68  // do not inherite pwrite
69  void pwrite();
70  };
71 }
72 #endif