1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "boundaryRegion.H"
29 #include "stringListOps.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 Foam::boundaryRegion::boundaryRegion()
39 Foam::boundaryRegion::boundaryRegion
41 const objectRegistry& registry,
43 const fileName& instance
48 readDict(registry, name, instance);
52 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
54 Foam::boundaryRegion::~boundaryRegion()
58 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
60 Foam::label Foam::boundaryRegion::append(const dictionary& dict)
63 forAllConstIter(Map<dictionary>, *this, iter)
65 if (maxId < iter.key())
71 insert(++maxId, dict);
76 Foam::Map<Foam::word> Foam::boundaryRegion::names() const
80 forAllConstIter(Map<dictionary>, *this, iter)
85 iter().lookupOrDefault<word>
88 "boundaryRegion_" + Foam::name(iter.key())
97 Foam::Map<Foam::word> Foam::boundaryRegion::names
99 const UList<wordRe>& patterns
104 forAllConstIter(Map<dictionary>, *this, iter)
106 word lookupName = iter().lookupOrDefault<word>
109 "boundaryRegion_" + Foam::name(iter.key())
112 if (findStrings(patterns, lookupName))
114 lookup.insert(iter.key(), lookupName);
122 Foam::Map<Foam::word> Foam::boundaryRegion::boundaryTypes() const
126 forAllConstIter(Map<dictionary>, *this, iter)
131 iter().lookupOrDefault<word>("BoundaryType", "patch")
139 Foam::label Foam::boundaryRegion::findIndex(const word& name) const
146 forAllConstIter(Map<dictionary>, *this, iter)
148 if (iter().lookupOrDefault<word>("Label", word::null) == name)
158 Foam::word Foam::boundaryRegion::boundaryType(const word& name) const
160 word bndType("patch");
162 label id = this->findIndex(name);
165 operator[](id).readIfPresent<word>("BoundaryType", bndType);
172 void Foam::boundaryRegion::readDict
174 const objectRegistry& registry,
176 const fileName& instance
181 // read constant/dictName
182 IOMap<dictionary> ioObj
189 IOobject::READ_IF_PRESENT,
195 if (ioObj.headerOk())
201 Info<< "no constant/boundaryRegion information available" << endl;
206 void Foam::boundaryRegion::writeDict
208 const objectRegistry& registry,
210 const fileName& instance
213 // write constant/dictName
214 IOMap<dictionary> ioObj
228 "persistent data for thirdParty mesh <-> OpenFOAM translation";
230 Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
232 OFstream os(ioObj.objectPath());
233 ioObj.writeHeader(os);
238 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
240 void Foam::boundaryRegion::operator=(const boundaryRegion& rhs)
242 Map<dictionary>::operator=(rhs);
246 void Foam::boundaryRegion::operator=(const Map<dictionary>& rhs)
248 Map<dictionary>::operator=(rhs);
252 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
254 void Foam::boundaryRegion::rename(const dictionary& mapDict)
261 // Use 1st pass to collect all the regions to be changed
262 // and 2nd pass to relabel regions.
263 // This avoid re-matching any renamed regions
266 forAllConstIter(dictionary, mapDict, iter)
268 word oldName(iter().stream());
270 label id = this->findIndex(oldName);
273 mapping.insert(id, iter().keyword());
277 forAllConstIter(Map<word>, mapping, iter)
279 dictionary& dict = operator[](iter.key());
281 Info<< "rename patch: " << iter()
282 << " <- " << word(dict.lookup("Label")) << nl;
284 dict.set("Label", iter());
289 // ************************************************************************* //