PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
pvdCollectionWriter.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2026 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#include "pvdCollectionWriter.h"
12#include <fstream>
13#include <iomanip>
14#include <stdexcept>
15
16namespace rw {
17
19 const std::string &pvd_path,
20 const std::vector<std::pair<double, std::string>> &time_and_vtu_relative_path) {
21
22 std::ofstream os(pvd_path);
23 if (!os)
24 throw std::runtime_error("writePvdCollectionFile: could not open " + pvd_path);
25
26 os << std::setprecision(17);
27 os << "<?xml version=\"1.0\"?>\n";
28 os << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
29 os << " <Collection>\n";
30 for (const auto &e : time_and_vtu_relative_path) {
31 os << " <DataSet timestep=\"" << e.first << "\" file=\"" << e.second << "\"/>\n";
32 }
33 os << " </Collection>\n";
34 os << "</VTKFile>\n";
35}
36
38 const std::string &pvtu_path,
39 const std::vector<std::string> &piece_vtu_relative_paths,
40 const std::vector<PvtuPointArray> &point_arrays) {
41
42 std::ofstream os(pvtu_path);
43 if (!os)
44 throw std::runtime_error("writePvtuCollectionFile: could not open " +
45 pvtu_path);
46
47 os << "<?xml version=\"1.0\"?>\n";
48 os << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" "
49 "byte_order=\"LittleEndian\">\n";
50 os << " <PUnstructuredGrid GhostLevel=\"0\">\n";
51 os << " <PPoints>\n";
52 os << " <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n";
53 os << " </PPoints>\n";
54 if (!point_arrays.empty()) {
55 os << " <PPointData>\n";
56 for (const auto &a : point_arrays) {
57 os << " <PDataArray type=\"" << a.type << "\" Name=\"" << a.name
58 << "\"";
59 if (a.number_of_components > 1)
60 os << " NumberOfComponents=\"" << a.number_of_components << "\"";
61 os << "/>\n";
62 }
63 os << " </PPointData>\n";
64 }
65 for (const auto &piece : piece_vtu_relative_paths) {
66 os << " <Piece Source=\"" << piece << "\"/>\n";
67 }
68 os << " </PUnstructuredGrid>\n";
69 os << "</VTKFile>\n";
70}
71
72} // namespace rw
Collection of methods and database related to reading and writing.
void writePvdCollectionFile(const std::string &pvd_path, const std::vector< std::pair< double, std::string > > &time_and_vtu_relative_path)
Write a ParaView VTK collection (.pvd) that lists VTU files with timesteps.
void writePvtuCollectionFile(const std::string &pvtu_path, const std::vector< std::string > &piece_vtu_relative_paths, const std::vector< PvtuPointArray > &point_arrays)
Write a ParaView parallel VTU (.pvtu) that lists per-rank .vtu pieces.