FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/polyMesh.H>
28 #include <meshTools/faceSet.H>
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 defineTypeNameAndDebug(faceToCell, 0);
38 
39 addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
40 
41 addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
42 
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
47 (
48  faceToCell::typeName,
49  "\n Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
50  " Select cells that are the owner|neighbour|any"
51  " of the faces in the faceSet or where all faces are in the faceSet\n\n"
52 );
53 
54 template<>
56 {
57  "neighbour",
58  "owner",
59  "any",
60  "all"
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  for
77  (
78  faceSet::const_iterator iter = loadedSet.begin();
79  iter != loadedSet.end();
80  ++iter
81  )
82  {
83  label faceI = iter.key();
84 
85  if ((option_ == OWNER) || (option_ == ANY))
86  {
87  label cellI = mesh_.faceOwner()[faceI];
88 
89  addOrDelete(set, cellI, add);
90  }
91 
92  if (mesh_.isInternalFace(faceI))
93  {
94  if ((option_ == NEIGHBOUR) || (option_ == ANY))
95  {
96  label cellI = mesh_.faceNeighbour()[faceI];
97 
98  addOrDelete(set, cellI, add);
99  }
100  }
101  }
102 
103  // Handle all selection.
104  if (option_ == ALL)
105  {
106  // Count number of selected faces per cell.
107 
108  Map<label> facesPerCell(loadedSet.size());
109 
110  for
111  (
112  faceSet::const_iterator iter = loadedSet.begin();
113  iter != loadedSet.end();
114  ++iter
115  )
116  {
117  label faceI = iter.key();
118 
119  label own = mesh_.faceOwner()[faceI];
120 
121  Map<label>::iterator fndOwn = facesPerCell.find(own);
122 
123  if (fndOwn == facesPerCell.end())
124  {
125  facesPerCell.insert(own, 1);
126  }
127  else
128  {
129  fndOwn()++;
130  }
131 
132  if (mesh_.isInternalFace(faceI))
133  {
134  label nei = mesh_.faceNeighbour()[faceI];
135 
136  Map<label>::iterator fndNei = facesPerCell.find(nei);
137 
138  if (fndNei == facesPerCell.end())
139  {
140  facesPerCell.insert(nei, 1);
141  }
142  else
143  {
144  fndNei()++;
145  }
146  }
147  }
148 
149  // Include cells that are referenced as many times as they have faces
150  // -> all faces in set.
151  for
152  (
153  Map<label>::const_iterator iter = facesPerCell.begin();
154  iter != facesPerCell.end();
155  ++iter
156  )
157  {
158  label cellI = iter.key();
159 
160  if (iter() == mesh_.cells()[cellI].size())
161  {
162  addOrDelete(set, cellI, add);
163  }
164  }
165  }
166 }
167 
168 
169 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
170 
171 // Construct from components
173 (
174  const polyMesh& mesh,
175  const word& setName,
176  const faceAction option
177 )
178 :
179  topoSetSource(mesh),
180  setName_(setName),
181  option_(option)
182 {}
183 
184 
185 // Construct from dictionary
187 (
188  const polyMesh& mesh,
189  const dictionary& dict
190 )
191 :
192  topoSetSource(mesh),
193  setName_(dict.lookup("set")),
194  option_(faceActionNames_.read(dict.lookup("option")))
195 {}
196 
197 
198 // Construct from Istream
200 (
201  const polyMesh& mesh,
202  Istream& is
203 )
204 :
205  topoSetSource(mesh),
206  setName_(checkIs(is)),
207  option_(faceActionNames_.read(checkIs(is)))
208 {}
209 
210 
211 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
212 
214 {}
215 
216 
217 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
218 
220 (
221  const topoSetSource::setAction action,
222  topoSet& set
223 ) const
224 {
225  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
226  {
227  Info<< " Adding cells according to faceSet " << setName_
228  << " ..." << endl;
229 
230  combine(set, true);
231  }
232  else if (action == topoSetSource::DELETE)
233  {
234  Info<< " Removing cells according to faceSet " << setName_
235  << " ..." << endl;
236 
237  combine(set, false);
238  }
239 }
240 
241 
242 // ************************ vim: set sw=4 sts=4 et: ************************ //