dune-vtk 2.12
Loading...
Searching...
No Matches
timeserieswriter.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3#pragma once
4
5#include <cassert>
6#include <optional>
7#include <string>
8#include <tuple>
9#include <vector>
10
12#include <dune/vtk/types.hh>
15
16namespace Dune::Vtk
17{
19
24 template <class VtkWriter>
26 : public Vtk::FileWriter
27 {
28 protected:
30 using pos_type = typename std::ostream::pos_type;
31
32 template <class W>
33 using HasWriteTimeseriesSerialFile = decltype(&W::writeTimeseriesSerialFile);
34 // static_assert(Std::is_detected<HasWriteTimeseriesSerialFile, VtkWriter>::value, "");
35
36 template <class W>
37 using HasWriteTimeseriesParallelFile = decltype(&W::writeTimeseriesParallelFile);
38 // static_assert(Std::is_detected<HasWriteTimeseriesParallelFile, VtkWriter>::value, "");
39
40 public:
42 template <class... Args,
43 disableCopyMove<Self, Args...> = 0>
45 : vtkWriter_{std::forward<Args>(args)...}
46 {
47 assert(vtkWriter_.format_ != Vtk::FormatTypes::ASCII && "Timeseries writer requires APPENDED mode");
48 std::srand(std::time(nullptr));
49
50 // put temporary file to /tmp directory
51 tmpDir_ = Vtk::Path("/tmp/TimeseriesWriter_" + Vtk::uid(10) + "/");
52 }
53
56
58
68 void writeTimestep (double time, std::string const& fn,
70 bool writeCollection = true) const;
71
73 // NOTE: requires an aforegoing call to \ref writeTimestep
82 virtual std::string write (std::string const& fn, std::optional<std::string> dir = {}) const override;
83
85 template <class Function, class... Args>
87 {
88 vtkWriter_.addPointData(fct, std::forward<Args>(args)...);
89 return *this;
90 }
91
93 template <class Function, class... Args>
95 {
96 vtkWriter_.addCellData(fct, std::forward<Args>(args)...);
97 return *this;
98 }
99
100 protected:
103
104 mutable bool initialized_ = false;
105
106 // block size of attached data
108
111 };
112
113} // end namespace Dune::Vtk
114
STL namespace.
Definition datacollector.hh:19
std::string uid(std::size_t len=8)
Definition uid.hh:12
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
Definition filewriter.hh:11
Definition function.hh:20
File-Writer for Vtk timeseries .vtu files.
Definition timeserieswriter.hh:27
Vtk::Path tmpDir_
Definition timeserieswriter.hh:102
TimeseriesWriter & addPointData(Function const &fct, Args &&... args)
Attach point data to the writer,.
Definition timeserieswriter.hh:86
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:44
TimeseriesWriter Self
Definition timeserieswriter.hh:29
typename std::ostream::pos_type pos_type
Definition timeserieswriter.hh:30
TimeseriesWriter & addCellData(Function const &fct, Args &&... args)
Attach cell data to the writer,.
Definition timeserieswriter.hh:94
TimeseriesWriter(Args &&... args)
Constructor, stores the gridView.
Definition timeserieswriter.hh:44
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:80
std::string filenameMesh_
Definition timeserieswriter.hh:109
bool initialized_
Definition timeserieswriter.hh:104
decltype(&W::writeTimeseriesParallelFile) HasWriteTimeseriesParallelFile
Definition timeserieswriter.hh:37
VtkWriter vtkWriter_
Definition timeserieswriter.hh:101
~TimeseriesWriter()
Remove all written intermediate files and remove temporary directory.
Definition timeserieswriter.impl.hh:28
decltype(&W::writeTimeseriesSerialFile) HasWriteTimeseriesSerialFile
Definition timeserieswriter.hh:33
std::vector< std::uint64_t > blocks_
Definition timeserieswriter.hh:107
std::vector< std::pair< double, std::string > > timesteps_
Definition timeserieswriter.hh:110
Definition filesystem.hh:15
Default choice of VTK Writer for several grid types.
Definition vtkwriter.hh:50
VtkWriterBase & addPointData(Function &&fct, const Vtk::FieldInfo &info)
Attach point data to the writer.
Definition vtkwriterbase.hh:120
VtkWriterBase & addCellData(Function &&fct, const Vtk::FieldInfo &info)
Attach cell data to the writer.
Definition vtkwriterbase.hh:159
T srand(T... args)
T time(T... args)