Loading...
Searching...
No Matches
foamVtkLagrangianWriter.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) 2016-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::vtk::lagrangianWriter
28
29Description
30 Write lagrangian (cloud) positions and fields (as PointData) in
31 VTP format. Legacy VTK format is intentionally not supported since
32 the VTP format provides much better field selection in ParaView, and for
33 consistency with the Foam::functionObjects::vtkCloud function object.
34
35 The file output states are managed by the Foam::vtk::fileWriter class.
36 FieldData (eg, TimeValue) must appear before any geometry pieces.
37
38Note
39 If fields should be CellData instead of PointData (default), this
40 must be decided at construction time.
41
42SourceFiles
43 foamVtkLagrangianWriter.cxx
44 foamVtkLagrangianWriter.txx
45
46\*---------------------------------------------------------------------------*/
47
48#ifndef Foam_vtk_lagrangianWriter_H
49#define Foam_vtk_lagrangianWriter_H
50
51#include "fvMesh.H"
52#include "pointField.H"
53#include "foamVtkFileWriter.H"
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57namespace Foam
58{
59
60// Forward Declarations
61class IOobjectList;
62template<class Type> class IOField;
63
64namespace vtk
65{
67/*---------------------------------------------------------------------------*\
68 Class vtk::lagrangianWriter Declaration
69\*---------------------------------------------------------------------------*/
70
72:
73 public vtk::fileWriter
74{
75 // Private Member Data
76
77 //- Reference to the OpenFOAM mesh (or subset)
78 const fvMesh& mesh_;
79
80 //- The cloud name
81 const word cloudName_;
82
83 //- Slab addressing for field points of the current Piece
84 OffsetRange<label> pointSlab_;
85
86 //- Write as CellData (verts) instead of as PointData.
87 const bool useVerts_;
88
89
90 // Private Member Functions
91
92 //- Total number of field points for the current Piece
93 label nTotalPoints() const noexcept { return pointSlab_.total(); }
94
95 //- The cloud directory for the current cloud name.
96 fileName cloudDir() const;
97
98 //- Transcribe the cloud into pointField
99 pointField positions() const;
100
101 //- Write vertex (cells)
102 void writeVerts();
103
104protected:
105
106 // Protected Member Functions
107
108 //- Begin CellData output section for specified number of fields.
109 // Must be called prior to writing any cell data fields.
110 // \param nFields is the number of fields, which is required for
111 // legacy format.
112 // \note Expected calling states: (PIECE | POINT_DATA).
113 //
114 // \return True if the state changed
115 virtual bool beginCellData(label nFields=0);
116
117 //- Begin PointData for specified number of fields.
118 // Must be called prior to writing any point data fields.
119 // \param nFields is the number of fields, which is required for
120 // legacy format.
121 // \note Expected calling states: (PIECE | CELL_DATA).
122 //
123 // \return True if the state changed
124 virtual bool beginPointData(label nFields=0);
125
126
127public:
128
129 // Generated Methods
130
131 //- No copy construct
132 lagrangianWriter(const lagrangianWriter&) = delete;
133
134 //- No copy assignment
135 void operator=(const lagrangianWriter&) = delete;
136
137
138 // Constructors
139
140 //- Construct from components (default format INLINE_BASE64)
141 // \param useVerts Define VERTS and use CellData instead of PointData.
143 (
144 const fvMesh& mesh,
145 const word& cloudName,
147 bool useVerts = false
148 );
149
150 //- Construct from components (default format INLINE_BASE64),
151 //- and open the file for writing.
152 // The file name is with/without an extension.
154 (
155 const fvMesh& mesh,
157 const fileName& file,
159 );
160
161 //- Construct from components and open the file for writing.
162 // The file name is with/without an extension.
164 (
165 const fvMesh& mesh,
168 const fileName& file,
170 );
171
172
173 //- Destructor
174 virtual ~lagrangianWriter() = default;
175
176
177 // Member Functions
178
179 //- File extension for current format type.
181
182 //- File extension for given output type. Always ".vtp"
183 inline static word ext(vtk::outputOptions)
184 {
185 // No legacy
187 }
188
189
190 //- Write file header (non-collective)
191 // \note Expected calling states: (OPENED).
192 virtual bool beginFile(std::string title = "");
194 //- Write cloud positions
195 // Also writes the file header if not previously written.
196 // \note Must be called prior to writing CellData or PointData
197 virtual bool writeGeometry();
198
199
200 //- Begin parcel (PointData) output section
201 // Must be called prior to writing data fields.
202 // \note Expected calling states: (PIECE).
203 //
204 // \return True if the state changed
205 bool beginParcelData();
207 //- Explicitly end parcel (PointData) output and switch to PIECE state
208 // Ignored (no-op) if not currently in the parcel state.
209 bool endParcelData();
210
211
212 // Write
213
214 //- Write the IOField
215 template<class Type>
216 void write(const IOField<Type>& field);
217
218 //- Write IOFields
219 template<class Type>
220 label writeFields(const wordList& fieldNames, bool verbose=true);
221
222 //- Write IOFields
223 template<class Type>
224 label writeFields(const IOobjectList& objects, bool verbose=true);
225};
226
227
228// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229
230} // End namespace vtk
231} // End namespace Foam
232
233// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234
235#ifdef NoRepository
236 #include "foamVtkLagrangianWriter.txx"
237#endif
238
240// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241
242#endif
243
244// ************************************************************************* //
const word cloudName(propsDict.get< word >("cloud"))
A primitive field of type <T> with automated input and output.
Definition IOField.H:53
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
A tuple of integers comprising start, size, total.
Definition OffsetRange.H:82
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
Definition UPstream.H:1669
A class for handling file names.
Definition fileName.H:75
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
vtk::outputOptions opts() const noexcept
The output options in use.
bool parallel() const noexcept
Parallel output requested?
word ext() const
File extension for current format type.
lagrangianWriter(const fvMesh &mesh, const word &cloudName, const fileName &file, bool parallel=UPstream::parRun())
Construct from components (default format INLINE_BASE64), and open the file for writing.
void operator=(const lagrangianWriter &)=delete
No copy assignment.
label writeFields(const wordList &fieldNames, bool verbose=true)
Write IOFields.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
bool beginParcelData()
Begin parcel (PointData) output section.
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
lagrangianWriter(const lagrangianWriter &)=delete
No copy construct.
void write(const IOField< Type > &field)
Write the IOField.
static word ext(vtk::outputOptions)
File extension for given output type. Always ".vtp".
bool endParcelData()
Explicitly end parcel (PointData) output and switch to PIECE state.
word ext() const
File extension for current format type.
label writeFields(const IOobjectList &objects, bool verbose=true)
Write IOFields.
virtual bool writeGeometry()
Write cloud positions.
lagrangianWriter(const fvMesh &mesh, const word &cloudName, const vtk::outputOptions opts=vtk::formatType::INLINE_BASE64, bool useVerts=false)
Construct from components (default format INLINE_BASE64).
virtual ~lagrangianWriter()=default
Destructor.
virtual bool beginFile(std::string title="")
Write file header (non-collective).
lagrangianWriter(const fvMesh &mesh, const word &cloudName, const vtk::outputOptions opts, const fileName &file, bool parallel=UPstream::parRun())
Construct from components and open the file for writing.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
A class for handling words, derived from Foam::string.
Definition word.H:66
rDeltaTY field()
dynamicFvMesh & mesh
Namespace for handling VTK output. Contains classes and functions for writing VTK file content.
@ POLY_DATA
"PolyData"
@ INLINE_BASE64
XML inline base64, base64Formatter.
Definition foamVtkCore.H:91
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
vectorField pointField
pointField is a vectorField.
runTime write()