Loading...
Searching...
No Matches
boundaryInfo.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) 2015 OpenFOAM Foundation
9 Copyright (C) 2018 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 "boundaryInfo.H"
30#include "Time.H"
31#include "polyMesh.H"
32#include "processorPolyPatch.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
39}
40
41// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42
43Foam::IOPtrList<Foam::entry> Foam::boundaryInfo::readBoundaryDict
44(
45 const Time& runTime,
46 const word& regionName
47) const
48{
49 Info<< " Reading mesh boundaries" << endl;
50
51 const_cast<word&>(IOPtrList<entry>::typeName) = polyBoundaryMesh::typeName;
52 IOPtrList<entry> boundaryPatchList
53 (
54 IOobject
55 (
56 "boundary",
57 runTime.findInstance(polyMesh::meshDir(regionName), "boundary"),
59 runTime,
63 )
64 );
65
66 // remove zero-sized patches
67 PtrList<entry> boundaryPatchListNew;
68 forAll(boundaryPatchList, patchI)
69 {
70 const dictionary& dict = boundaryPatchList[patchI].dict();
71 const word pType = dict.get<word>("type");
72 bool procPatch = pType == processorPolyPatch::typeName;
73
74 bool addPatch = true;
75 if (!procPatch)
76 {
77 label nFaces = dict.get<label>("nFaces");
78 if (returnReduceAnd(nFaces == 0))
79 {
80 addPatch = false;
81 }
82 }
83
84 if (addPatch)
85 {
86 boundaryPatchListNew.append(boundaryPatchList[patchI].clone());
87 }
88 }
89
90 boundaryPatchList.transfer(boundaryPatchListNew);
91
92 return boundaryPatchList;
93}
94
95
96// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
97
99:
100 boundaryDict_(readBoundaryDict(runTime, regionName)),
101 names_(),
102 types_(),
103 constraint_(),
104 groups_(),
105 allGroupNames_()
106{
107 names_.setSize(boundaryDict_.size());
108 types_.setSize(boundaryDict_.size());
109 constraint_.setSize(boundaryDict_.size(), false);
110 groups_.setSize(boundaryDict_.size());
111
112 forAll(boundaryDict_, patchI)
113 {
114 const dictionary& dict = boundaryDict_[patchI].dict();
115
116 names_[patchI] = dict.dictName();
117 dict.readEntry("type", types_[patchI]);
118 if (polyPatch::constraintType(types_[patchI]))
119 {
120 constraint_[patchI] = true;
121 }
122
123 if (dict.readIfPresent("inGroups", groups_[patchI]))
124 {
125 allGroupNames_.insert(groups_[patchI]);
126 }
127 }
128}
129
130
131// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132
134{
135 return names_;
136}
137
138
140{
141 return types_;
142}
143
144
146{
147 return constraint_;
148}
149
150
151const Foam::List<Foam::wordList>& Foam::boundaryInfo::groups() const
152{
153 return groups_;
154}
155
156
158{
159 return allGroupNames_;
160}
161
162
163void Foam::boundaryInfo::setType(const label patchI, const word& condition)
164{
165 if (constraint_[patchI])
166 {
167 // not overriding constraint types
168 return;
169 }
170
171 if (regExp(".*[Mm]apped.*").match(types_[patchI]))
172 {
173 // ugly hack to avoid overriding mapped types
174 return;
175 }
176
177 if (condition == "wall")
178 {
179 types_[patchI] = condition;
180 }
181 else
182 {
183 types_[patchI] = "patch";
184 }
185
186 dictionary& patchDict = boundaryDict_[patchI].dict();
187 patchDict.add("type", types_[patchI], true);
188}
189
190
191void Foam::boundaryInfo::write() const
192{
193 boundaryDict_.write();
194}
195
196
197// ************************************************************************* //
A PtrList of objects of type <T> with automated input and output.
Definition IOPtrList.H:53
@ NO_REGISTER
Do not request registration (bool: false).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
void write() const
Write the boundary dictionary.
const wordList & types() const
Patch types.
const List< wordList > & groups() const
Groups.
const wordList & names() const
Patch names.
const boolList & constraint() const
Constraint flag.
const wordHashSet & allGroupNames() const
Set of all group names.
boundaryInfo(const Time &runTime, const word &regionName)
Constructor.
void setType(const label patchI, const word &condition)
Set the patch type based on the condition.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition dictionary.C:625
virtual void write(Ostream &os) const =0
Write.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir).
Definition polyMesh.C:826
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTemplateTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information for templates, useful.
Definition className.H:158
engineTime & runTime
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
bool match(const UList< wordRe > &selectors, const std::string &text)
True if text matches one of the selector expressions.
Definition stringOps.H:79
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
messageStream Info
Information stream (stdout output on master, null elsewhere).
regExpCxx regExp
Selection of preferred regular expression implementation.
Definition regExpFwd.H:37
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
List< bool > boolList
A List of bools.
Definition List.H:60
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299