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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 IOstreamOption streamOpt,
92 const dictionary& options
93)
94{
95 DebugInFunction << "Writing to " << name << endl;
96
97 auto* mfuncPtr = writefileExtensionMemberFunctionTable(fileType);
98
99 if (!mfuncPtr)
100 {
102 (
103 "extension",
104 fileType,
105 *writefileExtensionMemberFunctionTablePtr_
106 ) << exit(FatalError);
107 }
108
109 mfuncPtr(name, mesh, streamOpt, options);
110}
111
112
114(
115 const fileName& name,
116 const edgeMesh& mesh,
117 IOstreamOption streamOpt,
118 const dictionary& options
119)
120{
121 write(name, name.ext(), mesh, streamOpt, options);
122}
123
124
126{
127 os << indent << "points : " << points().size() << nl;
128 os << indent << "edges : " << edges().size() << nl;
129 os << indent << "boundingBox : " << boundBox(this->points()) << endl;
130}
131
132
133// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
134
136{
137 fileFormats::edgeMeshFormat::write(os, em.points_, em.edges_);
138
140 return os;
141}
142
143
145{
146 fileFormats::edgeMeshFormat::read(is, em.points_, em.edges_);
147
148 em.pointEdgesPtr_.reset(nullptr);
149
151 return is;
152}
153
154
155// ************************************************************************* //
The IOstreamOption is a simple container for options an IOstream can normally have.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:56
edgeMesh()
Default construct.
Definition: edgeMeshI.H:45
bool read(const fileName &name, const word &fileType)
Read from file. Chooses reader based on explicit extension.
Definition: edgeMeshIO.C:75
virtual void writeStats(Ostream &) const
Definition: edgeMeshIO.C:125
A class for handling file names.
Definition: fileName.H:76
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:218
virtual bool write()
Write the output fields.
A class for handling words, derived from Foam::string.
Definition: word.H:68
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
word lessExt() const
Return word without extension (part before last .)
Definition: word.C:113
dynamicFvMesh & mesh
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:457
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
#define FUNCTION_NAME
#define DebugInFunction
Report an information message using Foam::Info.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
Istream & operator>>(Istream &, directionInfo &)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
runTime write()