fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / meshTools / sets / faceSources / pointToFace / pointToFace.C
blob4e2e66cffd51e38fdb1b7e7d0818beb699d71231
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 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
19     for more details.
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
25 \*---------------------------------------------------------------------------*/
27 #include "pointToFace.H"
28 #include "polyMesh.H"
29 #include "pointSet.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
38 defineTypeNameAndDebug(pointToFace, 0);
40 addToRunTimeSelectionTable(topoSetSource, pointToFace, word);
42 addToRunTimeSelectionTable(topoSetSource, pointToFace, istream);
47 Foam::topoSetSource::addToUsageTable Foam::pointToFace::usage_
49     pointToFace::typeName,
50     "\n    Usage: pointToFace <pointSet> any|all\n\n"
51     "    Select faces with\n"
52     "    -any point in the pointSet\n"
53     "    -all points in the pointSet\n\n"
56 template<>
57 const char* Foam::NamedEnum<Foam::pointToFace::pointAction, 2>::names[] =
59     "any",
60     "all"
63 const Foam::NamedEnum<Foam::pointToFace::pointAction, 2>
64     Foam::pointToFace::pointActionNames_;
67 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
69 void Foam::pointToFace::combine(topoSet& set, const bool add) const
71     // Load the set
72     pointSet loadedSet(mesh_, setName_);
74     if (option_ == ANY)
75     {
76         // Add faces with any point in loadedSet
77         for
78         (
79             pointSet::const_iterator iter = loadedSet.begin();
80             iter != loadedSet.end();
81             ++iter
82         )
83         {
84             label pointI = iter.key();
86             const labelList& pFaces = mesh_.pointFaces()[pointI];
88             forAll(pFaces, pFaceI)
89             {
90                 addOrDelete(set, pFaces[pFaceI], add);
91             }
92         }
93     }
94     else if (option_ == ALL)
95     {
96         // Add all faces whose points are all in set.
98         // Count number of points using face.
99         Map<label> numPoints(loadedSet.size());
101         forAllConstIter(pointSet, loadedSet, iter)
102         {
103             label pointI = iter.key();
105             const labelList& pFaces = mesh_.pointFaces()[pointI];
107             forAll(pFaces, pFaceI)
108             {
109                 label faceI = pFaces[pFaceI];
111                 Map<label>::iterator fndFace = numPoints.find(faceI);
113                 if (fndFace == numPoints.end())
114                 {
115                     numPoints.insert(faceI, 1);
116                 }
117                 else
118                 {
119                     fndFace()++;
120                 }
121             }
122         }
125         // Include faces that are referenced as many times as there are points
126         // in face -> all points of face
127         for
128         (
129             Map<label>::const_iterator iter = numPoints.begin();
130             iter != numPoints.end();
131             ++iter
132         )
133         {
134             label faceI = iter.key();
136             if (iter() == mesh_.faces()[faceI].size())
137             {
138                 addOrDelete(set, faceI, add);
139             }
140         }
141     }
145 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
147 // Construct from components
148 Foam::pointToFace::pointToFace
150     const polyMesh& mesh,
151     const word& setName,
152     const pointAction option
155     topoSetSource(mesh),
156     setName_(setName),
157     option_(option)
161 // Construct from dictionary
162 Foam::pointToFace::pointToFace
164     const polyMesh& mesh,
165     const dictionary& dict
168     topoSetSource(mesh),
169     setName_(dict.lookup("set")),
170     option_(pointActionNames_.read(dict.lookup("option")))
174 // Construct from Istream
175 Foam::pointToFace::pointToFace
177     const polyMesh& mesh,
178     Istream& is
181     topoSetSource(mesh),
182     setName_(checkIs(is)),
183     option_(pointActionNames_.read(checkIs(is)))
187 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
189 Foam::pointToFace::~pointToFace()
193 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
195 void Foam::pointToFace::applyToSet
197     const topoSetSource::setAction action,
198     topoSet& set
199 ) const
201     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
202     {
203         Info<< "    Adding faces according to pointSet " << setName_
204             << " ..." << endl;
206         combine(set, true);
207     }
208     else if (action == topoSetSource::DELETE)
209     {
210         Info<< "    Removing faces according to pointSet " << setName_
211             << " ..." << endl;
213         combine(set, false);
214     }
218 // ************************************************************************* //