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 -------------------------------------------------------------------------------
11 License
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"
33 #include "vtkUnstructuredReader.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 
64  objectRegistry obr
65  (
66  IOobject
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,
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 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:72
const pointField & points() const noexcept
Return points.
Definition: edgeMeshI.H:92
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: TimeNew.C:26
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:418
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only...
A simple container for options an IOstream can normally have.
Ignore writing from objectRegistry::writeObject()
Encapsulated combinations of output format options. This is primarily useful when defining the output...
unsigned precision() const noexcept
Return the ASCII write precision.
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.
Write edge/points (optionally with fields) as a vtp file or a legacy vtk file.
VTKedgeFormat(const fileName &filename)
Read construct from file name.
Definition: VTKedgeFormat.C:31
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:47
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
Definition: IFstream.H:51
const edgeList & edges() const noexcept
Return edges.
Definition: edgeMeshI.H:98
Nothing to be read.
Legacy ASCII, legacyAsciiFormatter.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
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...
virtual bool read(const fileName &filename) override
Read from file.
Definition: VTKedgeFormat.C:42
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Do not request registration (bool: false)