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 -------------------------------------------------------------------------------
11 License
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 
36 namespace Foam
37 {
38  defineTemplateTypeNameAndDebug(IOPtrList<entry>, 0);
39 }
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 Foam::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(regionName/polyMesh::meshSubDir, "boundary"),
59  runTime,
62  false
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  reduce(nFaces, sumOp<label>());
79  if (nFaces == 0)
80  {
81  addPatch = false;
82  }
83  }
84 
85  if (addPatch)
86  {
87  boundaryPatchListNew.append(boundaryPatchList[patchI].clone());
88  }
89  }
90 
91  boundaryPatchList.transfer(boundaryPatchListNew);
92 
93  return boundaryPatchList;
94 }
95 
96 
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 
99 Foam::boundaryInfo::boundaryInfo(const Time& runTime, const word& regionName)
100 :
101  boundaryDict_(readBoundaryDict(runTime, regionName)),
102  names_(),
103  types_(),
104  constraint_(),
105  groups_(),
106  allGroupNames_()
107 {
108  names_.setSize(boundaryDict_.size());
109  types_.setSize(boundaryDict_.size());
110  constraint_.setSize(boundaryDict_.size(), false);
111  groups_.setSize(boundaryDict_.size());
112 
113  forAll(boundaryDict_, patchI)
114  {
115  const dictionary& dict = boundaryDict_[patchI].dict();
116 
117  names_[patchI] = dict.dictName();
118  dict.readEntry("type", types_[patchI]);
119  if (polyPatch::constraintType(types_[patchI]))
120  {
121  constraint_[patchI] = true;
122  }
123 
124  if (dict.readIfPresent("inGroups", groups_[patchI]))
125  {
126  allGroupNames_.insert(groups_[patchI]);
127  }
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
135 {
136  return names_;
137 }
138 
139 
141 {
142  return types_;
143 }
144 
145 
147 {
148  return constraint_;
149 }
150 
151 
153 {
154  return groups_;
155 }
156 
157 
159 {
160  return allGroupNames_;
161 }
162 
163 
164 void Foam::boundaryInfo::setType(const label patchI, const word& condition)
165 {
166  if (constraint_[patchI])
167  {
168  // not overriding constraint types
169  return;
170  }
171 
172  if (regExp(".*[Mm]apped.*").match(types_[patchI]))
173  {
174  // ugly hack to avoid overriding mapped types
175  return;
176  }
177 
178  if (condition == "wall")
179  {
180  types_[patchI] = condition;
181  }
182  else
183  {
184  types_[patchI] = "patch";
185  }
186 
187  dictionary& patchDict = boundaryDict_[patchI].dict();
188  patchDict.add("type", types_[patchI], true);
189 }
190 
191 
192 void Foam::boundaryInfo::write() const
193 {
194  boundaryDict_.write();
195 }
196 
197 
198 // ************************************************************************* //
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:191
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::boundaryInfo::names
const wordList & names() const
Foam::IOPtrList< Foam::entry >
Foam::boundaryInfo::constraint
const boolList & constraint() const
Foam::boundaryInfo::groups
const List< wordList > & groups() const
Foam::polyMesh::meshSubDir
static word meshSubDir
Definition: polyMesh.H:317
Foam::defineTemplateTypeNameAndDebug
defineTemplateTypeNameAndDebug(faScalarMatrix, 0)
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
polyMesh.H
Foam::HashSet
A HashTable with keys but without contents that is similar to std::unordered_set.
Definition: HashSet.H:73
boundaryInfo.H
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:45
Foam::boundaryInfo::allGroupNames
const wordHashSet & allGroupNames() const
Foam::Info
messageStream Info
Foam::boundaryInfo::setType
void setType(const label patchI, const word &condition)
dict
dictionary dict
Definition: searchingEngine.H:14
processorPolyPatch.H
Foam
Definition: atmBoundaryLayer.C:26
Foam::boundaryInfo::boundaryInfo
boundaryInfo(const Time &runTime, const word &regionName)
Time.H
Foam::boundaryInfo::types
const wordList & types() const
Foam::stringOps::match
bool match(const UList< wordRe > &patterns, const std::string &text)
Definition: stringOps.H:72
Foam::regExp
regExpPosix regExp
Selection of preferred regular expression implementation.
Definition: regExpFwd.H:36
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::boundaryInfo::write
void write() const
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:181