surfacePatchIOList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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 {
33 }
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 (
40  const IOobject& io
41 )
42 :
44  regIOobject(io)
45 {
47  "surfacePatchIOList::surfacePatchIOList"
48  "(const IOobject& io)";
49 
50 
51  if
52  (
55  )
56  {
58  {
60  << "Specified IOobject::MUST_READ_IF_MODIFIED but class"
61  << " does not support automatic rereading."
62  << endl;
63  }
64 
65 
66  surfacePatchList& patches = *this;
67 
68  // read polyPatchList
69  Istream& is = readStream(typeName);
70 
71  PtrList<entry> patchEntries(is);
72  patches.setSize(patchEntries.size());
73 
74  label facei = 0;
75 
77  {
78  const dictionary& dict = patchEntries[patchi].dict();
79 
80  label patchSize = dict.lookup<label>("nFaces");
81  label startFacei = dict.lookup<label>("startFace");
82 
83  patches[patchi] =
85  (
86  word(dict.lookup("geometricType")),
87  patchEntries[patchi].keyword(),
88  patchSize,
89  startFacei,
90  patchi
91  );
92 
93 
94  if (startFacei != facei)
95  {
97  << "Patches are not ordered. Start of patch " << patchi
98  << " does not correspond to sum of preceding patches."
99  << endl
100  << "while reading " << objectPath()
101  << exit(FatalError);
102  }
103 
104  facei += patchSize;
105  }
106 
107  // Check state of IOstream
108  is.check(functionName.c_str());
109 
110  close();
111  }
112 }
113 
114 // Construct from IOObject
116 (
117  const IOobject& io,
119 )
120 :
122  regIOobject(io)
123 {}
124 
125 
126 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
127 
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
134 
135 // writeData member function required by regIOobject
137 {
138  os << *this;
139  return os.good();
140 }
141 
142 
143 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
144 
146 {
147  os << patches.size() << nl << token::BEGIN_LIST;
148 
150  {
151  patches[patchi].writeDict(os);
152  }
153 
154  os << token::END_LIST;
155 
156  return os;
157 }
158 
159 
160 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
161 
162 
163 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
164 
165 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:119
readOption readOpt() const
Definition: IOobject.H:360
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:330
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A functionName is a word starting with '#'.
Definition: functionName.H:60
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
fileName objectPath() const
Return complete path + object name.
Definition: regIOobject.H:158
void close()
Close Istream.
Istream & readStream(const word &, const bool read=true)
Return Istream and check object type against that given.
A class for handling character strings derived from std::string.
Definition: string.H:79
IOobject for a surfacePatchList.
bool writeData(Ostream &) const
writeData member function required by regIOobject
surfacePatchIOList(const IOobject &io)
Construct from IOobject.
'Patch' on surface as subset of triSurface.
Definition: surfacePatch.H:61
@ BEGIN_LIST
Definition: token.H:109
@ END_LIST
Definition: token.H:110
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
const fvPatchList & patches
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
defineTypeNameAndDebug(combustionModel, 0)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
error FatalError
static const char nl
Definition: Ostream.H:266
dictionary dict