VTKedgeFormat.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2019-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
28
29#include "VTKedgeFormat.H"
30#include "Fstream.H"
31#include "Time.H"
32#include "foamVtkLineWriter.H"
34
35// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36
38(
39 const fileName& filename
40)
41{
42 read(filename);
43}
44
45
46// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
47
49(
50 const fileName& filename
51)
52{
53 IFstream is(filename);
54 if (!is.good())
55 {
57 << "Cannot read file " << filename
58 << exit(FatalError);
59 }
60
61 // Use dummy Time for objectRegistry
62 autoPtr<Time> dummyTimePtr(Time::New());
63
65 (
67 (
68 "vtk::edgeFormat",
69 *dummyTimePtr,
72 false
73 )
74 );
75
76 // Construct reader to read file
77 vtkUnstructuredReader reader(obr, is);
78
79
80 // Extract lines
81 storedPoints().transfer(reader.points());
82
83 label nEdges = 0;
84 for (const auto& lineVerts : reader.lines())
85 {
86 if (lineVerts.size() > 1)
87 {
88 nEdges += (lineVerts.size()-1);
89 }
90 }
91 storedEdges().resize(nEdges);
92
93 nEdges = 0;
94 for (const auto& lineVerts : reader.lines())
95 {
96 for (label i = 1; i < lineVerts.size(); ++i)
97 {
98 storedEdges()[nEdges++] = edge(lineVerts[i-1], lineVerts[i]);
99 }
100 }
101
102 return true;
103}
104
105
107(
108 const fileName& filename,
109 const edgeMesh& eMesh,
111 const dictionary& options
112)
113{
114 // NB: restrict output to legacy ascii so that we are still able
115 // to read it with vtkUnstructuredReader
116
118
119 opts.precision
120 (
121 options.getOrDefault("precision", IOstream::defaultPrecision())
122 );
123
125 (
126 eMesh.points(),
127 eMesh.edges(),
128 opts,
129 filename,
130 false // non-parallel write (edgeMesh already serialized)
131 );
132
133 writer.beginFile("OpenFOAM edgeMesh");
134 writer.writeGeometry();
135}
136
137
138// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Input from file stream, using an ISstream.
Definition: IFstream.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
The IOstreamOption is a simple container for options an IOstream can normally have.
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
virtual bool read()
Re-read model coefficients if they have changed.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:56
const pointField & points() const noexcept
Return points.
Definition: edgeMeshI.H:99
const edgeList & edges() const noexcept
Return edges.
Definition: edgeMeshI.H:105
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
Provide a means of writing VTK legacy format.
Definition: VTKedgeFormat.H:56
virtual bool read(const fileName &name)
Read from file.
Definition: VTKedgeFormat.C:49
A class for handling file names.
Definition: fileName.H:76
virtual bool write()
Write the output fields.
Registry of regIOobjects.
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
const labelListList & lines() const noexcept
1D cells (=open lines)
const pointField & points() const noexcept
Points.
Write edge/points (optionally with fields) as a vtp file or a legacy vtk file.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
unsigned precision() const noexcept
Return the ASCII write precision.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const labelList nEdges(UPstream::listGatherValues< label >(aMesh.nEdges()))
@ LEGACY_ASCII
Legacy ASCII, legacyAsciiFormatter.
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130