foamVtkSurfaceFieldWriter.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::vtk::surfaceFieldWriter
29 
30 Description
31  Write surfaces fields (as PointData) in VTP format.
32  Legacy VTK format is intentionally not supported.
33 
34  The file output is structured as HEAD, FIELD_DATA, PIECE followed by any
35  CELL_DATA or POINT_DATA. These states are tracked internally to help
36  detect logic errors.
37 
38  The FieldData element is to be placed prior to writing any geometry
39  Piece. This moves the information to the front of the output file
40  for visibility and simplifies the logic.
41 
42 Note
43  Parallel output is combined into a single Piece without point merging,
44  which is similar to using multi-piece data sets, but allows more
45  convenient creation as a streaming process.
46  In the future, the duplicate points at processor connections
47  may be addressed using ghost points.
48 
49 SourceFiles
50  surfaceFieldWriter.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef Foam_vtk_surfaceFieldWriter_H
55 #define Foam_vtk_surfaceFieldWriter_H
56 
57 #include "foamVtkFileWriter.H"
58 #include "fvMesh.H"
59 #include "pointField.H"
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 namespace vtk
66 {
67 
68 /*---------------------------------------------------------------------------*\
69  Class vtk::surfaceFieldWriter Declaration
70 \*---------------------------------------------------------------------------*/
71 
73 :
74  public vtk::fileWriter
75 {
76  // Private Member Data
77 
78  //- Reference to the OpenFOAM mesh (or subset)
79  const fvMesh& mesh_;
80 
81  //- The number of field points for the current Piece
82  label numberOfPoints_;
83 
84 
85 public:
86 
87  // Generated Methods
88 
89  //- No copy construct
90  surfaceFieldWriter(const surfaceFieldWriter&) = delete;
91 
92  //- No copy assignment
93  void operator=(const surfaceFieldWriter&) = delete;
94 
95 
96  // Constructors
97 
98  //- Construct from mesh (default format INLINE_BASE64)
100  (
101  const fvMesh& mesh,
103  );
104 
105  //- Construct from mesh (default format INLINE_BASE64),
106  //- and open the file for writing.
107  // The file name is with/without an extension.
109  (
110  const fvMesh& mesh,
111  const fileName& file,
112  bool parallel = Pstream::parRun()
113  );
114 
115  //- Construct from mesh and open the file for writing.
116  // The file name is with/without an extension.
118  (
119  const fvMesh& mesh,
120  const vtk::outputOptions opts,
121  const fileName& file,
122  bool parallel = Pstream::parRun()
123  );
124 
125 
126  //- Destructor
127  virtual ~surfaceFieldWriter() = default;
128 
129 
130  // Member Functions
131 
132  //- File extension for current format type.
133  using vtk::fileWriter::ext;
134 
135  //- File extension for given output type
136  inline static word ext(vtk::outputOptions)
137  {
138  // No legacy
140  }
141 
142 
143  //- Write file header (non-collective)
144  // \note Expected calling states: (OPENED).
145  virtual bool beginFile(std::string title = "");
146 
147  //- Write cloud positions
148  // Also writes the file header if not previously written.
149  // \note Must be called prior to writing CellData or PointData
150  virtual bool writeGeometry();
151 
152  //- Begin CellData output section for specified number of fields.
153  // Must be called prior to writing any cell data fields.
154  // \param nFields is the number of fields, which is required for
155  // legacy format.
156  // \note Expected calling states: (PIECE | POINT_DATA).
157  //
158  // \return True if the state changed
159  virtual bool beginCellData(label nFields=0);
160 
161  //- Begin PointData output section
162  // Must be called prior to writing data fields.
163  // \note Expected calling states: (PIECE).
164  //
165  // \return True if the state changed
166  virtual bool beginPointData(label nFields=0);
167 
168 
169  // Write
170 
171  //- Write field
172  void write(const surfaceVectorField& field);
173 };
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 } // End namespace vtk
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************************************************************* //
bool parallel() const noexcept
Parallel output requested?
rDeltaTY field()
A class for handling file names.
Definition: fileName.H:72
virtual bool beginPointData(label nFields=0)
Begin PointData output section.
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.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1586
vtk::outputOptions opts() const noexcept
The output options in use.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
surfaceFieldWriter(const surfaceFieldWriter &)=delete
No copy construct.
virtual ~surfaceFieldWriter()=default
Destructor.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
void operator=(const surfaceFieldWriter &)=delete
No copy assignment.
dynamicFvMesh & mesh
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 surfaceVectorField &field)
Write field.
virtual bool writeGeometry()
Write cloud positions.
Write surfaces fields (as PointData) in VTP format. Legacy VTK format is intentionally not supported...
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
XML inline base64, base64Formatter.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Namespace for OpenFOAM.