1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 "pointToFace.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(pointToFace, 0);
37 addToRunTimeSelectionTable(topoSetSource, pointToFace, word);
38 addToRunTimeSelectionTable(topoSetSource, pointToFace, istream);
41 const char* Foam::NamedEnum
43 Foam::pointToFace::pointAction,
53 Foam::topoSetSource::addToUsageTable Foam::pointToFace::usage_
55 pointToFace::typeName,
56 "\n Usage: pointToFace <pointSet> any|all\n\n"
57 " Select faces with\n"
58 " -any point in the pointSet\n"
59 " -all points in the pointSet\n\n"
62 const Foam::NamedEnum<Foam::pointToFace::pointAction, 2>
63 Foam::pointToFace::pointActionNames_;
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 void Foam::pointToFace::combine(topoSet& set, const bool add) const
71 pointSet loadedSet(mesh_, setName_);
75 // Add faces with any point in loadedSet
76 forAllConstIter(pointSet, loadedSet, iter)
78 const label pointI = iter.key();
79 const labelList& pFaces = mesh_.pointFaces()[pointI];
81 forAll(pFaces, pFaceI)
83 addOrDelete(set, pFaces[pFaceI], add);
87 else if (option_ == ALL)
89 // Add all faces whose points are all in set.
91 // Count number of points using face.
92 Map<label> numPoints(loadedSet.size());
94 forAllConstIter(pointSet, loadedSet, iter)
96 const label pointI = iter.key();
97 const labelList& pFaces = mesh_.pointFaces()[pointI];
99 forAll(pFaces, pFaceI)
101 const label faceI = pFaces[pFaceI];
103 Map<label>::iterator fndFace = numPoints.find(faceI);
105 if (fndFace == numPoints.end())
107 numPoints.insert(faceI, 1);
117 // Include faces that are referenced as many times as there are points
118 // in face -> all points of face
119 forAllConstIter(Map<label>, numPoints, iter)
121 const label faceI = iter.key();
123 if (iter() == mesh_.faces()[faceI].size())
125 addOrDelete(set, faceI, add);
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
134 // Construct from components
135 Foam::pointToFace::pointToFace
137 const polyMesh& mesh,
139 const pointAction option
148 // Construct from dictionary
149 Foam::pointToFace::pointToFace
151 const polyMesh& mesh,
152 const dictionary& dict
156 setName_(dict.lookup("set")),
157 option_(pointActionNames_.read(dict.lookup("option")))
161 // Construct from Istream
162 Foam::pointToFace::pointToFace
164 const polyMesh& mesh,
169 setName_(checkIs(is)),
170 option_(pointActionNames_.read(checkIs(is)))
174 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
176 Foam::pointToFace::~pointToFace()
180 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
182 void Foam::pointToFace::applyToSet
184 const topoSetSource::setAction action,
188 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
190 Info<< " Adding faces according to pointSet " << setName_
195 else if (action == topoSetSource::DELETE)
197 Info<< " Removing faces according to pointSet " << setName_
205 // ************************************************************************* //