FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "nbrToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 
00029 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 defineTypeNameAndDebug(nbrToCell, 0);
00037 
00038 addToRunTimeSelectionTable(topoSetSource, nbrToCell, word);
00039 
00040 addToRunTimeSelectionTable(topoSetSource, nbrToCell, istream);
00041 
00042 }
00043 
00044 
00045 Foam::topoSetSource::addToUsageTable Foam::nbrToCell::usage_
00046 (
00047     nbrToCell::typeName,
00048     "\n    Usage: nbrToCell <nNeighbours>\n\n"
00049     "    Select all cells with <= nNeighbours neighbouring cells\n\n"
00050 );
00051 
00052 
00053 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00054 
00055 void Foam::nbrToCell::combine(topoSet& set, const bool add) const
00056 {
00057     const cellList& cells = mesh().cells();
00058     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00059 
00060     boolList isCoupled(mesh_.nFaces()-mesh_.nInternalFaces(), false);
00061 
00062     forAll(patches, patchI)
00063     {
00064         const polyPatch& pp = patches[patchI];
00065 
00066         if (pp.coupled())
00067         {
00068             label faceI = pp.start();
00069             forAll(pp, i)
00070             {
00071                 isCoupled[faceI-mesh_.nInternalFaces()] = true;
00072                 faceI++;
00073             }
00074         }
00075     }
00076 
00077     forAll(cells, cellI)
00078     {
00079         const cell& cFaces = cells[cellI];
00080 
00081         label nNbrCells = 0;
00082 
00083         forAll(cFaces, i)
00084         {
00085             label faceI = cFaces[i];
00086 
00087             if (mesh_.isInternalFace(faceI))
00088             {
00089                 nNbrCells++;
00090             }
00091             else if (isCoupled[faceI-mesh_.nInternalFaces()])
00092             {
00093                 nNbrCells++;
00094             }
00095         }
00096 
00097         if (nNbrCells <= minNbrs_)
00098         {
00099             addOrDelete(set, cellI, add);
00100         }
00101     }
00102 }
00103 
00104 
00105 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00106 
00107 // Construct from components
00108 Foam::nbrToCell::nbrToCell
00109 (
00110     const polyMesh& mesh,
00111     const label minNbrs
00112 )
00113 :
00114     topoSetSource(mesh),
00115     minNbrs_(minNbrs)
00116 {}
00117 
00118 
00119 // Construct from dictionary
00120 Foam::nbrToCell::nbrToCell
00121 (
00122     const polyMesh& mesh,
00123     const dictionary& dict
00124 )
00125 :
00126     topoSetSource(mesh),
00127     minNbrs_(readLabel(dict.lookup("neighbours")))
00128 {}
00129 
00130 
00131 // Construct from Istream
00132 Foam::nbrToCell::nbrToCell
00133 (
00134     const polyMesh& mesh,
00135     Istream& is
00136 )
00137 :
00138     topoSetSource(mesh),
00139     minNbrs_(readLabel(checkIs(is)))
00140 {}
00141 
00142 
00143 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00144 
00145 Foam::nbrToCell::~nbrToCell()
00146 {}
00147 
00148 
00149 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00150 
00151 void Foam::nbrToCell::applyToSet
00152 (
00153     const topoSetSource::setAction action,
00154     topoSet& set
00155 ) const
00156 {
00157     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00158     {
00159         Info<< "    Adding cells with only " << minNbrs_ << " or less"
00160                 " neighbouring cells" << " ..." << endl;
00161 
00162         combine(set, true);
00163     }
00164     else if (action == topoSetSource::DELETE)
00165     {
00166         Info<< "    Removing cells with only " << minNbrs_ << " or less"
00167                 " neighbouring cells" << " ..." << endl;
00168 
00169         combine(set, false);
00170     }
00171 }
00172 
00173 
00174 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines