dune-vtk 2.12
Loading...
Searching...
No Matches
timeserieswriter.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <optional>
5#include <string>
6#include <tuple>
7#include <vector>
8
10#include <dune/vtk/types.hh>
13
14namespace Dune::Vtk
15{
17
22 template <class VtkWriter>
24 : public Vtk::FileWriter
25 {
26 protected:
28 using pos_type = typename std::ostream::pos_type;
29
30 template <class W>
31 using HasWriteTimeseriesSerialFile = decltype(&W::writeTimeseriesSerialFile);
32 // static_assert(Std::is_detected<HasWriteTimeseriesSerialFile, VtkWriter>::value, "");
33
34 template <class W>
35 using HasWriteTimeseriesParallelFile = decltype(&W::writeTimeseriesParallelFile);
36 // static_assert(Std::is_detected<HasWriteTimeseriesParallelFile, VtkWriter>::value, "");
37
38 public:
40 template <class... Args,
41 disableCopyMove<Self, Args...> = 0>
42 TimeseriesWriter (Args&&... args)
43 : vtkWriter_{std::forward<Args>(args)...}
44 {
45 assert(vtkWriter_.format_ != Vtk::FormatTypes::ASCII && "Timeseries writer requires APPENDED mode");
46 std::srand(std::time(nullptr));
47
48 // put temporary file to /tmp directory
49 tmpDir_ = Vtk::Path("/tmp/TimeseriesWriter_" + Vtk::uid(10) + "/");
50 }
51
54
56
66 void writeTimestep (double time, std::string const& fn,
68 bool writeCollection = true) const;
69
71 // NOTE: requires an aforegoing call to \ref writeTimestep
80 virtual std::string write (std::string const& fn, std::optional<std::string> dir = {}) const override;
81
83 template <class Function, class... Args>
84 TimeseriesWriter& addPointData (Function const& fct, Args&&... args)
85 {
86 vtkWriter_.addPointData(fct, std::forward<Args>(args)...);
87 return *this;
88 }
89
91 template <class Function, class... Args>
92 TimeseriesWriter& addCellData (Function const& fct, Args&&... args)
93 {
94 vtkWriter_.addCellData(fct, std::forward<Args>(args)...);
95 return *this;
96 }
97
98 protected:
101
102 mutable bool initialized_ = false;
103
104 // block size of attached data
106
109 };
110
111} // end namespace Dune::Vtk
112
STL namespace.
Definition writer.hh:16
std::string uid(std::size_t len=8)
Definition uid.hh:10
Definition filewriter.hh:9
Definition function.hh:18
File-Writer for Vtk timeseries .vtu files.
Definition timeserieswriter.hh:25
Vtk::Path tmpDir_
Definition timeserieswriter.hh:100
TimeseriesWriter & addPointData(Function const &fct, Args &&... args)
Attach point data to the writer,.
Definition timeserieswriter.hh:84
void writeTimestep(double time, std::string const &fn, std::optional< std::string > tmpDir={}, bool writeCollection=true) const
Write the attached data to the file.
Definition timeserieswriter.impl.hh:42
TimeseriesWriter Self
Definition timeserieswriter.hh:27
typename std::ostream::pos_type pos_type
Definition timeserieswriter.hh:28
TimeseriesWriter & addCellData(Function const &fct, Args &&... args)
Attach cell data to the writer,.
Definition timeserieswriter.hh:92
TimeseriesWriter(Args &&... args)
Constructor, stores the gridView.
Definition timeserieswriter.hh:42
virtual std::string write(std::string const &fn, std::optional< std::string > dir={}) const override
Writes all timesteps to single timeseries file.
Definition timeserieswriter.impl.hh:78
std::string filenameMesh_
Definition timeserieswriter.hh:107
bool initialized_
Definition timeserieswriter.hh:102
decltype(&W::writeTimeseriesParallelFile) HasWriteTimeseriesParallelFile
Definition timeserieswriter.hh:35
VtkWriter vtkWriter_
Definition timeserieswriter.hh:99
~TimeseriesWriter()
Remove all written intermediate files and remove temporary directory.
Definition timeserieswriter.impl.hh:26
decltype(&W::writeTimeseriesSerialFile) HasWriteTimeseriesSerialFile
Definition timeserieswriter.hh:31
std::vector< std::uint64_t > blocks_
Definition timeserieswriter.hh:105
std::vector< std::pair< double, std::string > > timesteps_
Definition timeserieswriter.hh:108
Definition filesystem.hh:13
Default choice of VTK Writer for several grid types.
Definition vtkwriter.hh:48
VtkWriterBase & addPointData(Function &&fct, const Vtk::FieldInfo &info)
Attach point data to the writer.
Definition vtkwriterbase.hh:118
VtkWriterBase & addCellData(Function &&fct, const Vtk::FieldInfo &info)
Attach cell data to the writer.
Definition vtkwriterbase.hh:157
T srand(T... args)
T time(T... args)