Transferred copyright to the OpenFOAM Foundation
[OpenFOAM-2.0.x.git] / src / meshTools / sets / faceSources / pointToFace / pointToFace.C
blob81e13e4fc459d26bdd85ee0bd8c0edc00c48f114
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
27 #include "polyMesh.H"
28 #include "pointSet.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(pointToFace, 0);
37     addToRunTimeSelectionTable(topoSetSource, pointToFace, word);
38     addToRunTimeSelectionTable(topoSetSource, pointToFace, istream);
40     template<>
41     const char* Foam::NamedEnum
42     <
43         Foam::pointToFace::pointAction,
44         2
45     >::names[] =
46     {
47         "any",
48         "all"
49     };
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
70     // Load the set
71     pointSet loadedSet(mesh_, setName_);
73     if (option_ == ANY)
74     {
75         // Add faces with any point in loadedSet
76         forAllConstIter(pointSet, loadedSet, iter)
77         {
78             const label pointI = iter.key();
79             const labelList& pFaces = mesh_.pointFaces()[pointI];
81             forAll(pFaces, pFaceI)
82             {
83                 addOrDelete(set, pFaces[pFaceI], add);
84             }
85         }
86     }
87     else if (option_ == ALL)
88     {
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)
95         {
96             const label pointI = iter.key();
97             const labelList& pFaces = mesh_.pointFaces()[pointI];
99             forAll(pFaces, pFaceI)
100             {
101                 const label faceI = pFaces[pFaceI];
103                 Map<label>::iterator fndFace = numPoints.find(faceI);
105                 if (fndFace == numPoints.end())
106                 {
107                     numPoints.insert(faceI, 1);
108                 }
109                 else
110                 {
111                     fndFace()++;
112                 }
113             }
114         }
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)
120         {
121             const label faceI = iter.key();
123             if (iter() == mesh_.faces()[faceI].size())
124             {
125                 addOrDelete(set, faceI, add);
126             }
127         }
128     }
132 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
134 // Construct from components
135 Foam::pointToFace::pointToFace
137     const polyMesh& mesh,
138     const word& setName,
139     const pointAction option
142     topoSetSource(mesh),
143     setName_(setName),
144     option_(option)
148 // Construct from dictionary
149 Foam::pointToFace::pointToFace
151     const polyMesh& mesh,
152     const dictionary& dict
155     topoSetSource(mesh),
156     setName_(dict.lookup("set")),
157     option_(pointActionNames_.read(dict.lookup("option")))
161 // Construct from Istream
162 Foam::pointToFace::pointToFace
164     const polyMesh& mesh,
165     Istream& is
168     topoSetSource(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,
185     topoSet& set
186 ) const
188     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
189     {
190         Info<< "    Adding faces according to pointSet " << setName_
191             << " ..." << endl;
193         combine(set, true);
194     }
195     else if (action == topoSetSource::DELETE)
196     {
197         Info<< "    Removing faces according to pointSet " << setName_
198             << " ..." << endl;
200         combine(set, false);
201     }
205 // ************************************************************************* //