3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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:
10#ifndef DUMUX_VTKSEQUENCEWRITER_HH
11#define DUMUX_VTKSEQUENCEWRITER_HH
12
13#include <vector>
14#include <iostream>
15#include <sstream>
16#include <fstream>
17#include <iomanip>
18#include <memory>
19
20#include <dune/grid/io/file/vtk/common.hh>
21#include <dune/common/path.hh>
22
23
24namespace Dumux {
25
38 template<class VTKWriter>
40 {
41 std::shared_ptr<VTKWriter > vtkWriter_;
42 std::vector<double> timesteps_;
43 std::string name_,path_,extendpath_;
44 int rank_;
45 int size_;
46 public:
63 explicit VTKSequenceWriter( std::shared_ptr<VTKWriter > vtkWriter,
64 const std::string& name,
65 const std::string& path,
66 const std::string& extendpath,
67 int rank,
68 int size)
69 : vtkWriter_(vtkWriter),
70 name_(name), path_(path),
71 extendpath_(extendpath),
72 rank_(rank),
73 size_(size)
74 {}
75
77
78
84 void write (double time, Dune::VTK::OutputType type = Dune::VTK::ascii)
85 {
86 /* remember current time step */
87 unsigned int count = timesteps_.size();
88 timesteps_.push_back(time);
89
90 /* write VTK file */
91 if(size_==1)
92 vtkWriter_->write(Dune::concatPaths(path_,seqName(count)),type);
93 else
94 vtkWriter_->pwrite(seqName(count), path_,extendpath_,type);
95
96 /* write pvd file ... only on rank 0 */
97 if (rank_==0) {
98 std::ofstream pvdFile;
99 pvdFile.exceptions(std::ios_base::badbit | std::ios_base::failbit |
100 std::ios_base::eofbit);
101 std::string pvdname = name_ + ".pvd";
102 pvdFile.open(pvdname.c_str());
103 pvdFile << "<?xml version=\"1.0\"?> \n"
104 << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << Dune::VTK::getEndiannessString() << "\"> \n"
105 << "<Collection> \n";
106 for (unsigned int i=0; i<=count; i++)
107 {
108 // filename
109 std::string piecepath;
110 std::string fullname;
111 if(size_==1) {
112 piecepath = path_;
113 fullname = vtkWriter_->getSerialPieceName(seqName(i), piecepath);
114 }
115 else {
116 piecepath = Dune::concatPaths(path_, extendpath_);
117 fullname = vtkWriter_->getParallelHeaderName(seqName(i), piecepath, size_);
118 }
119 pvdFile << "<DataSet timestep=\"" << timesteps_[i]
120 << "\" group=\"\" part=\"0\" name=\"\" file=\""
121 << fullname << "\"/> \n";
122 }
123 pvdFile << "</Collection> \n"
124 << "</VTKFile> \n" << std::flush;
125 pvdFile.close();
126 }
127 }
128 private:
129
130 // create sequence name
131 std::string seqName(unsigned int count) const
132 {
133 std::stringstream n;
134 n.fill('0');
135 n << name_ << "-" << std::setw(5) << count;
136 return n.str();
137 }
138 };
139
140} // end namespace Dumux
141
142#endif
Definition: adapt.hh:29
Base class to write pvd-files which contains a list of all collected vtk-files. This is a modified ve...
Definition: vtksequencewriter.hh:40
~VTKSequenceWriter()
Definition: vtksequencewriter.hh:76
VTKSequenceWriter(std::shared_ptr< VTKWriter > vtkWriter, const std::string &name, const std::string &path, const std::string &extendpath, int rank, int size)
Set up the VTKSequenceWriter class.
Definition: vtksequencewriter.hh:63
void write(double time, Dune::VTK::OutputType type=Dune::VTK::ascii)
Writes VTK data for the given time,.
Definition: vtksequencewriter.hh:84