searchablePlate.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 "searchablePlate.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "SortableList.H"
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036 defineTypeNameAndDebug(searchablePlate, 0);
00037 addToRunTimeSelectionTable(searchableSurface, searchablePlate, dict);
00038
00039 }
00040
00041
00042
00043
00044 Foam::direction Foam::searchablePlate::calcNormal(const point& span)
00045 {
00046 direction normalDir = 3;
00047
00048 for (direction dir = 0; dir < vector::nComponents; dir++)
00049 {
00050 if (span[dir] < 0)
00051 {
00052 FatalErrorIn("searchablePlate::calcNormal()")
00053 << "Span should have two positive and one zero entry. Now:"
00054 << span << exit(FatalError);
00055 }
00056 else if (span[dir] < VSMALL)
00057 {
00058 if (normalDir == 3)
00059 {
00060 normalDir = dir;
00061 }
00062 else
00063 {
00064
00065 normalDir = 3;
00066 break;
00067 }
00068 }
00069 }
00070
00071 if (normalDir == 3)
00072 {
00073 FatalErrorIn("searchablePlate::calcNormal()")
00074 << "Span should have one and only zero entry. Now:" << span
00075 << exit(FatalError);
00076 }
00077
00078 return normalDir;
00079 }
00080
00081
00082
00083 Foam::pointIndexHit Foam::searchablePlate::findNearest
00084 (
00085 const point& sample,
00086 const scalar nearestDistSqr
00087 ) const
00088 {
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 pointIndexHit info(true, sample, 0);
00099 info.rawPoint()[normalDir_] = origin_[normalDir_];
00100
00101
00102 for (direction dir = 0; dir < vector::nComponents; dir++)
00103 {
00104 if (dir != normalDir_)
00105 {
00106 if (info.rawPoint()[dir] < origin_[dir])
00107 {
00108 info.rawPoint()[dir] = origin_[dir];
00109 }
00110 else if (info.rawPoint()[dir] > origin_[dir]+span_[dir])
00111 {
00112 info.rawPoint()[dir] = origin_[dir]+span_[dir];
00113 }
00114 }
00115 }
00116
00117
00118
00119 if (magSqr(info.rawPoint() - sample) > nearestDistSqr)
00120 {
00121 info.setMiss();
00122 info.setIndex(-1);
00123 }
00124
00125 return info;
00126 }
00127
00128
00129 Foam::pointIndexHit Foam::searchablePlate::findLine
00130 (
00131 const point& start,
00132 const point& end
00133 ) const
00134 {
00135 pointIndexHit info
00136 (
00137 true,
00138 vector::zero,
00139 0
00140 );
00141
00142 const vector dir(end-start);
00143
00144 if (mag(dir[normalDir_]) < VSMALL)
00145 {
00146 info.setMiss();
00147 info.setIndex(-1);
00148 }
00149 else
00150 {
00151 scalar t = (origin_[normalDir_]-start[normalDir_]) / dir[normalDir_];
00152
00153 if (t < 0 || t > 1)
00154 {
00155 info.setMiss();
00156 info.setIndex(-1);
00157 }
00158 else
00159 {
00160 info.rawPoint() = start+t*dir;
00161 info.rawPoint()[normalDir_] = origin_[normalDir_];
00162
00163
00164 for (direction dir = 0; dir < vector::nComponents; dir++)
00165 {
00166 if (dir != normalDir_)
00167 {
00168 if (info.rawPoint()[dir] < origin_[dir])
00169 {
00170 info.setMiss();
00171 info.setIndex(-1);
00172 break;
00173 }
00174 else if (info.rawPoint()[dir] > origin_[dir]+span_[dir])
00175 {
00176 info.setMiss();
00177 info.setIndex(-1);
00178 break;
00179 }
00180 }
00181 }
00182 }
00183 }
00184
00185
00186 if (info.hit())
00187 {
00188 treeBoundBox bb(origin_, origin_+span_);
00189 bb.min()[normalDir_] -= 1E-6;
00190 bb.max()[normalDir_] += 1E-6;
00191
00192 if (!bb.contains(info.hitPoint()))
00193 {
00194 FatalErrorIn("searchablePlate::findLine(..)")
00195 << "bb:" << bb << endl
00196 << "origin_:" << origin_ << endl
00197 << "span_:" << span_ << endl
00198 << "normalDir_:" << normalDir_ << endl
00199 << "hitPoint:" << info.hitPoint()
00200 << abort(FatalError);
00201 }
00202 }
00203
00204 return info;
00205 }
00206
00207
00208
00209
00210 Foam::searchablePlate::searchablePlate
00211 (
00212 const IOobject& io,
00213 const point& origin,
00214 const vector& span
00215 )
00216 :
00217 searchableSurface(io),
00218 origin_(origin),
00219 span_(span),
00220 normalDir_(calcNormal(span_))
00221 {
00222 if (debug)
00223 {
00224 Info<< "searchablePlate::searchablePlate :"
00225 << " origin:" << origin_
00226 << " origin+span:" << origin_+span_
00227 << " normal:" << vector::componentNames[normalDir_]
00228 << endl;
00229 }
00230 }
00231
00232
00233 Foam::searchablePlate::searchablePlate
00234 (
00235 const IOobject& io,
00236 const dictionary& dict
00237 )
00238 :
00239 searchableSurface(io),
00240 origin_(dict.lookup("origin")),
00241 span_(dict.lookup("span")),
00242 normalDir_(calcNormal(span_))
00243 {
00244 if (debug)
00245 {
00246 Info<< "searchablePlate::searchablePlate :"
00247 << " origin:" << origin_
00248 << " origin+span:" << origin_+span_
00249 << " normal:" << vector::componentNames[normalDir_]
00250 << endl;
00251 }
00252 }
00253
00254
00255
00256
00257 Foam::searchablePlate::~searchablePlate()
00258 {}
00259
00260
00261
00262
00263 const Foam::wordList& Foam::searchablePlate::regions() const
00264 {
00265 if (regions_.empty())
00266 {
00267 regions_.setSize(1);
00268 regions_[0] = "region0";
00269 }
00270 return regions_;
00271 }
00272
00273
00274 void Foam::searchablePlate::findNearest
00275 (
00276 const pointField& samples,
00277 const scalarField& nearestDistSqr,
00278 List<pointIndexHit>& info
00279 ) const
00280 {
00281 info.setSize(samples.size());
00282
00283 forAll(samples, i)
00284 {
00285 info[i] = findNearest(samples[i], nearestDistSqr[i]);
00286 }
00287 }
00288
00289
00290 void Foam::searchablePlate::findLine
00291 (
00292 const pointField& start,
00293 const pointField& end,
00294 List<pointIndexHit>& info
00295 ) const
00296 {
00297 info.setSize(start.size());
00298
00299 forAll(start, i)
00300 {
00301 info[i] = findLine(start[i], end[i]);
00302 }
00303 }
00304
00305
00306 void Foam::searchablePlate::findLineAny
00307 (
00308 const pointField& start,
00309 const pointField& end,
00310 List<pointIndexHit>& info
00311 ) const
00312 {
00313 findLine(start, end, info);
00314 }
00315
00316
00317 void Foam::searchablePlate::findLineAll
00318 (
00319 const pointField& start,
00320 const pointField& end,
00321 List<List<pointIndexHit> >& info
00322 ) const
00323 {
00324 List<pointIndexHit> nearestInfo;
00325 findLine(start, end, nearestInfo);
00326
00327 info.setSize(start.size());
00328 forAll(info, pointI)
00329 {
00330 if (nearestInfo[pointI].hit())
00331 {
00332 info[pointI].setSize(1);
00333 info[pointI][0] = nearestInfo[pointI];
00334 }
00335 else
00336 {
00337 info[pointI].clear();
00338 }
00339 }
00340 }
00341
00342
00343 void Foam::searchablePlate::getRegion
00344 (
00345 const List<pointIndexHit>& info,
00346 labelList& region
00347 ) const
00348 {
00349 region.setSize(info.size());
00350 region = 0;
00351 }
00352
00353
00354 void Foam::searchablePlate::getNormal
00355 (
00356 const List<pointIndexHit>& info,
00357 vectorField& normal
00358 ) const
00359 {
00360 normal.setSize(info.size());
00361 normal = vector::zero;
00362 forAll(normal, i)
00363 {
00364 normal[i][normalDir_] = 1.0;
00365 }
00366 }
00367
00368
00369 void Foam::searchablePlate::getVolumeType
00370 (
00371 const pointField& points,
00372 List<volumeType>& volType
00373 ) const
00374 {
00375 FatalErrorIn
00376 (
00377 "searchableCollection::getVolumeType(const pointField&"
00378 ", List<volumeType>&) const"
00379 ) << "Volume type not supported for plate."
00380 << exit(FatalError);
00381 }
00382
00383
00384
Copyright © 2000-2009 OpenCFD Ltd