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,
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 
98 Foam::boundaryInfo::boundaryInfo(const Time& runTime, const word& regionName)
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 
152 {
153  return groups_;
154 }
155 
156 
158 {
159  return allGroupNames_;
160 }
161 
162 
163 void 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 
191 void Foam::boundaryInfo::write() const
192 {
193  boundaryDict_.write();
194 }
195 
196 
197 // ************************************************************************* //
bool match(const UList< wordRe > &patterns, const std::string &text)
Return true if text matches one of the regular expressions.
Definition: stringOps.H:77
dictionary dict
void setType(const label patchI, const word &condition)
Set the patch type based on the condition.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:402
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
regExpPosix regExp
Selection of preferred regular expression implementation.
Definition: regExpFwd.H:36
Ignore writing from objectRegistry::writeObject()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
Foam::word regionName(Foam::polyMesh::defaultRegion)
const List< wordList > & groups() const
Groups.
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
const wordList & names() const
Patch names.
const wordList & types() const
Patch types.
defineTemplateTypeNameAndDebug(faScalarMatrix, 0)
const boolList & constraint() const
Constraint flag.
const wordHashSet & allGroupNames() const
Set of all group names.
messageStream Info
Information stream (stdout output on master, null elsewhere)
void write() const
Write the boundary dictionary.
Do not request registration (bool: false)
boundaryInfo(const Time &runTime, const word &regionName)
Constructor.
Namespace for OpenFOAM.