Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / meshTools / sets / cellSources / faceToCell / faceToCell.C
blob0c9f0ce300f1020b267f80d4310e7eef71e6e156
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 "faceToCell.H"
28 #include "polyMesh.H"
29 #include "faceSet.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
38 defineTypeNameAndDebug(faceToCell, 0);
40 addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
42 addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
47 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
49     faceToCell::typeName,
50     "\n    Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
51     "    Select cells that are the owner|neighbour|any"
52     " of the faces in the faceSet or where all faces are in the faceSet\n\n"
55 template<>
56 const char* Foam::NamedEnum<Foam::faceToCell::faceAction, 4>::names[] =
58     "neighbour",
59     "owner",
60     "any",
61     "all"
64 const Foam::NamedEnum<Foam::faceToCell::faceAction, 4>
65     Foam::faceToCell::faceActionNames_;
68 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
70 void Foam::faceToCell::combine(topoSet& set, const bool add) const
72     // Load the set
73     faceSet loadedSet(mesh_, setName_);
76     // Handle owner/neighbour/any selection
77     for
78     (
79         faceSet::const_iterator iter = loadedSet.begin();
80         iter != loadedSet.end();
81         ++iter
82     )
83     {
84         label faceI = iter.key();
86         if ((option_ == OWNER) || (option_ == ANY))
87         {
88             label cellI = mesh_.faceOwner()[faceI];
90             addOrDelete(set, cellI, add);
91         }
93         if (mesh_.isInternalFace(faceI))
94         {
95             if ((option_ == NEIGHBOUR) || (option_ == ANY))
96             {
97                 label cellI = mesh_.faceNeighbour()[faceI];
99                 addOrDelete(set, cellI, add);
100             }
101         }
102     }
104     // Handle all selection.
105     if (option_ == ALL)
106     {
107         // Count number of selected faces per cell.
109         Map<label> facesPerCell(loadedSet.size());
111         for
112         (
113             faceSet::const_iterator iter = loadedSet.begin();
114             iter != loadedSet.end();
115             ++iter
116         )
117         {
118             label faceI = iter.key();
120             label own = mesh_.faceOwner()[faceI];
122             Map<label>::iterator fndOwn = facesPerCell.find(own);
124             if (fndOwn == facesPerCell.end())
125             {
126                 facesPerCell.insert(own, 1);
127             }
128             else
129             {
130                 fndOwn()++;
131             }
133             if (mesh_.isInternalFace(faceI))
134             {
135                 label nei = mesh_.faceNeighbour()[faceI];
137                 Map<label>::iterator fndNei = facesPerCell.find(nei);
139                 if (fndNei == facesPerCell.end())
140                 {
141                     facesPerCell.insert(nei, 1);
142                 }
143                 else
144                 {
145                     fndNei()++;
146                 }
147             }
148         }
150         // Include cells that are referenced as many times as they have faces
151         // -> all faces in set.
152         for
153         (
154             Map<label>::const_iterator iter = facesPerCell.begin();
155             iter != facesPerCell.end();
156             ++iter
157         )
158         {
159             label cellI = iter.key();
161             if (iter() == mesh_.cells()[cellI].size())
162             {
163                 addOrDelete(set, cellI, add);
164             }
165         }
166     }
170 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
172 // Construct from components
173 Foam::faceToCell::faceToCell
175     const polyMesh& mesh,
176     const word& setName,
177     const faceAction option
180     topoSetSource(mesh),
181     setName_(setName),
182     option_(option)
186 // Construct from dictionary
187 Foam::faceToCell::faceToCell
189     const polyMesh& mesh,
190     const dictionary& dict
193     topoSetSource(mesh),
194     setName_(dict.lookup("set")),
195     option_(faceActionNames_.read(dict.lookup("option")))
199 // Construct from Istream
200 Foam::faceToCell::faceToCell
202     const polyMesh& mesh,
203     Istream& is
206     topoSetSource(mesh),
207     setName_(checkIs(is)),
208     option_(faceActionNames_.read(checkIs(is)))
212 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
214 Foam::faceToCell::~faceToCell()
218 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
220 void Foam::faceToCell::applyToSet
222     const topoSetSource::setAction action,
223     topoSet& set
224 ) const
226     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
227     {
228         Info<< "    Adding cells according to faceSet " << setName_
229             << " ..." << endl;
231         combine(set, true);
232     }
233     else if (action == topoSetSource::DELETE)
234     {
235         Info<< "    Removing cells according to faceSet " << setName_
236             << " ..." << endl;
238         combine(set, false);
239     }
243 // ************************************************************************* //