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-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 \*---------------------------------------------------------------------------*/
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  << "POINTS " << nPoints << " float" << nl;
117 }
118 
119 
121 (
122  std::ostream& os,
123  label nPolys,
124  label nConnectivity
125 )
126 {
127  os << nl
128  << "POLYGONS " << nPolys << ' ' << (nPolys + nConnectivity) << nl;
129 }
130 
131 
133 (
134  vtk::formatter& fmt,
135  label nFields
136 )
137 {
138  fmt.os()
139  << "FIELD FieldData " << nFields << nl;
140 }
141 
142 
144 (
145  vtk::formatter& fmt,
146  label nFields
147 )
148 {
149  legacy::fieldData(fmt, nFields);
150 }
151 
152 
154 (
155  vtk::formatter& fmt,
156  label nCells,
157  label nFields
158 )
159 {
160  fmt.os()
161  << nl
162  << legacy::dataTypeNames[vtk::fileTag::CELL_DATA]
163  << ' ' << nCells << nl;
164  legacy::fieldData(fmt, nFields);
165 }
166 
167 
169 (
170  vtk::formatter& fmt,
171  label nPoints,
172  label nFields
173 )
174 {
175  fmt.os()
176  << nl
178  << ' ' << nPoints << nl;
179  legacy::fieldData(fmt, nFields);
180 }
181 
182 
184 (
185  vtk::formatter& fmt,
186  scalar timeValue
187 )
188 {
189  legacy::floatField<1>(fmt, "TimeValue", 1);
190  fmt.write(timeValue);
191  fmt.flush();
192 }
193 
194 
195 template<Foam::direction nComp>
197 (
198  vtk::formatter& fmt,
199  const word& fieldName,
200  label nEntries
201 )
202 {
203  fmt.os()
204  << fieldName << ' '
205  << int(nComp) << ' ' << nEntries << " double" << nl;
206 }
207 
208 
209 template<Foam::direction nComp>
211 (
212  vtk::formatter& fmt,
213  const word& fieldName,
214  label nEntries
215 )
216 {
217  fmt.os()
218  << fieldName << ' '
219  << int(nComp) << ' ' << nEntries << " float" << nl;
220 }
221 
222 
223 template<Foam::direction nComp>
224 inline void Foam::vtk::legacy::intField
225 (
226  vtk::formatter& fmt,
227  const word& fieldName,
228  label nEntries
229 )
230 {
231  fmt.os()
232  << fieldName << ' '
233  << int(nComp) << ' ' << nEntries << " int" << nl;
234 }
235 
236 
237 // ************************************************************************* //
Foam::SymmTensor< scalar >
Foam::vtk::legacy::dataTypeNames
const Foam::Enum< vtk::fileTag > dataTypeNames
Legacy data type names (CELL_DATA, POINT_DATA)
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:62
Foam::vtk::legacy::contentNames
const Foam::Enum< vtk::fileTag > contentNames
Legacy content names (POLYDATA, UNSTRUCTURED_GRID)
Foam::expressions::patchExpr::POINT_DATA
Point data.
Definition: patchExprFwd.H:60
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::SymmTensor::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:169
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:133
Foam::vtk::legacy::beginFieldData
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
Definition: foamVtkOutputI.H:144
Foam::SymmTensor::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:184
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::YZ
Definition: SymmTensor.H:82
Foam::SymmTensor::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.
Definition: foamVtkOutput.C:213
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::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:154
Foam::SymmTensor::XY
Definition: SymmTensor.H:82
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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
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::SymmTensor::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:197
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68