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 
58 bool Foam::edgeMesh::read(const fileName& name)
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 // ************************************************************************* //
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
void transfer(edgeMesh &)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:197
A class for handling file names.
Definition: fileName.H:79
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:226
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
static autoPtr< edgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
Definition: edgeMeshNew.C:31
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:287
edgeMesh()
Construct null.
Definition: edgeMesh.C:123
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
const edgeList & edges() const
Return edges.
Definition: edgeMeshI.H:68
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
const pointField & points() const
Return points.
Definition: edgeMeshI.H:62
Points connected by edges.
Definition: edgeMesh.H:69
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:117
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Ostream & operator<<(Ostream &, const ensightPart &)
static void write(const fileName &, const edgeMesh &)
Write to file.
Definition: edgeMeshIO.C:87
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:272
static Ostream & write(Ostream &, const pointField &, const edgeList &)
Write edgeMesh components to stream.
#define InfoInFunction
Report an information message using Foam::Info.