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