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 {
32  defineTypeNameAndDebug(surfacePatchIOList, 0);
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  (
53  readOpt() == IOobject::MUST_READ
54  || readOpt() == IOobject::MUST_READ_IF_MODIFIED
55  )
56  {
57  if (readOpt() == IOobject::MUST_READ_IF_MODIFIED)
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 
76  forAll(patches, patchi)
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,
118  const surfacePatchList& patches
119 )
120 :
121  surfacePatchList(patches),
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 
149  forAll(patches, patchi)
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 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
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:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
List< surfacePatch > surfacePatchList
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
&#39;Patch&#39; on surface as subset of triSurface.
Definition: surfacePatch.H:58
IOobject for a surfacePatchList.
A functionName is a word starting with &#39;#&#39;.
Definition: functionName.H:57
A class for handling words, derived from string.
Definition: word.H:59
bool writeData(Ostream &) const
writeData member function required by regIOobject
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void setSize(const label)
Reset size of List.
Definition: List.C:281
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
surfacePatchIOList(const IOobject &io)
Construct from IOobject.
Ostream & operator<<(Ostream &, const ensightPart &)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
A class for handling character strings derived from std::string.
Definition: string.H:76
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864