vtksequencewriter.hh
00001 #ifndef DUNE_VTKSEQUENCE_HH
00002 #define DUNE_VTKSEQUENCE_HH
00003
00004 #include <dune/grid/io/file/vtk/vtkwriter.hh>
00005
00006 namespace Dune {
00007
00016 template< class GridView >
00017 class VTKSequenceWriter : public VTKWriter<GridView> {
00018 typedef VTKWriter<GridView> BaseType;
00019 typedef VTKSequenceWriter<GridView> ThisType;
00020 std::string name_,path_,extendpath_;
00021 unsigned int count_;
00022 std::ofstream seqFile_;
00023 public:
00024 explicit VTKSequenceWriter ( const GridView &gridView,
00025 const std::string& name,
00026 const std::string& path,
00027 const std::string& extendpath,
00028 VTKOptions::DataMode dm = VTKOptions::conforming )
00029 : BaseType(gridView,dm),
00030 name_(name), path_(path),
00031 extendpath_(extendpath),
00032 count_(0),
00033 seqFile_()
00034 {
00035 if (gridView.comm().rank()==0) {
00036 std::stringstream pvdname;
00037 pvdname << name << ".pvd";
00038 seqFile_.open(pvdname.str().c_str());
00039 seqFile_ << "<?xml version=\"1.0\"?> \n"
00040 << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\"> \n"
00041 << "<Collection> \n" << std::flush;
00042 }
00043 }
00044 ~VTKSequenceWriter() {
00045 if (seqFile_.is_open()) {
00046 seqFile_ << "</Collection> \n"
00047 << "</VTKFile> \n" << std::flush;
00048 }
00049 }
00050 void write (double time,
00051 VTKOptions::OutputType ot = VTKOptions::ascii)
00052 {
00053 std::stringstream name;
00054 name.fill('0');
00055 name << name_ << "-" << std::setw(5) << count_;
00056 std::string pvtuName = BaseType::pwrite(name.str().c_str(),
00057 path_.c_str(),extendpath_.c_str(),ot);
00058 if (seqFile_.is_open()) {
00059 seqFile_ << "<DataSet timestep=\"" << time
00060 << "\" group=\"\" part=\"0\" name=\"\" file=\""
00061 << pvtuName << "\"/> \n" << std::flush;
00062 }
00063 ++count_;
00064 }
00065 private:
00066
00067 void pwrite();
00068 };
00069 }
00070 #endif