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-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 "faceZoneToCell.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(faceZoneToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
36 
37  template<>
38  const char* Foam::NamedEnum
39  <
41  2
42  >::names[] =
43  {
44  "master",
45  "slave"
46  };
47 }
48 
49 
51  Foam::faceZoneToCell::faceActionNames_;
52 
53 
54 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 
56 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
57 {
58  bool hasMatched = false;
59 
60  forAll(mesh_.faceZones(), i)
61  {
62  const faceZone& zone = mesh_.faceZones()[i];
63 
64  if (zoneName_.match(zone.name()))
65  {
66  const labelList& cellLabels =
67  (
68  option_ == MASTER
69  ? zone.masterCells()
70  : zone.slaveCells()
71  );
72 
73  Info<< " Found matching zone " << zone.name()
74  << " with " << returnReduce(cellLabels.size(), sumOp<label>())
75  << " cells on selected side." << endl;
76 
77  hasMatched = true;
78 
79  forAll(cellLabels, i)
80  {
81  // Only do active cells
82  if (cellLabels[i] >= 0 && cellLabels[i] < mesh_.nCells())
83  {
84  addOrDelete(set, cellLabels[i], add);
85  }
86  }
87  }
88  }
89 
90  if (!hasMatched)
91  {
93  << "Cannot find any faceZone named " << zoneName_ << endl
94  << "Valid names are " << mesh_.faceZones().names() << endl;
95  }
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
102 (
103  const polyMesh& mesh,
104  const word& zoneName,
105  const faceAction option
106 )
107 :
108  topoSetSource(mesh),
109  zoneName_(zoneName),
110  option_(option)
111 {}
112 
113 
115 (
116  const polyMesh& mesh,
117  const dictionary& dict
118 )
119 :
120  topoSetSource(mesh),
121  zoneName_(dict.lookupBackwardsCompatible({"zone", "name"})),
122  option_(faceActionNames_.read(dict.lookup("option")))
123 {}
124 
125 
126 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
127 
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
135 (
136  const topoSetSource::setAction action,
137  topoSet& set
138 ) const
139 {
140  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
141  {
142  Info<< " Adding all " << faceActionNames_[option_]
143  << " cells of faceZone " << zoneName_ << " ..." << endl;
144 
145  combine(set, true);
146  }
147  else if (action == topoSetSource::DELETE)
148  {
149  Info<< " Removing all " << faceActionNames_[option_]
150  << " cells of faceZone " << zoneName_ << " ..." << endl;
151 
152  combine(set, false);
153  }
154 }
155 
156 
157 // ************************************************************************* //
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const labelList & masterCells() const
Return labels of master cells (cells next to the master face.
Definition: faceZone.C:324
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
virtual ~faceZoneToCell()
Destructor.
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
faceAction
Enumeration defining the valid options.
Base class for zones.
Definition: zone.H:57
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
const word & name() const
Return name.
Definition: zone.H:147
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
const labelList & slaveCells() const
Return labels of slave cells.
Definition: faceZone.C:335
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
faceZoneToCell(const polyMesh &mesh, const word &zoneName, const faceAction option)
Construct from components.
#define WarningInFunction
Report a warning using Foam::Warning.
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:76
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
ITstream & lookupBackwardsCompatible(const wordList &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream, trying a list of keywords.
Definition: dictionary.C:875
Namespace for OpenFOAM.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:77
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864