foamVtkGenericPatchWriter.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) 2018-2023 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::GenericPatchWriter
28 
29 Description
30  Write concrete PrimitivePatch faces/points (optionally with fields)
31  as a vtp file or a legacy vtk file.
32  The patch type is limited to representations of polygon faces
33  and 3D points and must support the following methods:
34 
35  - localPoints()
36  - localFaces()
37  .
38 
39  The file output states are managed by the Foam::vtk::fileWriter class.
40  FieldData (eg, TimeValue) must appear before any geometry pieces.
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 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef Foam_vtk_GenericPatchWriter_H
50 #define Foam_vtk_GenericPatchWriter_H
51 
52 #include "foamVtkPolyWriter.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 namespace vtk
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class vtk::GenericPatchWriter Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class PatchType>
67 :
68  public vtk::polyWriter
69 {
70  // Private Member Data
71 
72  //- Reference to faces/points as a patch
73  const PatchType& pp_;
74 
75 
76  // Private Member Functions
77 
78  //- No copy construct
80 
81  //- No copy assignment
82  void operator=(const GenericPatchWriter<PatchType>&) = delete;
83 
84 
85 public:
86 
87  // Constructors
88 
89  //- Construct from patch (default output INLINE_BASE64)
90  explicit GenericPatchWriter
91  (
92  const PatchType& pp,
94  )
95  :
96  vtk::polyWriter(opts),
97  pp_(pp)
98  {}
99 
100  //- Construct from components (default output INLINE_BASE64),
101  //- and open the file for writing.
102  // The file name is with/without an extension.
104  (
105  const PatchType& pp,
106  const fileName& file,
107  bool parallel = Pstream::parRun()
108  )
109  :
110  vtk::polyWriter(file, parallel),
111  pp_(pp)
112  {}
113 
114  //- Construct from components and open the file for writing.
115  // The file name is with/without an extension.
117  (
118  const PatchType& pp,
119  const vtk::outputOptions opts,
120  const fileName& file,
121  bool parallel = Pstream::parRun()
122  )
123  :
124  vtk::polyWriter(opts, file, parallel),
125  pp_(pp)
126  {}
127 
128 
129  //- Destructor
130  virtual ~GenericPatchWriter() = default;
131 
132 
133  // Member Functions
134 
135  //- Reference to the originating face/points patch
136  const PatchType& patch() const noexcept
137  {
138  return pp_;
139  }
140 
141  //- Write file header (non-collective)
142  // \note Expected calling states: (OPENED).
143  virtual bool beginFile(std::string title = "surface")
144  {
145  return vtk::polyWriter::beginFile(title);
146  }
148  //- Write patch topology
149  // Also writes the file header if not previously written.
150  // \note Must be called prior to writing CellData or PointData
151  virtual bool writeGeometry()
152  {
153  return writePolyGeometry(pp_.localPoints(), pp_.localFaces());
154  }
155 
156 
157  // Write Fields
158 
159  //- Write processor ids for each poly as CellData
160  bool writeProcIDs()
161  {
162  if (this->isPointData())
163  {
165  }
167  }
168 };
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 } // End namespace vtk
174 } // End namespace Foam
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #endif
180 // ************************************************************************* //
bool parallel() const noexcept
Parallel output requested?
const PatchType & patch() const noexcept
Reference to the originating face/points patch.
Write concrete PrimitivePatch faces/points (optionally with fields) as a vtp file or a legacy vtk fil...
virtual bool beginFile(std::string title="surface")
Write file header (non-collective)
A class for handling file names.
Definition: fileName.H:72
bool writeProcIDs()
Write processor ids for each poly as CellData.
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...
bool writeProcIDs(const label nValues)
Write nValues of processor ids as CellData or PointData (no-op in serial)
label nLocalPoints_
Local number of points.
const direction noexcept
Definition: Scalar.H:258
virtual ~GenericPatchWriter()=default
Destructor.
virtual bool writeGeometry()
Write patch topology.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
bool isPointData() const noexcept
True if output state corresponds to POINT_DATA.
bool writePolyGeometry(const pointField &points, const faceList &faces)
Low-level write face/point topology. Normally used by writeGeometry() in a derived class...
label nLocalPolys_
Local number of polys (faces)
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
XML inline base64, base64Formatter.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.