Dune Core Modules (2.3.1)

vtksequencewriter.hh
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
9namespace 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,
30 VTK::DataMode dm = VTK::conforming )
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
Grid view abstract base class.
Definition: gridview.hh:57
const CollectiveCommunication & comm() const
obtain collective communication object
Definition: gridview.hh:232
Writer for the ouput of grid functions in the vtk format.
Definition: vtksequencewriter.hh:20
void write(double time, VTK::OutputType ot=VTK::ascii)
Writes VTK data for the given time.
Definition: vtksequencewriter.hh:42
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:60
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
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
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:40
DataMode
Whether to produce conforming or non-conforming output.
Definition: common.hh:64
std::string concatPaths(const std::string &base, const std::string &p)
concatenate two paths
Definition: path.cc:30
Dune namespace.
Definition: alignment.hh:14
Provides file i/o for the visualization toolkit.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)