extendedEdgeMeshFormat.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2021 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 "extendedEdgeMeshFormat.H"
27 #include "IFstream.H"
28 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 (
35  const fileName& filename
36 )
37 {
38  read(filename);
39 }
40 
41 
42 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
43 
45 (
46  const fileName& filename
47 )
48 {
49  clear();
50 
51  fileName dir = filename.path();
52  fileName caseName = dir.name();
53  fileName rootPath = dir.path();
54 
55  // Construct dummy time to use as an objectRegistry
56  Time dummyTime
57  (
58  ".", // rootPath,
59  ".", // caseName,
60  "system", // systemName,
61  "constant", // constantName,
62  false // enableFunctionObjects
63  );
64 
65  // Construct IOobject to re-use the headerOk & readHeader
66  // (so we can read ascii and binary)
68  (
69  filename,
70  dummyTime,
71  IOobject::NO_READ,
72  IOobject::NO_WRITE,
73  false
74  );
75 
76  if (!io.headerOk())
77  {
79  << "Cannot read file " << filename
80  << exit(FatalError);
81  }
82 
83  const fileName fName(io.filePath());
84 
85  autoPtr<IFstream> isPtr(new IFstream(fName));
86  bool ok = false;
87  if (isPtr().good())
88  {
89  Istream& is = isPtr();
90  ok = io.readHeader(is);
91 
92  if (ok)
93  {
94  // Use extendedEdgeMesh IO
95  is >> *this;
96  ok = is.good();
97  }
98  }
99 
100  return ok;
101 }
102 
103 
104 // ************************************************************************* //
tUEqn clear()
A class for handling file names.
Definition: fileName.H:79
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Templated form of IOobject providing type information for file reading and header type checking...
Definition: IOobject.H:537
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual bool read(const fileName &)
Read from file.
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
fileName filePath() const
Return the path for the file for this Type.
Definition: IOobject.H:572
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
extendedEdgeMeshFormat(const fileName &)
Construct from file name.
bool readHeader(Istream &)
Read header.
word name() const
Return file name (part beyond last /)
Definition: fileName.C:195
Input from file stream.
Definition: IFstream.H:81
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:265
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52