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-2019 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 foamVtkOutput_H
46 #define foamVtkOutput_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  //- Write a list of uint8_t values.
98  // The output does not include the payload size.
99  void writeListParallel(vtk::formatter& fmt, const UList<uint8_t>& values);
100 
101  //- Component-wise write of a value (N times)
102  template<class Type>
103  inline void write(vtk::formatter& fmt, const Type& val, const label n=1);
104 
105 
106  //- Write a list of values.
107  // The output does not include the payload size.
108  template<class Type>
109  void writeList(vtk::formatter& fmt, const UList<Type>& values);
110 
111  //- Write a list of values.
112  // The output does not include the payload size.
113  template<class Type, unsigned N>
114  void writeList(vtk::formatter& fmt, const FixedList<Type, N>& values);
115 
116 
117  //- Write a list of values via indirect addressing.
118  // The output does not include the payload size.
119  template<class Type>
120  void writeList
121  (
122  vtk::formatter& fmt,
123  const UList<Type>& values,
124  const labelUList& addressing
125  );
126 
127  //- Write a list of values via indirect addressing.
128  // The output does not include the payload size.
129  template<class Type>
130  void writeList
131  (
132  vtk::formatter& fmt,
133  const UList<Type>& values,
134  const bitSet& selected
135  );
136 
137  //- Write a list of values and a list of values via indirect addressing.
138  // The output does not include the payload size.
139  template<class Type>
140  void writeLists
141  (
142  vtk::formatter& fmt,
143  const UList<Type>& values1,
144  const UList<Type>& values2,
145  const labelUList& addressing
146  );
147 
148 
149  //- Write a list of values.
150  // The output does not include the payload size.
151  template<class Type>
152  void writeListParallel
153  (
154  vtk::formatter& fmt,
155  const UList<Type>& values
156  );
157 
158  //- Write a list of values, with constant per-processor offset
159  // The output does not include the payload size.
160  void writeListParallel
161  (
162  vtk::formatter& fmt,
163  const UList<label>& values,
164  const globalIndex& procOffset
165  );
166 
167  //- Write a list of values via indirect addressing.
168  // The output does not include the payload size.
169  template<class Type>
170  void writeListParallel
171  (
172  vtk::formatter& fmt,
173  const UList<Type>& values,
174  const labelUList& addressing
175  );
176 
177  //- Write a list of values via indirect addressing.
178  // The output does not include the payload size.
179  template<class Type>
180  void writeListParallel
181  (
182  vtk::formatter& fmt,
183  const UList<Type>& values,
184  const bitSet& selected
185  );
186 
187  //- Write a list of values and another list of values.
188  // The output does not include the payload size.
189  template<class Type>
190  void writeListsParallel
191  (
192  vtk::formatter& fmt,
193  const UList<Type>& values1,
194  const UList<Type>& values2
195  );
196 
197  //- Write a list of values and a list of values via indirect addressing.
198  // The output does not include the payload size.
199  template<class Type>
200  void writeListsParallel
201  (
202  vtk::formatter& fmt,
203  const UList<Type>& values1,
204  const UList<Type>& values2,
205  const labelUList& addressing
206  );
207 
208 
209 /*---------------------------------------------------------------------------*\
210  Namespace legacy
211 \*---------------------------------------------------------------------------*/
212 
213 namespace legacy
214 {
215 
216 // Functions
217 
218  //- Emit header for legacy file.
219  // Writes "ASCII" or "BINARY" depending on specified type.
220  void fileHeader(std::ostream& os, const std::string& title, bool binary);
221 
222  //- Emit header for legacy file, with "ASCII" or "BINARY" depending on
223  //- the formatter type.
224  // If the contentType is non-empty, it is used for "DATASET" line.
225  void fileHeader
226  (
227  vtk::formatter& fmt,
228  const std::string& title,
229  const std::string& contentType
230  );
231 
232  //- Emit header for legacy file, with "ASCII" or "BINARY" depending on
233  //- the formatter type.
234  // Includes "DATASET" with the specified dataset type.
235  inline void fileHeader
236  (
237  vtk::formatter& fmt,
238  const std::string& title,
239  vtk::fileTag contentType
240  );
241 
242  //- Emit header for legacy file, with "ASCII" or "BINARY" depending on
243  //- the formatter type.
244  // Includes "DATASET" of the templated dataset type.
245  template<vtk::fileTag ContentType>
246  inline void fileHeader(vtk::formatter& fmt, const std::string& title);
247 
248  //- Emit header for POINTS (with trailing newline).
249  inline void beginPoints(std::ostream& os, label nPoints);
250 
251  //- Emit header for POLYGONS (with trailing newline).
252  // The nConnectivity is the sum of all connectivity points used,
253  // but \b without additional space for the size prefixes.
254  // The additional prefix sizes are added internally.
255  inline void beginPolys(std::ostream& os, label nPolys, label nConnectivity);
256 
257 
258  //- Emit "FIELD FieldData <n>"
259  inline void fieldData(vtk::formatter& fmt, label nFields);
260 
261  //- Emit legacy FIELD FieldData nFields.
262  inline void beginFieldData(vtk::formatter& fmt, label nFields);
263 
264  //- Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
265  inline void beginCellData
266  (
267  vtk::formatter& fmt,
268  label nCells,
269  label nFields
270  );
271 
272  //- Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
273  inline void beginPointData
274  (
275  vtk::formatter& fmt,
276  label nPoints,
277  label nFields
278  );
279 
280 
281  //- Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
282  inline void writeTimeValue(vtk::formatter& fmt, scalar timeValue);
283 
284  //- Start output of float field with the specified name.
285  template<direction nComp>
286  inline void floatField
287  (
288  vtk::formatter& fmt,
289  const word& name,
290  const label nEntries
291  );
292 
293  //- Start output of double field with the specified name.
294  template<direction nComp>
295  inline void doubleField
296  (
297  vtk::formatter& fmt,
298  const word& name,
299  const label nEntries
300  );
301 
302  //- Start output of int field with the specified name.
303  template<direction nComp>
304  inline void intField
305  (
306  vtk::formatter& fmt,
307  const word& name,
308  const label nEntries
309  );
310 
311 } // End namespace legacy
312 
313 
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 
316 } // End namespace vtk
317 } // End namespace Foam
318 
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 #include "foamVtkOutputI.H"
323 
324 #ifdef NoRepository
325  #include "foamVtkOutputTemplates.C"
326 #endif
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 #endif
331 
332 // ************************************************************************* //
Foam::vtk::writeListParallel
void writeListParallel(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:126
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:121
Foam::vtk::legacy::beginPointData
void beginPointData(vtk::formatter &fmt, label nPoints, label nFields)
Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
Definition: foamVtkOutputI.H:169
Foam::vtk::legacy::fieldData
void fieldData(vtk::formatter &fmt, label nFields)
Emit "FIELD FieldData <n>".
Definition: foamVtkOutputI.H:133
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:255
foamVtkOutputI.H
bitSet.H
Foam::vtk::legacy::beginFieldData
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
Definition: foamVtkOutputI.H:144
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:184
symmTensor.H
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
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:113
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.
Definition: foamVtkOutput.C:224
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:154
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:333
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:211
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:225
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:35
Foam::vtk::newFormatter
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
Definition: foamVtkOutput.C:48
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
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:197
autoPtr.H
Enum.H