initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / faceSources / cellToFace / cellToFace.C
blob59d3e2e9ebb95fdf5c7e8fc8c7c5d653fe1d8ad3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 \*---------------------------------------------------------------------------*/
27 #include "cellToFace.H"
28 #include "polyMesh.H"
29 #include "cellSet.H"
30 #include "Time.H"
31 #include "syncTools.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
39 defineTypeNameAndDebug(cellToFace, 0);
41 addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
43 addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
48 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
50     cellToFace::typeName,
51     "\n    Usage: cellToFace <cellSet> all|both\n\n"
52     "    Select -all : all faces of cells in the cellSet\n"
53     "           -both: faces where both neighbours are in the cellSet\n\n"
56 template<>
57 const char* Foam::NamedEnum<Foam::cellToFace::cellAction, 2>::names[] =
59     "all",
60     "both"
63 const Foam::NamedEnum<Foam::cellToFace::cellAction, 2>
64     Foam::cellToFace::cellActionNames_;
67 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
69 void Foam::cellToFace::combine(topoSet& set, const bool add) const
71     // Load the set
72     if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
73     {
74         SeriousError<< "Cannot load set "
75             << setName_ << endl;
76     }
77     
78     cellSet loadedSet(mesh_, setName_);
80     if (option_ == ALL)
81     {
82         // Add all faces from cell
83         for
84         (
85             cellSet::const_iterator iter = loadedSet.begin();
86             iter != loadedSet.end();
87             ++iter
88         )
89         {
90             label cellI = iter.key();
92             const labelList& cFaces = mesh_.cells()[cellI];
94             forAll(cFaces, cFaceI)
95             {
96                 addOrDelete(set, cFaces[cFaceI], add);
97             }
98         }
99     }
100     else if (option_ == BOTH)
101     {
102         // Add all faces whose both neighbours are in set.
104         label nInt = mesh_.nInternalFaces();
105         const labelList& own = mesh_.faceOwner();
106         const labelList& nei = mesh_.faceNeighbour();
107         const polyBoundaryMesh& patches = mesh_.boundaryMesh();
110         // Check all internal faces
111         for (label faceI = 0; faceI < nInt; faceI++)
112         {
113             if (loadedSet.found(own[faceI]) && loadedSet.found(nei[faceI]))
114             {
115                 addOrDelete(set, faceI, add);
116             }
117         }
120         // Get coupled cell status
121         boolList neiInSet(mesh_.nFaces()-nInt, false);
123         forAll(patches, patchI)
124         {
125             const polyPatch& pp = patches[patchI];
127             if (pp.coupled())
128             {
129                 label faceI = pp.start();
130                 forAll(pp, i)
131                 {
132                     neiInSet[faceI-nInt] = loadedSet.found(own[faceI]);
133                     faceI++;
134                 }
135             }
136         }
137         syncTools::swapBoundaryFaceList(mesh_, neiInSet, false);
140         // Check all boundary faces
141         forAll(patches, patchI)
142         {
143             const polyPatch& pp = patches[patchI];
145             if (pp.coupled())
146             {
147                 label faceI = pp.start();
148                 forAll(pp, i)
149                 {
150                     if (loadedSet.found(own[faceI]) && neiInSet[faceI-nInt])
151                     {
152                         addOrDelete(set, faceI, add);
153                     }
154                     faceI++;
155                 }
156             }
157         }
158     }
162 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
164 // Construct from componenta
165 Foam::cellToFace::cellToFace
167     const polyMesh& mesh,
168     const word& setName,
169     const cellAction option
172     topoSetSource(mesh),
173     setName_(setName),
174     option_(option)
178 // Construct from dictionary
179 Foam::cellToFace::cellToFace
181     const polyMesh& mesh,
182     const dictionary& dict          
185     topoSetSource(mesh),
186     setName_(dict.lookup("set")),
187     option_(cellActionNames_.read(dict.lookup("option")))
191 // Construct from Istream
192 Foam::cellToFace::cellToFace
194     const polyMesh& mesh,
195     Istream& is
198     topoSetSource(mesh),
199     setName_(checkIs(is)),
200     option_(cellActionNames_.read(checkIs(is)))
204 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
206 Foam::cellToFace::~cellToFace()
210 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
212 void Foam::cellToFace::applyToSet
214     const topoSetSource::setAction action,
215     topoSet& set
216 ) const
218     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
219     {
220         Pout<< "    Adding faces according to cellSet " << setName_
221             << " ..." << endl;
223         combine(set, true);
224     }
225     else if (action == topoSetSource::DELETE)
226     {
227         Pout<< "    Removing faces according to cellSet " << setName_
228             << " ..." << endl;
230         combine(set, false);
231     }
235 // ************************************************************************* //