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 "curveSet.H"
00028 #include "meshSearch.H"
00029 #include "DynamicList.H"
00030 #include "polyMesh.H"
00031
00032 #include "Cloud.H"
00033 #include "passiveParticle.H"
00034 #include "IDLList.H"
00035
00036 #include "addToRunTimeSelectionTable.H"
00037
00038
00039
00040 namespace Foam
00041 {
00042 defineTypeNameAndDebug(curveSet, 0);
00043 addToRunTimeSelectionTable(sampledSet, curveSet, word);
00044 }
00045
00046
00047
00048
00049
00050 bool Foam::curveSet::trackToBoundary
00051 (
00052 Particle<passiveParticle>& singleParticle,
00053 label& sampleI,
00054 DynamicList<point>& samplingPts,
00055 DynamicList<label>& samplingCells,
00056 DynamicList<label>& samplingFaces,
00057 DynamicList<scalar>& samplingCurveDist
00058 ) const
00059 {
00060
00061 const point& trackPt = singleParticle.position();
00062
00063 while(true)
00064 {
00065
00066 const vector offset = sampleCoords_[sampleI+1] - sampleCoords_[sampleI];
00067 const scalar smallDist = mag(tol*offset);
00068
00069 point oldPos = trackPt;
00070 label facei = -1;
00071 do
00072 {
00073 singleParticle.stepFraction() = 0;
00074 singleParticle.track(sampleCoords_[sampleI+1]);
00075 }
00076 while
00077 (
00078 !singleParticle.onBoundary()
00079 && (mag(trackPt - oldPos) < smallDist)
00080 );
00081
00082 if (singleParticle.onBoundary())
00083 {
00084
00085
00086 if
00087 (
00088 mag(trackPt - sampleCoords_[sampleI+1])
00089 < smallDist
00090 )
00091 {
00092
00093
00094
00095
00096 samplingPts.append(trackPt);
00097 samplingCells.append(singleParticle.cell());
00098 samplingFaces.append(facei);
00099
00100
00101 samplingCurveDist.append(1.0*(sampleI+1));
00102 }
00103 return true;
00104 }
00105
00106
00107 samplingPts.append(trackPt);
00108 samplingCells.append(singleParticle.cell());
00109 samplingFaces.append(-1);
00110
00111
00112 scalar dist =
00113 mag(trackPt - sampleCoords_[sampleI])
00114 / mag(sampleCoords_[sampleI+1] - sampleCoords_[sampleI]);
00115 samplingCurveDist.append(sampleI + dist);
00116
00117
00118 sampleI++;
00119
00120 if (sampleI == sampleCoords_.size() - 1)
00121 {
00122
00123
00124
00125 return false;
00126 }
00127 }
00128 }
00129
00130
00131 void Foam::curveSet::calcSamples
00132 (
00133 DynamicList<point>& samplingPts,
00134 DynamicList<label>& samplingCells,
00135 DynamicList<label>& samplingFaces,
00136 DynamicList<label>& samplingSegments,
00137 DynamicList<scalar>& samplingCurveDist
00138 ) const
00139 {
00140
00141 if (sampleCoords_.size() < 2)
00142 {
00143 FatalErrorIn("curveSet::calcSamples()")
00144 << "Incorrect sample specification. Too few points:"
00145 << sampleCoords_ << exit(FatalError);
00146 }
00147 point oldPoint = sampleCoords_[0];
00148 for(label sampleI = 1; sampleI < sampleCoords_.size(); sampleI++)
00149 {
00150 if (mag(sampleCoords_[sampleI] - oldPoint) < SMALL)
00151 {
00152 FatalErrorIn("curveSet::calcSamples()")
00153 << "Incorrect sample specification."
00154 << " Point " << sampleCoords_[sampleI-1]
00155 << " at position " << sampleI-1
00156 << " and point " << sampleCoords_[sampleI]
00157 << " at position " << sampleI
00158 << " are too close" << exit(FatalError);
00159 }
00160 oldPoint = sampleCoords_[sampleI];
00161 }
00162
00163
00164 label segmentI = 0;
00165
00166
00167 label startSegmentI = 0;
00168
00169 label sampleI = 0;
00170
00171 point lastSample(GREAT, GREAT, GREAT);
00172 while(true)
00173 {
00174
00175 point trackPt;
00176 label trackCellI = -1;
00177 label trackFaceI = -1;
00178
00179 do
00180 {
00181 const vector offset =
00182 sampleCoords_[sampleI+1] - sampleCoords_[sampleI];
00183 const scalar smallDist = mag(tol*offset);
00184
00185
00186
00187 List<pointIndexHit> bHits = searchEngine().intersections
00188 (
00189 sampleCoords_[sampleI],
00190 sampleCoords_[sampleI+1]
00191 );
00192
00193 point bPoint(GREAT, GREAT, GREAT);
00194 label bFaceI = -1;
00195
00196 if (bHits.size())
00197 {
00198 bPoint = bHits[0].hitPoint();
00199 bFaceI = bHits[0].index();
00200 }
00201
00202
00203
00204 bool isSample =
00205 getTrackingPoint
00206 (
00207 sampleCoords_[sampleI+1] - sampleCoords_[sampleI],
00208 sampleCoords_[sampleI],
00209 bPoint,
00210 bFaceI,
00211
00212 trackPt,
00213 trackCellI,
00214 trackFaceI
00215 );
00216
00217 if (isSample && (mag(lastSample - trackPt) > smallDist))
00218 {
00219
00220
00221
00222
00223
00224
00225
00226
00227 samplingPts.append(trackPt);
00228 samplingCells.append(trackCellI);
00229 samplingFaces.append(trackFaceI);
00230
00231
00232
00233 scalar dist =
00234 mag(trackPt - sampleCoords_[sampleI])
00235 / mag(sampleCoords_[sampleI+1] - sampleCoords_[sampleI]);
00236 samplingCurveDist.append(sampleI + dist);
00237
00238 lastSample = trackPt;
00239 }
00240
00241 if (trackCellI == -1)
00242 {
00243
00244 sampleI++;
00245 }
00246 } while((trackCellI == -1) && (sampleI < sampleCoords_.size() - 1));
00247
00248 if (sampleI == sampleCoords_.size() - 1)
00249 {
00250
00251
00252
00253 break;
00254 }
00255
00256
00257
00258
00259
00260
00261 Cloud<passiveParticle> particles(mesh(), IDLList<passiveParticle>());
00262
00263 passiveParticle singleParticle
00264 (
00265 particles,
00266 trackPt,
00267 trackCellI
00268 );
00269
00270 bool bReached = trackToBoundary
00271 (
00272 singleParticle,
00273 sampleI,
00274 samplingPts,
00275 samplingCells,
00276 samplingFaces,
00277 samplingCurveDist
00278 );
00279
00280
00281 for(label i = samplingPts.size() - 1; i >= startSegmentI; --i)
00282 {
00283 samplingSegments.append(segmentI);
00284 }
00285
00286 if (!bReached)
00287 {
00288
00289
00290
00291 break;
00292 }
00293 lastSample = singleParticle.position();
00294
00295
00296
00297 sampleI++;
00298
00299 if (sampleI == sampleCoords_.size() - 1)
00300 {
00301
00302
00303
00304 break;
00305 }
00306
00307 segmentI++;
00308
00309 startSegmentI = samplingPts.size();
00310 }
00311 }
00312
00313
00314 void Foam::curveSet::genSamples()
00315 {
00316
00317 DynamicList<point> samplingPts;
00318 DynamicList<label> samplingCells;
00319 DynamicList<label> samplingFaces;
00320 DynamicList<label> samplingSegments;
00321 DynamicList<scalar> samplingCurveDist;
00322
00323 calcSamples
00324 (
00325 samplingPts,
00326 samplingCells,
00327 samplingFaces,
00328 samplingSegments,
00329 samplingCurveDist
00330 );
00331
00332 samplingPts.shrink();
00333 samplingCells.shrink();
00334 samplingFaces.shrink();
00335 samplingSegments.shrink();
00336 samplingCurveDist.shrink();
00337
00338 setSamples
00339 (
00340 samplingPts,
00341 samplingCells,
00342 samplingFaces,
00343 samplingSegments,
00344 samplingCurveDist
00345 );
00346 }
00347
00348
00349
00350
00351 Foam::curveSet::curveSet
00352 (
00353 const word& name,
00354 const polyMesh& mesh,
00355 meshSearch& searchEngine,
00356 const word& axis,
00357 const List<point>& sampleCoords
00358 )
00359 :
00360 sampledSet(name, mesh, searchEngine, axis),
00361 sampleCoords_(sampleCoords)
00362 {
00363 genSamples();
00364
00365 if (debug)
00366 {
00367 write(Info);
00368 }
00369 }
00370
00371
00372 Foam::curveSet::curveSet
00373 (
00374 const word& name,
00375 const polyMesh& mesh,
00376 meshSearch& searchEngine,
00377 const dictionary& dict
00378 )
00379 :
00380 sampledSet(name, mesh, searchEngine, dict),
00381 sampleCoords_(dict.lookup("points"))
00382 {
00383 genSamples();
00384
00385 if (debug)
00386 {
00387 write(Info);
00388 }
00389 }
00390
00391
00392
00393
00394 Foam::curveSet::~curveSet()
00395 {}
00396
00397
00398
00399
00400 Foam::point Foam::curveSet::getRefPoint(const List<point>& pts) const
00401 {
00402 if (pts.size())
00403 {
00404
00405 return pts[0];
00406 }
00407 else
00408 {
00409 return vector::zero;
00410 }
00411 }
00412
00413
00414