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

pointToCell.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 "pointToCell.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(pointToCell, 0);
00038 
00039 addToRunTimeSelectionTable(topoSetSource, pointToCell, word);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, pointToCell, istream);
00042 
00043 }
00044 
00045 
00046 Foam::topoSetSource::addToUsageTable Foam::pointToCell::usage_
00047 (
00048     pointToCell::typeName,
00049     "\n    Usage: pointToCell <pointSet> any\n\n"
00050     "    Select all cells with any point in the pointSet\n\n"
00051 );
00052 
00053 template<>
00054 const char* Foam::NamedEnum<Foam::pointToCell::pointAction, 1>::names[] =
00055 {
00056     "any"
00057 };
00058 
00059 
00060 const Foam::NamedEnum<Foam::pointToCell::pointAction, 1>
00061     Foam::pointToCell::pointActionNames_;
00062 
00063 
00064 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00065 
00066 void Foam::pointToCell::combine(topoSet& set, const bool add) const
00067 {
00068     // Load the set
00069     pointSet loadedSet(mesh_, setName_);
00070 
00071 
00072     // Handle any selection
00073     if (option_ == ANY)
00074     {
00075         for
00076         (
00077             pointSet::const_iterator iter = loadedSet.begin();
00078             iter != loadedSet.end();
00079             ++iter
00080         )
00081         {
00082             label pointI = iter.key();
00083 
00084             const labelList& pCells = mesh_.pointCells()[pointI];
00085 
00086             forAll(pCells, pCellI)
00087             {
00088                 addOrDelete(set, pCells[pCellI], add);
00089             }
00090         }
00091     }
00092 }
00093 
00094 
00095 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00096 
00097 // Construct from components
00098 Foam::pointToCell::pointToCell
00099 (
00100     const polyMesh& mesh,
00101     const word& setName,
00102     const pointAction option
00103 )
00104 :
00105     topoSetSource(mesh),
00106     setName_(setName),
00107     option_(option)
00108 {}
00109 
00110 
00111 // Construct from dictionary
00112 Foam::pointToCell::pointToCell
00113 (
00114     const polyMesh& mesh,
00115     const dictionary& dict
00116 )
00117 :
00118     topoSetSource(mesh),
00119     setName_(dict.lookup("set")),
00120     option_(pointActionNames_.read(dict.lookup("option")))
00121 {}
00122 
00123 
00124 // Construct from Istream
00125 Foam::pointToCell::pointToCell
00126 (
00127     const polyMesh& mesh,
00128     Istream& is
00129 )
00130 :
00131     topoSetSource(mesh),
00132     setName_(checkIs(is)),
00133     option_(pointActionNames_.read(checkIs(is)))
00134 {}
00135 
00136 
00137 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00138 
00139 Foam::pointToCell::~pointToCell()
00140 {}
00141 
00142 
00143 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00144 
00145 void Foam::pointToCell::applyToSet
00146 (
00147     const topoSetSource::setAction action,
00148     topoSet& set
00149 ) const
00150 {
00151     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00152     {
00153         Info<< "    Adding cells according to pointSet " << setName_
00154             << " ..." << endl;
00155 
00156         combine(set, true);
00157     }
00158     else if (action == topoSetSource::DELETE)
00159     {
00160         Info<< "    Removing cells according to pointSet " << setName_
00161             << " ..." << endl;
00162 
00163         combine(set, false);
00164     }
00165 }
00166 
00167 
00168 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines