VTKsurfaceFormatCore.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 
29 #include "clock.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
35 (
36  const dictionary& dict,
38 )
39 {
40  opts.legacy(true); // Legacy. Use VTPsurfaceFormat for non-legacy
41  opts.append(false); // No append format for legacy
42 
43  opts.ascii
44  (
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 )
63 {
64  vtk::legacy::fileHeader<vtk::fileTag::POLY_DATA>
65  (
66  format,
67  ("surface written " + clock::dateTime())
68  );
69 
70  vtk::legacy::beginPoints(format.os(), pts.size());
71 
73  format.flush();
74 }
75 
76 
78 (
80  const UList<surfZone>& zones
81 )
82 {
83  // Zone ids as CellData
84 
85  // Number of faces covered by the zones
86  label nFaces = 0;
87  for (const surfZone& z : zones)
88  {
89  nFaces += z.size();
90  }
91 
92  vtk::legacy::beginCellData(format, nFaces, 1); // 1 field
93  vtk::legacy::intField<1>(format, "region", nFaces); // 1 component
94 
95  label zoneId = 0;
96  for (const surfZone& z : zones)
97  {
98  vtk::write(format, zoneId, z.size());
99  ++zoneId;
100  }
101  format.flush();
102 }
103 
104 
106 (
108  const labelUList& zoneIds
109 )
110 {
111  // Zone ids as CellData
112 
113  // Number of faces
114  const label nFaces = zoneIds.size();
115 
116  vtk::legacy::beginCellData(format, nFaces, 1); // 1 field
117  vtk::legacy::intField<1>(format, "region", nFaces); // 1 component
118 
119  vtk::writeList(format, zoneIds);
120  format.flush();
121 }
122 
123 
124 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
Abstract class for a VTK output stream formatter.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool append() const noexcept
True if output format uses an append mode.
A surface zone on a MeshedSurface.
Definition: surfZone.H:52
"ascii" (normal default)
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:423
static vtk::outputOptions formatOptions(const dictionary &dict, vtk::outputOptions opts=vtk::formatType::LEGACY_ASCII)
Extract format options (default format LEGACY_ASCII)
Encapsulated combinations of output format options. This is primarily useful when defining the output...
static void writeCellData(vtk::formatter &format, const UList< surfZone > &zones)
Write regions (zones) information as CellData.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
void beginPoints(std::ostream &os, label nPoints)
Emit header for POINTS (with trailing newline).
unsigned precision() const noexcept
Return the ASCII write precision.
static std::string dateTime()
The current wall-clock date/time (in local time) as a string in ISO-8601 format (yyyy-mm-ddThh:mm:ss)...
Definition: clock.C:53
void beginCellData(vtk::formatter &fmt, label nCells, label nFields)
Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
bool ascii() const noexcept
True if output format is ASCII.
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:105
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
word format(conversionProperties.get< word >("format"))
static streamFormat formatEnum(const word &fmtName, const streamFormat deflt=streamFormat::ASCII)
Lookup streamFormat enum corresponding to the string (ascii | binary).
bool legacy() const noexcept
True if writer uses legacy file format.
static void writeHeader(vtk::formatter &format, const UList< point > &pts)
Write header information with points.
const pointField & pts