faBoundaryMeshEntries.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) 2022-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "faBoundaryMeshEntries.H"
29 #include "processorFaPatch.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
40 
42 :
44  (
45  IOobject(io, IOobjectOption::NO_REGISTER)
46  )
47 {
48  // readIOcontents()
49  if (isReadRequired() || (isReadOptional() && headerOk()))
50  {
51  // Read as entries
52  Istream& is = readStream(typeName);
53 
54  is >> *this;
55  close();
56  }
57 }
58 
59 
60 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
61 
64 {
65  faBoundaryMeshEntries reader(io);
66 
67  return PtrList<entry>(std::move(static_cast<PtrList<entry>&>(reader)));
68 }
69 
70 
71 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 
76 // Extract optional entry from dictionaries and return as a list
77 template<class T>
78 static inline List<T> extract
79 (
80  const word& key,
81  const UPtrList<entry>& entries,
82  const T& initValue
83 )
84 {
85  List<T> result(entries.size(), initValue);
86 
87  forAll(entries, i)
88  {
89  const dictionary& dict = entries[i].dict();
90  dict.readIfPresent(key, result[i]);
91  }
92 
93  return result;
94 }
95 
96 } // End namespace
97 
98 
99 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
100 
101 void Foam::faBoundaryMeshEntries::removeProcPatches(PtrList<entry>& entries)
102 {
103  // Truncate at the first processor patch entry
104 
105  label nNonProcessor = entries.size();
106 
107  forAll(entries, patchi)
108  {
109  const dictionary& dict = entries[patchi].dict();
110 
111  const word pType = dict.get<word>("type");
112  if (pType == processorFaPatch::typeName)
113  {
114  nNonProcessor = patchi;
115  break;
116  }
117  }
118 
119  entries.resize(nNonProcessor);
120 }
121 
122 
124 (
125  Ostream& os,
126  const UPtrList<entry>& entries
127 )
128 {
129  os << entries.size();
130 
131  if (entries.empty())
132  {
133  // 0-sized : can write with less vertical space
135  }
136  else
137  {
138  os << nl << token::BEGIN_LIST << incrIndent << nl;
139 
140  forAll(entries, patchi)
141  {
142  const auto& key = entries[patchi].keyword();
143  const auto& dict = entries[patchi].dict();
144 
145  dict.writeEntry(key, os);
146  }
148  }
151  return os.good();
152 }
153 
154 
156 (
157  const UPtrList<entry>& entries
158 )
159 {
160  return extract<word>("type", entries, "patch");
161 }
162 
163 
164 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
167 {
168  removeProcPatches(*this);
169 }
170 
173 {
174  return extract<word>("type", *this, "patch");
175 }
176 
177 
179 {
180  writeEntries(os, *this);
181 }
182 
183 
185 (
186  const word& keyword,
187  Ostream& os
188 ) const
189 {
190  const PtrList<entry>& entries = *this;
191 
192  if (!keyword.empty())
193  {
194  os.write(keyword);
195  os << (entries.empty() ? token::SPACE : token::NL);
196  }
198  writeEntries(os, entries);
199 
200  if (!keyword.empty()) os.endEntry();
201 }
202 
203 
205 {
206  return writeEntries(os, *this);
207 }
208 
209 
211 (
212  IOstreamOption streamOpt,
213  const bool writeOnProc
214 ) const
215 {
217  return regIOobject::writeObject(streamOpt, writeOnProc);
218 }
219 
220 
221 // ************************************************************************* //
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
Definition: dictionaryIO.C:157
faBoundaryMeshEntries(const IOobject &io)
Read construct from IOobject. Never register!
dictionary dict
static bool writeEntries(Ostream &os, const UPtrList< entry > &entries)
Write list of entries.
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
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.
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
defineTypeName(manifoldCellsMeshObject)
void writeEntry(Ostream &os) const
Write as a plain list of entries.
void close()
Close Istream.
A class for handling words, derived from Foam::string.
Definition: word.H:63
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
Space [isspace].
Definition: token.H:131
void removeProcPatches()
Truncate at the first processor patch entry.
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
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
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)
virtual bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
Read and store dictionary entries for finite-area boundary patches. The object is *never* registered ...
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
Definition: UPtrListI.H:99
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...
static PtrList< entry > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
wordList types() const
Return a list of patch types, uses the "patch" entry.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write using stream options, forces UNCOMPRESSED.
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
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:180
Namespace for OpenFOAM.