pvdwriter.hh 2.27 KB
Newer Older
1
2
3
4
5
6
7
8
#pragma once

#include <iosfwd>
#include <string>
#include <vector>
#include <tuple>

#include <dune/vtk/vtktypes.hh>
9
#include <dune/vtk/filewriter.hh>
10
11
12
13
14
15

namespace Dune
{
  /// File-Writer for ParaView .pvd files
  template <class VtkWriter>
  class PvdWriter
16
      : public FileWriter
17
18
19
  {
    using Self = PvdWriter;

20
    // static_assert(IsVtkWriter<VtkWriter>::value, "Writer must implement the VtkWriterInterface.");
21
22
23
24
25
26
27

  public:
    /// Constructor, creates a VtkWriter with constructor arguments forwarded
    template <class... Args, disableCopyMove<Self,Args...> = 0>
    explicit PvdWriter (Args&&... args)
      : vtkWriter_{std::forward<Args>(args)...}
    {
28
29
      format_ = vtkWriter_.getFormat();
      datatype_ = vtkWriter_.getDatatype();
30
31
    }

32
    /// Write the attached data to the file
33
34
35
36
37
38
39
40
41
42
43
44
    /**
     * Create timestep files for the data associated to the current timestep `time`.
     *
     * \param time  The time value of the written data
     * \param fn  Filename of the file to write to. Is stored in \ref timesteps_.
     * \param writeCollection  Create a collection .pvd file directly
     **/
    void writeTimestep (double time, std::string const& fn, bool writeCollection = true) const;

    /// Writes collection of timesteps to .pvd file.
    // NOTE: requires an aforging call to \ref writeTimestep
    virtual void write (std::string const& fn) const override;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

    /// Attach point data to the writer, \see VtkFunction for possible arguments
    template <class Function, class... Args>
    PvdWriter& addPointData (Function const& fct, Args&&... args)
    {
      vtkWriter_.addPointData(fct, std::forward<Args>(args)...);
      return *this;
    }

    /// Attach cell data to the writer, \see VtkFunction for possible arguments
    template <class Function, class... Args>
    PvdWriter& addCellData (Function const& fct, Args&&... args)
    {
      vtkWriter_.addCellData(fct, std::forward<Args>(args)...);
      return *this;
    }

  protected:
    /// Write a series of vtk files in a .pvd ParaView Data file
64
    void writeFile (std::ofstream& out) const;
65
66
67
68
69

  protected:
    VtkWriter vtkWriter_;
    Vtk::FormatTypes format_;
    Vtk::DataTypes datatype_;
70
71

    mutable std::vector<std::pair<double, std::string>> timesteps_;
72
73
74
75
76
  };

} // end namespace Dune

#include "pvdwriter.impl.hh"