OGS
MeshLib::IO::PVDFile Class Reference

Detailed Description

Writes a basic PVD file for use with Paraview.

Definition at line 24 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 28 of file PVDFile.h.

29 : pvd_filename(std::move(pvd_fname))
30 {
31 }
std::string const pvd_filename
Definition PVDFile.h:36

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 30 of file PVDFile.cpp.

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}
#define OGS_FATAL(...)
Definition Error.h:26
std::vector< std::pair< double, std::string > > _datasets
Definition PVDFile.h:40
MPI_Comm OGS_COMM_WORLD
Definition MPI.cpp:15
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 40 of file PVDFile.h.

Referenced by addVTUFile().

◆ pvd_filename

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

Definition at line 36 of file PVDFile.h.

Referenced by addVTUFile().


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