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-2012 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
39 Foam::surfacePatchIOList::surfacePatchIOList
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  (
54  readOpt() == IOobject::MUST_READ
55  || readOpt() == IOobject::MUST_READ_IF_MODIFIED
56  )
57  {
58  if (readOpt() == IOobject::MUST_READ_IF_MODIFIED)
59  {
60  WarningIn
61  (
62  "surfacePatchIOList::surfacePatchIOList\n"
63  "(\n"
64  " const IOobject&\n"
65  ")"
66  ) << "Specified IOobject::MUST_READ_IF_MODIFIED but class"
67  << " does not support automatic rereading."
68  << endl;
69  }
70 
71 
72  surfacePatchList& patches = *this;
73 
74  // read polyPatchList
75  Istream& is = readStream(typeName);
76 
77  PtrList<entry> patchEntries(is);
78  patches.setSize(patchEntries.size());
79 
80  label faceI = 0;
81 
82  forAll(patches, patchI)
83  {
84  const dictionary& dict = patchEntries[patchI].dict();
85 
86  label patchSize = readLabel(dict.lookup("nFaces"));
87  label startFaceI = readLabel(dict.lookup("startFace"));
88 
89  patches[patchI] =
91  (
92  word(dict.lookup("geometricType")),
93  patchEntries[patchI].keyword(),
94  patchSize,
95  startFaceI,
96  patchI
97  );
98 
99 
100  if (startFaceI != faceI)
101  {
102  FatalErrorIn(functionName)
103  << "Patches are not ordered. Start of patch " << patchI
104  << " does not correspond to sum of preceding patches."
105  << endl
106  << "while reading " << io.objectPath()
107  << exit(FatalError);
108  }
109 
110  faceI += patchSize;
111  }
112 
113  // Check state of IOstream
114  is.check(functionName.c_str());
115 
116  close();
117  }
118 }
119 
120 // Construct from IOObject
121 Foam::surfacePatchIOList::surfacePatchIOList
122 (
123  const IOobject& io,
124  const surfacePatchList& patches
125 )
126 :
127  surfacePatchList(patches),
128  regIOobject(io)
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
133 
135 {}
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
140 
141 // writeData member function required by regIOobject
143 {
144  os << *this;
145  return os.good();
146 }
147 
148 
149 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
150 
152 {
153  os << patches.size() << nl << token::BEGIN_LIST;
154 
155  forAll(patches, patchI)
156  {
157  patches[patchI].writeDict(os);
158  }
159 
160  os << token::END_LIST;
161 
162  return os;
163 }
164 
165 
166 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
167 
168 
169 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
170 
171 // ************************************************************************* //
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
bool writeData(Ostream &) const
writeData member function required by regIOobject
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
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
A class for handling character strings derived from std::string.
Definition: string.H:74
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Namespace for OpenFOAM.
label readLabel(Istream &is)
Definition: label.H:64
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
List< surfacePatch > surfacePatchList
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
dictionary dict
static const char nl
Definition: Ostream.H:260
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:363
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
IOobject for a surfacePatchList.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
defineTypeNameAndDebug(combustionModel, 0)
&#39;Patch&#39; on surface as subset of triSurface.
Definition: surfacePatch.H:51