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

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