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

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>::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}
#define OGS_FATAL(...)
Definition Error.h:26
std::vector< std::pair< double, std::string > > _datasets
Definition PVDFile.h:40
std::string getVtuFileNameForPetscOutputWithoutExtension(std::string const &file_name)

References _datasets, MeshLib::IO::getVtuFileNameForPetscOutputWithoutExtension(), 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: