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 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  ("fileFormats::extendedEdgeMeshFormat::read(const fileName&)")
80  << "Cannot read file " << filename
81  << exit(FatalError);
82  }
83 
84  autoPtr<IFstream> isPtr(new IFstream(io.filePath()));
85  bool ok = false;
86  if (isPtr().good())
87  {
88  Istream& is = isPtr();
89  ok = io.readHeader(is);
90 
91  if (ok)
92  {
93  // Use extendedEdgeMesh IO
94  is >> *this;
95  ok = is.good();
96  }
97  }
98 
99  return ok;
100 }
101 
102 
103 // ************************************************************************* //
word name() const
Return file name (part beyond last /)
Definition: fileName.C:206
fileName filePath() const
Return complete path + object name if the file exists.
Definition: IOobject.C:323
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:287
Input from file stream.
Definition: IFstream.H:81
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
A class for handling file names.
Definition: fileName.H:69
bool read(const char *, int32_t &)
Definition: int32IO.C:87
bool headerOk()
Read and check header info.
Definition: IOobject.C:424
bool readHeader(Istream &)
Read header.
UEqn clear()
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
virtual bool read(const fileName &)
Read from file.