edgeMeshIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "edgeMesh.H"
27 #include "boundBox.H"
28 #include "edgeMeshFormat.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 (
34  const fileName& name,
35  const word& ext
36 )
37 :
38  points_(0),
39  edges_(0),
40  pointEdgesPtr_(nullptr)
41 {
42  read(name, ext);
43 }
44 
45 
47 :
48  points_(0),
49  edges_(0),
50  pointEdgesPtr_(nullptr)
51 {
52  read(name);
53 }
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
59 {
60  word ext = name.ext();
61  if (ext == "gz")
62  {
63  fileName unzipName = name.lessExt();
64  return read(unzipName, unzipName.ext());
65  }
66  else
67  {
68  return read(name, ext);
69  }
70 }
71 
72 
73 // Read from file in given format
75 (
76  const fileName& name,
77  const word& ext
78 )
79 {
80  // read via selector mechanism
81  transfer(New(name, ext)());
82  return true;
83 }
84 
85 
87 (
88  const fileName& name,
89  const edgeMesh& mesh
90 )
91 {
92  if (debug)
93  {
94  InfoInFunction << "Writing to " << name << endl;
95  }
96 
97  const word ext = name.ext();
98 
99  writefileExtensionMemberFunctionTable::iterator mfIter =
100  writefileExtensionMemberFunctionTablePtr_->find(ext);
101 
102  if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
103  {
105  << "Unknown file extension " << ext << nl << nl
106  << "Valid types are :" << endl
107  << writefileExtensionMemberFunctionTablePtr_->sortedToc()
108  << exit(FatalError);
109  }
110  else
111  {
112  mfIter()(name, mesh);
113  }
114 }
115 
116 
118 {
119  os << indent << "points : " << points().size() << nl;
120  os << indent << "edges : " << edges().size() << nl;
121  os << indent << "boundingBox : " << boundBox(this->points()) << endl;
122 }
123 
124 
125 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
126 
128 {
129  fileFormats::edgeMeshFormat::write(os, em.points_, em.edges_);
130 
131  // Check state of Ostream
132  os.check("Ostream& operator<<(Ostream&, const edgeMesh&)");
133 
134  return os;
135 }
136 
137 
139 {
140  fileFormats::edgeMeshFormat::read(is, em.points_, em.edges_);
141 
142  em.pointEdgesPtr_.clear();
143 
144  // Check state of Istream
145  is.check("Istream& operator>>(Istream&, edgeMesh&)");
146 
147  return is;
148 }
149 
150 
151 // ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
Points connected by edges.
Definition: edgeMesh.H:72
edgeMesh()
Construct null.
Definition: edgeMesh.C:122
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:117
static void write(const fileName &, const edgeMesh &)
Write to file.
Definition: edgeMeshIO.C:87
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
static Ostream & write(Ostream &, const pointField &, const edgeList &)
Write edgeMesh components to stream.
A class for handling file names.
Definition: fileName.H:82
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:299
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
#define InfoInFunction
Report an information message using Foam::Info.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
bool read(const char *, int32_t &)
Definition: int32IO.C:85
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
Istream & operator>>(Istream &, pistonPointEdgeData &)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
error FatalError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
static const char nl
Definition: Ostream.H:266