1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 "cellToFace.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(cellToFace, 0);
42 addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
44 addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
49 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
52 "\n Usage: cellToFace <cellSet> all|both\n\n"
53 " Select -all : all faces of cells in the cellSet\n"
54 " -both: faces where both neighbours are in the cellSet\n\n"
58 const char* Foam::NamedEnum<Foam::cellToFace::cellAction, 2>::names[] =
64 const Foam::NamedEnum<Foam::cellToFace::cellAction, 2>
65 Foam::cellToFace::cellActionNames_;
68 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70 void Foam::cellToFace::combine(topoSet& set, const bool add) const
73 if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
75 SeriousError<< "Cannot load set "
79 cellSet loadedSet(mesh_, setName_);
83 // Add all faces from cell
86 cellSet::const_iterator iter = loadedSet.begin();
87 iter != loadedSet.end();
91 label cellI = iter.key();
93 const labelList& cFaces = mesh_.cells()[cellI];
95 forAll(cFaces, cFaceI)
97 addOrDelete(set, cFaces[cFaceI], add);
101 else if (option_ == BOTH)
103 // Add all faces whose both neighbours are in set.
105 // Count number of cells using face.
106 Map<label> numCells(loadedSet.size());
110 cellSet::const_iterator iter = loadedSet.begin();
111 iter != loadedSet.end();
115 label cellI = iter.key();
117 const labelList& cFaces = mesh_.cells()[cellI];
119 forAll(cFaces, cFaceI)
121 label faceI = cFaces[cFaceI];
123 Map<label>::iterator fndFace = numCells.find(faceI);
125 if (fndFace == numCells.end())
127 numCells.insert(faceI, 1);
136 // Include faces that are referenced twice
139 Map<label>::const_iterator iter = numCells.begin();
140 iter != numCells.end();
146 addOrDelete(set, iter.key(), add);
153 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
155 // Construct from componenta
156 Foam::cellToFace::cellToFace
158 const polyMesh& mesh,
160 const cellAction option
169 // Construct from dictionary
170 Foam::cellToFace::cellToFace
172 const polyMesh& mesh,
173 const dictionary& dict
177 setName_(dict.lookup("set")),
178 option_(cellActionNames_.read(dict.lookup("option")))
182 // Construct from Istream
183 Foam::cellToFace::cellToFace
185 const polyMesh& mesh,
190 setName_(checkIs(is)),
191 option_(cellActionNames_.read(checkIs(is)))
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
197 Foam::cellToFace::~cellToFace()
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
203 void Foam::cellToFace::applyToSet
205 const topoSetSource::setAction action,
209 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
211 Pout<< " Adding faces according to cellSet " << setName_
216 else if (action == topoSetSource::DELETE)
218 Pout<< " Removing faces according to cellSet " << setName_
226 // ************************************************************************* //