fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / meshTools / sets / cellSources / nbrToCell / nbrToCell.C
blobd5ed81411c40d9bdb992155f4ff5cfa6e18f4d75
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 "nbrToCell.H"
28 #include "polyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
37 defineTypeNameAndDebug(nbrToCell, 0);
39 addToRunTimeSelectionTable(topoSetSource, nbrToCell, word);
41 addToRunTimeSelectionTable(topoSetSource, nbrToCell, istream);
46 Foam::topoSetSource::addToUsageTable Foam::nbrToCell::usage_
48     nbrToCell::typeName,
49     "\n    Usage: nbrToCell <nNeighbours>\n\n"
50     "    Select all cells with <= nNeighbours neighbouring cells\n\n"
54 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
56 void Foam::nbrToCell::combine(topoSet& set, const bool add) const
58     const cellList& cells = mesh().cells();
59     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
61     boolList isCoupled(mesh_.nFaces()-mesh_.nInternalFaces(), false);
63     forAll(patches, patchI)
64     {
65         const polyPatch& pp = patches[patchI];
67         if (pp.coupled())
68         {
69             label faceI = pp.start();
70             forAll(pp, i)
71             {
72                 isCoupled[faceI-mesh_.nInternalFaces()] = true;
73                 faceI++;
74             }
75         }
76     }
78     forAll(cells, cellI)
79     {
80         const cell& cFaces = cells[cellI];
82         label nNbrCells = 0;
84         forAll(cFaces, i)
85         {
86             label faceI = cFaces[i];
88             if (mesh_.isInternalFace(faceI))
89             {
90                 nNbrCells++;
91             }
92             else if (isCoupled[faceI-mesh_.nInternalFaces()])
93             {
94                 nNbrCells++;
95             }
96         }
98         if (nNbrCells <= minNbrs_)
99         {
100             addOrDelete(set, cellI, add);
101         }
102     }
106 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
108 // Construct from components
109 Foam::nbrToCell::nbrToCell
111     const polyMesh& mesh,
112     const label minNbrs
115     topoSetSource(mesh),
116     minNbrs_(minNbrs)
120 // Construct from dictionary
121 Foam::nbrToCell::nbrToCell
123     const polyMesh& mesh,
124     const dictionary& dict
127     topoSetSource(mesh),
128     minNbrs_(readLabel(dict.lookup("neighbours")))
132 // Construct from Istream
133 Foam::nbrToCell::nbrToCell
135     const polyMesh& mesh,
136     Istream& is
139     topoSetSource(mesh),
140     minNbrs_(readLabel(checkIs(is)))
144 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
146 Foam::nbrToCell::~nbrToCell()
150 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
152 void Foam::nbrToCell::applyToSet
154     const topoSetSource::setAction action,
155     topoSet& set
156 ) const
158     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
159     {
160         Info<< "    Adding cells with only " << minNbrs_ << " or less"
161                 " neighbouring cells" << " ..." << endl;
163         combine(set, true);
164     }
165     else if (action == topoSetSource::DELETE)
166     {
167         Info<< "    Removing cells with only " << minNbrs_ << " or less"
168                 " neighbouring cells" << " ..." << endl;
170         combine(set, false);
171     }
175 // ************************************************************************* //