GCC Code Coverage Report


Directory: gridformat/
File: gridformat/vtk/xml_time_series_writer.hpp
Date: 2026-10-12 17:50:57
Exec Total Coverage
Lines: 18 18 100.0%
Functions: 20 20 100.0%
Branches: 11 22 50.0%

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 #include <gridformat/grid/writer.hpp>
18
19 namespace GridFormat {
20
21 /*!
22 * \ingroup VTK
23 * \brief Writer for time series of a VTK-XML file format.
24 * Populates the "TimeValue" metadata field supported by VTK.
25 */
26 template<typename VTKWriter>
27 class VTKXMLTimeSeriesWriter : public TimeSeriesGridWriter<typename VTKWriter::Grid> {
28 using ParentType = TimeSeriesGridWriter<typename VTKWriter::Grid>;
29
30 public:
31 10 explicit VTKXMLTimeSeriesWriter(VTKWriter&& writer, std::string base_filename)
32 10 : ParentType(writer.grid(), writer.writer_options())
33 10 , _vtk_writer{std::move(writer)}
34 30 , _base_filename{std::move(base_filename)}
35 10 {}
36
37 private:
38 44 std::string _write(double _time) override {
39 44 this->copy_fields(_vtk_writer);
40
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);
41
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));
42 44 _vtk_writer.clear();
43 44 return filename;
44 }
45
46 44 std::string _get_filename(const std::integral auto index) const {
47
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);
48 }
49
50 44 std::string _get_file_number_string(const std::integral auto index) const {
51
1/2
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
44 std::ostringstream file_number;
52
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;
53
1/2
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
88 return file_number.str();
54 44 }
55
56 VTKWriter _vtk_writer;
57 std::string _base_filename;
58 std::string _pvd_filename;
59 };
60
61 template<typename VTKWriter>
62 VTKXMLTimeSeriesWriter(VTKWriter&&) -> VTKXMLTimeSeriesWriter<std::remove_cvref_t<VTKWriter>>;
63
64 } // namespace GridFormat
65
66 #endif // GRIDFORMAT_VTK_XML_TIME_SERIES_WRITER_HPP_
67