initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / sets / faceSources / cellToFace / cellToFace.C
blobecef589ef2a7b260436b683901d510ca269f92aa
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "cellToFace.H"
30 #include "polyMesh.H"
31 #include "cellSet.H"
32 #include "Time.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
40 defineTypeNameAndDebug(cellToFace, 0);
42 addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
44 addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
49 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
51     cellToFace::typeName,
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"
57 template<>
58 const char* Foam::NamedEnum<Foam::cellToFace::cellAction, 2>::names[] =
60     "all",
61     "both"
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
72     // Load the set
73     if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
74     {
75         SeriousError<< "Cannot load set "
76             << setName_ << endl;
77     }
78     
79     cellSet loadedSet(mesh_, setName_);
81     if (option_ == ALL)
82     {
83         // Add all faces from cell
84         for
85         (
86             cellSet::const_iterator iter = loadedSet.begin();
87             iter != loadedSet.end();
88             ++iter
89         )
90         {
91             label cellI = iter.key();
93             const labelList& cFaces = mesh_.cells()[cellI];
95             forAll(cFaces, cFaceI)
96             {
97                 addOrDelete(set, cFaces[cFaceI], add);
98             }
99         }
100     }
101     else if (option_ == BOTH)
102     {
103         // Add all faces whose both neighbours are in set.
105         // Count number of cells using face.
106         Map<label> numCells(loadedSet.size());
108         for
109         (
110             cellSet::const_iterator iter = loadedSet.begin();
111             iter != loadedSet.end();
112             ++iter
113         )
114         {
115             label cellI = iter.key();
117             const labelList& cFaces = mesh_.cells()[cellI];
119             forAll(cFaces, cFaceI)
120             {
121                 label faceI = cFaces[cFaceI];
123                 Map<label>::iterator fndFace = numCells.find(faceI);
125                 if (fndFace == numCells.end())
126                 {
127                     numCells.insert(faceI, 1);
128                 }
129                 else
130                 {
131                     fndFace()++;
132                 }
133             }
134         }
136         // Include faces that are referenced twice
137         for
138         (
139             Map<label>::const_iterator iter = numCells.begin();
140             iter != numCells.end();
141             ++iter
142         )
143         {
144             if (iter() == 2)
145             {
146                 addOrDelete(set, iter.key(), add);
147             }
148         }
149     }
153 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
155 // Construct from componenta
156 Foam::cellToFace::cellToFace
158     const polyMesh& mesh,
159     const word& setName,
160     const cellAction option
163     topoSetSource(mesh),
164     setName_(setName),
165     option_(option)
169 // Construct from dictionary
170 Foam::cellToFace::cellToFace
172     const polyMesh& mesh,
173     const dictionary& dict          
176     topoSetSource(mesh),
177     setName_(dict.lookup("set")),
178     option_(cellActionNames_.read(dict.lookup("option")))
182 // Construct from Istream
183 Foam::cellToFace::cellToFace
185     const polyMesh& mesh,
186     Istream& is
189     topoSetSource(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,
206     topoSet& set
207 ) const
209     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
210     {
211         Pout<< "    Adding faces according to cellSet " << setName_
212             << " ..." << endl;
214         combine(set, true);
215     }
216     else if (action == topoSetSource::DELETE)
217     {
218         Pout<< "    Removing faces according to cellSet " << setName_
219             << " ..." << endl;
221         combine(set, false);
222     }
226 // ************************************************************************* //