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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "boundaryInfo.H"
27 #include "Time.H"
28 #include "polyMesh.H"
29 #include "processorPolyPatch.H"
30 
31 using namespace Foam;
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
38 }
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
43 (
44  const Time& runTime,
45  const word& regionName
46 ) const
47 {
48  Info<< " Reading mesh boundaries" << endl;
49 
50  const_cast<word&>(IOPtrList<entry>::typeName) = polyBoundaryMesh::typeName;
51  IOPtrList<entry> boundaryPatchList
52  (
53  IOobject
54  (
55  "boundary",
56  runTime.findInstance(regionName/polyMesh::meshSubDir, "boundary"),
58  runTime,
61  false
62  )
63  );
64 
65  // remove zero-sized patches
66  PtrList<entry> boundaryPatchListNew;
67  forAll(boundaryPatchList, patchI)
68  {
69  const dictionary& dict = boundaryPatchList[patchI].dict();
70  const word pType = dict.lookup("type");
71  bool procPatch = pType == processorPolyPatch::typeName;
72 
73  bool addPatch = true;
74  if (!procPatch)
75  {
76  label nFaces = readLabel(dict.lookup("nFaces"));
77  reduce(nFaces, sumOp<label>());
78  if (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.lookup("type") >> types_[patchI];
118  if (polyPatch::constraintType(types_[patchI]))
119  {
120  constraint_[patchI] = true;
121  }
122 
123  if (dict.found("inGroups"))
124  {
125  dict.lookup("inGroups") >> groups_[patchI];
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 (wordRe(".*[mM]apped.*", wordRe::DETECT).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::dictionaryName::dictName
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::boundaryInfo::names
const wordList & names() const
Patch names.
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::PtrList::append
void append(T *)
Append an element at the end of the list.
Foam::IOPtrList
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::boundaryInfo::constraint
const boolList & constraint() const
Constraint flag.
Foam::boundaryInfo::groups
const List< wordList > & groups() const
Groups.
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::wordRe::DETECT
@ DETECT
Definition: wordRe.H:98
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh.H
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
Foam::wordRe
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
boundaryInfo.H
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:43
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::boundaryInfo::allGroupNames
const wordHashSet & allGroupNames() const
Set of all group names.
Foam::Info
messageStream Info
Foam::boundaryInfo::setType
void setType(const label patchI, const word &condition)
Set the patch type based on the condition.
Foam::PtrList< entry >
Foam::boundaryInfo::readBoundaryDict
IOPtrList< entry > readBoundaryDict(const Time &runTime, const word &regionName) const
Read the boundary dict.
Foam::boundaryInfo::names_
wordList names_
Patch names.
Definition: boundaryInfo.H:60
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
processorPolyPatch.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Time::findInstance
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Return the location of "dir" containing the file "name".
Definition: findInstance.C:38
Foam::boundaryInfo::boundaryInfo
boundaryInfo(const Time &runTime, const word &regionName)
Constructor.
Foam::boundaryInfo::types
const wordList & types() const
Patch types.
Foam::sumOp
Definition: ops.H:162
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::defineTemplateTypeNameAndDebug
defineTemplateTypeNameAndDebug(IOPtrList< ensightPart >, 0)
Foam::boundaryInfo::write
void write() const
Write the boundary dictionary.
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729