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-2025, OpenGeoSys Community "
114 "(http://www.opengeosys.org)",
118 cmd.add(log_level_arg);
120 TCLAP::UnlabeledValueArg<std::string> pvd_file_arg(
121 "pvd-file",
"Input (.pvd) file",
true,
"",
"INPUT_FILE");
122 cmd.add(pvd_file_arg);
124 TCLAP::ValueArg<std::string> outdir_arg(
125 "o",
"output-directory",
"Output. The output directory to write to",
126 false,
".",
"OUTPUT_PATH");
129 cmd.parse(argc, argv);
136 auto const timeseries =
readPvd(pvd_file_arg.getValue());
138 if (timeseries.empty())
145 std::unique_ptr<MeshLib::Mesh> main_mesh;
147 std::filesystem::path
const output_file{
150 std::filesystem::path output_file_path{outdir_arg.getValue()};
151 if (outdir_arg.getValue() !=
"")
156 std::set<std::string> variable_output_names;
157 std::unique_ptr<MeshLib::IO::XdmfHdfWriter> mesh_xdmf_hdf_writer;
160 auto [time, filename] = timeseries[0];
161 DBUG(
"{} - {}", time, filename);
165 if (main_mesh ==
nullptr)
167 OGS_FATAL(
"Could not read mesh from '{:s}'.",
171 for (
auto const& p : main_mesh->getProperties())
173 variable_output_names.insert(std::string(p.first));
175 mesh_xdmf_hdf_writer = std::make_unique<MeshLib::IO::XdmfHdfWriter>(
176 std::vector{std::cref(*main_mesh)}, output_file_path,
177 0 , time, variable_output_names,
182 for (std::size_t timestep = 1; timestep < timeseries.size(); ++timestep)
184 auto [time, filename] = timeseries[timestep];
185 DBUG(
"{} - {}", time, filename);
191 OGS_FATAL(
"Could not read mesh from '{:s}'.",
197 fmt::format(
"Error in comparison of mesh from file '{:s}' to the "
203 for (
auto& [name, pv] : main_mesh->getProperties())
218 "Could not copy property vector '{:s}' from '{:s}' mesh to the "
223 mesh_xdmf_hdf_writer->writeStep(time);