Loading...
Searching...
No Matches
patchToFace.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "patchToFace.H"
30#include "polyMesh.H"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35namespace Foam
36{
43 (
46 word,
47 patch
48 );
50 (
53 istream,
54 patch
55 );
56}
57
58
59Foam::topoSetSource::addToUsageTable Foam::patchToFace::usage_
60(
61 patchToFace::typeName,
62 "\n Usage: patchToFace patch\n\n"
63 " Select all faces in the patch. Note:accepts wildcards for patch.\n\n"
64);
65
66
67// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68
69void Foam::patchToFace::combine(topoSet& set, const bool add) const
70{
72 (
73 selectedPatches_,
74 true, // warn if not found
75 true // use patch groups if available
76 );
77
78 for (const label patchi : patchIDs)
79 {
80 const polyPatch& pp = mesh_.boundaryMesh()[patchi];
81
82 if (verbose_)
83 {
84 Info<< " Found matching patch " << pp.name() << " with "
85 << returnReduce(pp.size(), sumOp<label>()) << " faces" << endl;
86 }
87
88 for (const label facei : pp.range())
89 {
90 addOrDelete(set, facei, add);
91 }
92 }
93
94 if (patchIDs.empty())
95 {
97 << "Cannot find any patches matching "
98 << flatOutput(selectedPatches_) << nl
99 << "Valid names: " << flatOutput(mesh_.boundaryMesh().names())
101 }
102}
103
104
105// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106
108(
109 const polyMesh& mesh,
110 const wordRe& patchName
112:
114 selectedPatches_(one{}, patchName)
115{}
116
117
119(
120 const polyMesh& mesh,
121 const dictionary& dict
122)
123:
125 selectedPatches_()
126{
127 // Look for 'patches' and 'patch', but accept 'name' as well
128 if (!dict.readIfPresent("patches", selectedPatches_))
129 {
130 selectedPatches_.resize(1);
131 selectedPatches_.front() =
132 dict.getCompat<wordRe>("patch", {{"name", 1806}});
133 }
134}
135
136
138(
139 const polyMesh& mesh,
140 Istream& is
141)
142:
144 selectedPatches_(one{}, wordRe(checkIs(is)))
145{}
146
147
148// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149
151(
152 const topoSetSource::setAction action,
153 topoSet& set
154) const
155{
156 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
157 {
158 if (verbose_)
159 {
160 Info<< " Adding all faces of patches: "
161 << flatOutput(selectedPatches_) << " ..." << endl;
162 }
163
164 combine(set, true);
165 }
166 else if (action == topoSetSource::SUBTRACT)
167 {
168 if (verbose_)
169 {
170 Info<< " Removing all faces of patches: "
171 << flatOutput(selectedPatches_) << " ..." << endl;
172 }
173
174 combine(set, false);
175 }
176}
177
178
179// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
labelList patchIDs
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition one.H:57
A topoSetFaceSource to select cells associated with given patch(es).
patchToFace(const polyMesh &mesh, const wordRe &patchName)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
labelHashSet patchSet(const UList< wordRe > &select, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition polyMesh.H:609
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
topoSetFaceSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
messageStream Info
Information stream (stdout output on master, null elsewhere).
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dict add("bounds", meshBb)
dictionary dict