dune-pdelab  2.4.1
pvdwriter.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 #ifndef DUNE_VTK_PVDWRITER_HH
4 #define DUNE_VTK_PVDWRITER_HH
5 
6 #warning dune/pdelab/instationary/pvdwriter.hh and the class PVDWriter are deprecated, please use VTKSequenceWriter or SubsamplingVTKSequenceWriter from dune-grid instead
7 
8 
9 #include <vector>
10 #include <fstream>
11 #include <dune/common/deprecated.hh>
12 #include <dune/grid/io/file/vtk/vtkwriter.hh>
13 #include "onestep.hh"
14 
15 #include <stdlib.h>
16 
17 namespace Dune
18 {
19 
20  template< class GridView, class VTK = VTKWriter<GridView> >
21  class DUNE_DEPRECATED_MSG("Deprecated in DUNE-PDELab 2.4. Please use VTKSequenceWriter from DUNE-Grid instead!") PVDWriter : public VTK
22  {
23  GridView gv;
24  std::string basename;
26  std::string path;
27  std::vector<double> timesteps;
28  Dune::VTK::OutputType outputtype;
29  unsigned int offset;
30 
31  public:
32 
33  PVDWriter(const GridView & gv_, std::string basename_,
34  Dune::VTK::DataMode datamode_ = Dune::VTK::conforming,
35  Dune::VTK::OutputType outputtype_ = Dune::VTK::appendedraw,
36  std::string path_="vtk", unsigned int offset_=0) :
37  VTK(gv_,datamode_), gv(gv_),
38  basename(basename_), fn(basename_,offset_),
39  path(path_), outputtype(outputtype_),
40  offset(offset_){}
41 
42  void write(double time)
43  {
44  /* remember current time step */
45  timesteps.push_back(time);
46  /* make sure the directory exists */
47  // mkdir("vtk", 777);
48  /* write VTK file */
49  VTK::pwrite(fn.getName(),path,"",outputtype);
50  /* write pvd file */
51  std::string pvdname = basename + ".pvd";
52  std::ofstream pvd(pvdname.c_str());
53  //std::cout << "WRITE PVD FILE " << pvdname << std::endl;
54  assert(pvd.is_open());
55  pvd << std::fixed;
56  pvd << "<?xml version=\"1.0\"?>\n"
57  << "<VTKFile type=\"Collection\" version=\"0.1\">\n"
58  << "<Collection>\n";
59  PDELab::FilenameHelper fnloop(basename,offset);
60  for (unsigned int i=0; i<timesteps.size(); i++)
61  {
62  std::string fname = this->getParallelHeaderName(fnloop.getName(), path, gv.comm().size());
63  pvd << " <DataSet timestep=\"" << timesteps[i]
64  << "\" file=\"" << fname << "\"/>\n";
65  fnloop.increment();
66  }
67  pvd << "</Collection>\n"
68  << "</VTKFile>\n";
69  pvd.close();
70 
71  /* increment counter */
72  fn.increment();
73  }
74  };
75 
76 } // end namespace Dune
77 
78 #endif // DUNE_VTK_PVDWRITER_HH
Definition: pvdwriter.hh:21
PVDWriter(const GridView &gv_, std::string basename_, Dune::VTK::DataMode datamode_=Dune::VTK::conforming, Dune::VTK::OutputType outputtype_=Dune::VTK::appendedraw, std::string path_="vtk", unsigned int offset_=0)
Definition: pvdwriter.hh:33
Definition: instationaryfilenamehelper.hh:16
Definition: adaptivity.hh:27
void increment()
Definition: instationaryfilenamehelper.hh:43
const char * getName(int i_)
Definition: instationaryfilenamehelper.hh:31
void write(double time)
Definition: pvdwriter.hh:42
const std::size_t offset
Definition: localfunctionspace.hh:74
Definition: pdelab.hh:436
Definition: vtk.hh:32