VTPsurfaceFormatCore.C
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-2020 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 #include "VTPsurfaceFormatCore.H"
29 #include "clock.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
35 (
36  const dictionary& dict,
38 )
39 {
40  opts.legacy(false); // Non-legacy. Use VTKsurfaceFormat for legacy
41  opts.append(false); // No append format
42 
43  opts.ascii
44  (
45  IOstream::ASCII
46  == IOstream::formatEnum("format", dict, IOstream::BINARY)
47  );
48 
49  opts.precision
50  (
51  dict.getOrDefault("precision", IOstream::defaultPrecision())
52  );
53 
54  return opts;
55 }
56 
57 
59 (
61  const UList<point>& pts,
62  const label nFaces
63 )
64 {
65  // XML (inline)
66 
67  format
68  .xmlHeader()
69  .xmlComment("surface written " + clock::dateTime())
70  .beginVTKFile<vtk::fileTag::POLY_DATA>();
71 
72  // <Piece>
73  format
74  .tag
75  (
76  vtk::fileTag::PIECE,
77  vtk::fileAttr::NUMBER_OF_POINTS, pts.size(),
78  vtk::fileAttr::NUMBER_OF_POLYS, nFaces
79  );
80 
81 
82  // Points
83 
84  const uint64_t payLoad = vtk::sizeofData<float, 3>(pts.size());
85 
86  format.tag(vtk::fileTag::POINTS)
87  .beginDataArray<float, 3>(vtk::dataArrayAttr::POINTS);
88 
89  format.writeSize(payLoad);
90 
91  vtk::writeList(format, pts);
92  format.flush();
93 
94  format
95  .endDataArray()
96  .endTag(vtk::fileTag::POINTS);
97 }
98 
99 
101 (
103 )
104 {
105  format.endPiece(); //<-- slight cheat. </Piece> too
106 
107  format.endTag(vtk::fileTag::POLY_DATA)
108  .endVTKFile();
109 }
110 
111 
113 (
115  const UList<surfZone>& zones
116 )
117 {
118  // Zone ids as CellData
119 
120  // Number of faces covered by the zones
121  label nFaces = 0;
122  for (const surfZone& z : zones)
123  {
124  nFaces += z.size();
125  }
126 
127  const uint64_t payLoad = vtk::sizeofData<label>(nFaces);
128 
129  format.beginCellData();
130  format.beginDataArray<label>("region");
131  format.writeSize(payLoad);
132 
133  label zoneId = 0;
134  for (const surfZone& z : zones)
135  {
136  vtk::write(format, zoneId, z.size());
137  ++zoneId;
138  }
139 
140  format.flush();
141  format.endDataArray();
142 
143  format.endCellData();
144 }
145 
146 
148 (
150  const labelUList& zoneIds
151 )
152 {
153  // Zone ids as CellData
154 
155  const uint64_t payLoad = vtk::sizeofData<label>(zoneIds.size());
156 
157  format.beginCellData();
158  format.beginDataArray<label>("region");
159 
160  format.writeSize(payLoad);
161  vtk::writeList(format, zoneIds);
162 
163  format.flush();
164  format.endDataArray();
165 
166  format.endCellData();
167 }
168 
169 
170 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::outputOptions::precision
unsigned precision() const
Return the ASCII write precision.
Definition: foamVtkOutputOptionsI.H:126
Foam::vtk::outputOptions::legacy
bool legacy() const
True if writer uses legacy file format.
Definition: foamVtkOutputOptionsI.H:88
format
word format(conversionProperties.get< word >("format"))
Foam::fileFormats::VTPsurfaceFormatCore::writeFooter
static void writeFooter(vtk::formatter &format)
Write footer.
Definition: VTPsurfaceFormatCore.C:101
Foam::fileFormats::VTPsurfaceFormatCore::writeCellData
static void writeCellData(vtk::formatter &format, const UList< surfZone > &zones)
Write regions (zones) information as CellData.
Definition: VTPsurfaceFormatCore.C:113
Foam::vtk::outputOptions::ascii
bool ascii() const
True if output format is ASCII.
Definition: foamVtkOutputOptionsI.H:120
Foam::vtk::outputOptions::append
bool append() const
True if output format uses an append mode.
Definition: foamVtkOutputOptionsI.H:104
clock.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
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::fileFormats::VTPsurfaceFormatCore::formatOptions
static vtk::outputOptions formatOptions(const dictionary &dict, vtk::outputOptions opts=vtk::formatType::INLINE_BASE64)
Extract format options (default format INLINE_BASE64)
Definition: VTPsurfaceFormatCore.C:35
VTPsurfaceFormatCore.H
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:56
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::fileFormats::VTPsurfaceFormatCore::writeHeader
static void writeHeader(vtk::formatter &format, const UList< point > &pts, const label nFaces)
Write header information with points.
Definition: VTPsurfaceFormatCore.C:59
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::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68