Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
34namespace Foam
37}
38
39
40// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
41
43:
45 (
46 IOobject(io, IOobjectOption::NO_REGISTER)
47 )
48{
49 // readIOcontents()
50 if (isReadRequired() || (isReadOptional() && headerOk()))
51 {
52 // Read as entries
53 Istream& is = readStream(typeName);
54
55 is >> *this;
56 close();
57 }
58}
59
60
61// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
62
65{
66 polyBoundaryMeshEntries reader(io);
67
68 return PtrList<entry>(std::move(static_cast<PtrList<entry>&>(reader)));
69}
70
71
72// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
73
74namespace Foam
75{
76
77// Extract optional entry from dictionaries and return as a list
78template<class T>
79static inline List<T> extract
80(
81 const word& key,
82 const UPtrList<entry>& entries,
83 const T& initValue
84)
85{
86 List<T> result(entries.size(), initValue);
87
88 forAll(entries, i)
89 {
90 const dictionary& dict = entries[i].dict();
91 dict.readIfPresent(key, result[i]);
92 }
93
94 return result;
96
97} // End namespace
98
99
100// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
101
102void Foam::polyBoundaryMeshEntries::removeProcPatches(PtrList<entry>& entries)
103{
104 // Truncate at the first processor patch entry
105
106 label nNonProcessor = entries.size();
107
108 forAll(entries, patchi)
109 {
110 const dictionary& dict = entries[patchi].dict();
111
112 const word pType = dict.get<word>("type");
113 if (pType == processorPolyPatch::typeName)
114 {
115 nNonProcessor = patchi;
116 break;
118 }
119
120 entries.resize(nNonProcessor);
121}
122
123
125(
126 Ostream& os,
127 const UPtrList<entry>& entries
128)
129{
130 os << entries.size();
131
132 if (entries.empty())
133 {
134 // 0-sized : can write with less vertical space
136 }
137 else
138 {
139 os << nl << token::BEGIN_LIST << incrIndent << nl;
140
141 forAll(entries, patchi)
142 {
143 const auto& key = entries[patchi].keyword();
144 const auto& dict = entries[patchi].dict();
145
146 dict.writeEntry(key, os);
147 }
150
151 os.check(FUNCTION_NAME);
152 return os.good();
153}
154
155
157(
158 const UPtrList<entry>& entries
159)
160{
161 return extract<word>("type", entries, "patch");
162}
163
164
166(
167 const UPtrList<entry>& entries
168)
169{
170 return extract<label>("startFace", entries, 0);
171}
172
173
175(
176 const UPtrList<entry>& entries
177)
179 return extract<label>("nFaces", entries, 0);
180}
181
182
183// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
188}
189
192{
193 return extract<word>("type", *this, "patch");
194}
195
198{
199 return extract<label>("startFace", *this, 0);
200}
201
204{
205 return extract<label>("nFaces", *this, 0);
206}
207
210{
211 writeEntries(os, *this);
212}
213
214
216(
217 const word& keyword,
218 Ostream& os
219) const
220{
221 const PtrList<entry>& entries = *this;
222
223 if (!keyword.empty())
224 {
225 os.write(keyword);
226 os << (entries.empty() ? token::SPACE : token::NL);
227 }
229 writeEntries(os, entries);
230
231 if (!keyword.empty()) os.endEntry();
232}
233
236{
237 return writeEntries(os, *this);
238}
239
240
242(
243 IOstreamOption streamOpt,
244 const bool writeOnProc
245) const
246{
248 return regIOobject::writeObject(streamOpt, writeOnProc);
249}
250
251
252// ************************************************************************* //
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
@ NO_REGISTER
Do not request registration (bool: false).
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
compressionType compression() const noexcept
Get the stream compression.
@ UNCOMPRESSED
compression = false
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:72
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
constexpr PtrList() noexcept
Definition PtrListI.H:29
void resize(const label newLen)
Adjust size of PtrList.
Definition PtrList.C:124
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition UPtrList.H:101
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
Definition UPtrListI.H:99
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
Read and store dictionary entries for boundary patches The object is *never* registered to avoid regi...
labelList patchStarts() const
Return a list of patch start face indices, uses "startFace" entry.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write using stream options, forces UNCOMPRESSED.
wordList types() const
Return a list of patch types, uses the "patch" entry.
virtual bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
polyBoundaryMeshEntries(const IOobject &io)
Read construct from IOobject. Never register!
static PtrList< entry > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
static bool writeEntries(Ostream &os, const UPtrList< entry > &entries)
Write list of entries.
static void removeProcPatches(PtrList< entry > &entries)
Truncate entries at the first processor patch entry.
void writeEntry(Ostream &os) const
Write as a plain list of entries.
labelList patchSizes() const
Return a list of patch sizes, uses "nFaces" entry.
void removeProcPatches()
Truncate at the first processor patch entry.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
void close()
Close Istream.
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
bool headerOk()
Read and check header info. Does not check the headerClassName.
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
@ SPACE
Space [isspace].
Definition token.H:144
@ NL
Newline [isspace].
Definition token.H:143
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
OBJstream os(runTime.globalPath()/outputName)
const auto & io
#define FUNCTION_NAME
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
static List< T > extract(const word &key, const UPtrList< entry > &entries, const T &initValue)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition Ostream.H:490
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299