foamVtkSurfaceWriter.C
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 \*---------------------------------------------------------------------------*/
27 
28 #include "foamVtkSurfaceWriter.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 Foam::vtk::surfaceWriter::surfaceWriter
33 (
34  const pointField& points,
35  const faceList& faces,
36  const vtk::outputOptions opts
37 )
38 :
39  vtk::polyWriter(opts),
40 
41  points_(std::cref<pointField>(points)),
42  faces_(std::cref<faceList>(faces)),
43  instant_()
44 {}
45 
46 
47 Foam::vtk::surfaceWriter::surfaceWriter
48 (
49  const pointField& points,
50  const faceList& faces,
51  const fileName& file,
52  bool parallel
53 )
54 :
56 {
57  open(file, parallel);
58 }
59 
60 
61 Foam::vtk::surfaceWriter::surfaceWriter
62 (
63  const pointField& points,
64  const faceList& faces,
65  const vtk::outputOptions opts,
66  const fileName& file,
67  bool parallel
68 )
69 :
70  surfaceWriter(points, faces, opts)
71 {
72  open(file, parallel);
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
79 {
80  instant_ = inst;
81 }
82 
83 
84 bool Foam::vtk::surfaceWriter::beginFile(std::string title)
85 {
86  if (title.size())
87  {
88  return vtk::fileWriter::beginFile(title);
89  }
90 
91  if (!instant_.name().empty())
92  {
94  (
95  "time='" + instant_.name() + "'"
96  );
97  }
98 
99  // Provide default title
100  return vtk::fileWriter::beginFile("surface");
101 }
102 
105 {
106  return writePolyGeometry(points_.get(), faces_.get());
107 }
108 
109 
111 {
112  if (!instant_.name().empty())
113  {
114  vtk::fileWriter::writeTimeValue(instant_.value());
115  }
116 }
117 
118 
120 (
121  const pointField& points,
122  const faceList& faces
123 )
124 {
125  endPiece();
126 
127  points_ = std::cref<pointField>(points);
128  faces_ = std::cref<faceList>(faces);
129 }
130 
131 
133 {
134  if (this->isPointData())
135  {
136  return vtk::fileWriter::writeProcIDs(nLocalPoints_);
137  }
138  return vtk::fileWriter::writeProcIDs(nLocalPolys_);
139 }
140 
141 
142 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:72
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
void writeTimeValue(scalar timeValue)
Write "TimeValue" FieldData (name as per Catalyst output)
Encapsulated combinations of output format options. This is primarily useful when defining the output...
const pointField & points
bool writeProcIDs(const label nValues)
Write nValues of processor ids as CellData or PointData (no-op in serial)
virtual bool beginFile(std::string title="")
Write file header (non-collective)
void piece(const pointField &points, const faceList &faces)
Reset point/face references to begin a new piece.
bool writeProcIDs()
Write processor ids for each poly as CellData or for each point as PointData, depending on isPointDat...
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
virtual void setTime(const instant &inst)
Define a time name/value for the output.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
virtual bool writeGeometry()
Write patch topology.
void writeTimeValue()
Write the currently set time as "TimeValue" FieldData.