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

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