Loading [MathJax]/extensions/tex2jax.js
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
20#include "BaseLib/MPI.h"
21#endif
22
23#include "BaseLib/Error.h"
25
26namespace MeshLib
27{
28namespace IO
29{
30void PVDFile::addVTUFile(const std::string& vtu_fname, double timestep)
31{
32#ifdef USE_PETSC
33 int mpi_size;
34 MPI_Comm_size(BaseLib::MPI::OGS_COMM_WORLD, &mpi_size);
35 if (mpi_size == 1)
36 {
37 _datasets.emplace_back(timestep, vtu_fname);
38 }
39 else
40 {
41 auto const vtu_file_name =
43
44 _datasets.emplace_back(timestep, vtu_file_name + ".pvtu");
45 }
46#else
47 _datasets.emplace_back(timestep, vtu_fname);
48#endif
49
50 std::ofstream fh(pvd_filename.c_str());
51 if (!fh)
52 {
53 OGS_FATAL("could not open file `{:s}'", pvd_filename);
54 }
55
56 fh << std::setprecision(std::numeric_limits<double>::max_digits10);
57
58 fh << "<?xml version=\"1.0\"?>\n"
59 "<VTKFile type=\"Collection\" version=\"0.1\" "
60 "byte_order=\"LittleEndian\""
61 " compressor=\"vtkZLibDataCompressor\">\n"
62 " <Collection>\n";
63
64 for (auto const& pair : _datasets)
65 {
66 fh << " <DataSet timestep=\"" << pair.first
67 << "\" group=\"\" part=\"0\" file=\"" << pair.second << "\"/>\n";
68 }
69
70 fh << " </Collection>\n</VTKFile>\n";
71}
72
73} // namespace IO
74} // 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:30
MPI_Comm OGS_COMM_WORLD
Definition MPI.cpp:15
std::string getVtuFileNameForPetscOutputWithoutExtension(std::string const &file_name)