foamVtkIndPatchWriter.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::indirectPatchWriter
28 
29 Description
30  Write indirectPrimitivePatch 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  foamVtkIndPatchWriter.C
45  foamVtkIndPatchWriterTemplates.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef foamVtkIndPatchWriter_H
50 #define foamVtkIndPatchWriter_H
51 
52 #include "foamVtkFileWriter.H"
53 #include "indirectPrimitivePatch.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace vtk
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class vtk::indirectPatchWriter Declaration
64 \*---------------------------------------------------------------------------*/
65 
67 :
68  public vtk::fileWriter
69 {
70  // Private Member Data
71 
72  //- Reference to the faces as an indirect patch
73  const indirectPrimitivePatch& pp_;
74 
75  //- The number of field points for the current Piece
76  label numberOfPoints_;
77 
78  //- The number of field cells (faces) for the current Piece
79  label numberOfCells_;
80 
81  //- Local number of points
82  label nLocalPoints_;
83 
84  //- Local number of faces
85  label nLocalFaces_;
86 
87  //- Local face vertices (connectivity) count. Sum of face sizes.
88  label nLocalVerts_;
89 
90 
91  // Private Member Functions
92 
93  //- Determine sizes (nLocalPoints_, nLocalFaces_, nLocalVerts_),
94  //- and begin piece
95  void beginPiece();
96 
97  //- Write patch points
98  void writePoints();
99 
100  //- Write patch faces, legacy format
101  // \param pointOffset processor-local point offset
102  void writePolysLegacy(const label pointOffset);
103 
104  //- Write patch faces
105  // \param pointOffset processor-local point offset
106  void writePolys(const label pointOffset);
107 
108 
109  //- No copy construct
110  indirectPatchWriter(const indirectPatchWriter&) = delete;
111 
112  //- No copy assignment
113  void operator=(const indirectPatchWriter&) = delete;
114 
115 
116 public:
117 
118  // Constructors
119 
120  //- Construct from patch (default output INLINE_BASE64)
121  explicit indirectPatchWriter
122  (
123  const indirectPrimitivePatch& pp,
125  );
126 
127  //- Construct from components (default output INLINE_BASE64),
128  // and open the file for writing.
129  // The file name is with/without an extension.
131  (
132  const indirectPrimitivePatch& pp,
133  const fileName& file,
134  bool parallel = Pstream::parRun()
135  );
136 
137  //- Construct from components and open the file for writing.
138  // The file name is with/without an extension.
140  (
141  const indirectPrimitivePatch& pp,
142  const vtk::outputOptions opts,
143  const fileName& file,
144  bool parallel = Pstream::parRun()
145  );
146 
147 
148  //- Destructor
149  virtual ~indirectPatchWriter() = default;
150 
151 
152  // Member Functions
153 
154  //- File extension for current format type.
155  using vtk::fileWriter::ext;
156 
157  //- File extension for given output type
158  inline static word ext(vtk::outputOptions opts)
159  {
161  }
162 
163  //- Reference to the indirect patch
164  inline const indirectPrimitivePatch& patch() const
165  {
166  return pp_;
167  }
168 
169 
170  //- Write file header (non-collective)
171  // \note Expected calling states: (OPENED).
172  virtual bool beginFile(std::string title = "");
173 
174  //- Write patch topology
175  // Also writes the file header if not previously written.
176  // \note Must be called prior to writing CellData or PointData
177  virtual bool writeGeometry();
178 
179  //- Begin CellData output section for specified number of fields.
180  // Must be called prior to writing any cell data fields.
181  // \param nFields is for legacy format only.
182  // When nFields=0, this a no-op for legacy format.
183  // \note Expected calling states: (PIECE | POINT_DATA).
184  //
185  // \return True if the state changed
186  virtual bool beginCellData(label nFields = 0);
187 
188  //- Begin PointData for specified number of fields.
189  // Must be called prior to writing any point data fields.
190  // \param nFields is for legacy format only.
191  // When nFields=0, this a no-op for legacy format.
192  // \note Expected calling states: (PIECE | CELL_DATA).
193  //
194  // \return True if the state changed
195  virtual bool beginPointData(label nFields = 0);
196 
197 
198  // Write
199 
200  //- Write a uniform field of Cell (Face) or Point values
201  template<class Type>
202  void writeUniform(const word& fieldName, const Type& val);
203 
204  //- Write a list of Cell (Face) or Point values
205  template<class Type>
206  void write(const word& fieldName, const UList<Type>& field);
207 };
208 
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 } // End namespace vtk
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #ifdef NoRepository
219 #endif
220 
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 #endif
225 
226 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::indirectPatchWriter
Write indirectPrimitivePatch faces/points (optionally with fields) as a vtp file or a legacy vtk file...
Definition: foamVtkIndPatchWriter.H:65
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::vtk::indirectPatchWriter::~indirectPatchWriter
virtual ~indirectPatchWriter()=default
Destructor.
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::indirectPatchWriter::writeGeometry
virtual bool writeGeometry()
Write patch topology.
Definition: foamVtkIndPatchWriter.C:411
Foam::vtk::fileTag::POLY_DATA
"PolyData"
foamVtkFileWriter.H
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:415
Foam::vtk::indirectPatchWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Face) or Point values.
Definition: foamVtkIndPatchWriterTemplates.C:33
Foam::vtk::indirectPatchWriter::ext
static word ext(vtk::outputOptions opts)
File extension for given output type.
Definition: foamVtkIndPatchWriter.H:157
Foam::vtk::indirectPatchWriter::beginCellData
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Definition: foamVtkIndPatchWriter.C:437
field
rDeltaTY field()
Foam::vtk::indirectPatchWriter::patch
const indirectPrimitivePatch & patch() const
Reference to the indirect patch.
Definition: foamVtkIndPatchWriter.H:163
indirectPrimitivePatch.H
Foam::vtk::formatType::INLINE_BASE64
XML inline base64, base64Formatter.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::indirectPatchWriter::write
void write(const word &fieldName, const UList< Type > &field)
Write a list of Cell (Face) or Point values.
Definition: foamVtkIndPatchWriterTemplates.C:60
Foam::vtk::indirectPatchWriter::beginPointData
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
Definition: foamVtkIndPatchWriter.C:443
Foam::UList< Type >
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
foamVtkIndPatchWriterTemplates.C
Foam::vtk::indirectPatchWriter::beginFile
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Definition: foamVtkIndPatchWriter.C:399
Foam::vtk::fileWriter::ext
word ext() const
File extension for current format type.
Definition: foamVtkFileWriterI.H:68
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:85