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-2018 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::lagrangianWriter
28 
29 Description
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 
38 Note
39  If fields should be CellData instead of PointData (default), this
40  must be decided at construction time.
41 
42 SourceFiles
43  lagrangianWriter.C
44  lagrangianWriterTemplates.C
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 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class IOobjectList;
62 template<class Type> class IOField;
63 
64 namespace vtk
65 {
66 
67 /*---------------------------------------------------------------------------*\
68  Class vtk::lagrangianWriter Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 class lagrangianWriter
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  //- The number of field points for the current Piece
84  label numberOfPoints_;
85 
86  //- Write as CellData (verts) instead of as PointData.
87  const bool useVerts_;
88 
89 
90  // Private Member Functions
91 
92  //- The cloud directory for the current cloud name.
93  fileName cloudDir() const;
94 
95  //- Transcribe the cloud into pointField
96  pointField positions() const;
97 
98  //- Write vertex (cells)
99  void writeVerts();
100 
101 
102  //- No copy construct
103  lagrangianWriter(const lagrangianWriter&) = delete;
104 
105  //- No copy assignment
106  void operator=(const lagrangianWriter&) = delete;
107 
108 
109 protected:
110 
111  // Protected Member Functions
112 
113  //- Begin CellData output section for specified number of fields.
114  // Must be called prior to writing any cell data fields.
115  // \param nFields is the number of fields, which is required for
116  // legacy format.
117  // \note Expected calling states: (PIECE | POINT_DATA).
118  //
119  // \return True if the state changed
120  virtual bool beginCellData(label nFields=0);
121 
122  //- Begin PointData for specified number of fields.
123  // Must be called prior to writing any point data fields.
124  // \param nFields is the number of fields, which is required for
125  // legacy format.
126  // \note Expected calling states: (PIECE | CELL_DATA).
127  //
128  // \return True if the state changed
129  virtual bool beginPointData(label nFields=0);
130 
131 
132 public:
133 
134  // Constructors
135 
136  //- Construct from components (default format INLINE_BASE64)
137  // \param useVerts Define VERTS and use CellData instead of PointData.
139  (
140  const fvMesh& mesh,
141  const word& cloudName,
143  bool useVerts = false
144  );
145 
146  //- Construct from components (default format INLINE_BASE64),
147  //- and open the file for writing.
148  // The file name is with/without an extension.
150  (
151  const fvMesh& mesh,
152  const word& cloudName,
153  const fileName& file,
154  bool parallel = Pstream::parRun()
155  );
156 
157  //- Construct from components and open the file for writing.
158  // The file name is with/without an extension.
160  (
161  const fvMesh& mesh,
162  const word& cloudName,
163  const vtk::outputOptions opts,
164  const fileName& file,
165  bool parallel = Pstream::parRun()
166  );
167 
168 
169  //- Destructor
170  virtual ~lagrangianWriter() = default;
171 
172 
173  // Member Functions
174 
175  //- File extension for current format type.
176  using vtk::fileWriter::ext;
177 
178  //- File extension for given output type. Always ".vtp"
179  inline static word ext(vtk::outputOptions)
180  {
181  // No legacy
183  }
184 
185 
186  //- Write file header (non-collective)
187  // \note Expected calling states: (OPENED).
188  virtual bool beginFile(std::string title = "");
189 
190  //- Write cloud positions
191  // Also writes the file header if not previously written.
192  // \note Must be called prior to writing CellData or PointData
193  virtual bool writeGeometry();
194 
195 
196  //- Begin parcel (PointData) output section
197  // Must be called prior to writing data fields.
198  // \note Expected calling states: (PIECE).
199  //
200  // \return True if the state changed
201  bool beginParcelData();
202 
203  //- Explicitly end parcel (PointData) output and switch to PIECE state
204  // Ignored (no-op) if not currently in the parcel state.
205  bool endParcelData();
206 
207 
208  // Write
209 
210  //- Write the IOField
211  template<class Type>
212  void write(const IOField<Type>& field);
214  //- Write IOFields
215  template<class Type>
216  label writeFields(const wordList& fieldNames, bool verbose=true);
217 
218  //- Write IOFields
219  template<class Type>
220  label writeFields(const IOobjectList& objects, bool verbose=true);
221 };
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 } // End namespace vtk
227 } // End namespace Foam
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #ifdef NoRepository
233 #endif
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 #endif
239 
240 // ************************************************************************* //
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
bool parallel() const noexcept
Parallel output requested?
bool beginParcelData()
Begin parcel (PointData) output section.
rDeltaTY field()
A class for handling file names.
Definition: fileName.H:72
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
bool endParcelData()
Explicitly end parcel (PointData) output and switch to PIECE state.
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data). These output formats are structured as DECLARED, FIELD_DATA, PIECE followed by any CELL_DATA or POINT_DATA.
virtual ~lagrangianWriter()=default
Destructor.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
vtk::outputOptions opts() const noexcept
The output options in use.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
dynamicFvMesh & mesh
const word cloudName(propsDict.get< word >("cloud"))
word ext() const
File extension for current format type.
A class for handling words, derived from Foam::string.
Definition: word.H:63
void write(const IOField< Type > &field)
Write the IOField.
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label writeFields(const wordList &fieldNames, bool verbose=true)
Write IOFields.
XML inline base64, base64Formatter.
Write lagrangian (cloud) positions and fields (as PointData) in VTP format. Legacy VTK format is inte...
virtual bool beginFile(std::string title="")
Write file header (non-collective)
A primitive field of type <T> with automated input and output.
virtual bool writeGeometry()
Write cloud positions.
Namespace for OpenFOAM.