33std::vector<std::pair<double, std::string>>
readPvd(
34 std::string
const& pvd_filename)
36 DBUG(
"Start reading the PVD file {:s}", pvd_filename);
37 boost::property_tree::ptree pvd;
38 read_xml(pvd_filename, pvd,
39 boost::property_tree::xml_parser::trim_whitespace);
41 std::vector<std::pair<double, std::string>> timeseries;
42 for (
auto const& dataset : pvd.get_child(
"VTKFile.Collection"))
44 if (dataset.first !=
"DataSet")
46 OGS_FATAL(
"Expected DataSet tag but got '{:s}'", dataset.first);
49 auto const time = dataset.second.get<
double>(
"<xmlattr>.timestep");
50 auto const file = dataset.second.get<std::string>(
"<xmlattr>.file");
51 timeseries.emplace_back(time, file);
53 DBUG(
"Finished reading the PVD file {:s}", pvd_filename);
109int main(
int argc,
char* argv[])
112 "Converts a time series from PVD to XDMF format.\n\n"
113 "OpenGeoSys-6 software, version " +
116 "Copyright (c) 2012-2024, OpenGeoSys Community "
117 "(http://www.opengeosys.org)",
120 TCLAP::ValueArg<std::string> log_level_arg(
122 "the verbosity of logging messages: none, error, warn, info, "
132 cmd.add(log_level_arg);
134 TCLAP::UnlabeledValueArg<std::string> pvd_file_arg(
"pvd-file",
"pvd file",
136 cmd.add(pvd_file_arg);
138 TCLAP::ValueArg<std::string> outdir_arg(
"o",
"output-directory",
139 "the output directory to write to",
143 cmd.parse(argc, argv);
145 MPI_Init(&argc, &argv);
151 auto const timeseries =
readPvd(pvd_file_arg.getValue());
153 if (timeseries.empty())
160 std::unique_ptr<MeshLib::Mesh> main_mesh;
162 std::filesystem::path
const output_file{
165 std::filesystem::path output_file_path{outdir_arg.getValue()};
166 if (outdir_arg.getValue() !=
"")
171 std::set<std::string> variable_output_names;
172 std::unique_ptr<MeshLib::IO::XdmfHdfWriter> mesh_xdmf_hdf_writer;
175 auto [time, filename] = timeseries[0];
176 DBUG(
"{} - {}", time, filename);
180 if (main_mesh ==
nullptr)
182 OGS_FATAL(
"Could not read mesh from '{:s}'.",
186 for (
auto const& p : main_mesh->getProperties())
188 variable_output_names.insert(std::string(p.first));
190 mesh_xdmf_hdf_writer = std::make_unique<MeshLib::IO::XdmfHdfWriter>(
191 std::vector{std::cref(*main_mesh)}, output_file_path,
192 0 , time, variable_output_names,
197 for (std::size_t timestep = 1; timestep < timeseries.size(); ++timestep)
199 auto [time, filename] = timeseries[timestep];
200 DBUG(
"{} - {}", time, filename);
206 OGS_FATAL(
"Could not read mesh from '{:s}'.",
212 fmt::format(
"Error in comparison of mesh from file '{:s}' to the "
218 for (
auto& [name, pv] : main_mesh->getProperties())
233 "Could not copy property vector '{:s}' from '{:s}' mesh to the "
238 mesh_xdmf_hdf_writer->writeStep(time);