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-2024 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  false // enableFunctionObjects
61  );
62 
63  // Construct IOobject to reuse the headerOk & readHeader
64  // (so we can read ascii and binary)
66  (
67  filename,
68  dummyTime,
71  false
72  );
73 
74  if (!io.headerOk())
75  {
77  << "Cannot read file " << filename
78  << exit(FatalError);
79  }
80 
81  const fileName fName(io.filePath());
82 
83  autoPtr<IFstream> isPtr(new IFstream(fName));
84  bool ok = false;
85  if (isPtr().good())
86  {
87  Istream& is = isPtr();
88  ok = io.readHeader(is);
89 
90  if (ok)
91  {
92  // Use extendedEdgeMesh IO
93  is >> *this;
94  ok = is.good();
95  }
96  }
97 
98  return ok;
99 }
100 
101 
102 // ************************************************************************* //
Input from file stream.
Definition: IFstream.H:85
bool readHeader(Istream &)
Read header.
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
virtual bool read(const fileName &)
Read from file.
extendedEdgeMeshFormat(const fileName &)
Construct from file name.
A class for handling file names.
Definition: fileName.H:82
word name() const
Return file name (part beyond last /)
Definition: fileName.C:195
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:265
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:531
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
fileName filePath() const
Return the path for the file for this Type.
Definition: IOobject.H:563
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
tUEqn clear()
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError