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-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 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
29 
31 (
32  vtk::formatter& fmt,
33  const std::string& title,
34  vtk::fileTag contentType
35 )
36 {
37  legacy::fileHeader(fmt, title, legacy::contentNames[contentType]);
38 }
39 
40 
41 template<Foam::vtk::fileTag ContentType>
43 (
44  vtk::formatter& fmt,
45  const std::string& title
46 )
47 {
48  legacy::fileHeader(fmt, title, legacy::contentNames[ContentType]);
49 }
50 
51 
52 inline void Foam::vtk::legacy::beginPoints(std::ostream& os, label nPoints)
53 {
54  os << nl
55  << legacy::fileTagNames[vtk::fileTag::POINTS]
56  << ' ' << nPoints
57  << " float" << nl;
58 }
59 
60 
62 (
63  std::ostream& os,
64  label nVerts,
65  label nConnectivity
66 )
67 {
68  if (nConnectivity <= 0)
69  {
70  nConnectivity = nVerts;
71  }
72  os << nl
73  << legacy::fileTagNames[vtk::fileTag::VERTS]
74  << ' ' << nVerts
75  << ' ' << (nVerts + nConnectivity) << nl;
76 }
77 
78 
80 (
81  std::ostream& os,
82  label nLines,
83  label nConnectivity
84 )
85 {
86  if (nConnectivity <= 0)
87  {
88  nConnectivity = 2*nLines;
89  }
90  os << nl
91  << legacy::fileTagNames[vtk::fileTag::LINES]
92  << ' ' << nLines
93  << ' ' << (nLines + nConnectivity) << nl;
94 }
95 
96 
98 (
99  std::ostream& os,
100  label nPolys,
101  label nConnectivity
102 )
103 {
104  os << nl
105  << legacy::fileTagNames[vtk::fileTag::POLYS]
106  << ' ' << nPolys
107  << ' ' << (nPolys + nConnectivity) << nl;
108 }
109 
110 
112 (
113  vtk::formatter& fmt,
114  label nFields
115 )
116 {
117  fmt.os()
118  << "FIELD FieldData " << nFields << nl;
119 }
120 
121 
123 (
124  vtk::formatter& fmt,
125  label nFields
126 )
127 {
128  legacy::fieldData(fmt, nFields);
129 }
130 
131 
133 (
134  vtk::formatter& fmt,
135  label nCells,
136  label nFields
137 )
138 {
139  fmt.os()
140  << nl
141  << legacy::fileTagNames[vtk::fileTag::CELL_DATA]
142  << ' ' << nCells << nl;
143  legacy::fieldData(fmt, nFields);
144 }
145 
146 
148 (
149  vtk::formatter& fmt,
150  label nPoints,
151  label nFields
152 )
153 {
154  fmt.os()
155  << nl
157  << ' ' << nPoints << nl;
158  legacy::fieldData(fmt, nFields);
159 }
160 
161 
163 (
164  vtk::formatter& fmt,
165  scalar timeValue
166 )
167 {
168  legacy::floatField<1>(fmt, "TimeValue", 1);
169  fmt.write(timeValue);
170  fmt.flush();
171 }
172 
173 
174 template<Foam::direction nComp>
176 (
177  vtk::formatter& fmt,
178  const word& fieldName,
179  label nEntries
180 )
181 {
182  fmt.os()
183  << fieldName << ' '
184  << int(nComp) << ' ' << nEntries << " double" << nl;
185 }
186 
187 
188 template<Foam::direction nComp>
190 (
191  vtk::formatter& fmt,
192  const word& fieldName,
193  label nEntries
194 )
195 {
196  fmt.os()
197  << fieldName << ' '
198  << int(nComp) << ' ' << nEntries << " float" << nl;
199 }
200 
201 
202 template<Foam::direction nComp>
203 inline void Foam::vtk::legacy::intField
204 (
205  vtk::formatter& fmt,
206  const word& fieldName,
207  label nEntries
208 )
209 {
210  fmt.os()
211  << fieldName << ' '
212  << int(nComp) << ' ' << nEntries << " int" << nl;
213 }
214 
215 
216 // ************************************************************************* //
void intField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of int field with the specified name.
Abstract class for a VTK output stream formatter.
const Foam::Enum< fileTag > fileTagNames
Strings corresponding to the vtk XML tags.
void fileHeader(std::ostream &os, const std::string &title, bool binary)
Emit header for legacy file (vtk DataFile Version 2.0)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
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.
const Foam::Enum< vtk::fileTag > contentNames
Legacy content names (POLYDATA, UNSTRUCTURED_GRID)
void fieldData(vtk::formatter &fmt, label nFields)
Emit "FIELD FieldData <n>".
void beginPoints(std::ostream &os, label nPoints)
Emit header for POINTS (with trailing newline).
std::ostream & os() noexcept
Access to the underlying output stream.
A class for handling words, derived from Foam::string.
Definition: word.H:63
label nPoints
void writeTimeValue(vtk::formatter &fmt, scalar timeValue)
Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
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=-1)
Emit header for LINES (with trailing newline).
void beginVerts(std::ostream &os, label nVerts, label nConnectivity=-1)
Emit header for VERTICES (with trailing newline).
fileTag
Some common XML tags for vtk files.
Definition: foamVtkCore.H:153
void doubleField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of double field with the specified name.
void floatField(vtk::formatter &fmt, const word &name, const label nEntries)
Start output of float field with the specified name.