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 | Copyright (C) 2011-2013 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_(NULL)
41 {
42  read(name, ext);
43 }
44 
45 
47 :
48  points_(0),
49  edges_(0),
50  pointEdgesPtr_(NULL)
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  Info<< "edgeMesh::write"
95  "(const fileName&, const edgeMesh&) : "
96  "writing to " << name
97  << endl;
98  }
99 
100  const word ext = name.ext();
101 
102  writefileExtensionMemberFunctionTable::iterator mfIter =
103  writefileExtensionMemberFunctionTablePtr_->find(ext);
104 
105  if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
106  {
108  (
109  "MeshedSurface::write"
110  "(const fileName&, const MeshedSurface&)"
111  ) << "Unknown file extension " << ext << nl << nl
112  << "Valid types are :" << endl
113  << writefileExtensionMemberFunctionTablePtr_->sortedToc()
114  << exit(FatalError);
115  }
116  else
117  {
118  mfIter()(name, mesh);
119  }
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 
134 {
135  fileFormats::edgeMeshFormat::write(os, em.points_, em.edges_);
136 
137  // Check state of Ostream
138  os.check("Ostream& operator<<(Ostream&, const edgeMesh&)");
139 
140  return os;
141 }
142 
143 
145 {
146  fileFormats::edgeMeshFormat::read(is, em.points_, em.edges_);
147 
148  em.pointEdgesPtr_.clear();
149 
150  // Check state of Istream
151  is.check("Istream& operator>>(Istream&, edgeMesh&)");
152 
153  return is;
154 }
155 
156 
157 // ************************************************************************* //
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:123
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:323
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
const pointField & points() const
Return points.
Definition: edgeMeshI.H:39
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
static void write(const fileName &, const edgeMesh &)
Write to file.
Definition: edgeMeshIO.C:87
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
dynamicFvMesh & mesh
edgeMesh()
Construct null.
Definition: edgeMesh.C:123
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
static autoPtr< edgeMesh > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
Definition: edgeMeshNew.C:31
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Points connected by edges.
Definition: edgeMesh.H:69
error FatalError
static Ostream & write(Ostream &, const pointField &, const edgeList &)
Write edgeMesh components to stream.
A class for handling file names.
Definition: fileName.H:69
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:307
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool read(const char *, int32_t &)
Definition: int32IO.C:87
void transfer(edgeMesh &)
Transfer the contents of the argument and annul the argument.
Definition: edgeMesh.C:200
const edgeList & edges() const
Return edges.
Definition: edgeMeshI.H:45