1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "faceToCell.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(faceToCell, 0);
40 addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
42 addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
47 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
50 "\n Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
51 " Select cells that are the owner|neighbour|any"
52 " of the faces in the faceSet or where all faces are in the faceSet\n\n"
56 const char* Foam::NamedEnum<Foam::faceToCell::faceAction, 4>::names[] =
64 const Foam::NamedEnum<Foam::faceToCell::faceAction, 4>
65 Foam::faceToCell::faceActionNames_;
68 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70 void Foam::faceToCell::combine(topoSet& set, const bool add) const
73 faceSet loadedSet(mesh_, setName_);
76 // Handle owner/neighbour/any selection
79 faceSet::const_iterator iter = loadedSet.begin();
80 iter != loadedSet.end();
84 label faceI = iter.key();
86 if ((option_ == OWNER) || (option_ == ANY))
88 label cellI = mesh_.faceOwner()[faceI];
90 addOrDelete(set, cellI, add);
93 if (mesh_.isInternalFace(faceI))
95 if ((option_ == NEIGHBOUR) || (option_ == ANY))
97 label cellI = mesh_.faceNeighbour()[faceI];
99 addOrDelete(set, cellI, add);
104 // Handle all selection.
107 // Count number of selected faces per cell.
109 Map<label> facesPerCell(loadedSet.size());
113 faceSet::const_iterator iter = loadedSet.begin();
114 iter != loadedSet.end();
118 label faceI = iter.key();
120 label own = mesh_.faceOwner()[faceI];
122 Map<label>::iterator fndOwn = facesPerCell.find(own);
124 if (fndOwn == facesPerCell.end())
126 facesPerCell.insert(own, 1);
133 if (mesh_.isInternalFace(faceI))
135 label nei = mesh_.faceNeighbour()[faceI];
137 Map<label>::iterator fndNei = facesPerCell.find(nei);
139 if (fndNei == facesPerCell.end())
141 facesPerCell.insert(nei, 1);
150 // Include cells that are referenced as many times as they have faces
151 // -> all faces in set.
154 Map<label>::const_iterator iter = facesPerCell.begin();
155 iter != facesPerCell.end();
159 label cellI = iter.key();
161 if (iter() == mesh_.cells()[cellI].size())
163 addOrDelete(set, cellI, add);
170 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
172 // Construct from components
173 Foam::faceToCell::faceToCell
175 const polyMesh& mesh,
177 const faceAction option
186 // Construct from dictionary
187 Foam::faceToCell::faceToCell
189 const polyMesh& mesh,
190 const dictionary& dict
194 setName_(dict.lookup("set")),
195 option_(faceActionNames_.read(dict.lookup("option")))
199 // Construct from Istream
200 Foam::faceToCell::faceToCell
202 const polyMesh& mesh,
207 setName_(checkIs(is)),
208 option_(faceActionNames_.read(checkIs(is)))
212 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
214 Foam::faceToCell::~faceToCell()
218 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
220 void Foam::faceToCell::applyToSet
222 const topoSetSource::setAction action,
226 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
228 Info<< " Adding cells according to faceSet " << setName_
233 else if (action == topoSetSource::DELETE)
235 Info<< " Removing cells according to faceSet " << setName_
243 // ************************************************************************* //