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