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-2021 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
159  //- (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 // ************************************************************************* //
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:84
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:120
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
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:110
Foam::vtk::fileWriter::writeTimeValue
void writeTimeValue(scalar timeValue)
Write "TimeValue" FieldData (name as per Catalyst output)
Definition: foamVtkFileWriter.C:518
Foam::vtk::surfaceWriter::writeGeometry
virtual bool writeGeometry()
Write patch topology.
Definition: foamVtkSurfaceWriter.C:104
Foam::vtk::surfaceWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Poly) or Point values.
Definition: foamVtkSurfaceWriter.H:163
instant.H
Foam::vtk::surfaceWriter::setTime
virtual void setTime(const instant &inst)
Define a time name/value for the output.
Definition: foamVtkSurfaceWriter.C:78
Foam::vtk::fileWriter::parallel
bool parallel() const noexcept
Parallel output requested?
Definition: foamVtkFileWriterI.H:80
Foam::Field< vector >
Foam::vtk::surfaceWriter::writeProcIDs
bool writeProcIDs()
Definition: foamVtkSurfaceWriter.C:132
Foam::vtk::formatType::INLINE_BASE64
XML inline base64, base64Formatter.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::surfaceWriter
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
Definition: foamVtkSurfaceWriter.H:65
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::vtk::polyWriter::nLocalPolys_
label nLocalPolys_
Local number of polys (faces)
Definition: foamVtkPolyWriter.H:88
Foam::vtk::polyWriter
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
Definition: foamVtkPolyWriter.H:67
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
foamVtkPolyWriter.H