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

nearestToCell.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 "nearestToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <meshTools/meshSearch.H>
00029 
00030 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 defineTypeNameAndDebug(nearestToCell, 0);
00038 
00039 addToRunTimeSelectionTable(topoSetSource, nearestToCell, word);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, nearestToCell, istream);
00042 
00043 }
00044 
00045 
00046 Foam::topoSetSource::addToUsageTable Foam::nearestToCell::usage_
00047 (
00048     nearestToCell::typeName,
00049     "\n    Usage: nearestToCell (pt0 .. ptn)\n\n"
00050     "    Select the nearest cell for each of the points pt0 ..ptn\n\n"
00051 );
00052 
00053 
00054 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00055 
00056 void Foam::nearestToCell::combine(topoSet& set, const bool add) const
00057 {
00058     // Construct search engine withouth tet decomposition.
00059     meshSearch queryMesh(mesh_, false);
00060 
00061     forAll(points_, pointI)
00062     {
00063         addOrDelete(set, queryMesh.findNearestCell(points_[pointI]), add);
00064     }
00065 }
00066 
00067 
00068 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00069 
00070 // Construct from components
00071 Foam::nearestToCell::nearestToCell
00072 (
00073     const polyMesh& mesh,
00074     const pointField& points
00075 )
00076 :
00077     topoSetSource(mesh),
00078     points_(points)
00079 {}
00080 
00081 
00082 // Construct from dictionary
00083 Foam::nearestToCell::nearestToCell
00084 (
00085     const polyMesh& mesh,
00086     const dictionary& dict
00087 )
00088 :
00089     topoSetSource(mesh),
00090     points_(dict.lookup("points"))
00091 {}
00092 
00093 
00094 // Construct from Istream
00095 Foam::nearestToCell::nearestToCell
00096 (
00097     const polyMesh& mesh,
00098     Istream& is
00099 )
00100 :
00101     topoSetSource(mesh),
00102     points_(checkIs(is))
00103 {}
00104 
00105 
00106 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00107 
00108 Foam::nearestToCell::~nearestToCell()
00109 {}
00110 
00111 
00112 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00113 
00114 void Foam::nearestToCell::applyToSet
00115 (
00116     const topoSetSource::setAction action,
00117     topoSet& set
00118 ) const
00119 {
00120     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00121     {
00122         Info<< "    Adding cells nearest to " << points_ << endl;
00123 
00124         combine(set, true);
00125     }
00126     else if (action == topoSetSource::DELETE)
00127     {
00128         Info<< "    Removing cells nearest to " << points_ << endl;
00129 
00130         combine(set, false);
00131     }
00132 }
00133 
00134 
00135 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines