Line | Branch | Exec | Source |
---|---|---|---|
1 | // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de> | ||
2 | // SPDX-License-Identifier: MIT | ||
3 | /*! | ||
4 | * \file | ||
5 | * \ingroup VTK | ||
6 | * \copydoc GridFormat::VTKXMLTimeSeriesWriter | ||
7 | */ | ||
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 | |||
17 | namespace GridFormat { | ||
18 | |||
19 | /*! | ||
20 | * \ingroup VTK | ||
21 | * \brief Writer for time series of a VTK-XML file format. | ||
22 | * Populates the "TimeValue" metadata field supported by VTK. | ||
23 | */ | ||
24 | template<typename VTKWriter> | ||
25 | class VTKXMLTimeSeriesWriter : public TimeSeriesGridWriter<typename VTKWriter::Grid> { | ||
26 | using ParentType = TimeSeriesGridWriter<typename VTKWriter::Grid>; | ||
27 | |||
28 | public: | ||
29 | 10 | explicit VTKXMLTimeSeriesWriter(VTKWriter&& writer, std::string base_filename) | |
30 | 10 | : ParentType(writer.grid(), writer.writer_options()) | |
31 | 10 | , _vtk_writer{std::move(writer)} | |
32 | 30 | , _base_filename{std::move(base_filename)} | |
33 | 10 | {} | |
34 | |||
35 | private: | ||
36 | 44 | std::string _write(double _time) override { | |
37 | 44 | this->copy_fields(_vtk_writer); | |
38 |
2/4✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
|
88 | _vtk_writer.set_meta_data("TimeValue", _time); |
39 |
2/4✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
|
44 | const auto filename = _vtk_writer.write(_get_filename(this->_step_count)); |
40 | 44 | _vtk_writer.clear(); | |
41 | 44 | return filename; | |
42 | } | ||
43 | |||
44 | 44 | std::string _get_filename(const std::integral auto index) const { | |
45 |
3/6✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 44 times.
✗ Branch 8 not taken.
|
44 | return _base_filename + "-" + _get_file_number_string(index); |
46 | } | ||
47 | |||
48 | 44 | std::string _get_file_number_string(const std::integral auto index) const { | |
49 |
1/2✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
|
44 | std::ostringstream file_number; |
50 |
2/4✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 44 times.
✗ Branch 8 not taken.
|
44 | file_number << std::setw(5) << std::setfill('0') << index; |
51 |
1/2✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
|
88 | return file_number.str(); |
52 | 44 | } | |
53 | |||
54 | VTKWriter _vtk_writer; | ||
55 | std::string _base_filename; | ||
56 | std::string _pvd_filename; | ||
57 | }; | ||
58 | |||
59 | template<typename VTKWriter> | ||
60 | VTKXMLTimeSeriesWriter(VTKWriter&&) -> VTKXMLTimeSeriesWriter<std::remove_cvref_t<VTKWriter>>; | ||
61 | |||
62 | } // namespace GridFormat | ||
63 | |||
64 | #endif // GRIDFORMAT_VTK_XML_TIME_SERIES_WRITER_HPP_ | ||
65 |