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

faceToCell.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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "faceToCell.H"
00030 #include "polyMesh.H"
00031 #include "faceSet.H"
00032 
00033 #include "addToRunTimeSelectionTable.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 defineTypeNameAndDebug(faceToCell, 0);
00041 
00042 addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
00043 
00044 addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
00045 
00046 }
00047 
00048 
00049 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
00050 (
00051     faceToCell::typeName,
00052     "\n    Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
00053     "    Select cells that are the owner|neighbour|any"
00054     " of the faces in the faceSet or where all faces are in the faceSet\n\n"
00055 );
00056 
00057 template<>
00058 const char* Foam::NamedEnum<Foam::faceToCell::faceAction, 4>::names[] =
00059 {
00060     "neighbour",
00061     "owner",
00062     "any",
00063     "all"
00064 };
00065 
00066 const Foam::NamedEnum<Foam::faceToCell::faceAction, 4>
00067     Foam::faceToCell::faceActionNames_;
00068 
00069 
00070 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00071 
00072 void Foam::faceToCell::combine(topoSet& set, const bool add) const
00073 {
00074     // Load the set
00075     faceSet loadedSet(mesh_, setName_);
00076 
00077 
00078     // Handle owner/neighbour/any selection
00079     for
00080     (
00081         faceSet::const_iterator iter = loadedSet.begin();
00082         iter != loadedSet.end();
00083         ++iter
00084     )
00085     {
00086         label faceI = iter.key();
00087 
00088         if ((option_ == OWNER) || (option_ == ANY))
00089         {
00090             label cellI = mesh_.faceOwner()[faceI];
00091 
00092             addOrDelete(set, cellI, add);
00093         }
00094 
00095         if (mesh_.isInternalFace(faceI))
00096         {
00097             if ((option_ == NEIGHBOUR) || (option_ == ANY))
00098             {
00099                 label cellI = mesh_.faceNeighbour()[faceI];
00100 
00101                 addOrDelete(set, cellI, add);
00102             }
00103         }
00104     }
00105 
00106     // Handle all selection.
00107     if (option_ == ALL)
00108     {
00109         // Count number of selected faces per cell.
00110 
00111         Map<label> facesPerCell(loadedSet.size());
00112 
00113         for
00114         (
00115             faceSet::const_iterator iter = loadedSet.begin();
00116             iter != loadedSet.end();
00117             ++iter
00118         )
00119         {
00120             label faceI = iter.key();
00121 
00122             label own = mesh_.faceOwner()[faceI];
00123 
00124             Map<label>::iterator fndOwn = facesPerCell.find(own);
00125 
00126             if (fndOwn == facesPerCell.end())
00127             {
00128                 facesPerCell.insert(own, 1);
00129             }
00130             else
00131             {
00132                 fndOwn()++;
00133             }
00134 
00135             if (mesh_.isInternalFace(faceI))
00136             {
00137                 label nei = mesh_.faceNeighbour()[faceI];
00138 
00139                 Map<label>::iterator fndNei = facesPerCell.find(nei);
00140 
00141                 if (fndNei == facesPerCell.end())
00142                 {
00143                     facesPerCell.insert(nei, 1);
00144                 }
00145                 else
00146                 {
00147                     fndNei()++;
00148                 }
00149             }
00150         }
00151 
00152         // Include cells that are referenced as many times as they have faces
00153         // -> all faces in set.
00154         for
00155         (
00156             Map<label>::const_iterator iter = facesPerCell.begin();
00157             iter != facesPerCell.end();
00158             ++iter
00159         )
00160         {
00161             label cellI = iter.key();
00162 
00163             if (iter() == mesh_.cells()[cellI].size())
00164             {
00165                 addOrDelete(set, cellI, add);
00166             }
00167         }
00168     }
00169 }
00170 
00171 
00172 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00173 
00174 // Construct from components
00175 Foam::faceToCell::faceToCell
00176 (
00177     const polyMesh& mesh,
00178     const word& setName,
00179     const faceAction option
00180 )
00181 :
00182     topoSetSource(mesh),
00183     setName_(setName),
00184     option_(option)
00185 {}
00186 
00187 
00188 // Construct from dictionary
00189 Foam::faceToCell::faceToCell
00190 (
00191     const polyMesh& mesh,
00192     const dictionary& dict          
00193 )
00194 :
00195     topoSetSource(mesh),
00196     setName_(dict.lookup("set")),
00197     option_(faceActionNames_.read(dict.lookup("option")))
00198 {}
00199 
00200 
00201 // Construct from Istream
00202 Foam::faceToCell::faceToCell
00203 (
00204     const polyMesh& mesh,
00205     Istream& is
00206 )
00207 :
00208     topoSetSource(mesh),
00209     setName_(checkIs(is)),
00210     option_(faceActionNames_.read(checkIs(is)))
00211 {}
00212 
00213 
00214 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00215 
00216 Foam::faceToCell::~faceToCell()
00217 {}
00218 
00219 
00220 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00221 
00222 void Foam::faceToCell::applyToSet
00223 (
00224     const topoSetSource::setAction action,
00225     topoSet& set
00226 ) const
00227 {
00228     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00229     {
00230         Info<< "    Adding cells according to faceSet " << setName_
00231             << " ..." << endl;
00232 
00233         combine(set, true);
00234     }
00235     else if (action == topoSetSource::DELETE)
00236     {
00237         Info<< "    Removing cells according to faceSet " << setName_
00238             << " ..." << endl;
00239 
00240         combine(set, false);
00241     }
00242 }
00243 
00244 
00245 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd