nearestToPoint.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "nearestToPoint.H"
00028 #include "polyMesh.H"
00029 #include "meshSearch.H"
00030
00031 #include "addToRunTimeSelectionTable.H"
00032
00033
00034
00035 namespace Foam
00036 {
00037
00038 defineTypeNameAndDebug(nearestToPoint, 0);
00039
00040 addToRunTimeSelectionTable(topoSetSource, nearestToPoint, word);
00041
00042 addToRunTimeSelectionTable(topoSetSource, nearestToPoint, istream);
00043
00044 }
00045
00046
00047 Foam::topoSetSource::addToUsageTable Foam::nearestToPoint::usage_
00048 (
00049 nearestToPoint::typeName,
00050 "\n Usage: nearestToPoint (pt0 .. ptn)\n\n"
00051 " Select the nearest point for each of the points pt0 ..ptn\n\n"
00052 );
00053
00054
00055
00056
00057 void Foam::nearestToPoint::combine(topoSet& set, const bool add) const
00058 {
00059
00060
00061 forAll(points_, pointI)
00062 {
00063 const pointField& pts = mesh_.points();
00064
00065 if (pts.size())
00066 {
00067 label minPointI = 0;
00068 scalar minDistSqr = magSqr(pts[minPointI] - points_[pointI]);
00069
00070 for (label i = 1; i < pts.size(); i++)
00071 {
00072 scalar distSqr = magSqr(pts[i] - points_[pointI]);
00073
00074 if (distSqr < minDistSqr)
00075 {
00076 minDistSqr = distSqr;
00077 minPointI = i;
00078 }
00079 }
00080
00081 addOrDelete(set, minPointI, add);
00082 }
00083 }
00084 }
00085
00086
00087
00088
00089
00090 Foam::nearestToPoint::nearestToPoint
00091 (
00092 const polyMesh& mesh,
00093 const pointField& points
00094 )
00095 :
00096 topoSetSource(mesh),
00097 points_(points)
00098 {}
00099
00100
00101
00102 Foam::nearestToPoint::nearestToPoint
00103 (
00104 const polyMesh& mesh,
00105 const dictionary& dict
00106 )
00107 :
00108 topoSetSource(mesh),
00109 points_(dict.lookup("points"))
00110 {}
00111
00112
00113
00114 Foam::nearestToPoint::nearestToPoint
00115 (
00116 const polyMesh& mesh,
00117 Istream& is
00118 )
00119 :
00120 topoSetSource(mesh),
00121 points_(checkIs(is))
00122 {}
00123
00124
00125
00126
00127 Foam::nearestToPoint::~nearestToPoint()
00128 {}
00129
00130
00131
00132
00133 void Foam::nearestToPoint::applyToSet
00134 (
00135 const topoSetSource::setAction action,
00136 topoSet& set
00137 ) const
00138 {
00139 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00140 {
00141 Info<< " Adding points nearest to " << points_ << endl;
00142
00143 combine(set, true);
00144 }
00145 else if (action == topoSetSource::DELETE)
00146 {
00147 Info<< " Removing points nearest to " << points_ << endl;
00148
00149 combine(set, false);
00150 }
00151 }
00152
00153
00154
Copyright © 2000-2009 OpenCFD Ltd