dune-grid  2.3.1-rc1
vtksequencewriter.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 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  std::vector<double> timesteps_;
25  public:
26  explicit VTKSequenceWriter ( const GridView &gridView,
27  const std::string& name,
28  const std::string& path,
29  const std::string& extendpath,
31  : BaseType(gridView,dm),
32  name_(name), path_(path),
33  extendpath_(extendpath)
34  {}
36 
42  void write (double time, VTK::OutputType ot = VTK::ascii)
43  {
44  /* remember current time step */
45  unsigned int count = timesteps_.size();
46  timesteps_.push_back(time);
47 
48  /* make sure the directory exists */
49  // mkdir("vtk", 777);
50 
51  /* write VTK file */
52  std::string pvtuName = BaseType::pwrite(seqName(count), path_,extendpath_,ot);
53 
54  /* write pvd file ... only on rank 0 */
55  if (this->gridView_.comm().rank()==0) {
56  std::ofstream pvdFile;
57  pvdFile.exceptions(std::ios_base::badbit | std::ios_base::failbit |
58  std::ios_base::eofbit);
59  std::string pvdname = name_ + ".pvd";
60  pvdFile.open(pvdname.c_str());
61  pvdFile << "<?xml version=\"1.0\"?> \n"
62  << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\"> \n"
63  << "<Collection> \n";
64  for (unsigned int i=0; i<=count; i++)
65  {
66  // filename
67  std::string piecepath = concatPaths(path_, extendpath_);
68  std::string fullname =
69  this->getParallelPieceName(seqName(i), piecepath,
70  this->gridView_.comm().rank(),
71  this->gridView_.comm().size());
72  pvdFile << "<DataSet timestep=\"" << timesteps_[i]
73  << "\" group=\"\" part=\"0\" name=\"\" file=\""
74  << fullname << "\"/> \n";
75  }
76  pvdFile << "</Collection> \n"
77  << "</VTKFile> \n" << std::flush;
78  pvdFile.close();
79  }
80  }
81  private:
82 
83  // create sequence name
84  std::string seqName(unsigned int count) const
85  {
86  std::stringstream n;
87  n.fill('0');
88  n << name_ << "-" << std::setw(5) << count;
89  return n.str();
90  }
91 
92  // do not inherit pwrite
93  void pwrite();
94  };
95 
96 } // end namespace Dune
97 
98 #endif
GridView gridView_
Definition: vtkwriter.hh:1072
Writer for the ouput of grid functions in the vtk format.Writes arbitrary grid functions (living on c...
Definition: vtkwriter.hh:60
VTKSequenceWriter(const GridView &gridView, const std::string &name, const std::string &path, const std::string &extendpath, VTK::DataMode dm=VTK::conforming)
Definition: vtksequencewriter.hh:26
Output to the file is in ascii.
Definition: common.hh:42
void write(double time, VTK::OutputType ot=VTK::ascii)
Writes VTK data for the given time.
Definition: vtksequencewriter.hh:42
Provides file i/o for the visualization toolkit.
Writer for the ouput of grid functions in the vtk format.Writes arbitrary grid functions (living on c...
Definition: vtksequencewriter.hh:20
Grid view abstract base classInterface class for a view on grids. Grids return two types of view...
Definition: common/gridview.hh:56
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:40
Output conforming data.
Definition: common.hh:70
DataMode
Whether to produce conforming or non-conforming output.
Definition: common.hh:64
~VTKSequenceWriter()
Definition: vtksequencewriter.hh:35
const CollectiveCommunication & comm() const
obtain collective communication object
Definition: common/gridview.hh:232
std::string pwrite(const std::string &name, const std::string &path, const std::string &extendpath, VTK::OutputType type=VTK::ascii)
write output (interface might change later)
Definition: vtkwriter.hh:515
std::string getParallelPieceName(const std::string &name, const std::string &path, int commRank, int commSize) const
return name of a parallel piece file
Definition: vtkwriter.hh:534