zoneToFace.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 "zoneToFace.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::zoneToFace::combine(topoSet& set, const bool add) const
42 {
43  bool hasMatched = false;
44 
45  forAll(mesh_.faceZones(), i)
46  {
47  const faceZone& zone = mesh_.faceZones()[i];
48 
49  if (zoneName_.match(zone.name()))
50  {
51  const labelList& faceLabels = mesh_.faceZones()[i];
52 
53  Info<< " Found matching zone " << zone.name()
54  << " with " << returnReduce(faceLabels.size(), sumOp<label>())
55  << " faces." << endl;
56 
57  hasMatched = true;
58 
59  forAll(faceLabels, i)
60  {
61  // Only do active faces
62  if (faceLabels[i] < mesh_.nFaces())
63  {
64  addOrDelete(set, faceLabels[i], add);
65  }
66  }
67  }
68  }
69 
70  if (!hasMatched)
71  {
73  << "Cannot find any faceZone named " << zoneName_ << endl
74  << "Valid names are " << mesh_.faceZones().names() << endl;
75  }
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80 
82 (
83  const polyMesh& mesh,
84  const word& zoneName
85 )
86 :
87  topoSetSource(mesh),
88  zoneName_(zoneName)
89 {}
90 
91 
93 (
94  const polyMesh& mesh,
95  const dictionary& dict
96 )
97 :
98  topoSetSource(mesh),
99  zoneName_
100  (
101  dict.dictName() == "sourceInfo"
102  ? dict.lookupBackwardsCompatible({"zone", "name"})
103  : dict.lookup("zone")
104  )
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
109 
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 (
118  const topoSetSource::setAction action,
119  topoSet& set
120 ) const
121 {
122  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
123  {
124  Info<< " Adding all faces of faceZone " << zoneName_ << " ..."
125  << endl;
126 
127  combine(set, true);
128  }
129  else if (action == topoSetSource::DELETE)
130  {
131  Info<< " Removing all faces of faceZone " << zoneName_ << " ..."
132  << endl;
133 
134  combine(set, false);
135  }
136 }
137 
138 
139 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
wordList names() const
Return a list of zone names.
Definition: MeshZones.C:256
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
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const meshFaceZones & faceZones() const
Return face zones.
Definition: polyMesh.H:445
label nFaces() const
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
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
A class for handling words, derived from string.
Definition: word.H:62
A topoSetSource to select faces based on faceZone.
Definition: zoneToFace.H:52
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: zoneToFace.C:117
zoneToFace(const polyMesh &mesh, const word &zoneName)
Construct from components.
Definition: zoneToFace.C:82
virtual ~zoneToFace()
Destructor.
Definition: zoneToFace.C:110
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict