dune-vtk 2.8
Loading...
Searching...
No Matches
vtktimeserieswriter.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
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 VtkTimeseriesWriter (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/vtktimeserieswriter_" + Vtk::uid(10) + "/");
50 }
51
54
56
66 void writeTimestep (double time, std::string const& fn,
67 std::optional<std::string> tmpDir = {},
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 VtkTimeseriesWriter& 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 VtkTimeseriesWriter& 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
105 mutable std::vector<std::uint64_t> blocks_;
106
107 mutable std::string filenameMesh_;
108 mutable std::vector<std::pair<double, std::string>> timesteps_;
109 };
110
111} // end namespace Dune
112
Definition: writer.hh:13
std::string uid(std::size_t len=8)
Definition: uid.hh:12
Definition: filewriter.hh:11
Definition: filesystem.hh:15
File-Writer for Vtk timeseries .vtu files.
Definition: vtktimeserieswriter.hh:25
std::string filenameMesh_
Definition: vtktimeserieswriter.hh:107
std::vector< std::uint64_t > blocks_
Definition: vtktimeserieswriter.hh:105
decltype(&W::writeTimeseriesParallelFile) HasWriteTimeseriesParallelFile
Definition: vtktimeserieswriter.hh:35
VtkTimeseriesWriter(Args &&... args)
Constructor, stores the gridView.
Definition: vtktimeserieswriter.hh:42
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: vtktimeserieswriter.impl.hh:42
Vtk::Path tmpDir_
Definition: vtktimeserieswriter.hh:100
virtual std::string write(std::string const &fn, std::optional< std::string > dir={}) const override
Writes all timesteps to single timeseries file.
Definition: vtktimeserieswriter.impl.hh:78
typename std::ostream::pos_type pos_type
Definition: vtktimeserieswriter.hh:28
decltype(&W::writeTimeseriesSerialFile) HasWriteTimeseriesSerialFile
Definition: vtktimeserieswriter.hh:31
VtkWriter vtkWriter_
Definition: vtktimeserieswriter.hh:99
VtkTimeseriesWriter & addPointData(Function const &fct, Args &&... args)
Attach point data to the writer,.
Definition: vtktimeserieswriter.hh:84
VtkTimeseriesWriter Self
Definition: vtktimeserieswriter.hh:27
bool initialized_
Definition: vtktimeserieswriter.hh:102
std::vector< std::pair< double, std::string > > timesteps_
Definition: vtktimeserieswriter.hh:108
VtkTimeseriesWriter & addCellData(Function const &fct, Args &&... args)
Attach cell data to the writer,.
Definition: vtktimeserieswriter.hh:92
~VtkTimeseriesWriter()
Remove all written intermediate files and remove temporary directory.
Definition: vtktimeserieswriter.impl.hh:26
Default choice of VTK Writer for several grid types.
Definition: vtkwriter.hh:40
VtkWriterInterface & addPointData(Function &&fct, Args &&... args)
Attach point data to the writer.
Definition: vtkwriterinterface.hh:106
VtkWriterInterface & addCellData(Function &&fct, Args &&... args)
Attach cell data to the writer.
Definition: vtkwriterinterface.hh:124