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

cellToFace.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 "cellToFace.H"
00028 #include "polyMesh.H"
00029 #include "cellSet.H"
00030 #include "Time.H"
00031 #include "syncTools.H"
00032 #include "addToRunTimeSelectionTable.H"
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 defineTypeNameAndDebug(cellToFace, 0);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
00042 
00043 addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
00044 
00045 }
00046 
00047 
00048 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
00049 (
00050     cellToFace::typeName,
00051     "\n    Usage: cellToFace <cellSet> all|both\n\n"
00052     "    Select -all : all faces of cells in the cellSet\n"
00053     "           -both: faces where both neighbours are in the cellSet\n\n"
00054 );
00055 
00056 template<>
00057 const char* Foam::NamedEnum<Foam::cellToFace::cellAction, 2>::names[] =
00058 {
00059     "all",
00060     "both"
00061 };
00062 
00063 const Foam::NamedEnum<Foam::cellToFace::cellAction, 2>
00064     Foam::cellToFace::cellActionNames_;
00065 
00066 
00067 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00068 
00069 void Foam::cellToFace::combine(topoSet& set, const bool add) const
00070 {
00071     // Load the set
00072     if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
00073     {
00074         SeriousError<< "Cannot load set "
00075             << setName_ << endl;
00076     }
00077     
00078     cellSet loadedSet(mesh_, setName_);
00079 
00080     if (option_ == ALL)
00081     {
00082         // Add all faces from cell
00083         for
00084         (
00085             cellSet::const_iterator iter = loadedSet.begin();
00086             iter != loadedSet.end();
00087             ++iter
00088         )
00089         {
00090             label cellI = iter.key();
00091 
00092             const labelList& cFaces = mesh_.cells()[cellI];
00093 
00094             forAll(cFaces, cFaceI)
00095             {
00096                 addOrDelete(set, cFaces[cFaceI], add);
00097             }
00098         }
00099     }
00100     else if (option_ == BOTH)
00101     {
00102         // Add all faces whose both neighbours are in set.
00103 
00104         label nInt = mesh_.nInternalFaces();
00105         const labelList& own = mesh_.faceOwner();
00106         const labelList& nei = mesh_.faceNeighbour();
00107         const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00108 
00109 
00110         // Check all internal faces
00111         for (label faceI = 0; faceI < nInt; faceI++)
00112         {
00113             if (loadedSet.found(own[faceI]) && loadedSet.found(nei[faceI]))
00114             {
00115                 addOrDelete(set, faceI, add);
00116             }
00117         }
00118 
00119 
00120         // Get coupled cell status
00121         boolList neiInSet(mesh_.nFaces()-nInt, false);
00122 
00123         forAll(patches, patchI)
00124         {
00125             const polyPatch& pp = patches[patchI];
00126 
00127             if (pp.coupled())
00128             {
00129                 label faceI = pp.start();
00130                 forAll(pp, i)
00131                 {
00132                     neiInSet[faceI-nInt] = loadedSet.found(own[faceI]);
00133                     faceI++;
00134                 }
00135             }
00136         }
00137         syncTools::swapBoundaryFaceList(mesh_, neiInSet, false);
00138 
00139 
00140         // Check all boundary faces
00141         forAll(patches, patchI)
00142         {
00143             const polyPatch& pp = patches[patchI];
00144 
00145             if (pp.coupled())
00146             {
00147                 label faceI = pp.start();
00148                 forAll(pp, i)
00149                 {
00150                     if (loadedSet.found(own[faceI]) && neiInSet[faceI-nInt])
00151                     {
00152                         addOrDelete(set, faceI, add);
00153                     }
00154                     faceI++;
00155                 }
00156             }
00157         }
00158     }
00159 }
00160 
00161 
00162 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00163 
00164 // Construct from componenta
00165 Foam::cellToFace::cellToFace
00166 (
00167     const polyMesh& mesh,
00168     const word& setName,
00169     const cellAction option
00170 )
00171 :
00172     topoSetSource(mesh),
00173     setName_(setName),
00174     option_(option)
00175 {}
00176 
00177 
00178 // Construct from dictionary
00179 Foam::cellToFace::cellToFace
00180 (
00181     const polyMesh& mesh,
00182     const dictionary& dict          
00183 )
00184 :
00185     topoSetSource(mesh),
00186     setName_(dict.lookup("set")),
00187     option_(cellActionNames_.read(dict.lookup("option")))
00188 {}
00189 
00190 
00191 // Construct from Istream
00192 Foam::cellToFace::cellToFace
00193 (
00194     const polyMesh& mesh,
00195     Istream& is
00196 )
00197 :
00198     topoSetSource(mesh),
00199     setName_(checkIs(is)),
00200     option_(cellActionNames_.read(checkIs(is)))
00201 {}
00202 
00203 
00204 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00205 
00206 Foam::cellToFace::~cellToFace()
00207 {}
00208 
00209 
00210 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00211 
00212 void Foam::cellToFace::applyToSet
00213 (
00214     const topoSetSource::setAction action,
00215     topoSet& set
00216 ) const
00217 {
00218     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00219     {
00220         Pout<< "    Adding faces according to cellSet " << setName_
00221             << " ..." << endl;
00222 
00223         combine(set, true);
00224     }
00225     else if (action == topoSetSource::DELETE)
00226     {
00227         Pout<< "    Removing faces according to cellSet " << setName_
00228             << " ..." << endl;
00229 
00230         combine(set, false);
00231     }
00232 }
00233 
00234 
00235 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd