Loading [MathJax]/extensions/tex2jax.js
3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_VTKSEQUENCEWRITER_HH
27#define DUMUX_VTKSEQUENCEWRITER_HH
28
29#include <vector>
30#include <iostream>
31#include <sstream>
32#include <fstream>
33#include <iomanip>
34#include <memory>
35
36#include <dune/grid/io/file/vtk/common.hh>
37#include <dune/common/path.hh>
38
39
40namespace Dumux {
41
54 template<class VTKWriter>
56 {
57 std::shared_ptr<VTKWriter > vtkWriter_;
58 std::vector<double> timesteps_;
59 std::string name_,path_,extendpath_;
60 int rank_;
61 int size_;
62 public:
79 explicit VTKSequenceWriter( std::shared_ptr<VTKWriter > vtkWriter,
80 const std::string& name,
81 const std::string& path,
82 const std::string& extendpath,
83 int rank,
84 int size)
85 : vtkWriter_(vtkWriter),
86 name_(name), path_(path),
87 extendpath_(extendpath),
88 rank_(rank),
89 size_(size)
90 {}
91
93
94
100 void write (double time, Dune::VTK::OutputType type = Dune::VTK::ascii)
101 {
102 /* remember current time step */
103 unsigned int count = timesteps_.size();
104 timesteps_.push_back(time);
105
106 /* write VTK file */
107 if(size_==1)
108 vtkWriter_->write(Dune::concatPaths(path_,seqName(count)),type);
109 else
110 vtkWriter_->pwrite(seqName(count), path_,extendpath_,type);
111
112 /* write pvd file ... only on rank 0 */
113 if (rank_==0) {
114 std::ofstream pvdFile;
115 pvdFile.exceptions(std::ios_base::badbit | std::ios_base::failbit |
116 std::ios_base::eofbit);
117 std::string pvdname = name_ + ".pvd";
118 pvdFile.open(pvdname.c_str());
119 pvdFile << "<?xml version=\"1.0\"?> \n"
120 << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << Dune::VTK::getEndiannessString() << "\"> \n"
121 << "<Collection> \n";
122 for (unsigned int i=0; i<=count; i++)
123 {
124 // filename
125 std::string piecepath;
126 std::string fullname;
127 if(size_==1) {
128 piecepath = path_;
129 fullname = vtkWriter_->getSerialPieceName(seqName(i), piecepath);
130 }
131 else {
132 piecepath = Dune::concatPaths(path_, extendpath_);
133 fullname = vtkWriter_->getParallelHeaderName(seqName(i), piecepath, size_);
134 }
135 pvdFile << "<DataSet timestep=\"" << timesteps_[i]
136 << "\" group=\"\" part=\"0\" name=\"\" file=\""
137 << fullname << "\"/> \n";
138 }
139 pvdFile << "</Collection> \n"
140 << "</VTKFile> \n" << std::flush;
141 pvdFile.close();
142 }
143 }
144 private:
145
146 // create sequence name
147 std::string seqName(unsigned int count) const
148 {
149 std::stringstream n;
150 n.fill('0');
151 n << name_ << "-" << std::setw(5) << count;
152 return n.str();
153 }
154 };
155
156} // end namespace Dumux
157
158#endif
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
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:56
~VTKSequenceWriter()
Definition: vtksequencewriter.hh:92
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:79
void write(double time, Dune::VTK::OutputType type=Dune::VTK::ascii)
Writes VTK data for the given time,.
Definition: vtksequencewriter.hh:100