1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "nearestToPoint.H"
28 #include "meshSearch.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(nearestToPoint, 0);
39 addToRunTimeSelectionTable(topoSetSource, nearestToPoint, word);
41 addToRunTimeSelectionTable(topoSetSource, nearestToPoint, istream);
46 Foam::topoSetSource::addToUsageTable Foam::nearestToPoint::usage_
48 nearestToPoint::typeName,
49 "\n Usage: nearestToPoint (pt0 .. ptn)\n\n"
50 " Select the nearest point for each of the points pt0 ..ptn\n\n"
54 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 void Foam::nearestToPoint::combine(topoSet& set, const bool add) const
58 // Do linear search since usually just a few points.
60 forAll(points_, pointI)
62 const pointField& pts = mesh_.points();
67 scalar minDistSqr = magSqr(pts[minPointI] - points_[pointI]);
69 for (label i = 1; i < pts.size(); i++)
71 scalar distSqr = magSqr(pts[i] - points_[pointI]);
73 if (distSqr < minDistSqr)
80 addOrDelete(set, minPointI, add);
86 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 // Construct from components
89 Foam::nearestToPoint::nearestToPoint
92 const pointField& points
100 // Construct from dictionary
101 Foam::nearestToPoint::nearestToPoint
103 const polyMesh& mesh,
104 const dictionary& dict
108 points_(dict.lookup("points"))
112 // Construct from Istream
113 Foam::nearestToPoint::nearestToPoint
115 const polyMesh& mesh,
124 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
126 Foam::nearestToPoint::~nearestToPoint()
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 void Foam::nearestToPoint::applyToSet
134 const topoSetSource::setAction action,
138 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
140 Info<< " Adding points nearest to " << points_ << endl;
144 else if (action == topoSetSource::DELETE)
146 Info<< " Removing points nearest to " << points_ << endl;
153 // ************************************************************************* //