OGS 6.2.1-97-g73d1aeda3
PVDFile.cpp
Go to the documentation of this file.
1 
10 #include "PVDFile.h"
11 
12 #include <fstream>
13 #include <iomanip>
14 #include <limits>
15 #include <logog/include/logog.hpp>
16 #include "BaseLib/Error.h"
18 
19 namespace MeshLib
20 {
21 namespace IO
22 {
23 
24 void PVDFile::addVTUFile(const std::string &vtu_fname, double timestep)
25 {
26  #ifdef USE_PETSC
27  auto const vtu_file_name =
28  getVtuFileNameForPetscOutputWithoutExtension(vtu_fname);
29 
30  _datasets.emplace_back(timestep, vtu_file_name + ".pvtu");
31  #else
32  _datasets.emplace_back(timestep, vtu_fname);
33  #endif
34 
35  std::ofstream fh(_pvd_filename.c_str());
36  if (!fh) {
37  OGS_FATAL("could not open file `%s'", _pvd_filename.c_str());
38  }
39 
40  fh << std::setprecision(std::numeric_limits<double>::digits10);
41 
42  fh << "<?xml version=\"1.0\"?>\n"
43  "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\""
44  " compressor=\"vtkZLibDataCompressor\">\n"
45  " <Collection>\n";
46 
47  for (auto const& pair : _datasets)
48  {
49  fh << " <DataSet timestep=\"" << pair.first
50  << "\" group=\"\" part=\"0\" file=\"" << pair.second << "\"/>\n";
51  }
52 
53  fh << " </Collection>\n</VTKFile>\n";
54 }
55 
56 } // namespace IO
57 } // namespace MeshLib
void addVTUFile(std::string const &vtu_fname, double timestep)
Add a VTU file to this PVD file.
Definition: PVDFile.cpp:24
Implementation of the VtuInterface class.
std::string const _pvd_filename
Definition: PVDFile.h:37
std::vector< std::pair< double, std::string > > _datasets
Definition: PVDFile.h:38
Interface for heuristic search length strategy.
Definition: ProjectData.h:30
#define OGS_FATAL(fmt,...)
Definition: Error.h:63