polyBoundaryMeshEntries.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2012 OpenFOAM Foundation
9  Copyright (C) 2020-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "processorPolyPatch.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 }
38 
39 
40 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
41 
43 :
45  (
46  IOobject(io, IOobjectOption::NO_REGISTER)
47  )
48 {
49  // readContents()
50 
51  if (isReadRequired() || (isReadOptional() && headerOk()))
52  {
53  // Read as entries
54  Istream& is = readStream(typeName);
55 
56  is >> *this;
57  close();
58  }
59 }
60 
61 
62 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
63 
66 {
67  polyBoundaryMeshEntries reader(io);
68 
69  return PtrList<entry>(std::move(static_cast<PtrList<entry>&>(reader)));
70 }
71 
72 
73 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 
78 // Extract optional entry from dictionaries and return as a list
79 template<class T>
80 static inline List<T> extract
81 (
82  const word& key,
83  const UPtrList<entry>& entries,
84  const T& initValue
85 )
86 {
87  List<T> result(entries.size(), initValue);
88 
89  forAll(entries, i)
90  {
91  const dictionary& dict = entries[i].dict();
92  dict.readIfPresent(key, result[i]);
93  }
94 
95  return result;
96 }
97 
98 } // End namespace
99 
100 
101 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
102 
103 void Foam::polyBoundaryMeshEntries::removeProcPatches(PtrList<entry>& entries)
104 {
105  // Truncate at the first processor patch entry
106 
107  label nNonProcessor = entries.size();
108 
109  forAll(entries, patchi)
110  {
111  const dictionary& dict = entries[patchi].dict();
112 
113  const word pType = dict.get<word>("type");
114  if (pType == processorPolyPatch::typeName)
115  {
116  nNonProcessor = patchi;
117  break;
118  }
119  }
120 
121  entries.resize(nNonProcessor);
122 }
123 
124 
126 (
127  Ostream& os,
128  const UPtrList<entry>& entries
129 )
130 {
131  os << entries.size();
132 
133  if (entries.empty())
134  {
135  // 0-sized : can write with less vertical space
137  }
138  else
139  {
140  os << nl << token::BEGIN_LIST << incrIndent << nl;
141 
142  forAll(entries, patchi)
143  {
144  const auto& key = entries[patchi].keyword();
145  const auto& dict = entries[patchi].dict();
146 
147  dict.writeEntry(key, os);
148  }
150  }
153  return os.good();
154 }
155 
156 
158 (
159  const UPtrList<entry>& entries
160 )
161 {
162  return extract<word>("type", entries, "patch");
163 }
164 
165 
167 (
168  const UPtrList<entry>& entries
169 )
170 {
171  return extract<label>("startFace", entries, 0);
172 }
173 
174 
176 (
177  const UPtrList<entry>& entries
178 )
179 {
180  return extract<label>("nFaces", entries, 0);
181 }
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
187 {
188  removeProcPatches(*this);
189 }
190 
193 {
194  return extract<word>("type", *this, "patch");
195 }
196 
199 {
200  return extract<label>("startFace", *this, 0);
201 }
202 
205 {
206  return extract<label>("nFaces", *this, 0);
207 }
208 
209 
211 {
212  writeEntries(os, *this);
213 }
214 
215 
217 (
218  const keyType& keyword,
219  Ostream& os
220 ) const
221 {
222  const PtrList<entry>& entries = *this;
223 
224  if (!keyword.empty())
225  {
226  os.write(keyword);
227  os << (entries.empty() ? token::SPACE : token::NL);
228  }
230  writeEntries(os, entries);
231 
232  if (!keyword.empty()) os.endEntry();
233 }
234 
235 
237 {
238  return writeEntries(os, *this);
239 }
240 
241 
243 (
244  IOstreamOption streamOpt,
245  const bool writeOnProc
246 ) const
247 {
249  return regIOobject::writeObject(streamOpt, writeOnProc);
250 }
251 
252 
253 // ************************************************************************* //
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
Definition: dictionaryIO.C:157
polyBoundaryMeshEntries(const IOobject &io)
Read construct from IOobject. Never register!
A class for handling keywords in dictionaries.
Definition: keyType.H:66
dictionary dict
void removeProcPatches()
Truncate at the first processor patch entry.
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write using stream options, forces UNCOMPRESSED.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Newline [isspace].
Definition: token.H:130
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:505
Begin list [isseparator].
Definition: token.H:161
A simple container for options an IOstream can normally have.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
wordList types() const
Return a list of patch types, uses the "patch" entry.
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
static List< T > extract(const word &key, const UPtrList< entry > &entries, const T &initValue)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static bool writeEntries(Ostream &os, const UPtrList< entry > &entries)
Write list of entries.
defineTypeName(manifoldCellsMeshObject)
void close()
Close Istream.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static PtrList< entry > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
Space [isspace].
Definition: token.H:131
End list [isseparator].
Definition: token.H:162
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
labelList patchSizes() const
Return a list of patch sizes, uses "nFaces" entry.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void writeEntry(Ostream &os) const
Write as a plain list of entries.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
compressionType compression() const noexcept
Get the stream compression.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:511
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
Definition: UPtrListI.H:99
labelList patchStarts() const
Return a list of patch start face indices, uses "startFace" entry.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:281
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
virtual bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual Ostream & endEntry()
Write end entry (&#39;;&#39;) followed by newline.
Definition: Ostream.C:117
Read and store dictionary entries for boundary patches The object is *never* registered to avoid regi...
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:502
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.