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-2021 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 LINES (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  inline void beginLines(std::ostream& os, label nLines, label nConnectivity);
262 
263  //- Emit header for POLYGONS (with trailing newline).
264  // The nConnectivity is the sum of all connectivity points used,
265  // but \b without additional space for the size prefixes.
266  // The additional prefix sizes are added internally.
267  inline void beginPolys(std::ostream& os, label nPolys, label nConnectivity);
268 
269 
270  //- Emit "FIELD FieldData <n>"
271  inline void fieldData(vtk::formatter& fmt, label nFields);
272 
273  //- Emit legacy FIELD FieldData nFields.
274  inline void beginFieldData(vtk::formatter& fmt, label nFields);
275 
276  //- Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
277  inline void beginCellData
278  (
279  vtk::formatter& fmt,
280  label nCells,
281  label nFields
282  );
283 
284  //- Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
285  inline void beginPointData
286  (
287  vtk::formatter& fmt,
288  label nPoints,
289  label nFields
290  );
291 
292 
293  //- Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
294  inline void writeTimeValue(vtk::formatter& fmt, scalar timeValue);
295 
296  //- Start output of float field with the specified name.
297  template<direction nComp>
298  inline void floatField
299  (
300  vtk::formatter& fmt,
301  const word& name,
302  const label nEntries
303  );
304 
305  //- Start output of double field with the specified name.
306  template<direction nComp>
307  inline void doubleField
308  (
309  vtk::formatter& fmt,
310  const word& name,
311  const label nEntries
312  );
313 
314  //- Start output of int field with the specified name.
315  template<direction nComp>
316  inline void intField
317  (
318  vtk::formatter& fmt,
319  const word& name,
320  const label nEntries
321  );
322 
323 } // End namespace legacy
324 
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 } // End namespace vtk
329 } // End namespace Foam
330 
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 #include "foamVtkOutputI.H"
335 
336 #ifdef NoRepository
337  #include "foamVtkOutputTemplates.C"
338 #endif
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 #endif
343 
344 // ************************************************************************* //
foamVtkFormatter.H
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
foamVtkOutputTemplates.C
Foam::vtk::writeIdentity
void writeIdentity(vtk::formatter &fmt, const label len, label start=0)
Write an identity list of labels.
Definition: foamVtkOutput.C:96
Foam::vtk::legacy::beginPolys
void beginPolys(std::ostream &os, label nPolys, label nConnectivity)
Emit header for POLYGONS (with trailing newline).
Definition: foamVtkOutputI.H:137
Foam::vtk::legacy::beginPointData
void beginPointData(vtk::formatter &fmt, label nPoints, label nFields)
Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
Definition: foamVtkOutputI.H:187
Foam::vtk::legacy::fieldData
void fieldData(vtk::formatter &fmt, label nFields)
Emit "FIELD FieldData <n>".
Definition: foamVtkOutputI.H:151
Foam::vtk::writeListsParallel
void writeListsParallel(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2)
Write a list of values and another list of values.
Definition: foamVtkOutputTemplates.C:353
foamVtkOutputI.H
bitSet.H
Foam::vtk::legacy::beginFieldData
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
Definition: foamVtkOutputI.H:162
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::vtk::formatType
formatType
The output format type for file contents.
Definition: foamVtkCore.H:65
Foam::vtk::legacy::writeTimeValue
void writeTimeValue(vtk::formatter &fmt, scalar timeValue)
Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
Definition: foamVtkOutputI.H:202
symmTensor.H
Foam::vtk::writeValueParallel
void writeValueParallel(vtk::formatter &fmt, const Type &val, const label count=1)
Component-wise write of a value (N times) in parallel.
Definition: foamVtkOutputTemplates.C:128
IOstream.H
Foam::vtk::writeList
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:112
Foam::vtk::writeLists
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.
Definition: foamVtkOutputTemplates.C:114
Foam::vtk::legacy::beginPoints
void beginPoints(std::ostream &os, label nPoints)
Emit header for POINTS (with trailing newline).
Definition: foamVtkOutputI.H:113
Foam::vtk::legacy::fileHeader
void fileHeader(std::ostream &os, const std::string &title, bool binary)
Emit header for legacy file (vtk DataFile Version 2.0)
Definition: foamVtkOutput.C:188
os
OBJstream os(runTime.globalPath()/outputName)
Foam::vtk::fileTag
fileTag
Some common XML tags for vtk files.
Definition: foamVtkCore.H:113
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::legacy::beginCellData
void beginCellData(vtk::formatter &fmt, label nCells, label nFields)
Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
Definition: foamVtkOutputI.H:172
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
Foam::vtk::legacy::beginLines
void beginLines(std::ostream &os, label nLines, label nConnectivity)
Emit header for LINES (with trailing newline).
Definition: foamVtkOutputI.H:123
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::vtk::legacy::floatField
void floatField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of float field with the specified name.
Definition: foamVtkOutputI.H:229
foamVtkCore.H
floatScalar.H
Foam::vtk::legacy::intField
void intField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of int field with the specified name.
Definition: foamVtkOutputI.H:243
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::vtk::newFormatter
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
Definition: foamVtkOutput.C:48
Foam::vtk::writeListParallel
void writeListParallel(vtk::formatter &fmt, const UList< Type > &values)
Write a list of values.
Definition: foamVtkOutputTemplates.C:164
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
Foam::vtk::legacy::doubleField
void doubleField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of double field with the specified name.
Definition: foamVtkOutputI.H:215
autoPtr.H
Enum.H