edgeMeshIO.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-2022 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 "edgeMesh.H"
30 #include "boundBox.H"
31 #include "edgeMeshFormat.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 (
37  const fileName& name,
38  const word& fileType
39 )
40 :
41  points_(),
42  edges_(),
43  pointEdgesPtr_(nullptr)
44 {
45  read(name, fileType);
46 }
47 
48 
50 :
51  points_(),
52  edges_(),
53  pointEdgesPtr_(nullptr)
54 {
55  read(name);
56 }
57 
58 
59 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
60 
62 {
63  if (name.has_ext("gz"))
64  {
65  return read(name.lessExt(), name.stem().ext());
66  }
67 
68  return read(name, name.ext());
69 }
70 
71 
73 (
74  const fileName& name,
75  const word& fileType
76 )
77 {
78  // Read via selector mechanism
79  transfer(*New(name, fileType));
80  return true;
81 }
82 
83 
85 (
86  const fileName& name,
87  const word& fileType,
88  const edgeMesh& mesh,
89  IOstreamOption streamOpt,
90  const dictionary& options
91 )
92 {
93  DebugInFunction << "Writing to " << name << endl;
94 
95  auto* mfuncPtr = writefileExtensionMemberFunctionTable(fileType);
96 
97  if (!mfuncPtr)
98  {
100  (
101  "extension",
102  fileType,
103  *writefileExtensionMemberFunctionTablePtr_
104  ) << exit(FatalError);
105  }
106 
107  mfuncPtr(name, mesh, streamOpt, options);
108 }
109 
110 
112 (
113  const fileName& name,
114  const edgeMesh& mesh,
115  IOstreamOption streamOpt,
116  const dictionary& options
117 )
118 {
119  write(name, name.ext(), mesh, streamOpt, options);
120 }
121 
122 
124 {
125  os << indent << "points : " << points().size() << nl;
126  os << indent << "edges : " << edges().size() << nl;
127  os << indent << "boundingBox : " << boundBox(this->points()) << endl;
128 }
129 
130 
131 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
132 
133 Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
134 {
135  fileFormats::edgeMeshFormat::write(os, em.points_, em.edges_);
136 
138  return os;
139 }
140 
141 
142 Foam::Istream& Foam::operator>>(Istream& is, edgeMesh& em)
143 {
144  fileFormats::edgeMeshFormat::read(is, em.points_, em.edges_);
145 
146  em.pointEdgesPtr_.reset(nullptr);
147 
148  is.check(FUNCTION_NAME);
149  return is;
150 }
151 
152 
153 // ************************************************************************* //
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
bool read(const fileName &name, const word &fileType)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:66
A class for handling file names.
Definition: fileName.H:72
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
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
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
static void write(const fileName &name, const edgeMesh &mesh, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file (format implicit in the extension)
Definition: edgeMeshIO.C:105
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
A simple container for options an IOstream can normally have.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:605
edgeMesh()
Default construct.
Definition: edgeMeshI.H:38
word ext() const
Return file name extension (part after last .)
Definition: wordI.H:171
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const pointField & points
bool has_ext() const
Various checks for extensions.
Definition: stringI.H:43
A class for handling words, derived from Foam::string.
Definition: word.H:63
#define DebugInFunction
Report an information message using Foam::Info.
Istream & operator>>(Istream &, directionInfo &)
word lessExt() const
Return word without extension (part before last .)
Definition: wordI.H:192
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:47
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:116
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
static Ostream & write(Ostream &, const pointField &, const edgeList &)
Write edgeMesh components to stream.