FileWriterBase.cpp 1 KB
Newer Older
1
#include "config.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
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
#include "FileWriterBase.hpp"

#include <amdis/AdaptInfo.hpp>
#include <amdis/Initfile.hpp>
#include <amdis/common/Filesystem.hpp>

namespace AMDiS
{

FileWriterBase::FileWriterBase(std::string const& base)
{
  Parameters::get(base + "->filename", filename_);
  Parameters::get(base + "->output directory", dir_);
  Parameters::get(base + "->name", name_);
  Parameters::get(base + "->write every i-th timestep", tsModulo_);
  Parameters::get(base + "->write after timestep", timeModulo_);

  test_exit(dir_ == "." || filesystem::exists(dir_), "Output directory '{}' does not exist!", dir_);
}


bool FileWriterBase::doWrite(AdaptInfo& adaptInfo) const
{
  if (timeModulo_ > 0.0 &&
      lastWriteTime_ > adaptInfo.startTime() &&
      lastWriteTime_ + timeModulo_ > adaptInfo.time() + 0.5*adaptInfo.minTimestep())
    return false;

  else if (tsModulo_ > 0 && adaptInfo.timestepNumber() % tsModulo_ != 0)
    return false;

  lastWriteTime_ = adaptInfo.time();
  return true;
}

} // end namespace AMDiS