foamVtkOutputI.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) 2017-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 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 namespace vtk
33 {
34 
35 //- Template specialization for label
36 template<>
37 inline void write<label>(vtk::formatter& fmt, const label& val, const label n)
38 {
39  for (label i=0; i < n; ++i)
40  {
41  fmt.write(val);
42  }
43 }
44 
45 
46 //- Template specialization for float
47 template<>
48 inline void write<float>(vtk::formatter& fmt, const float& val, const label n)
49 {
50  for (label i=0; i < n; ++i)
51  {
52  fmt.write(val);
53  }
54 }
55 
56 
57 //- Template specialization for double
58 template<>
59 inline void write<double>(vtk::formatter& fmt, const double& val, const label n)
60 {
61  for (label i=0; i < n; ++i)
62  {
63  fmt.write(val);
64  }
65 }
66 
67 
68 //- Template specialization for symmTensor ordering
69 // VTK order is (XX, YY, ZZ, XY, YZ, XZ)
70 template<>
71 inline void write(vtk::formatter& fmt, const symmTensor& val, const label n)
72 {
73  for (label i=0; i < n; ++i)
74  {
75  fmt.write(component(val, symmTensor::XX));
76  fmt.write(component(val, symmTensor::YY));
77  fmt.write(component(val, symmTensor::ZZ));
78  fmt.write(component(val, symmTensor::XY));
79  fmt.write(component(val, symmTensor::YZ));
80  fmt.write(component(val, symmTensor::XZ));
81  }
82 }
83 
84 
85 } // End namespace vtk
86 } // End namespace Foam
87 
88 
89 // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
90 
92 (
93  vtk::formatter& fmt,
94  const std::string& title,
95  vtk::fileTag contentType
96 )
97 {
98  legacy::fileHeader(fmt, title, legacy::contentNames[contentType]);
99 }
100 
101 
102 template<Foam::vtk::fileTag ContentType>
104 (
105  vtk::formatter& fmt,
106  const std::string& title
107 )
108 {
109  legacy::fileHeader(fmt, title, legacy::contentNames[ContentType]);
110 }
111 
112 
113 inline void Foam::vtk::legacy::beginPoints(std::ostream& os, label nPoints)
114 {
115  os << nl
116  << legacy::fileTagNames[vtk::fileTag::POINTS]
117  << ' ' << nPoints
118  << " float" << nl;
119 }
120 
121 
123 (
124  std::ostream& os,
125  label nLines,
126  label nConnectivity
127 )
128 {
129  os << nl
130  << legacy::fileTagNames[vtk::fileTag::LINES]
131  << ' ' << nLines
132  << ' ' << (nLines + nConnectivity) << nl;
133 }
134 
135 
137 (
138  std::ostream& os,
139  label nPolys,
140  label nConnectivity
141 )
142 {
143  os << nl
144  << legacy::fileTagNames[vtk::fileTag::POLYS]
145  << ' ' << nPolys
146  << ' ' << (nPolys + nConnectivity) << nl;
147 }
148 
149 
151 (
152  vtk::formatter& fmt,
153  label nFields
154 )
155 {
156  fmt.os()
157  << "FIELD FieldData " << nFields << nl;
158 }
159 
160 
162 (
163  vtk::formatter& fmt,
164  label nFields
165 )
166 {
167  legacy::fieldData(fmt, nFields);
168 }
169 
170 
172 (
173  vtk::formatter& fmt,
174  label nCells,
175  label nFields
176 )
177 {
178  fmt.os()
179  << nl
180  << legacy::fileTagNames[vtk::fileTag::CELL_DATA]
181  << ' ' << nCells << nl;
182  legacy::fieldData(fmt, nFields);
183 }
184 
185 
187 (
188  vtk::formatter& fmt,
189  label nPoints,
190  label nFields
191 )
192 {
193  fmt.os()
194  << nl
196  << ' ' << nPoints << nl;
197  legacy::fieldData(fmt, nFields);
198 }
199 
200 
202 (
203  vtk::formatter& fmt,
204  scalar timeValue
205 )
206 {
207  legacy::floatField<1>(fmt, "TimeValue", 1);
208  fmt.write(timeValue);
209  fmt.flush();
210 }
211 
212 
213 template<Foam::direction nComp>
215 (
216  vtk::formatter& fmt,
217  const word& fieldName,
218  label nEntries
219 )
220 {
221  fmt.os()
222  << fieldName << ' '
223  << int(nComp) << ' ' << nEntries << " double" << nl;
224 }
225 
226 
227 template<Foam::direction nComp>
229 (
230  vtk::formatter& fmt,
231  const word& fieldName,
232  label nEntries
233 )
234 {
235  fmt.os()
236  << fieldName << ' '
237  << int(nComp) << ' ' << nEntries << " float" << nl;
238 }
239 
240 
241 template<Foam::direction nComp>
242 inline void Foam::vtk::legacy::intField
243 (
244  vtk::formatter& fmt,
245  const word& fieldName,
246  label nEntries
247 )
248 {
249  fmt.os()
250  << fieldName << ' '
251  << int(nComp) << ' ' << nEntries << " int" << nl;
252 }
253 
254 
255 // ************************************************************************* //
Foam::SymmTensor
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements,...
Definition: SymmTensor.H:58
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::vtk::legacy::contentNames
const Foam::Enum< vtk::fileTag > contentNames
Legacy content names (POLYDATA, UNSTRUCTURED_GRID)
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::SymmTensor< scalar >::XX
Definition: SymmTensor.H:82
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::write< label >
void write< label >(vtk::formatter &fmt, const label &val, const label n)
Template specialization for label.
Definition: foamVtkOutputI.H:37
Foam::vtk::legacy::fieldData
void fieldData(vtk::formatter &fmt, label nFields)
Emit "FIELD FieldData <n>".
Definition: foamVtkOutputI.H:151
Foam::vtk::legacy::beginFieldData
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
Definition: foamVtkOutputI.H:162
Foam::SymmTensor< scalar >::YY
Definition: SymmTensor.H:82
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::vtk::formatter::os
std::ostream & os()
Access to the underlying output stream.
Definition: foamVtkFormatterI.H:70
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
Foam::vtk::write< double >
void write< double >(vtk::formatter &fmt, const double &val, const label n)
Template specialization for double.
Definition: foamVtkOutputI.H:59
Foam::SymmTensor< scalar >::YZ
Definition: SymmTensor.H:82
Foam::SymmTensor< scalar >::ZZ
Definition: SymmTensor.H:82
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::formatter::flush
virtual void flush()=0
Flush encoding, write newline etc.
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::fileTagNames
const Foam::Enum< fileTag > fileTagNames
Strings corresponding to the vtk XML tags.
Foam::vtk::write< float >
void write< float >(vtk::formatter &fmt, const float &val, const label n)
Template specialization for float.
Definition: foamVtkOutputI.H:48
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::SymmTensor< scalar >::XY
Definition: SymmTensor.H:82
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::nl
constexpr char nl
Definition: Ostream.H:404
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
Foam::expressions::POINT_DATA
Point data.
Definition: exprFieldAssociation.H:46
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::SymmTensor< scalar >::XZ
Definition: SymmTensor.H:82
Foam::vtk::formatter::write
virtual void write(const uint8_t val)=0
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
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68