OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

nbrToCell.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "nbrToCell.H"
00028 #include "polyMesh.H"
00029 
00030 #include "addToRunTimeSelectionTable.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 defineTypeNameAndDebug(nbrToCell, 0);
00038 
00039 addToRunTimeSelectionTable(topoSetSource, nbrToCell, word);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, nbrToCell, istream);
00042 
00043 }
00044 
00045 
00046 Foam::topoSetSource::addToUsageTable Foam::nbrToCell::usage_
00047 (
00048     nbrToCell::typeName,
00049     "\n    Usage: nbrToCell <nNeighbours>\n\n"
00050     "    Select all cells with <= nNeighbours neighbouring cells\n\n"
00051 );
00052 
00053 
00054 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00055 
00056 void Foam::nbrToCell::combine(topoSet& set, const bool add) const
00057 {
00058     const cellList& cells = mesh().cells();
00059     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00060 
00061     boolList isCoupled(mesh_.nFaces()-mesh_.nInternalFaces(), false);
00062 
00063     forAll(patches, patchI)
00064     {   
00065         const polyPatch& pp = patches[patchI];
00066 
00067         if (pp.coupled())
00068         {
00069             label faceI = pp.start();
00070             forAll(pp, i)
00071             {
00072                 isCoupled[faceI-mesh_.nInternalFaces()] = true;
00073                 faceI++;
00074             }
00075         }
00076     }
00077 
00078     forAll(cells, cellI)
00079     {
00080         const cell& cFaces = cells[cellI];
00081 
00082         label nNbrCells = 0;
00083 
00084         forAll(cFaces, i)
00085         {
00086             label faceI = cFaces[i];
00087 
00088             if (mesh_.isInternalFace(faceI))
00089             {
00090                 nNbrCells++;
00091             }
00092             else if (isCoupled[faceI-mesh_.nInternalFaces()])
00093             {
00094                 nNbrCells++;
00095             }
00096         }
00097 
00098         if (nNbrCells <= minNbrs_)
00099         {
00100             addOrDelete(set, cellI, add);
00101         }
00102     }
00103 }
00104 
00105 
00106 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00107 
00108 // Construct from components
00109 Foam::nbrToCell::nbrToCell
00110 (
00111     const polyMesh& mesh,
00112     const label minNbrs
00113 )
00114 :
00115     topoSetSource(mesh),
00116     minNbrs_(minNbrs)
00117 {}
00118 
00119 
00120 // Construct from dictionary
00121 Foam::nbrToCell::nbrToCell
00122 (
00123     const polyMesh& mesh,
00124     const dictionary& dict
00125 )
00126 :
00127     topoSetSource(mesh),
00128     minNbrs_(readLabel(dict.lookup("neighbours")))
00129 {}
00130 
00131 
00132 // Construct from Istream
00133 Foam::nbrToCell::nbrToCell
00134 (
00135     const polyMesh& mesh,
00136     Istream& is
00137 )
00138 :
00139     topoSetSource(mesh),
00140     minNbrs_(readLabel(checkIs(is)))
00141 {}
00142 
00143 
00144 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00145 
00146 Foam::nbrToCell::~nbrToCell()
00147 {}
00148 
00149 
00150 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00151 
00152 void Foam::nbrToCell::applyToSet
00153 (
00154     const topoSetSource::setAction action,
00155     topoSet& set
00156 ) const
00157 {
00158     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00159     {
00160         Info<< "    Adding cells with only " << minNbrs_ << " or less"
00161                 " neighbouring cells" << " ..." << endl;
00162 
00163         combine(set, true);
00164     }
00165     else if (action == topoSetSource::DELETE)
00166     {
00167         Info<< "    Removing cells with only " << minNbrs_ << " or less"
00168                 " neighbouring cells" << " ..." << endl;
00169 
00170         combine(set, false);
00171     }
00172 }
00173 
00174 
00175 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd