OGS
MeshLib::IO::PVDFile Class Reference

Detailed Description

Writes a basic PVD file for use with Paraview.

Definition at line 17 of file PVDFile.h.

#include <PVDFile.h>

Public Member Functions

 PVDFile (std::string pvd_fname)
 Set a PVD file path.
void addVTUFile (std::string const &vtu_fname, double timestep)
 Add a VTU file to this PVD file.

Public Attributes

std::string const pvd_filename

Private Attributes

std::vector< std::pair< double, std::string > > _datasets

Constructor & Destructor Documentation

◆ PVDFile()

MeshLib::IO::PVDFile::PVDFile ( std::string pvd_fname)
inlineexplicit

Set a PVD file path.

Definition at line 21 of file PVDFile.h.

22 : pvd_filename(std::move(pvd_fname))
23 {
24 }
std::string const pvd_filename
Definition PVDFile.h:29

References pvd_filename.

Member Function Documentation

◆ addVTUFile()

void MeshLib::IO::PVDFile::addVTUFile ( std::string const & vtu_fname,
double timestep )

Add a VTU file to this PVD file.

Definition at line 23 of file PVDFile.cpp.

24{
25#ifdef USE_PETSC
26 int mpi_size;
27 MPI_Comm_size(BaseLib::MPI::OGS_COMM_WORLD, &mpi_size);
28 if (mpi_size == 1)
29 {
30 _datasets.emplace_back(timestep, vtu_fname);
31 }
32 else
33 {
34 auto const vtu_file_name =
36
37 _datasets.emplace_back(timestep, vtu_file_name + ".pvtu");
38 }
39#else
40 _datasets.emplace_back(timestep, vtu_fname);
41#endif
42
43 std::ofstream fh(pvd_filename.c_str());
44 if (!fh)
45 {
46 OGS_FATAL("could not open file `{:s}'", pvd_filename);
47 }
48
49 fh << std::setprecision(std::numeric_limits<double>::max_digits10);
50
51 fh << "<?xml version=\"1.0\"?>\n"
52 "<VTKFile type=\"Collection\" version=\"0.1\" "
53 "byte_order=\"LittleEndian\""
54 " compressor=\"vtkZLibDataCompressor\">\n"
55 " <Collection>\n";
56
57 for (auto const& pair : _datasets)
58 {
59 fh << " <DataSet timestep=\"" << pair.first
60 << "\" group=\"\" part=\"0\" file=\"" << pair.second << "\"/>\n";
61 }
62
63 fh << " </Collection>\n</VTKFile>\n";
64}
#define OGS_FATAL(...)
Definition Error.h:19
std::vector< std::pair< double, std::string > > _datasets
Definition PVDFile.h:33
MPI_Comm OGS_COMM_WORLD
Definition MPI.cpp:9
std::string getVtuFileNameForPetscOutputWithoutExtension(std::string const &file_name)

References _datasets, MeshLib::IO::getVtuFileNameForPetscOutputWithoutExtension(), BaseLib::MPI::OGS_COMM_WORLD, OGS_FATAL, and pvd_filename.

Referenced by ProcessLib::outputMeshVtk().

Member Data Documentation

◆ _datasets

std::vector<std::pair<double, std::string> > MeshLib::IO::PVDFile::_datasets
private

Definition at line 33 of file PVDFile.h.

Referenced by addVTUFile().

◆ pvd_filename

std::string const MeshLib::IO::PVDFile::pvd_filename

Definition at line 29 of file PVDFile.h.

Referenced by PVDFile(), and addVTUFile().


The documentation for this class was generated from the following files: