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  // Private Member Functions
86 
87  //- Flatten boundary field values into a contiguous list
88  List<vector> flattenBoundary(const surfaceVectorField& field) const;
89 
90 
91  //- No copy construct
92  surfaceFieldWriter(const surfaceFieldWriter&) = delete;
93 
94  //- No copy assignment
95  void operator=(const surfaceFieldWriter&) = delete;
96 
97 
98 public:
99 
100  // Constructors
101 
102  //- Construct from mesh (default format INLINE_BASE64)
104  (
105  const fvMesh& mesh,
107  );
108 
109  //- Construct from mesh (default format INLINE_BASE64),
110  //- and open the file for writing.
111  // The file name is with/without an extension.
113  (
114  const fvMesh& mesh,
115  const fileName& file,
116  bool parallel = Pstream::parRun()
117  );
118 
119  //- Construct from mesh and open the file for writing.
120  // The file name is with/without an extension.
122  (
123  const fvMesh& mesh,
124  const vtk::outputOptions opts,
125  const fileName& file,
126  bool parallel = Pstream::parRun()
127  );
128 
129 
130  //- Destructor
131  virtual ~surfaceFieldWriter() = default;
132 
133 
134  // Member Functions
135 
136  //- File extension for current format type.
137  using vtk::fileWriter::ext;
138 
139  //- File extension for given output type
140  inline static word ext(vtk::outputOptions)
141  {
142  // No legacy
144  }
145 
146 
147  //- Write file header (non-collective)
148  // \note Expected calling states: (OPENED).
149  virtual bool beginFile(std::string title = "");
150 
151  //- Write cloud positions
152  // Also writes the file header if not previously written.
153  // \note Must be called prior to writing CellData or PointData
154  virtual bool writeGeometry();
155 
156  //- Begin CellData output section for specified number of fields.
157  // Must be called prior to writing any cell data fields.
158  // \param nFields is the number of fields, which is required for
159  // legacy format.
160  // \note Expected calling states: (PIECE | POINT_DATA).
161  //
162  // \return True if the state changed
163  virtual bool beginCellData(label nFields=0);
164 
165  //- Begin PointData output section
166  // Must be called prior to writing data fields.
167  // \note Expected calling states: (PIECE).
168  //
169  // \return True if the state changed
170  virtual bool beginPointData(label nFields=0);
171 
172 
173  // Write
174 
175  //- Write field
176  void write(const surfaceVectorField& field);
177 };
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace vtk
183 } // End namespace Foam
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::fileWriter
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
Definition: foamVtkFileWriter.H:66
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::vtk::fileWriter::opts
vtk::outputOptions opts() const
The output options in use.
Definition: foamVtkFileWriterI.H:62
Foam::vtk::fileExtension
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Foam::vtk::fileTag::POLY_DATA
"PolyData"
foamVtkFileWriter.H
Foam::vtk::surfaceFieldWriter::beginCellData
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Definition: foamVtkSurfaceFieldWriter.C:194
Foam::vtk::surfaceFieldWriter::beginFile
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Definition: foamVtkSurfaceFieldWriter.C:105
Foam::vtk::surfaceFieldWriter::write
void write(const surfaceVectorField &field)
Write field.
Definition: foamVtkSurfaceFieldWriter.C:208
Foam::vtk::fileWriter::parallel
bool parallel() const noexcept
Parallel output requested?
Definition: foamVtkFileWriterI.H:80
Foam::vtk::surfaceFieldWriter::beginPointData
virtual bool beginPointData(label nFields=0)
Begin PointData output section.
Definition: foamVtkSurfaceFieldWriter.C:201
Foam::vtk::surfaceFieldWriter::~surfaceFieldWriter
virtual ~surfaceFieldWriter()=default
Destructor.
Foam::vtk::surfaceFieldWriter::ext
static word ext(vtk::outputOptions)
File extension for given output type.
Definition: foamVtkSurfaceFieldWriter.H:139
Foam::vtk::surfaceFieldWriter::writeGeometry
virtual bool writeGeometry()
Write cloud positions.
Definition: foamVtkSurfaceFieldWriter.C:135
field
rDeltaTY field()
Foam::vtk::surfaceFieldWriter
Write surfaces fields (as PointData) in VTP format. Legacy VTK format is intentionally not supported.
Definition: foamVtkSurfaceFieldWriter.H:71
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vtk::formatType::INLINE_BASE64
XML inline base64, base64Formatter.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
pointField.H
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< vector >
Foam::GeometricField< vector, fvsPatchField, surfaceMesh >
Foam::vtk::fileWriter::ext
word ext() const
File extension for current format type.
Definition: foamVtkFileWriterI.H:68