Loading...
Searching...
No Matches
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)
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,
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,
110 IOstreamOption,
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
117 vtk::outputOptions opts(vtk::formatType::LEGACY_ASCII);
118
119 opts.precision
120 (
121 options.getOrDefault("precision", IOstream::defaultPrecision())
122 );
123
124 vtk::lineWriter writer
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::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
Definition IFstream.H:55
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition IOstream.H:437
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition TimeNew.C:26
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
pointField & storedPoints() noexcept
Non-const access to global points.
Definition edgeMeshI.H:24
edgeMesh(const faMesh &mesh)
Construct finite-area edge mesh faMesh reference.
Definition edgeFaMesh.H:58
const pointField & points() const noexcept
Return points.
Definition edgeMeshI.H:92
const edgeList & edges() const noexcept
Return edges.
Definition edgeMeshI.H:98
edgeList & storedEdges() noexcept
Non-const access to the edges.
Definition edgeMeshI.H:30
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition edge.H:62
VTKedgeFormat(const fileName &filename)
Read construct from file name.
virtual bool read(const fileName &filename) override
Read from file.
static void write(const fileName &filename, const edgeMesh &mesh, IOstreamOption=IOstreamOption(), const dictionary &options=dictionary::null)
Write edge mesh to file in legacy VTK format.
A class for handling file names.
Definition fileName.H:75
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:600
@ LEGACY_ASCII
Legacy ASCII, legacyAsciiFormatter.
Definition foamVtkCore.H:94
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125