foamVtkOutput.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Namespace
27  Foam::vtk
28 
29 Description
30  Namespace for handling VTK output.
31  Contains classes and functions for writing VTK file content.
32 
33 Namespace
34  Foam::vtk::legacy
35 
36 Description
37  Namespace for legacy VTK output constants and functions.
38 
39 SourceFiles
40  foamVtkOutput.C
41  foamVtkOutputTemplates.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef Foam_vtk_output_H
46 #define Foam_vtk_output_H
47 
48 #include "autoPtr.H"
49 #include "bitSet.H"
50 #include "Enum.H"
51 #include "foamVtkCore.H"
52 #include "foamVtkFormatter.H"
53 #include "floatScalar.H"
54 #include "symmTensor.H"
55 #include "IOstream.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward Declarations
63 class instant;
64 class globalIndex;
65 
66 namespace vtk
67 {
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 // General Functions
72 
73  //- Return a default asciiFormatter
74  autoPtr<vtk::formatter> newFormatter
75  (
76  std::ostream& os,
77  unsigned prec = IOstream::defaultPrecision()
78  );
79 
80  //- Return a new formatter based on the specified format type
81  autoPtr<vtk::formatter> newFormatter
82  (
83  std::ostream& os,
84  const enum formatType fmtType,
85  unsigned prec = IOstream::defaultPrecision()
86  );
87 
88 
89  //- Write an identity list of labels.
90  // The output does not include the payload size.
91  void writeIdentity(vtk::formatter& fmt, const label len, label start=0);
92 
93  //- Write a list of uint8_t values.
94  // The output does not include the payload size.
95  void writeList(vtk::formatter& fmt, const UList<uint8_t>& values);
96 
97  //- Component-wise write of a value (N times)
98  template<class Type>
99  inline void write(vtk::formatter& fmt, const Type& val, const label n=1);
100 
101  //- Component-wise write of a value (N times) in parallel
102  // The value and count may differ on each processor
103  template<class Type>
104  inline void writeValueParallel
105  (
106  vtk::formatter& fmt,
107  const Type& val,
108  const label count=1
109  );
110 
111 
112  //- Write a list of values.
113  // The output does not include the payload size.
114  template<class Type>
115  void writeList(vtk::formatter& fmt, const UList<Type>& values);
116 
117  //- Write a list of values.
118  // The output does not include the payload size.
119  template<class Type, unsigned N>
120  void writeList(vtk::formatter& fmt, const FixedList<Type, N>& values);
121 
122 
123  //- Write a list of values via indirect addressing.
124  // The output does not include the payload size.
125  template<class Type>
126  void writeList
127  (
128  vtk::formatter& fmt,
129  const UList<Type>& values,
130  const labelUList& addressing
131  );
132 
133  //- Write a list of values via indirect addressing.
134  // The output does not include the payload size.
135  template<class Type>
136  void writeList
137  (
138  vtk::formatter& fmt,
139  const UList<Type>& values,
140  const bitSet& selected
141  );
142 
143  //- Write a list of values and a list of values via indirect addressing.
144  // The output does not include the payload size.
145  template<class Type>
146  void writeLists
147  (
148  vtk::formatter& fmt,
149  const UList<Type>& values1,
150  const UList<Type>& values2,
151  const labelUList& addressing
152  );
153 
154 
155  //- Write a list of values.
156  // The output does not include the payload size.
157  template<class Type>
158  void writeListParallel
159  (
160  vtk::formatter& fmt,
161  const UList<Type>& values
162  );
163 
164  //- Write a list of values, with constant per-processor offset
165  // The output does not include the payload size.
166  void writeListParallel
167  (
168  vtk::formatter& fmt,
169  const UList<label>& values,
170  const globalIndex& procOffset
171  );
172 
173  //- Write a list of values via indirect addressing.
174  // The output does not include the payload size.
175  template<class Type>
176  void writeListParallel
177  (
178  vtk::formatter& fmt,
179  const UList<Type>& values,
180  const labelUList& addressing
181  );
182 
183  //- Write a list of values via indirect addressing.
184  // The output does not include the payload size.
185  template<class Type>
186  void writeListParallel
187  (
188  vtk::formatter& fmt,
189  const UList<Type>& values,
190  const bitSet& selected
191  );
192 
193  //- Write a list of values and another list of values.
194  // The output does not include the payload size.
195  template<class Type>
196  void writeListsParallel
197  (
198  vtk::formatter& fmt,
199  const UList<Type>& values1,
200  const UList<Type>& values2
201  );
202 
203  //- Write a list of values and a list of values via indirect addressing.
204  // The output does not include the payload size.
205  template<class Type>
206  void writeListsParallel
207  (
208  vtk::formatter& fmt,
209  const UList<Type>& values1,
210  const UList<Type>& values2,
211  const labelUList& addressing
212  );
213 
214 
215 /*---------------------------------------------------------------------------*\
216  Namespace legacy
217 \*---------------------------------------------------------------------------*/
218 
219 namespace legacy
220 {
221 
222 // Functions
223 
224  //- Emit header for legacy file (vtk DataFile Version 2.0)
225  // Writes "ASCII" or "BINARY" depending on specified type.
226  void fileHeader(std::ostream& os, const std::string& title, bool binary);
227 
228  //- Emit header for legacy file, with "ASCII" or "BINARY" depending on
229  //- the formatter type.
230  // If the contentType is non-empty, it is used for "DATASET" line.
231  void fileHeader
232  (
233  vtk::formatter& fmt,
234  const std::string& title,
235  const std::string& contentType
236  );
237 
238  //- Emit header for legacy file, with "ASCII" or "BINARY" depending on
239  //- the formatter type.
240  // Includes "DATASET" with the specified dataset type.
241  inline void fileHeader
242  (
243  vtk::formatter& fmt,
244  const std::string& title,
245  vtk::fileTag contentType
246  );
247 
248  //- Emit header for legacy file, with "ASCII" or "BINARY" depending on
249  //- the formatter type.
250  // Includes "DATASET" of the templated dataset type.
251  template<vtk::fileTag ContentType>
252  inline void fileHeader(vtk::formatter& fmt, const std::string& title);
253 
254  //- Emit header for POINTS (with trailing newline).
255  inline void beginPoints(std::ostream& os, label nPoints);
256 
257  //- Emit header for VERTICES (with trailing newline).
258  // The nConnectivity is the sum of all connectivity points used,
259  // but \b without additional space for the size prefixes.
260  // The additional prefix sizes are added internally.
261  // \note With nConnectivity == 0, assume one point per element
262  inline void beginVerts
263  (
264  std::ostream& os,
265  label nVerts,
266  label nConnectivity = 0
267  );
268 
269  //- Emit header for LINES (with trailing newline).
270  // The nConnectivity is the sum of all connectivity points used,
271  // but \b without additional space for the size prefixes.
272  // The additional prefix sizes are added internally.
273  // \note With nConnectivity == 0, assume two points per element
274  inline void beginLines
275  (
276  std::ostream& os,
277  label nLines,
278  label nConnectivity = 0
279  );
280 
281  //- Emit header for POLYGONS (with trailing newline).
282  // The nConnectivity is the sum of all connectivity points used,
283  // but \b without additional space for the size prefixes.
284  // The additional prefix sizes are added internally.
285  inline void beginPolys(std::ostream& os, label nPolys, label nConnectivity);
286 
287 
288  //- Emit "FIELD FieldData <n>"
289  inline void fieldData(vtk::formatter& fmt, label nFields);
290 
291  //- Emit legacy FIELD FieldData nFields.
292  inline void beginFieldData(vtk::formatter& fmt, label nFields);
293 
294  //- Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
295  inline void beginCellData
296  (
297  vtk::formatter& fmt,
298  label nCells,
299  label nFields
300  );
301 
302  //- Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
303  inline void beginPointData
304  (
305  vtk::formatter& fmt,
306  label nPoints,
307  label nFields
308  );
309 
310 
311  //- Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
312  inline void writeTimeValue(vtk::formatter& fmt, scalar timeValue);
313 
314  //- Start output of float field with the specified name.
315  template<direction nComp>
316  inline void floatField
317  (
318  vtk::formatter& fmt,
319  const word& name,
320  const label nEntries
321  );
322 
323  //- Start output of double field with the specified name.
324  template<direction nComp>
325  inline void doubleField
326  (
327  vtk::formatter& fmt,
328  const word& name,
329  const label nEntries
330  );
331 
332  //- Start output of int field with the specified name.
333  template<direction nComp>
334  inline void intField
335  (
336  vtk::formatter& fmt,
337  const word& name,
338  const label nEntries
339  );
340 
341 } // End namespace legacy
342 
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 } // End namespace vtk
347 } // End namespace Foam
348 
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 #include "foamVtkOutputI.H"
353 
354 #ifdef NoRepository
355  #include "foamVtkOutputTemplates.C"
356 #endif
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 #endif
361 
362 // ************************************************************************* //
void intField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of int field with the specified name.
void writeLists(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2, const labelUList &addressing)
Write a list of values and a list of values via indirect addressing.
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
Definition: foamVtkOutput.C:41
void writeListsParallel(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2)
Write a list of values and another list of values.
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:423
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
void beginPolys(std::ostream &os, label nPolys, label nConnectivity)
Emit header for POLYGONS (with trailing newline).
void beginPointData(vtk::formatter &fmt, label nPoints, label nFields)
Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
void fieldData(vtk::formatter &fmt, label nFields)
Emit "FIELD FieldData <n>".
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
void beginPoints(std::ostream &os, label nPoints)
Emit header for POINTS (with trailing newline).
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
void fileHeader(std::ostream &os, const std::string &title, bool binary)
Emit header for legacy file (vtk DataFile Version 2.0)
label nPoints
void writeIdentity(vtk::formatter &fmt, const label len, label start=0)
Write an identity list of labels.
Definition: foamVtkOutput.C:89
void writeTimeValue(vtk::formatter &fmt, scalar timeValue)
Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
formatType
The output format type for file contents.
Definition: foamVtkCore.H:66
void beginCellData(vtk::formatter &fmt, label nCells, label nFields)
Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
void beginLines(std::ostream &os, label nLines, label nConnectivity=0)
Emit header for LINES (with trailing newline).
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
OBJstream os(runTime.globalPath()/outputName)
fileTag
Some common XML tags for vtk files.
Definition: foamVtkCore.H:122
void doubleField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of double field with the specified name.
label n
void writeListParallel(vtk::formatter &fmt, const UList< Type > &values)
Write a list of values.
void floatField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of float field with the specified name.
void writeValueParallel(vtk::formatter &fmt, const Type &val, const label count=1)
Component-wise write of a value (N times) in parallel.
void beginVerts(std::ostream &os, label nVerts, label nConnectivity=0)
Emit header for VERTICES (with trailing newline).
Namespace for OpenFOAM.