faceToCell.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 "faceToCell.H"
27 #include "polyMesh.H"
28 #include "faceSet.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(faceToCell, 0);
36  addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
37 
38  template<>
39  const char* Foam::NamedEnum
40  <
42  4
43  >::names[] =
44  {
45  "neighbour",
46  "owner",
47  "any",
48  "all"
49  };
50 }
51 
52 
54  Foam::faceToCell::faceActionNames_;
55 
56 
57 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58 
59 void Foam::faceToCell::combine(topoSet& set, const bool add) const
60 {
61  // Load the set
62  faceSet loadedSet(mesh_, setName_);
63 
64 
65  // Handle owner/neighbour/any selection
66  forAllConstIter(faceSet, loadedSet, iter)
67  {
68  const label facei = iter.key();
69 
70  if ((option_ == OWNER) || (option_ == ANY))
71  {
72  const label celli = mesh_.faceOwner()[facei];
73 
74  addOrDelete(set, celli, add);
75  }
76 
77  if (mesh_.isInternalFace(facei))
78  {
79  if ((option_ == NEIGHBOUR) || (option_ == ANY))
80  {
81  const label celli = mesh_.faceNeighbour()[facei];
82 
83  addOrDelete(set, celli, add);
84  }
85  }
86  }
87 
88  // Handle all selection.
89  if (option_ == ALL)
90  {
91  // Count number of selected faces per cell.
92 
93  Map<label> facesPerCell(loadedSet.size());
94 
95  forAllConstIter(faceSet, loadedSet, iter)
96  {
97  const label facei = iter.key();
98  const label own = mesh_.faceOwner()[facei];
99 
100  Map<label>::iterator fndOwn = facesPerCell.find(own);
101 
102  if (fndOwn == facesPerCell.end())
103  {
104  facesPerCell.insert(own, 1);
105  }
106  else
107  {
108  fndOwn()++;
109  }
110 
111  if (mesh_.isInternalFace(facei))
112  {
113  label nei = mesh_.faceNeighbour()[facei];
114 
115  Map<label>::iterator fndNei = facesPerCell.find(nei);
116 
117  if (fndNei == facesPerCell.end())
118  {
119  facesPerCell.insert(nei, 1);
120  }
121  else
122  {
123  fndNei()++;
124  }
125  }
126  }
127 
128  // Include cells that are referenced as many times as they have faces
129  // -> all faces in set.
130  forAllConstIter(Map<label>, facesPerCell, iter)
131  {
132  const label celli = iter.key();
133 
134  if (iter() == mesh_.cells()[celli].size())
135  {
136  addOrDelete(set, celli, add);
137  }
138  }
139  }
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
144 
146 (
147  const polyMesh& mesh,
148  const word& setName,
149  const faceAction option
150 )
151 :
152  topoSetSource(mesh),
153  setName_(setName),
154  option_(option)
155 {}
156 
157 
159 (
160  const polyMesh& mesh,
161  const dictionary& dict
162 )
163 :
164  topoSetSource(mesh),
165  setName_(dict.lookup("set")),
166  option_(faceActionNames_.read(dict.lookup("option")))
167 {}
168 
169 
170 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
171 
173 {}
174 
175 
176 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177 
179 (
180  const topoSetSource::setAction action,
181  topoSet& set
182 ) const
183 {
184  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
185  {
186  Info<< " Adding cells according to faceSet " << setName_
187  << " ..." << endl;
188 
189  combine(set, true);
190  }
191  else if (action == topoSetSource::DELETE)
192  {
193  Info<< " Removing cells according to faceSet " << setName_
194  << " ..." << endl;
195 
196  combine(set, false);
197  }
198 }
199 
200 
201 // ************************************************************************* //
A list of face labels.
Definition: faceSet.H:48
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: faceToCell.C:179
A class for handling words, derived from string.
Definition: word.H:59
virtual ~faceToCell()
Destructor.
Definition: faceToCell.C:172
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
faceToCell(const polyMesh &mesh, const word &setName, const faceAction option)
Construct from components.
Definition: faceToCell.C:146
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
faceAction
Enumeration defining the valid options.
Definition: faceToCell.H:55
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