20 #include <vtkXMLPUnstructuredGridWriter.h>
21 #include <vtkXMLUnstructuredGridWriter.h>
31 void FixPvtu(
const std::string& filename,
const std::string& file_prefix,
34 std::ifstream ifs(filename);
35 ifs.seekg(0, std::ios::end);
36 size_t size = ifs.tellg();
37 std::string buffer(size,
' ');
39 ifs.read(&buffer[0], size);
42 std::string find =
Concat(
"<Piece Source=\"", file_prefix,
"_0.vtu\"/>");
43 std::stringstream new_file;
44 auto pos = buffer.find(find);
45 if (pos == std::string::npos) {
49 new_file << buffer.substr(0, pos);
50 for (uint64_t i = 0; i < pieces; ++i) {
51 new_file <<
"<Piece Source=\"" << file_prefix <<
"_" << i <<
".vtu\"/>\n";
53 new_file << buffer.substr(pos + find.size(), buffer.size());
55 std::ofstream ofs(filename);
56 ofs << new_file.str();
61 const std::string& folder,
const std::string& file_prefix,
62 const std::vector<vtkUnstructuredGrid*>& grids)
const {
66 #pragma omp parallel for schedule(static, 1)
67 for (
int i = 0; i < tinfo->GetMaxThreads(); ++i) {
69 vtkNew<vtkXMLPUnstructuredGridWriter> pvtu_writer;
70 auto filename =
Concat(folder,
"/", file_prefix,
".pvtu");
71 pvtu_writer->SetFileName(filename.c_str());
73 pvtu_writer->SetInputData(grids[0]);
74 pvtu_writer->SetDataModeToBinary();
75 pvtu_writer->SetEncodeAppendedData(
false);
76 if (!param->visualization_compress_pv_files) {
77 pvtu_writer->SetCompressorTypeToNone();
81 FixPvtu(filename, file_prefix, max_threads);
83 vtkNew<vtkXMLUnstructuredGridWriter> vtu_writer;
84 vtu_writer->SetGlobalWarningDisplay(
false);
85 auto filename =
Concat(folder,
"/", file_prefix,
"_", i,
".vtu");
86 vtu_writer->SetFileName(filename.c_str());
87 vtu_writer->SetInputData(grids[i]);
88 vtu_writer->SetDataModeToBinary();
89 vtu_writer->SetEncodeAppendedData(
false);
90 if (!param->visualization_compress_pv_files) {
91 vtu_writer->SetCompressorTypeToNone();