foamVtkLineWriter.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) 2021-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 "foamVtkLineWriter.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 Foam::vtk::lineWriter::lineWriter
33 (
34  const pointField& points,
35  const edgeList& edges,
36  const vtk::outputOptions opts
37 )
38 :
39  vtk::polyWriter(opts),
40 
41  points_(std::cref<pointField>(points)),
42  edges_(std::cref<edgeList>(edges)),
43  instant_()
44 {}
45 
46 
47 Foam::vtk::lineWriter::lineWriter
48 (
49  const pointField& points,
50  const edgeList& edges,
51  const fileName& file,
52  bool parallel
53 )
54 :
56 {
57  open(file, parallel);
58 }
59 
60 
61 Foam::vtk::lineWriter::lineWriter
62 (
63  const pointField& points,
64  const edgeList& edges,
65  const vtk::outputOptions opts,
66  const fileName& file,
67  bool parallel
68 )
69 :
70  lineWriter(points, edges, opts)
71 {
72  open(file, parallel);
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
79 {
80  instant_ = inst;
81 }
82 
83 
84 bool Foam::vtk::lineWriter::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("edges");
101 }
102 
105 {
106  return writeLineGeometry(points_.get(), edges_.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 edgeList& edges
123 )
124 {
125  endPiece();
126 
127  points_ = std::cref<pointField>(points);
128  edges_ = std::cref<edgeList>(edges);
129 }
130 
131 
133 {
134  if (this->isPointData())
135  {
136  return vtk::fileWriter::writeProcIDs(nLocalPoints_);
137  }
138  return vtk::fileWriter::writeProcIDs(nLocalLines_);
139 }
140 
141 
142 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:72
virtual bool beginFile(std::string title="")
Write file header (non-collective)
void piece(const pointField &points, const edgeList &edges)
Reset point/edge references to begin a new piece.
bool writeProcIDs()
Write processor ids for each line as CellData or for each point as PointData, depending on isPointDat...
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)
Write edge/points (optionally with fields) as a vtp file or a legacy vtk file.
virtual void setTime(const instant &inst)
Define a time name/value for the output.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
virtual bool beginFile(std::string title="")
Write file header (non-collective)
virtual bool writeGeometry()
Write patch topology.
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
void writeTimeValue()
Write the currently set time as "TimeValue" FieldData.