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-2016 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  {
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] =
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
116 Foam::surfacePatchIOList::surfacePatchIOList
117 (
118  const IOobject& io,
119  const surfacePatchList& patches
120 )
121 :
122  surfacePatchList(patches),
123  regIOobject(io)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 
135 
136 // writeData member function required by regIOobject
138 {
139  os << *this;
140  return os.good();
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
145 
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 // ************************************************************************* //
dictionary dict
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:363
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
List< surfacePatch > surfacePatchList
&#39;Patch&#39; on surface as subset of triSurface.
Definition: surfacePatch.H:58
IOobject for a surfacePatchList.
A class for handling words, derived from string.
Definition: word.H:59
label readLabel(Istream &is)
Definition: label.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
defineTypeNameAndDebug(combustionModel, 0)
void setSize(const label)
Reset size of List.
Definition: List.C:295
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Ostream & operator<<(Ostream &, const ensightPart &)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
A class for handling character strings derived from std::string.
Definition: string.H:74
bool writeData(Ostream &) const
writeData member function required by regIOobject
Namespace for OpenFOAM.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451