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-2015 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 
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  << "Unknown file extension " << ext << nl << nl
109  << "Valid types are :" << endl
110  << writefileExtensionMemberFunctionTablePtr_->sortedToc()
111  << exit(FatalError);
112  }
113  else
114  {
115  mfIter()(name, mesh);
116  }
117 }
118 
119 
121 {
122  os << indent << "points : " << points().size() << nl;
123  os << indent << "edges : " << edges().size() << nl;
124  os << indent << "boundingBox : " << boundBox(this->points()) << endl;
125 }
126 
127 
128 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
129 
131 {
133 
134  // Check state of Ostream
135  os.check("Ostream& operator<<(Ostream&, const edgeMesh&)");
136 
137  return os;
138 }
139 
140 
142 {
144 
145  em.pointEdgesPtr_.clear();
146 
147  // Check state of Istream
148  is.check("Istream& operator>>(Istream&, edgeMesh&)");
149 
150  return is;
151 }
152 
153 
154 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::edgeMesh::points_
pointField points_
Vertices of the edges.
Definition: edgeMesh.H:76
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::edgeMesh::edgeMesh
edgeMesh()
Construct null.
Definition: edgeMesh.C:123
edgeMeshFormat.H
Foam::edgeMesh::pointEdgesPtr_
autoPtr< labelListList > pointEdgesPtr_
From point to edges.
Definition: edgeMesh.H:82
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::edgeMesh::read
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
edgeMesh.H
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::edgeMesh::writeStats
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:120
Foam::fileFormats::edgeMeshFormat::write
static Ostream & write(Ostream &, const pointField &, const edgeList &)
Write edgeMesh components to stream.
Definition: edgeMeshFormat.C:128
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Foam::edgeMesh::write
static void write(const fileName &, const edgeMesh &)
Write to file.
Definition: edgeMeshIO.C:87
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::fileFormats::edgeMeshFormat::read
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
Definition: edgeMeshFormat.C:104
boundBox.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::edgeMesh::edges_
edgeList edges_
The edges defining the boundary.
Definition: edgeMesh.H:79
Foam::edgeMesh
Points connected by edges.
Definition: edgeMesh.H:69
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47