FileWriterBase.hpp 2.17 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once

#include <limits>
#include <string>

namespace AMDiS
{
  // forward declaration
  class AdaptInfo;

  /// Interface class for filewriters
  class FileWriterInterface
  {
  public:
    /// Virtual destructor
    virtual ~FileWriterInterface() = default;

    /// Pure virtual method to be implemented by derived classes
    virtual void write(AdaptInfo& adaptInfo, bool force) = 0;
  };

  /// \brief Base class for filewriters
  /**
   * Read parameters common for all filewriters, where `BASE` is given by the
   * constructor parameter `base`:
   * - `[BASE]->filename`:  Base name of the filename, not including the file extension
   * - `[BASE]->output directory`: Directory where to put the files
   * - `[BASE]->name`:  Name of the data vector in the output file
   * - `[BASE]->write every i-th timestep`:  Timestep number interval.
   * - `[BASE]->write after timestep`:  Time interval.
   *
   * Some other parameters found in some filewriter implementations:
   * - `[BASE]->mode`:  File mode, either ASCII=0, BINARY=1, or COMPRESSED=2
   * - `[BASE]->precision`:  Output precision, either FLOAT=0, DOUBLE=1
   * - `[BASE]->animation`:  Write animation files, or append the timestep to the filename.
   **/
  class FileWriterBase
      : public FileWriterInterface
  {
  public:
    /// Constructor. Reads common parameters.
    FileWriterBase(std::string const& base);

    /// Return whether to write the current timestep or not
    bool doWrite(AdaptInfo& adaptInfo) const;

  public:
    std::string const& filename() const
    {
      return filename_;
    }

    std::string const& dir() const
    {
      return dir_;
    }

    std::string const& name() const
    {
      return name_;
    }

  protected:
    /// Base part of output filename
    std::string filename_ = "solution";

    /// Output directory
    std::string dir_ = ".";

    /// Name of the data
    std::string name_ = "solution";

    /// Write every i'th timestep
    int tsModulo_ = 0;

    /// Write after every time interval
    double timeModulo_ = 0.0;

  private:
    // time counter for the interval output
    mutable double lastWriteTime_ = std::numeric_limits<double>::lowest();
  };

} // end namespace AMDiS