OGS
PVDFile.cpp
Go to the documentation of this file.
1
11#include "PVDFile.h"
12
13#include <fstream>
14#include <iomanip>
15#include <limits>
16
17#ifdef USE_PETSC
18#include <mpi.h>
19#endif
20
21#include "BaseLib/Error.h"
23
24namespace MeshLib
25{
26namespace IO
27{
28void PVDFile::addVTUFile(const std::string& vtu_fname, double timestep)
29{
30#ifdef USE_PETSC
31 int mpi_size;
32 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
33 if (mpi_size == 1)
34 {
35 _datasets.emplace_back(timestep, vtu_fname);
36 }
37 else
38 {
39 auto const vtu_file_name =
41
42 _datasets.emplace_back(timestep, vtu_file_name + ".pvtu");
43 }
44#else
45 _datasets.emplace_back(timestep, vtu_fname);
46#endif
47
48 std::ofstream fh(pvd_filename.c_str());
49 if (!fh)
50 {
51 OGS_FATAL("could not open file `{:s}'", pvd_filename);
52 }
53
54 fh << std::setprecision(std::numeric_limits<double>::max_digits10);
55
56 fh << "<?xml version=\"1.0\"?>\n"
57 "<VTKFile type=\"Collection\" version=\"0.1\" "
58 "byte_order=\"LittleEndian\""
59 " compressor=\"vtkZLibDataCompressor\">\n"
60 " <Collection>\n";
61
62 for (auto const& pair : _datasets)
63 {
64 fh << " <DataSet timestep=\"" << pair.first
65 << "\" group=\"\" part=\"0\" file=\"" << pair.second << "\"/>\n";
66 }
67
68 fh << " </Collection>\n</VTKFile>\n";
69}
70
71} // namespace IO
72} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:26
Implementation of the VtuInterface class.
std::string const pvd_filename
Definition PVDFile.h:36
std::vector< std::pair< double, std::string > > _datasets
Definition PVDFile.h:40
void addVTUFile(std::string const &vtu_fname, double timestep)
Add a VTU file to this PVD file.
Definition PVDFile.cpp:28
std::string getVtuFileNameForPetscOutputWithoutExtension(std::string const &file_name)