GridFormat 0.2.1
I/O-Library for grid-like data structures
Loading...
Searching...
No Matches
xml_time_series_writer.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2// SPDX-License-Identifier: MIT
8#ifndef GRIDFORMAT_VTK_XML_TIME_SERIES_WRITER_HPP_
9#define GRIDFORMAT_VTK_XML_TIME_SERIES_WRITER_HPP_
10
11#include <iomanip>
12#include <sstream>
13#include <utility>
14#include <string>
15#include <type_traits>
16
17namespace GridFormat {
18
24template<typename VTKWriter>
25class VTKXMLTimeSeriesWriter : public TimeSeriesGridWriter<typename VTKWriter::Grid> {
27
28 public:
29 explicit VTKXMLTimeSeriesWriter(VTKWriter&& writer, std::string base_filename)
30 : ParentType(writer.grid(), writer.writer_options())
31 , _vtk_writer{std::move(writer)}
32 , _base_filename{std::move(base_filename)}
33 {}
34
35 private:
36 std::string _write(double _time) override {
37 this->copy_fields(_vtk_writer);
38 _vtk_writer.set_meta_data("TimeValue", _time);
39 const auto filename = _vtk_writer.write(_get_filename(this->_step_count));
40 _vtk_writer.clear();
41 return filename;
42 }
43
44 std::string _get_filename(const std::integral auto index) const {
45 return _base_filename + "-" + _get_file_number_string(index);
46 }
47
48 std::string _get_file_number_string(const std::integral auto index) const {
49 std::ostringstream file_number;
50 file_number << std::setw(5) << std::setfill('0') << index;
51 return file_number.str();
52 }
53
54 VTKWriter _vtk_writer;
55 std::string _base_filename;
56 std::string _pvd_filename;
57};
58
59template<typename VTKWriter>
61
62} // namespace GridFormat
63
64#endif // GRIDFORMAT_VTK_XML_TIME_SERIES_WRITER_HPP_
Abstract base class for time series file writers.
Definition: writer.hpp:344
Writer for time series of a VTK-XML file format. Populates the "TimeValue" metadata field supported b...
Definition: xml_time_series_writer.hpp:25