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-2019 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 {
34  defineTypeNameAndDebug(patchToFace, 0);
35  addToRunTimeSelectionTable(topoSetSource, patchToFace, word);
36  addToRunTimeSelectionTable(topoSetSource, patchToFace, istream);
37 }
38 
39 
40 Foam::topoSetSource::addToUsageTable Foam::patchToFace::usage_
41 (
42  patchToFace::typeName,
43  "\n Usage: patchToFace patch\n\n"
44  " Select all faces in the patch. Note:accepts wildcards for patch.\n\n"
45 );
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::patchToFace::combine(topoSet& set, const bool add) const
51 {
52  labelHashSet patchIDs = mesh_.boundaryMesh().patchSet
53  (
54  List<wordRe>(1, patchName_),
55  true, // warn if not found
56  true // use patch groups if available
57  );
58 
59  forAllConstIter(labelHashSet, patchIDs, iter)
60  {
61  label patchi = iter.key();
62 
63  const polyPatch& pp = mesh_.boundaryMesh()[patchi];
64 
65  Info<< " Found matching patch " << pp.name()
66  << " with " << returnReduce(pp.size(), sumOp<label>())
67  << " faces." << endl;
68 
69  for
70  (
71  label facei = pp.start();
72  facei < pp.start() + pp.size();
73  facei++
74  )
75  {
76  addOrDelete(set, facei, add);
77  }
78  }
79 
80  if (patchIDs.empty())
81  {
83  << "Cannot find any patch named " << patchName_ << endl
84  << "Valid names are " << mesh_.boundaryMesh().names() << endl;
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 (
93  const polyMesh& mesh,
94  const word& patchName
95 )
96 :
97  topoSetSource(mesh),
98  patchName_(patchName)
99 {}
100 
101 
103 (
104  const polyMesh& mesh,
105  const dictionary& dict
106 )
107 :
108  topoSetSource(mesh),
109  patchName_(dict.lookup("name"))
110 {}
111 
112 
114 (
115  const polyMesh& mesh,
116  Istream& is
117 )
118 :
119  topoSetSource(mesh),
120  patchName_(checkIs(is))
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125 
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
133 (
134  const topoSetSource::setAction action,
135  topoSet& set
136 ) const
137 {
138  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
139  {
140  Info<< " Adding all faces of patch " << patchName_ << " ..." << endl;
141 
142  combine(set, true);
143  }
144  else if (action == topoSetSource::DELETE)
145  {
146  Info<< " Removing all faces of patch " << patchName_ << " ..."
147  << endl;
148 
149  combine(set, false);
150  }
151 }
152 
153 
154 // ************************************************************************* //
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: patchToFace.C:133
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211
virtual ~patchToFace()
Destructor.
Definition: patchToFace.C:126
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
patchToFace(const polyMesh &mesh, const word &patchName)
Construct from components.
Definition: patchToFace.C:92
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812