faceToCell.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 | Copyright (C) 2011-2016 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"
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(faceToCell, 0);
37  addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
38  addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
39 
40  template<>
41  const char* Foam::NamedEnum
42  <
44  4
45  >::names[] =
46  {
47  "neighbour",
48  "owner",
49  "any",
50  "all"
51  };
52 }
53 
54 
55 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
56 (
57  faceToCell::typeName,
58  "\n Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
59  " Select cells that are the owner|neighbour|any"
60  " of the faces in the faceSet or where all faces are in the faceSet\n\n"
61 );
62 
64  Foam::faceToCell::faceActionNames_;
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::faceToCell::combine(topoSet& set, const bool add) const
70 {
71  // Load the set
72  faceSet loadedSet(mesh_, setName_);
73 
74 
75  // Handle owner/neighbour/any selection
76  forAllConstIter(faceSet, loadedSet, iter)
77  {
78  const label facei = iter.key();
79 
80  if ((option_ == OWNER) || (option_ == ANY))
81  {
82  const label celli = mesh_.faceOwner()[facei];
83 
84  addOrDelete(set, celli, add);
85  }
86 
87  if (mesh_.isInternalFace(facei))
88  {
89  if ((option_ == NEIGHBOUR) || (option_ == ANY))
90  {
91  const label celli = mesh_.faceNeighbour()[facei];
92 
93  addOrDelete(set, celli, add);
94  }
95  }
96  }
97 
98  // Handle all selection.
99  if (option_ == ALL)
100  {
101  // Count number of selected faces per cell.
102 
103  Map<label> facesPerCell(loadedSet.size());
104 
105  forAllConstIter(faceSet, loadedSet, iter)
106  {
107  const label facei = iter.key();
108  const label own = mesh_.faceOwner()[facei];
109 
110  Map<label>::iterator fndOwn = facesPerCell.find(own);
111 
112  if (fndOwn == facesPerCell.end())
113  {
114  facesPerCell.insert(own, 1);
115  }
116  else
117  {
118  fndOwn()++;
119  }
120 
121  if (mesh_.isInternalFace(facei))
122  {
123  label nei = mesh_.faceNeighbour()[facei];
124 
125  Map<label>::iterator fndNei = facesPerCell.find(nei);
126 
127  if (fndNei == facesPerCell.end())
128  {
129  facesPerCell.insert(nei, 1);
130  }
131  else
132  {
133  fndNei()++;
134  }
135  }
136  }
137 
138  // Include cells that are referenced as many times as they have faces
139  // -> all faces in set.
140  forAllConstIter(Map<label>, facesPerCell, iter)
141  {
142  const label celli = iter.key();
143 
144  if (iter() == mesh_.cells()[celli].size())
145  {
146  addOrDelete(set, celli, add);
147  }
148  }
149  }
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
154 
155 // Construct from components
157 (
158  const polyMesh& mesh,
159  const word& setName,
160  const faceAction option
161 )
162 :
163  topoSetSource(mesh),
164  setName_(setName),
165  option_(option)
166 {}
167 
168 
169 // Construct from dictionary
171 (
172  const polyMesh& mesh,
173  const dictionary& dict
174 )
175 :
176  topoSetSource(mesh),
177  setName_(dict.lookup("set")),
178  option_(faceActionNames_.read(dict.lookup("option")))
179 {}
180 
181 
182 // Construct from Istream
184 (
185  const polyMesh& mesh,
186  Istream& is
187 )
188 :
189  topoSetSource(mesh),
190  setName_(checkIs(is)),
191  option_(faceActionNames_.read(checkIs(is)))
192 {}
193 
194 
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
196 
198 {}
199 
200 
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
202 
204 (
205  const topoSetSource::setAction action,
206  topoSet& set
207 ) const
208 {
209  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
210  {
211  Info<< " Adding cells according to faceSet " << setName_
212  << " ..." << endl;
213 
214  combine(set, true);
215  }
216  else if (action == topoSetSource::DELETE)
217  {
218  Info<< " Removing cells according to faceSet " << setName_
219  << " ..." << endl;
220 
221  combine(set, false);
222  }
223 }
224 
225 
226 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of face labels.
Definition: faceSet.H:48
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:110
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
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:204
A class for handling words, derived from string.
Definition: word.H:59
virtual ~faceToCell()
Destructor.
Definition: faceToCell.C:197
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
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:157
Class with constructor to add usage string to table.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
faceAction
Enumeration defining the valid options.
Definition: faceToCell.H:55
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576