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-2023 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 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef Foam_vtk_surfaceWriter_H
49 #define Foam_vtk_surfaceWriter_H
50 
51 #include "foamVtkPolyWriter.H"
52 #include "instant.H"
53 #include <functional>
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace vtk
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class vtk::surfaceWriter Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class surfaceWriter
67 :
68  public vtk::polyWriter
69 {
70  // Private Member Data
71 
72  //- Reference to the points
73  std::reference_wrapper<const pointField> points_;
74 
75  //- Reference to the faces
76  std::reference_wrapper<const faceList> faces_;
77 
78  //- Time name/value
79  instant instant_;
80 
81 
82  // Private Member Functions
83 
84  //- No copy construct
85  surfaceWriter(const surfaceWriter&) = delete;
86 
87  //- No copy assignment
88  void operator=(const surfaceWriter&) = delete;
89 
90 
91 public:
92 
93  // Constructors
94 
95  //- Construct from components (default format INLINE_BASE64)
97  (
98  const pointField& pts,
99  const faceList& faces,
101  );
102 
103  //- Construct from components (default format INLINE_BASE64),
104  //- and open the file for writing.
105  // The file name is with/without an extension.
107  (
108  const pointField& pts,
109  const faceList& faces,
110  const fileName& file,
111  bool parallel = Pstream::parRun()
112  );
113 
114  //- Construct from components and open the file for writing.
115  // The file name is with/without an extension.
117  (
118  const pointField& pts,
119  const faceList& faces,
120  const vtk::outputOptions opts,
121  const fileName& file,
122  bool parallel = Pstream::parRun()
123  );
124 
125 
126  //- Destructor
127  virtual ~surfaceWriter() = default;
128 
129 
130  // Member Functions
131 
132  //- Define a time name/value for the output
133  virtual void setTime(const instant& inst);
134 
135  //- Write file header (non-collective)
136  // \note Expected calling states: (OPENED).
137  virtual bool beginFile(std::string title = "");
138 
139  //- Write patch topology
140  // Also writes the file header if not previously written.
141  // \note Must be called prior to writing CellData or PointData
142  virtual bool writeGeometry();
143 
144  //- Write "TimeValue" FieldData (name as per Catalyst output)
145  // Must be called within the FIELD_DATA state.
146  // \note As a convenience this can also be called from
147  // (OPENED | DECLARED) states, in which case it invokes
148  // beginFieldData(1) internally.
150 
151  //- Write the currently set time as "TimeValue" FieldData
152  void writeTimeValue();
153 
154  //- Reset point/face references to begin a new piece
155  void piece(const pointField& points, const faceList& faces);
156 
157 
158  //- Write processor ids for each poly as CellData or for each point
159  //- as PointData, depending on isPointData() state. No-op in serial.
160  bool writeProcIDs();
161 
162  //- Write a uniform field of Cell (Poly) or Point values
163  template<class Type>
164  void writeUniform(const word& fieldName, const Type& val)
165  {
166  polyWriter::writeUniformValue<Type>(nLocalPolys_, fieldName, val);
167  }
168 };
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 } // End namespace vtk
174 } // End namespace Foam
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #endif
179 
180 // ************************************************************************* //
bool parallel() const noexcept
Parallel output requested?
A class for handling file names.
Definition: fileName.H:72
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
vtk::outputOptions opts() const noexcept
The output options in use.
void writeTimeValue(scalar timeValue)
Write "TimeValue" FieldData (name as per Catalyst output)
Encapsulated combinations of output format options. This is primarily useful when defining the output...
const pointField & points
virtual bool beginFile(std::string title="")
Write file header (non-collective)
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual ~surfaceWriter()=default
Destructor.
void piece(const pointField &points, const faceList &faces)
Reset point/face references to begin a new piece.
bool writeProcIDs()
Write processor ids for each poly as CellData or for each point as PointData, depending on isPointDat...
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
virtual void setTime(const instant &inst)
Define a time name/value for the output.
label nLocalPolys_
Local number of polys (faces)
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
XML inline base64, base64Formatter.
virtual bool writeGeometry()
Write patch topology.
void writeTimeValue()
Write the currently set time as "TimeValue" FieldData.
Namespace for OpenFOAM.
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Poly) or Point values.
const pointField & pts