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-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 #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  const word formatName = dict.lookupOrDefault<word>("format", "");
44  if (formatName.size())
45  {
46  opts.ascii(IOstream::formatEnum(formatName) == IOstream::ASCII);
47  }
48 
49  opts.precision
50  (
51  dict.lookupOrDefault
52  (
53  "precision",
54  IOstream::defaultPrecision()
55  )
56  );
57 
58  return opts;
59 }
60 
61 
63 (
65  const UList<point>& pts,
66  const label nFaces
67 )
68 {
69  // XML (inline)
70 
71  format
72  .xmlHeader()
73  .xmlComment("surface written " + clock::dateTime())
74  .beginVTKFile<vtk::fileTag::POLY_DATA>();
75 
76  // <Piece>
77  format
78  .tag
79  (
80  vtk::fileTag::PIECE,
81  vtk::fileAttr::NUMBER_OF_POINTS, pts.size(),
82  vtk::fileAttr::NUMBER_OF_POLYS, nFaces
83  );
84 
85 
86  // Points
87 
88  const uint64_t payLoad = vtk::sizeofData<float, 3>(pts.size());
89 
90  format.tag(vtk::fileTag::POINTS)
91  .beginDataArray<float, 3>(vtk::dataArrayAttr::POINTS);
92 
93  format.writeSize(payLoad);
94 
95  vtk::writeList(format, pts);
96  format.flush();
97 
98  format
99  .endDataArray()
100  .endTag(vtk::fileTag::POINTS);
101 }
102 
103 
105 (
107 )
108 {
109  format.endPiece(); //<-- slight cheat. </Piece> too
110 
111  format.endTag(vtk::fileTag::POLY_DATA)
112  .endVTKFile();
113 }
114 
115 
117 (
119  const UList<surfZone>& zones
120 )
121 {
122  // Zone ids as CellData
123 
124  // Number of faces covered by the zones
125  label nFaces = 0;
126  for (const surfZone& z : zones)
127  {
128  nFaces += z.size();
129  }
130 
131  const uint64_t payLoad = vtk::sizeofData<label>(nFaces);
132 
133  format.beginCellData();
134  format.beginDataArray<label>("region");
135  format.writeSize(payLoad);
136 
137  label zoneId = 0;
138  for (const surfZone& z : zones)
139  {
140  vtk::write(format, zoneId, z.size());
141  ++zoneId;
142  }
143 
144  format.flush();
145  format.endDataArray();
146 
147  format.endCellData();
148 }
149 
150 
152 (
154  const labelUList& zoneIds
155 )
156 {
157  // Zone ids as CellData
158 
159  const uint64_t payLoad = vtk::sizeofData<label>(zoneIds.size());
160 
161  format.beginCellData();
162  format.beginDataArray<label>("region");
163 
164  format.writeSize(payLoad);
165  vtk::writeList(format, zoneIds);
166 
167  format.flush();
168  format.endDataArray();
169 
170  format.endCellData();
171 }
172 
173 
174 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:105
Foam::fileFormats::VTPsurfaceFormatCore::writeCellData
static void writeCellData(vtk::formatter &format, const UList< surfZone > &zones)
Write regions (zones) information as CellData.
Definition: VTPsurfaceFormatCore.C:117
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:121
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:65
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:63
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::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68