1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "faceToCell.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(faceToCell, 0);
37 addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
38 addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
41 const char* Foam::NamedEnum
43 Foam::faceToCell::faceAction,
55 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
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"
63 const Foam::NamedEnum<Foam::faceToCell::faceAction, 4>
64 Foam::faceToCell::faceActionNames_;
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
69 void Foam::faceToCell::combine(topoSet& set, const bool add) const
72 faceSet loadedSet(mesh_, setName_);
75 // Handle owner/neighbour/any selection
76 forAllConstIter(faceSet, loadedSet, iter)
78 const label faceI = iter.key();
80 if ((option_ == OWNER) || (option_ == ANY))
82 const label cellI = mesh_.faceOwner()[faceI];
84 addOrDelete(set, cellI, add);
87 if (mesh_.isInternalFace(faceI))
89 if ((option_ == NEIGHBOUR) || (option_ == ANY))
91 const label cellI = mesh_.faceNeighbour()[faceI];
93 addOrDelete(set, cellI, add);
98 // Handle all selection.
101 // Count number of selected faces per cell.
103 Map<label> facesPerCell(loadedSet.size());
105 forAllConstIter(faceSet, loadedSet, iter)
107 const label faceI = iter.key();
108 const label own = mesh_.faceOwner()[faceI];
110 Map<label>::iterator fndOwn = facesPerCell.find(own);
112 if (fndOwn == facesPerCell.end())
114 facesPerCell.insert(own, 1);
121 if (mesh_.isInternalFace(faceI))
123 label nei = mesh_.faceNeighbour()[faceI];
125 Map<label>::iterator fndNei = facesPerCell.find(nei);
127 if (fndNei == facesPerCell.end())
129 facesPerCell.insert(nei, 1);
138 // Include cells that are referenced as many times as they have faces
139 // -> all faces in set.
140 forAllConstIter(Map<label>, facesPerCell, iter)
142 const label cellI = iter.key();
144 if (iter() == mesh_.cells()[cellI].size())
146 addOrDelete(set, cellI, add);
153 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
155 // Construct from components
156 Foam::faceToCell::faceToCell
158 const polyMesh& mesh,
160 const faceAction option
169 // Construct from dictionary
170 Foam::faceToCell::faceToCell
172 const polyMesh& mesh,
173 const dictionary& dict
177 setName_(dict.lookup("set")),
178 option_(faceActionNames_.read(dict.lookup("option")))
182 // Construct from Istream
183 Foam::faceToCell::faceToCell
185 const polyMesh& mesh,
190 setName_(checkIs(is)),
191 option_(faceActionNames_.read(checkIs(is)))
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
197 Foam::faceToCell::~faceToCell()
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
203 void Foam::faceToCell::applyToSet
205 const topoSetSource::setAction action,
209 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
211 Info<< " Adding cells according to faceSet " << setName_
216 else if (action == topoSetSource::DELETE)
218 Info<< " Removing cells according to faceSet " << setName_
226 // ************************************************************************* //