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

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