edgeMeshFormat.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) 2017-2019 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 "edgeMeshFormat.H"
30#include "IOobject.H"
31#include "IFstream.H"
32#include "clock.H"
33#include "Time.H"
34#include "featureEdgeMesh.H"
35
36// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37
39(
40 const fileName& filename
41)
42{
43 read(filename);
44}
45
46
47// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
48
50(
51 const fileName& filename
52)
53{
54 clear();
55
56 // Use dummy Time for objectRegistry
57 autoPtr<Time> dummyTimePtr(Time::New());
58
59 // Construct IOobject to re-use the headerOk & readHeader
60 // (so we can read ascii and binary)
62 (
63 filename,
64 *dummyTimePtr,
67 false
68 );
69
70 if (!io.typeHeaderOk<featureEdgeMesh>(false))
71 {
73 << "Cannot read file " << filename
74 << exit(FatalError);
75 }
76
77 const fileName fName(typeFilePath<featureEdgeMesh>(io));
78
79 autoPtr<IFstream> isPtr(new IFstream(fName));
80 bool ok = false;
81 if (isPtr().good())
82 {
83 Istream& is = isPtr();
84 ok = io.readHeader(is);
85
86 if (ok)
87 {
88 ok = read(is, this->storedPoints(), this->storedEdges());
89 }
90 }
91
92 return ok;
93}
94
95
97(
98 Istream& is,
99 pointField& pointLst,
100 edgeList& edgeLst
101)
102{
103 if (!is.good())
104 {
106 << "read error "
107 << exit(FatalError);
108 }
109
110 is >> pointLst;
111 is >> edgeLst;
112
113 return true;
114}
115
116
118(
119 Ostream& os,
120 const pointField& pointLst,
121 const edgeList& edgeLst
122)
123{
124 if (!os.good())
125 {
127 << "bad output stream " << os.name()
128 << exit(FatalError);
129 }
130
131 os << "\n// points:" << nl << pointLst << nl
132 << "\n// edges:" << nl << edgeLst << nl;
133
135
136 os.check(FUNCTION_NAME);
137 return os;
138}
139
140
142(
143 const fileName& filename,
144 const edgeMesh& mesh,
145 IOstreamOption streamOpt,
146 const dictionary& options
147)
148{
149 // Use dummy Time for objectRegistry
150 autoPtr<Time> dummyTimePtr(Time::New());
151
152 // Construct IOobject to re-use the writeHeader
154 (
155 filename,
156 *dummyTimePtr,
159 false
160 );
161 io.note() = "written " + clock::dateTime();
162
163 // Write in serial only
164 autoPtr<OFstream> osPtr(new OFstream(filename, streamOpt));
165
166 if (!osPtr().good())
167 {
169 << "Cannot open file for writing " << filename
170 << exit(FatalIOError);
171 }
172
173 OFstream& os = osPtr();
174 bool ok = io.writeHeader(os, featureEdgeMesh::typeName);
175
176 if (!ok)
177 {
179 << "Cannot write header"
180 << exit(FatalIOError);
181 }
182
183 write(os, mesh.points(), mesh.edges());
184
185 os.check(FUNCTION_NAME);
186}
187
188
189// ************************************************************************* //
Input from file stream, using an ISstream.
Definition: IFstream.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
The IOstreamOption is a simple container for options an IOstream can normally have.
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Output to file stream, using an OSstream.
Definition: OFstream.H:57
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.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
static std::string dateTime()
Definition: clock.C:60
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
Provide a means of reading/writing the single-file OpenFOAM edge format.
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
A class for handling file names.
Definition: fileName.H:76
virtual bool write()
Write the output fields.
patchWriters clear()
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define FUNCTION_NAME
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
IOerror FatalIOError
error FatalError
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()
static const char *const typeName
The type name used in ensight case files.