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

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