extendedEdgeMeshFormat.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 | Copyright (C) 2013-2015 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 "edgeMeshFormat.H"
28 #include "IFstream.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 Foam::fileFormats::extendedEdgeMeshFormat::extendedEdgeMeshFormat
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)
67  IOobject io
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  autoPtr<IFstream> isPtr(new IFstream(io.filePath()));
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 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:69
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:319
tUEqn clear()
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
virtual bool read(const fileName &)
Read from file.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool readHeader(Istream &)
Read header.
word name() const
Return file name (part beyond last /)
Definition: fileName.C:179
bool read(const char *, int32_t &)
Definition: int32IO.C:85
fileName filePath() const
Return complete path + object name if the file exists.
Definition: IOobject.C:299
Input from file stream.
Definition: IFstream.H:81
bool headerOk()
Read and check header info.
Definition: IOobject.C:400
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:249