patchToFace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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 "patchToFace.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::patchToFace::combine(topoSet& set, const bool add) const
42 {
44  (
45  List<wordRe>(1, patchName_),
46  true, // warn if not found
47  true // use patch groups if available
48  );
49 
50  forAllConstIter(labelHashSet, patchIDs, iter)
51  {
52  label patchi = iter.key();
53 
54  const polyPatch& pp = mesh_.boundaryMesh()[patchi];
55 
56  Info<< " Found matching patch " << pp.name()
57  << " with " << returnReduce(pp.size(), sumOp<label>())
58  << " faces." << endl;
59 
60  for
61  (
62  label facei = pp.start();
63  facei < pp.start() + pp.size();
64  facei++
65  )
66  {
67  addOrDelete(set, facei, add);
68  }
69  }
70 
71  if (patchIDs.empty())
72  {
74  << "Cannot find any patch named " << patchName_ << endl
75  << "Valid names are " << mesh_.boundaryMesh().names() << endl;
76  }
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
83 (
84  const polyMesh& mesh,
85  const word& patchName
86 )
87 :
88  topoSetSource(mesh),
89  patchName_(patchName)
90 {}
91 
92 
94 (
95  const polyMesh& mesh,
96  const dictionary& dict
97 )
98 :
99  topoSetSource(mesh),
100  patchName_
101  (
102  dict.dictName() == "sourceInfo"
103  ? dict.lookupBackwardsCompatible({"patch", "name"})
104  : dict.lookup("patch")
105  )
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
110 
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
118 (
119  const topoSetSource::setAction action,
120  topoSet& set
121 ) const
122 {
123  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
124  {
125  Info<< " Adding all faces of patch " << patchName_ << " ..." << endl;
126 
127  combine(set, true);
128  }
129  else if (action == topoSetSource::DELETE)
130  {
131  Info<< " Removing all faces of patch " << patchName_ << " ..."
132  << endl;
133 
134  combine(set, false);
135  }
136 }
137 
138 
139 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Macros for easy insertion into run-time selection tables.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:860
A topoSetSource to select faces based on usage in patches.
Definition: patchToFace.H:52
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: patchToFace.C:118
virtual ~patchToFace()
Destructor.
Definition: patchToFace.C:111
patchToFace(const polyMesh &mesh, const word &patchName)
Construct from components.
Definition: patchToFace.C:83
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
wordList names() const
Return a list of patch names.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:403
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict