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

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