foamVtkSurfaceWriter.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) 2018-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 Class
27  Foam::vtk::surfaceWriter
28 
29 Description
30  Write faces/points (optionally with fields)
31  as a vtp file or a legacy vtk file.
32 
33  The file output states are managed by the Foam::vtk::fileWriter class.
34  FieldData (eg, TimeValue) must appear before any geometry pieces.
35 
36 Note
37  Parallel output is combined into a single Piece without point merging,
38  which is similar to using multi-piece data sets, but allows more
39  convenient creation as a streaming process.
40  In the future, the duplicate points at processor connections
41  may be addressed using ghost points.
42 
43 SourceFiles
44  foamVtkSurfaceWriter.C
45  foamVtkSurfaceWriterTemplates.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef foamVtkSurfaceWriter_H
50 #define foamVtkSurfaceWriter_H
51 
52 #include "foamVtkFileWriter.H"
53 #include "pointField.H"
54 #include "faceList.H"
55 #include "instant.H"
56 #include <functional>
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 namespace vtk
63 {
64 
65 /*---------------------------------------------------------------------------*\
66  Class vtk::surfaceWriter Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class surfaceWriter
70 :
71  public vtk::fileWriter
72 {
73  // Private Member Data
74 
75  //- Reference to the points
76  std::reference_wrapper<const pointField> points_;
77 
78  //- Reference to the faces
79  std::reference_wrapper<const faceList> faces_;
80 
81  //- The number of field points for the current Piece
82  label numberOfPoints_;
83 
84  //- The number of field cells (faces) for the current Piece
85  label numberOfCells_;
86 
87  //- Local number of points
88  label nLocalPoints_;
89 
90  //- Local number of faces
91  label nLocalFaces_;
92 
93  //- Local face vertices (connectivity) count. Sum of face sizes.
94  label nLocalVerts_;
95 
96  //- Time name/value
97  instant instant_;
98 
99 
100  // Private Member Functions
101 
102  //- Determine sizes (nLocalPoints_, nLocalFaces_, nLocalVerts_),
103  //- and begin piece
104  void beginPiece();
105 
106  //- Write points
107  void writePoints();
108 
109  //- Write faces, legacy format
110  // \param pointOffset processor-local point offset
111  void writePolysLegacy(const label pointOffset);
112 
113  //- Write faces
114  // \param pointOffset processor-local point offset
115  void writePolys(const label pointOffset);
116 
117 
118  //- No copy construct
119  surfaceWriter(const surfaceWriter&) = delete;
120 
121  //- No copy assignment
122  void operator=(const surfaceWriter&) = delete;
123 
124 
125 public:
126 
127  // Constructors
128 
129  //- Construct from components (default format INLINE_BASE64)
131  (
132  const pointField& pts,
133  const faceList& faces,
135  );
136 
137  //- Construct from components (default format INLINE_BASE64),
138  //- and open the file for writing.
139  // The file name is with/without an extension.
141  (
142  const pointField& pts,
143  const faceList& faces,
144  const fileName& file,
145  bool parallel = Pstream::parRun()
146  );
147 
148  //- Construct from components and open the file for writing.
149  // The file name is with/without an extension.
151  (
152  const pointField& pts,
153  const faceList& faces,
154  const vtk::outputOptions opts,
155  const fileName& file,
156  bool parallel = Pstream::parRun()
157  );
158 
159 
160  //- Destructor
161  virtual ~surfaceWriter() = default;
162 
163 
164  // Member Functions
165 
166  //- File extension for current format type.
167  using vtk::fileWriter::ext;
168 
169  //- File extension for given output type
170  inline static word ext(vtk::outputOptions opts)
171  {
173  }
174 
175  //- Define a time name/value for the output
176  virtual void setTime(const instant& inst);
177 
178  //- Write file header (non-collective)
179  // \note Expected calling states: (OPENED).
180  virtual bool beginFile(std::string title = "");
181 
182  //- Write patch topology
183  // Also writes the file header if not previously written.
184  // \note Must be called prior to writing CellData or PointData
185  virtual bool writeGeometry();
186 
187  //- Begin CellData output section for specified number of fields.
188  // Must be called prior to writing any cell data fields.
189  // \param nFields is for legacy format only.
190  // When nFields=0, this a no-op for legacy format.
191  // \note Expected calling states: (PIECE | POINT_DATA).
192  //
193  // \return True if the state changed
194  virtual bool beginCellData(label nFields = 0);
195 
196  //- Begin PointData for specified number of fields.
197  // Must be called prior to writing any point data fields.
198  // \param nFields is for legacy format only.
199  // When nFields=0, this a no-op for legacy format.
200  // \note Expected calling states: (PIECE | CELL_DATA).
201  //
202  // \return True if the state changed
203  virtual bool beginPointData(label nFields = 0);
204 
205  //- Write "TimeValue" FieldData (name as per Catalyst output)
206  // Must be called within the FIELD_DATA state.
207  // \note As a convenience this can also be called from
208  // (OPENED | DECLARED) states, in which case it invokes
209  // beginFieldData(1) internally.
211 
212  //- Write the currently set time as "TimeValue" FieldData
213  void writeTimeValue();
214 
215  //- Reset point, face references to begin a new piece
216  void piece(const pointField& points, const faceList& faces);
217 
218 
219  // Write
220 
221  //- Write a uniform field of Cell (Face) or Point values
222  template<class Type>
223  void writeUniform(const word& fieldName, const Type& val);
224 
225  //- Write a list of Cell (Face) or Point values
226  template<class Type>
227  void write(const word& fieldName, const UList<Type>& field);
228 };
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace vtk
234 } // End namespace Foam
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 #ifdef NoRepository
240 #endif
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 #endif
246 
247 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::surfaceWriter::beginFile
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Definition: foamVtkSurfaceWriter.C:406
Foam::vtk::surfaceWriter::~surfaceWriter
virtual ~surfaceWriter()=default
Destructor.
Foam::vtk::surfaceWriter::piece
void piece(const pointField &points, const faceList &faces)
Reset point, face references to begin a new piece.
Definition: foamVtkSurfaceWriter.C:474
Foam::vtk::fileWriter::parallel
bool parallel() const
Parallel output requested?
Definition: foamVtkFileWriterI.H:80
Foam::vtk::fileWriter
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
Definition: foamVtkFileWriter.H:66
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::vtk::fileWriter::opts
vtk::outputOptions opts() const
The output options in use.
Definition: foamVtkFileWriterI.H:62
Foam::vtk::surfaceWriter::writeTimeValue
void writeTimeValue()
Write the currently set time as "TimeValue" FieldData.
Definition: foamVtkSurfaceWriter.C:464
Foam::vtk::surfaceWriter::beginCellData
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Definition: foamVtkSurfaceWriter.C:452
foamVtkSurfaceWriterTemplates.C
Foam::vtk::fileWriter::writeTimeValue
void writeTimeValue(scalar timeValue)
Write "TimeValue" FieldData (name as per Catalyst output)
Definition: foamVtkFileWriter.C:446
Foam::vtk::fileTag::POLY_DATA
"PolyData"
foamVtkFileWriter.H
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::vtk::surfaceWriter::writeGeometry
virtual bool writeGeometry()
Write patch topology.
Definition: foamVtkSurfaceWriter.C:426
Foam::vtk::surfaceWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Face) or Point values.
Definition: foamVtkSurfaceWriterTemplates.C:32
instant.H
faceList.H
Foam::vtk::surfaceWriter::setTime
virtual void setTime(const instant &inst)
Define a time name/value for the output.
Definition: foamVtkSurfaceWriter.C:400
Foam::Field< vector >
Foam::vtk::surfaceWriter::write
void write(const word &fieldName, const UList< Type > &field)
Write a list of Cell (Face) or Point values.
Definition: foamVtkSurfaceWriterTemplates.C:59
field
rDeltaTY field()
Foam::vtk::formatType::INLINE_BASE64
XML inline base64, base64Formatter.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::surfaceWriter::ext
static word ext(vtk::outputOptions opts)
File extension for given output type.
Definition: foamVtkSurfaceWriter.H:169
pointField.H
Foam::vtk::surfaceWriter
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
Definition: foamVtkSurfaceWriter.H:68
Foam::List< face >
Foam::UList< Type >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::vtk::outputOptions::ext
word ext(vtk::fileTag contentType) const
The file extension (legacy or xml) for the given content-type.
Definition: foamVtkOutputOptionsI.H:77
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::vtk::surfaceWriter::beginPointData
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
Definition: foamVtkSurfaceWriter.C:458
Foam::vtk::fileWriter::ext
word ext() const
File extension for current format type.
Definition: foamVtkFileWriterI.H:68