surfacePatchIOList.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) 2011-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 "surfacePatchIOList.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 defineTypeNameAndDebug(surfacePatchIOList, 0);
33 }
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
38 // Construct from IOObject
40 (
41  const IOobject& io
42 )
43 :
45  regIOobject(io)
46 {
47  Foam::string functionName =
48  "surfacePatchIOList::surfacePatchIOList"
49  "(const IOobject& io)";
50 
51 
52  if
53  (
56  )
57  {
59  {
61  << "Specified IOobject::MUST_READ_IF_MODIFIED but class"
62  << " does not support automatic rereading."
63  << endl;
64  }
65 
66 
67  surfacePatchList& patches = *this;
68 
69  // read polyPatchList
70  Istream& is = readStream(typeName);
71 
72  PtrList<entry> patchEntries(is);
73  patches.setSize(patchEntries.size());
74 
75  label faceI = 0;
76 
77  forAll(patches, patchI)
78  {
79  const dictionary& dict = patchEntries[patchI].dict();
80 
81  label patchSize = readLabel(dict.lookup("nFaces"));
82  label startFaceI = readLabel(dict.lookup("startFace"));
83 
84  patches[patchI] =
85  surfacePatch
86  (
87  word(dict.lookup("geometricType")),
88  patchEntries[patchI].keyword(),
89  patchSize,
90  startFaceI,
91  patchI
92  );
93 
94 
95  if (startFaceI != faceI)
96  {
98  << "Patches are not ordered. Start of patch " << patchI
99  << " does not correspond to sum of preceding patches."
100  << endl
101  << "while reading " << io.objectPath()
102  << exit(FatalError);
103  }
104 
105  faceI += patchSize;
106  }
107 
108  // Check state of IOstream
109  is.check(functionName.c_str());
110 
111  close();
112  }
113 }
114 
115 // Construct from IOObject
117 (
118  const IOobject& io,
120 )
121 :
123  regIOobject(io)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 
135 
136 // writeData member function required by regIOobject
137 bool Foam::surfacePatchIOList::writeData(Ostream& os) const
138 {
139  os << *this;
140  return os.good();
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
145 
146 Foam::Ostream& Foam::operator<<(Ostream& os, const surfacePatchIOList& patches)
147 {
148  os << patches.size() << nl << token::BEGIN_LIST;
149 
150  forAll(patches, patchI)
151  {
152  patches[patchI].writeDict(os);
153  }
154 
155  os << token::END_LIST;
156 
157  return os;
158 }
159 
160 
161 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
162 
163 
164 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
165 
166 // ************************************************************************* //
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::IOobject::MUST_READ_IF_MODIFIED
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:109
Foam::surfacePatchIOList::writeData
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: surfacePatchIOList.C:121
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::surfacePatchIOList::~surfacePatchIOList
~surfacePatchIOList()
Definition: surfacePatchIOList.C:113
Foam::IOobject::readOpt
readOption readOpt() const
Definition: IOobject.H:317
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::regIOobject::readStream
Istream & readStream()
Return Istream.
Definition: regIOobjectRead.C:34
Foam::token::BEGIN_LIST
@ BEGIN_LIST
Definition: token.H:100
Foam::regIOobject::close
void close()
Close Istream.
Definition: regIOobjectRead.C:148
Foam::surfacePatchIOList::surfacePatchIOList
surfacePatchIOList(const surfacePatchIOList &)
Disallow default bitwise copy construct.
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
patches
patches[0]
Definition: createSingleCellMesh.H:36
surfacePatchIOList.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::surfacePatchList
List< surfacePatch > surfacePatchList
Definition: surfacePatchList.H:44
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::token::END_LIST
@ END_LIST
Definition: token.H:101