30std::vector<std::pair<double, std::string>>
readPvd(
31 std::string
const& pvd_filename)
33 DBUG(
"Start reading the PVD file {:s}", pvd_filename);
34 boost::property_tree::ptree pvd;
35 read_xml(pvd_filename, pvd,
36 boost::property_tree::xml_parser::trim_whitespace);
38 std::vector<std::pair<double, std::string>> timeseries;
39 for (
auto const& dataset : pvd.get_child(
"VTKFile.Collection"))
41 if (dataset.first !=
"DataSet")
43 OGS_FATAL(
"Expected DataSet tag but got '{:s}'", dataset.first);
46 auto const time = dataset.second.get<
double>(
"<xmlattr>.timestep");
47 auto const file = dataset.second.get<std::string>(
"<xmlattr>.file");
48 timeseries.emplace_back(time, file);
50 DBUG(
"Finished reading the PVD file {:s}", pvd_filename);
106int main(
int argc,
char* argv[])
109 "Converts a time series from PVD to XDMF format.\n\n"
110 "OpenGeoSys-6 software, version " +
113 "Copyright (c) 2012-2024, OpenGeoSys Community "
114 "(http://www.opengeosys.org)",
117 TCLAP::ValueArg<std::string> log_level_arg(
119 "the verbosity of logging messages: none, error, warn, info, "
129 cmd.add(log_level_arg);
131 TCLAP::UnlabeledValueArg<std::string> pvd_file_arg(
"pvd-file",
"pvd file",
133 cmd.add(pvd_file_arg);
135 TCLAP::ValueArg<std::string> outdir_arg(
"o",
"output-directory",
136 "the output directory to write to",
140 cmd.parse(argc, argv);
146 auto const timeseries =
readPvd(pvd_file_arg.getValue());
148 if (timeseries.empty())
155 std::unique_ptr<MeshLib::Mesh> main_mesh;
157 std::filesystem::path
const output_file{
160 std::filesystem::path output_file_path{outdir_arg.getValue()};
161 if (outdir_arg.getValue() !=
"")
166 std::set<std::string> variable_output_names;
167 std::unique_ptr<MeshLib::IO::XdmfHdfWriter> mesh_xdmf_hdf_writer;
170 auto [time, filename] = timeseries[0];
171 DBUG(
"{} - {}", time, filename);
175 if (main_mesh ==
nullptr)
177 OGS_FATAL(
"Could not read mesh from '{:s}'.",
181 for (
auto const& p : main_mesh->getProperties())
183 variable_output_names.insert(std::string(p.first));
185 mesh_xdmf_hdf_writer = std::make_unique<MeshLib::IO::XdmfHdfWriter>(
186 std::vector{std::cref(*main_mesh)}, output_file_path,
187 0 , time, variable_output_names,
192 for (std::size_t timestep = 1; timestep < timeseries.size(); ++timestep)
194 auto [time, filename] = timeseries[timestep];
195 DBUG(
"{} - {}", time, filename);
201 OGS_FATAL(
"Could not read mesh from '{:s}'.",
207 fmt::format(
"Error in comparison of mesh from file '{:s}' to the "
213 for (
auto& [name, pv] : main_mesh->getProperties())
228 "Could not copy property vector '{:s}' from '{:s}' mesh to the "
233 mesh_xdmf_hdf_writer->writeStep(time);