Loading...
Searching...
No Matches
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)
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,
68 );
69
70 if (!io.typeHeaderOk<featureEdgeMesh>(false))
71 {
73 << "Cannot read file " << filename
74 << exit(FatalError);
75 }
76
77 const fileName fName(io.typeFilePath<featureEdgeMesh>());
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,
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 as an ISstream, normally using std::ifstream for the actual input.
Definition IFstream.H:55
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
A simple container for options an IOstream can normally have.
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition TimeNew.C:26
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static std::string dateTime()
The current wall-clock date/time (in local time) as a string in ISO-8601 format (yyyy-mm-ddThh:mm:ss)...
Definition clock.C:53
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Area discretisation.
Definition edgeFaMesh.H:50
pointField & storedPoints() noexcept
Non-const access to global points.
Definition edgeMeshI.H:24
edgeMesh(const faMesh &mesh)
Construct finite-area edge mesh faMesh reference.
Definition edgeFaMesh.H:58
edgeList & storedEdges() noexcept
Non-const access to the edges.
Definition edgeMeshI.H:30
static bool read(Istream &, pointField &, edgeList &)
Read edgeMesh components from stream.
static Ostream & write(Ostream &, const pointField &, const edgeList &)
Write edgeMesh components to stream.
edgeMeshFormat(const fileName &filename)
Construct from file name.
A class for handling file names.
Definition fileName.H:75
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
const auto & io
surface1 clear()
#define FUNCTION_NAME
List< edge > edgeList
List of edge.
Definition edgeList.H:32
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
runTime write()