foamVtkCoordSetWriter.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) 2022 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::coordSetWriter
28 
29 Description
30  Write as points/lines, 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  Non-parallel only
38 
39 SourceFiles
40  foamVtkCoordSetWriter.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef Foam_vtk_coordSetWriter_H
45 #define Foam_vtk_coordSetWriter_H
46 
47 #include "foamVtkPolyWriter.H"
48 #include "UPtrList.H"
49 #include "Field.H"
50 #include "instant.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 namespace vtk
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class vtk::coordSetWriter Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class coordSetWriter
64 :
65  public vtk::polyWriter
66 {
67 public:
68 
69  // Data Types
70 
71  //- Types of element output.
73  {
75  DEFAULT_ELEMENTS = 1,
76  POINT_ELEMENTS = 2,
77  LINE_ELEMENTS = 3
78  };
79 
80 private:
81 
82  // Private Member Data
83 
84  //- Reference to the points
86 
87  //- Time name/value
88  instant instant_;
89 
90  //- Preferred output element type
91  elemOutputType elemOutput_;
92 
93 
94  // Private Member Functions
95 
96 
97  // Private Member Functions
98 
99  //- Determine sizes (nLocalPoints_, nLocalLines_),
100  //- and begin piece
101  void beginPiece();
102 
103  //- Write points
104  void writePoints();
105 
106  //- Write vertices, legacy format
107  // \param pointOffset processor-local point offset
108  void writeVertsLegacy();
109 
110  //- Write vertices
111  // \param pointOffset processor-local point offset
112  void writeVerts();
113 
114  //- Write lines, legacy format
115  // \param pointOffset processor-local point offset
116  void writeLinesLegacy();
117 
118  //- Write lines
119  // \param pointOffset processor-local point offset
120  void writeLines();
121 
122 
123  //- No copy construct
124  coordSetWriter(const coordSetWriter&) = delete;
125 
126  //- No copy assignment
127  void operator=(const coordSetWriter&) = delete;
128 
129 
130 public:
131 
132  // Constructors
133 
134  //- Construct from components (default format INLINE_BASE64)
136  (
139  );
140 
141  //- Construct from components (default format INLINE_BASE64),
142  //- and open the file for writing.
143  // The file name is with/without an extension.
145  (
147  const fileName& file,
148  bool paralel = false /* ignored: always false */
149  );
150 
151  //- Construct from components and open the file for writing.
152  // The file name is with/without an extension.
154  (
156  const vtk::outputOptions opts,
157  const fileName& file,
158  bool paralel = false /* ignored: always false */
159  );
160 
161 
162  //- Destructor
163  virtual ~coordSetWriter() = default;
164 
165 
166  // Member Functions
167 
168  //- Define preferred element type
169  void setElementType(const elemOutputType elemOutput);
170 
171  //- Open file for writing. Non-parallel only
172  virtual bool open
173  (
174  const fileName& file,
175  bool parallel = false /* ignored: always false */
176  );
177 
178  //- Define a time name/value for the output
179  virtual void setTime(const instant& inst);
180 
181  //- Write file header (non-collective)
182  // \note Expected calling states: (OPENED).
183  virtual bool beginFile(std::string title = "");
184 
185  //- Write patch topology
186  // Also writes the file header if not previously written.
187  // \note Must be called prior to writing CellData or PointData
188  virtual bool writeGeometry();
189 
190  //- Write "TimeValue" FieldData (name as per Catalyst output)
191  // Must be called within the FIELD_DATA state.
192  // \note As a convenience this can also be called from
193  // (OPENED | DECLARED) states, in which case it invokes
194  // beginFieldData(1) internally.
196 
197  //- Write the currently set time as "TimeValue" FieldData
198  void writeTimeValue();
199 
200  //- Reset point references to begin a new piece
202 
203 
204  //- Write processor ids for each line as CellData or for each point
205  //- as PointData, depending on isPointData() state. No-op in serial.
206  // Not implemented.
207  bool writeProcIDs();
208 
209 
210  // Write
211 
212  //- Write primitive field of PointData
213  template<class Type>
214  void writePointData
215  (
216  const word& fieldName,
217  const UPtrList<const Field<Type>>& fieldPtrs
218  );
219 };
220 
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 } // End namespace vtk
225 } // End namespace Foam
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 #ifdef NoRepository
231 #endif
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #endif
236 
237 // ************************************************************************* //
bool parallel() const noexcept
Parallel output requested?
virtual void setTime(const instant &inst)
Define a time name/value for the output.
void setElementType(const elemOutputType elemOutput)
Define preferred element type.
A class for handling file names.
Definition: fileName.H:72
bool writeProcIDs()
Write processor ids for each line as CellData or for each point as PointData, depending on isPointDat...
Write as points/lines, optionally with fields, as a vtp file or a legacy vtk file.
vtk::outputOptions opts() const noexcept
The output options in use.
void writeTimeValue()
Write the currently set time as "TimeValue" FieldData.
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
Generic templated field type.
Definition: Field.H:62
virtual bool open(const fileName &file, bool parallel=false)
Open file for writing. Non-parallel only.
A class for handling words, derived from Foam::string.
Definition: word.H:63
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
virtual bool writeGeometry()
Write patch topology.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
void writePointData(const word &fieldName, const UPtrList< const Field< Type >> &fieldPtrs)
Write primitive field of PointData.
void piece(const UPtrList< const pointField > &points)
Reset point references to begin a new piece.
virtual ~coordSetWriter()=default
Destructor.
elemOutputType
Types of element output.
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
XML inline base64, base64Formatter.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Namespace for OpenFOAM.
const pointField & pts