1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 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
27 \*---------------------------------------------------------------------------*/
29 #include "faceToCell.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(faceToCell, 0);
42 addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
44 addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
49 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
52 "\n Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
53 " Select cells that are the owner|neighbour|any"
54 " of the faces in the faceSet or where all faces are in the faceSet\n\n"
58 const char* Foam::NamedEnum<Foam::faceToCell::faceAction, 4>::names[] =
66 const Foam::NamedEnum<Foam::faceToCell::faceAction, 4>
67 Foam::faceToCell::faceActionNames_;
70 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
72 void Foam::faceToCell::combine(topoSet& set, const bool add) const
75 faceSet loadedSet(mesh_, setName_);
78 // Handle owner/neighbour/any selection
81 faceSet::const_iterator iter = loadedSet.begin();
82 iter != loadedSet.end();
86 label faceI = iter.key();
88 if ((option_ == OWNER) || (option_ == ANY))
90 label cellI = mesh_.faceOwner()[faceI];
92 addOrDelete(set, cellI, add);
95 if (mesh_.isInternalFace(faceI))
97 if ((option_ == NEIGHBOUR) || (option_ == ANY))
99 label cellI = mesh_.faceNeighbour()[faceI];
101 addOrDelete(set, cellI, add);
106 // Handle all selection.
109 // Count number of selected faces per cell.
111 Map<label> facesPerCell(loadedSet.size());
115 faceSet::const_iterator iter = loadedSet.begin();
116 iter != loadedSet.end();
120 label faceI = iter.key();
122 label own = mesh_.faceOwner()[faceI];
124 Map<label>::iterator fndOwn = facesPerCell.find(own);
126 if (fndOwn == facesPerCell.end())
128 facesPerCell.insert(own, 1);
135 if (mesh_.isInternalFace(faceI))
137 label nei = mesh_.faceNeighbour()[faceI];
139 Map<label>::iterator fndNei = facesPerCell.find(nei);
141 if (fndNei == facesPerCell.end())
143 facesPerCell.insert(nei, 1);
152 // Include cells that are referenced as many times as they have faces
153 // -> all faces in set.
156 Map<label>::const_iterator iter = facesPerCell.begin();
157 iter != facesPerCell.end();
161 label cellI = iter.key();
163 if (iter() == mesh_.cells()[cellI].size())
165 addOrDelete(set, cellI, add);
172 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
174 // Construct from components
175 Foam::faceToCell::faceToCell
177 const polyMesh& mesh,
179 const faceAction option
188 // Construct from dictionary
189 Foam::faceToCell::faceToCell
191 const polyMesh& mesh,
192 const dictionary& dict
196 setName_(dict.lookup("set")),
197 option_(faceActionNames_.read(dict.lookup("option")))
201 // Construct from Istream
202 Foam::faceToCell::faceToCell
204 const polyMesh& mesh,
209 setName_(checkIs(is)),
210 option_(faceActionNames_.read(checkIs(is)))
214 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
216 Foam::faceToCell::~faceToCell()
220 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
222 void Foam::faceToCell::applyToSet
224 const topoSetSource::setAction action,
228 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
230 Info<< " Adding cells according to faceSet " << setName_
235 else if (action == topoSetSource::DELETE)
237 Info<< " Removing cells according to faceSet " << setName_
245 // ************************************************************************* //