Documentation 6b54b78464
Loading...
Searching...
No Matches
CParaviewXMLFileWriter.hpp
Go to the documentation of this file.
1/*!
2 * \file CParaviewXMLFileWriter.hpp
3 * \brief Headers fo paraview binary file writer class.
4 * \author T. Albring
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
30#include "CFileWriter.hpp"
31
33
34private:
35
36 /*!
37 * \brief Enum that defines the VTK datatypes
38 */
39 enum class VTKDatatype {
40 FLOAT32,
41 FLOAT64,
42 INT32,
43 INT64,
44 UINT8
45 };
46
47 /*!
48 * \brief Boolean storing whether we are on a big or little endian machine
49 */
50 bool bigEndian;
51
52 /*!
53 * \brief True to write the coordinates and fields in double precision instead of single.
54 */
55 bool doublePrecision = false;
56
57 /*!
58 * \brief The current data offset that is used to find data in the binary blob at the end of the file
59 */
60 unsigned long dataOffset;
61
62public:
63
64 /*!
65 * \brief File extension
66 */
67 const static string fileExt;
68
69 /*!
70 * \brief Construct a file writer using field names and the data sorter.
71 * \param[in] val_filename - The name of the file
72 * \param[in] valDataSorter - The parallel sorted data to write
73 */
74 CParaviewXMLFileWriter(string val_filename, CParallelDataSorter* valDataSorter);
75
76 /*!
77 * \brief Construct a file writer using field names and the data sorter.
78 * \param[in] valDataSorter - The parallel sorted data to write
79 */
80 CParaviewXMLFileWriter(CParallelDataSorter* valDataSorter, bool valDoublePrecision = false);
81
82 /*!
83 * \brief Destructor
84 */
86
87 /*!
88 * \brief Write sorted data to file in paraview binary file format
89 */
90 void WriteData(string val_filename) override ;
91
92private:
93
94 /*!
95 * \brief Add a new data array definition to the vtu file.
96 * \param[in] type - The vtk datatype
97 * \param[in] name - The name of the array
98 * \param[in] nComponents - The number of components
99 * \param[in] size - The total size of the array
100 * \param[in] globalSize - The global size of the array over all processors
101 */
102 void AddDataArray(VTKDatatype type, string name, unsigned short nComponents, unsigned long size, unsigned long globalSize);
103
104 /*!
105 * \brief Write an array that has previously been defined with ::AddDataArray to the vtu file in binary format
106 * \param[in] data - Pointer to the data
107 * \param[in] type - The vtk datatype
108 * \param[in] size - The total size of the array
109 * \param[in] globalSize - The global size of the array over all processors
110 * \param[in] offset - The displacement in the file view for the current processor
111 */
112 void WriteDataArray(const void* data, VTKDatatype type, unsigned long size, unsigned long globalSize,
113 unsigned long offset);
114
115 /*!
116 * \brief Write the first values of a buffer as an array of type T with ::WriteDataArray, the values are converted
117 * if the buffer holds another type (e.g. double written as float, int64_t written as int32_t).
118 * \param[in] buffer - The data of this processor.
119 * \param[in] type - The vtk datatype, matching T.
120 * \param[in] size - The number of values of this processor to write.
121 * \param[in] globalSize - The global size of the array over all processors
122 * \param[in] offset - The displacement in the file view for the current processor
123 */
124 template <class T, class U>
125 void WriteDataArrayOfType(const vector<U>& buffer, VTKDatatype type, unsigned long size, unsigned long globalSize,
126 unsigned long offset);
127
128 /*!
129 * \brief Get the type string and size of a VTK datatype
130 * \param[in] type - The VTK datatype
131 * \param[out] typeStr - The string name of the type
132 * \param[out] typeSize - The size in bytes of the type
133 */
134 inline void GetTypeInfo(const VTKDatatype type, string &typeStr, unsigned long &typeSize) const {
135 switch (type) {
136 case VTKDatatype::FLOAT64:
137 typeStr = "\"Float64\"";
138 typeSize = sizeof(double);
139 break;
140 case VTKDatatype::FLOAT32:
141 typeStr = "\"Float32\"";
142 typeSize = sizeof(float);
143 break;
144 case VTKDatatype::INT32:
145 typeStr = "\"Int32\"";
146 typeSize = sizeof(int32_t);
147 break;
148 case VTKDatatype::INT64:
149 typeStr = "\"Int64\"";
150 typeSize = sizeof(int64_t);
151 break;
152 case VTKDatatype::UINT8:
153 typeStr = "\"UInt8\"";
154 typeSize = sizeof(char);
155 break;
156 default:
157 SU2_MPI::Error("Unknown Type", CURRENT_FUNCTION);
158 break;
159 }
160 }
161};
162
Headers fo the file writer class.
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
Definition CFileWriter.hpp:42
int size
The MPI size, aka the number of processors.
Definition CFileWriter.hpp:53
Definition CParallelDataSorter.hpp:39
Definition CParaviewXMLFileWriter.hpp:32
~CParaviewXMLFileWriter() override
Destructor.
CParaviewXMLFileWriter(string val_filename, CParallelDataSorter *valDataSorter)
Construct a file writer using field names and the data sorter.
static const string fileExt
File extension.
Definition CParaviewXMLFileWriter.hpp:67
void WriteData(string val_filename) override
Write sorted data to file in paraview binary file format.
Definition CParaviewXMLFileWriter.cpp:63
#define CURRENT_FUNCTION
Definition mpi_structure.hpp:59