boundaryRegion.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 OpenFOAM Foundation
9 Copyright (C) 2019-2020 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
29#include "boundaryRegion.H"
30#include "IOMap.H"
31#include "OFstream.H"
32
33// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34
36:
38{}
39
40
42(
43 const objectRegistry& registry,
44 const word& name,
45 const fileName& instance
46)
47:
49{
50 readDict(registry, name, instance);
51}
52
53
54// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
55
57{
58 label maxId = -1;
59 forAllConstIters(*this, iter)
60 {
61 if (maxId < iter.key())
62 {
63 maxId = iter.key();
64 }
65 }
66
67 insert(++maxId, dict);
68 return maxId;
69}
70
71
73{
75
76 forAllConstIters(*this, iter)
77 {
78 lookup.insert
79 (
80 iter.key(),
81 iter().getOrDefault<word>
82 (
83 "Label",
84 "boundaryRegion_" + Foam::name(iter.key())
85 )
86 );
87 }
88
89 return lookup;
90}
91
92
94(
95 const wordRes& patterns
96) const
97{
99
100 forAllConstIters(*this, iter)
101 {
102 const word lookupName = iter().getOrDefault<word>
103 (
104 "Label",
105 "boundaryRegion_" + Foam::name(iter.key())
106 );
107
108 if (patterns.match(lookupName))
109 {
110 lookup.insert(iter.key(), lookupName);
111 }
112 }
113
114 return lookup;
115}
116
117
119{
121
122 forAllConstIters(*this, iter)
123 {
124 lookup.insert
125 (
126 iter.key(),
127 iter().getOrDefault<word>("BoundaryType", "patch")
128 );
129 }
130
131 return lookup;
132}
133
134
136{
137 if (name.empty())
138 {
139 return -1;
140 }
141
142 forAllConstIters(*this, iter)
143 {
144 if (iter().getOrDefault<word>("Label", word::null) == name)
145 {
146 return iter.key();
147 }
148 }
149
150 return -1;
151}
152
153
155{
156 word bndType("patch");
157
158 label id = this->findIndex(name);
159 if (id >= 0)
160 {
161 operator[](id).readIfPresent<word>("BoundaryType", bndType);
162 }
163
164 return bndType;
165}
166
167
169(
170 const objectRegistry& registry,
171 const word& name,
172 const fileName& instance
173)
174{
175 clear();
176
177 // read constant/dictName
179 (
181 (
182 name,
183 instance,
184 registry,
187 false
188 )
189 );
190
191 if (ioObj.headerOk())
192 {
193 *this = ioObj;
194 }
195 else
196 {
197 Info<< "no constant/boundaryRegion information available" << endl;
198 }
199}
200
201
203(
204 const objectRegistry& registry,
205 const word& name,
206 const fileName& instance
207) const
208{
209 // write constant/dictName
211 (
213 (
214 name,
215 instance,
216 registry,
219 false
220 )
221 );
222
223 ioObj.note() =
224 "persistent data for thirdParty mesh <-> OpenFOAM translation";
225
226 Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
227
228 OFstream os(ioObj.objectPath());
229 ioObj.writeHeader(os);
230 os << *this;
231}
232
233
234// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
235
237{
239}
240
241
243{
245}
246
247
248// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
249
251{
252 if (mapDict.empty())
253 {
254 return;
255 }
256
257 // Use 1st pass to collect all the regions to be changed
258 // and 2nd pass to relabel regions.
259 // This avoid re-matching any renamed regions
260
261 Map<word> mapping;
262 for (const entry& dEntry : mapDict)
263 {
264 const word oldName(dEntry.stream());
265
266 const label id = this->findIndex(oldName);
267 if (id >= 0)
268 {
269 mapping.insert(id, dEntry.keyword());
270 }
271 }
272
273 forAllConstIters(mapping, iter)
274 {
275 dictionary& dict = operator[](iter.key());
276
277 Info<< "rename patch: " << iter()
278 << " <- " << dict.get<word>("Label") << nl;
279
280 dict.set("Label", iter());
281 }
282}
283
284
285// ************************************************************************* //
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
A Map of objects of type <T> with automated input and output. Is a global object; i....
Definition: IOMap.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
const string & note() const noexcept
Return the optional note.
Definition: IOobjectI.H:95
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:214
bool writeHeader(Ostream &os) const
Write header with current type()
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
void operator=(const this_type &rhs)
Copy assignment.
Definition: Map.H:117
Output to file stream, using an OSstream.
Definition: OFstream.H:57
The boundaryRegion persistent data saved as a Map<dictionary>.
word boundaryType(const word &name) const
Return BoundaryType corresponding to patch 'name'.
label findIndex(const word &name) const
Return index corresponding to patch 'name'.
boundaryRegion()
Construct null.
Map< word > boundaryTypes() const
Return a Map of (id => type)
Map< word > names() const
Return a Map of (id => name)
void readDict(const objectRegistry &, const word &name="boundaryRegion", const fileName &instance="constant")
Read constant/boundaryRegion.
void rename(const dictionary &)
Rename regions.
void operator=(const boundaryRegion &)
Assignment.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:780
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
A class for handling file names.
Definition: fileName.H:76
Foam::dictionary writeDict() const
Write to dictionary.
Registry of regIOobjects.
Lookup type of boundary radiation properties.
Definition: lookup.H:66
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:438
bool append() const noexcept
True if output format uses an append mode.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
Definition: wordResI.H:91
A class for handling words, derived from Foam::string.
Definition: word.H:68
patchWriters clear()
OBJstream os(runTime.globalPath()/outputName)
label findIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Deprecated(2017-10) search for first occurrence of the given element.
Definition: ListOps.H:398
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
dictionary dict
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278