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-2020 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  word ext(name.ext());
64  if (ext == "gz")
65  {
66  fileName unzipName = name.lessExt();
67  return read(unzipName, unzipName.ext());
68  }
69 
70  return read(name, ext);
71 }
72 
73 
75 (
76  const fileName& name,
77  const word& fileType
78 )
79 {
80  // Read via selector mechanism
81  transfer(*New(name, fileType));
82  return true;
83 }
84 
85 
87 (
88  const fileName& name,
89  const word& fileType,
90  const edgeMesh& mesh
91 )
92 {
93  DebugInFunction << "Writing to " << name << endl;
94 
95  auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(fileType);
96 
97  if (!mfIter.found())
98  {
100  (
101  "extension",
102  fileType,
103  *writefileExtensionMemberFunctionTablePtr_
104  ) << exit(FatalError);
105  }
106 
107  mfIter()(name, mesh);
108 }
109 
110 
112 (
113  const fileName& name,
114  const edgeMesh& mesh
115 )
116 {
117  write(name, name.ext(), mesh);
118 }
119 
120 
122 {
123  os << indent << "points : " << points().size() << nl;
124  os << indent << "edges : " << edges().size() << nl;
125  os << indent << "boundingBox : " << boundBox(this->points()) << endl;
126 }
127 
128 
129 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
130 
132 {
133  fileFormats::edgeMeshFormat::write(os, em.points_, em.edges_);
134 
135  os.check(FUNCTION_NAME);
136  return os;
137 }
138 
139 
141 {
142  fileFormats::edgeMeshFormat::read(is, em.points_, em.edges_);
143 
144  em.pointEdgesPtr_.reset(nullptr);
145 
146  is.check(FUNCTION_NAME);
147  return is;
148 }
149 
150 
151 // ************************************************************************* //
Foam::word::lessExt
word lessExt() const
Return word without extension (part before last .)
Definition: word.C:113
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::edgeMesh::edgeMesh
edgeMesh()
Default construct.
Definition: edgeMeshI.H:45
Foam::edgeMesh::read
bool read(const fileName &name, const word &fileType)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
edgeMeshFormat.H
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::word::ext
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
Foam::edgeMesh::write
static void write(const fileName &name, const edgeMesh &mesh)
Write to file (format implicit in the extension)
Definition: edgeMeshIO.C:112
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
edgeMesh.H
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:365
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::edgeMesh::writeStats
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:121
Foam::fileFormats::edgeMeshFormat::write
static Ostream & write(Ostream &, const pointField &, const edgeList &)
Write edgeMesh components to stream.
Definition: edgeMeshFormat.C:118
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::FatalError
error FatalError
FatalErrorInLookup
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:385
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:228
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:320
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::fileFormats::edgeMeshFormat::read
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
Definition: edgeMeshFormat.C:97
boundBox.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
points
const pointField & points
Definition: gmvOutputHeader.H:1
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::edgeMesh
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:52