faceZoneToCell.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-2025 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 "faceZoneToCell.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
36 }
37 
40 {
41  "master",
42  "slave"
43 };
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
49 {
50  bool hasMatched = false;
51 
52  forAll(mesh_.faceZones(), i)
53  {
54  const faceZone& zone = mesh_.faceZones()[i];
55 
56  if (zoneName_.match(zone.name()))
57  {
58  const labelList& cellLabels =
59  (
60  option_ == MASTER
61  ? zone.masterCells()
62  : zone.slaveCells()
63  );
64 
65  Info<< " Found matching zone " << zone.name()
66  << " with " << returnReduce(cellLabels.size(), sumOp<label>())
67  << " cells on selected side." << endl;
68 
69  hasMatched = true;
70 
71  forAll(cellLabels, i)
72  {
73  // Only do active cells
74  if (cellLabels[i] >= 0 && cellLabels[i] < mesh_.nCells())
75  {
76  addOrDelete(set, cellLabels[i], add);
77  }
78  }
79  }
80  }
81 
82  if (!hasMatched)
83  {
85  << "Cannot find any faceZone named " << zoneName_ << endl
86  << "Valid names are " << mesh_.faceZones().toc() << endl;
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
94 (
95  const polyMesh& mesh,
96  const word& zoneName,
97  const faceAction option
98 )
99 :
101  zoneName_(zoneName),
102  option_(option)
103 {}
104 
105 
107 (
108  const polyMesh& mesh,
109  const dictionary& dict
110 )
111 :
113  zoneName_(dict.lookupBackwardsCompatible({"zone", "name"})),
114  option_(faceActionNames_.read(dict.lookup("option")))
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
119 
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 (
128  const topoSetSource::setAction action,
129  topoSet& set
130 ) const
131 {
132  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
133  {
134  Info<< " Adding all " << faceActionNames_[option_]
135  << " cells of faceZone " << zoneName_ << " ..." << endl;
136 
137  combine(set, true);
138  }
139  else if (action == topoSetSource::DELETE)
140  {
141  Info<< " Removing all " << faceActionNames_[option_]
142  << " cells of faceZone " << zoneName_ << " ..." << endl;
143 
144  combine(set, false);
145  }
146 }
147 
148 
149 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
wordList toc() const
Return the table of contents.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
A topoSetSource to select cells based on side of faceZone.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual ~faceZoneToCell()
Destructor.
faceZoneToCell(const polyMesh &mesh, const word &zoneName, const faceAction option)
Construct from components.
static const NamedEnum< faceAction, 2 > faceActionNames_
Names of the valid options.
faceAction
Enumeration defining the valid options.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const faceZoneList & faceZones() const
Return face zones.
Definition: polyMesh.H:443
label nCells() 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:87
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:61
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
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
defineTypeNameAndDebug(combustionModel, 0)
void add(LagrangianPatchField< typename typeOfSum< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
dictionary dict