1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "uniformSet.H"
27 #include "meshSearch.H"
28 #include "DynamicList.H"
32 #include "passiveParticle.H"
35 #include "addToRunTimeSelectionTable.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(uniformSet, 0);
42 addToRunTimeSelectionTable(sampledSet, uniformSet, word);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 // Finds along line (samplePt + t * offset) next sample beyond or equal to
50 // Updates samplePt, sampleI
51 bool Foam::uniformSet::nextSample
53 const point& currentPt,
55 const scalar smallDist,
60 bool pointFound = false;
62 const vector normOffset = offset/mag(offset);
67 for(; sampleI < nPoints_; sampleI++)
69 scalar s = (samplePt - currentPt) & normOffset;
73 // samplePt is close to or beyond currentPt -> use it
85 // Sample singly connected segment. Returns false if end_ reached.
86 bool Foam::uniformSet::trackToBoundary
88 Particle<passiveParticle>& singleParticle,
91 DynamicList<point>& samplingPts,
92 DynamicList<label>& samplingCells,
93 DynamicList<label>& samplingFaces,
94 DynamicList<scalar>& samplingCurveDist
97 // distance vector between sampling points
98 const vector offset = (end_ - start_)/(nPoints_ - 1);
99 const vector smallVec = tol*offset;
100 const scalar smallDist = mag(smallVec);
103 const point& trackPt = singleParticle.position();
107 // Find next samplePt on/after trackPt. Update samplePt, sampleI
108 if (!nextSample(trackPt, offset, smallDist, samplePt, sampleI))
113 Info<< "trackToBoundary : Reached end : samplePt now:"
114 << samplePt << " sampleI now:" << sampleI << endl;
119 if (mag(samplePt - trackPt) < smallDist)
121 // trackPt corresponds with samplePt. Store and use next samplePt
124 Info<< "trackToBoundary : samplePt corresponds to trackPt : "
125 << " trackPt:" << trackPt << " samplePt:" << samplePt
129 samplingPts.append(trackPt);
130 samplingCells.append(singleParticle.cell());
131 samplingFaces.append(-1);
132 samplingCurveDist.append(mag(trackPt - start_));
134 // go to next samplePt
135 if (!nextSample(trackPt, offset, smallDist, samplePt, sampleI))
140 Info<< "trackToBoundary : Reached end : "
141 << " samplePt now:" << samplePt
142 << " sampleI now:" << sampleI
153 Info<< "Searching along trajectory from "
154 << " trackPt:" << trackPt
155 << " trackCellI:" << singleParticle.cell()
156 << " to:" << samplePt << endl;
159 point oldPos = trackPt;
163 singleParticle.stepFraction() = 0;
164 singleParticle.track(samplePt);
168 Info<< "Result of tracking "
169 << " trackPt:" << trackPt
170 << " trackCellI:" << singleParticle.cell()
171 << " trackFaceI:" << singleParticle.face()
172 << " onBoundary:" << singleParticle.onBoundary()
173 << " samplePt:" << samplePt
174 << " smallDist:" << smallDist
180 !singleParticle.onBoundary()
181 && (mag(trackPt - oldPos) < smallDist)
184 if (singleParticle.onBoundary())
186 //Info<< "trackToBoundary : reached boundary" << endl;
187 if (mag(trackPt - samplePt) < smallDist)
189 //Info<< "trackToBoundary : boundary is also sampling point"
191 // Reached samplePt on boundary
192 samplingPts.append(trackPt);
193 samplingCells.append(singleParticle.cell());
194 samplingFaces.append(facei);
195 samplingCurveDist.append(mag(trackPt - start_));
201 //Info<< "trackToBoundary : reached internal sampling point" << endl;
202 // Reached samplePt in cell or on internal face
203 samplingPts.append(trackPt);
204 samplingCells.append(singleParticle.cell());
205 samplingFaces.append(-1);
206 samplingCurveDist.append(mag(trackPt - start_));
208 // go to next samplePt
213 void Foam::uniformSet::calcSamples
215 DynamicList<point>& samplingPts,
216 DynamicList<label>& samplingCells,
217 DynamicList<label>& samplingFaces,
218 DynamicList<label>& samplingSegments,
219 DynamicList<scalar>& samplingCurveDist
222 // distance vector between sampling points
223 if ((nPoints_ < 2) || (mag(end_ - start_) < SMALL))
225 FatalErrorIn("uniformSet::calcSamples()")
226 << "Incorrect sample specification. Either too few points or"
227 << " start equals end point." << endl
228 << "nPoints:" << nPoints_
229 << " start:" << start_
234 const vector offset = (end_ - start_)/(nPoints_ - 1);
235 const vector normOffset = offset/mag(offset);
236 const vector smallVec = tol*offset;
237 const scalar smallDist = mag(smallVec);
239 // Get all boundary intersections
240 List<pointIndexHit> bHits = searchEngine().intersections
246 point bPoint(GREAT, GREAT, GREAT);
251 bPoint = bHits[0].hitPoint();
252 bFaceI = bHits[0].index();
255 // Get first tracking point. Use bPoint, bFaceI if provided.
258 label trackCellI = -1;
259 label trackFaceI = -1;
274 if (trackCellI == -1)
276 // Line start_ - end_ does not intersect domain at all.
277 // (or is along edge)
278 // Set points and cell/face labels to empty lists
285 samplingPts.append(start_);
286 samplingCells.append(trackCellI);
287 samplingFaces.append(trackFaceI);
288 samplingCurveDist.append(0.0);
292 // Track until hit end of all boundary intersections
295 // current segment number
298 // starting index of current segment in samplePts
299 label startSegmentI = 0;
302 point samplePt = start_;
304 // index in bHits; current boundary intersection
309 // Initialize tracking starting from trackPt
310 Cloud<passiveParticle> particles(mesh(), IDLList<passiveParticle>());
312 passiveParticle singleParticle
319 bool reachedBoundary = trackToBoundary
330 // fill sampleSegments
331 for(label i = samplingPts.size() - 1; i >= startSegmentI; --i)
333 samplingSegments.append(segmentI);
337 if (!reachedBoundary)
341 Info<< "calcSamples : Reached end of samples: "
342 << " samplePt now:" << samplePt
343 << " sampleI now:" << sampleI
350 bool foundValidB = false;
352 while (bHitI < bHits.size())
355 (bHits[bHitI].hitPoint() - singleParticle.position())
360 Info<< "Finding next boundary : "
361 << "bPoint:" << bHits[bHitI].hitPoint()
362 << " tracking:" << singleParticle.position()
367 if (dist > smallDist)
369 // hitpoint is past tracking position
381 // No valid boundary intersection found beyond tracking position
385 // Update starting point for tracking
387 trackPt = pushIn(bPoint, trackFaceI);
388 trackCellI = getBoundaryCell(trackFaceI);
392 startSegmentI = samplingPts.size();
397 void Foam::uniformSet::genSamples()
399 // Storage for sample points
400 DynamicList<point> samplingPts;
401 DynamicList<label> samplingCells;
402 DynamicList<label> samplingFaces;
403 DynamicList<label> samplingSegments;
404 DynamicList<scalar> samplingCurveDist;
415 samplingPts.shrink();
416 samplingCells.shrink();
417 samplingFaces.shrink();
418 samplingSegments.shrink();
419 samplingCurveDist.shrink();
431 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
433 Foam::uniformSet::uniformSet
436 const polyMesh& mesh,
437 meshSearch& searchEngine,
444 sampledSet(name, mesh, searchEngine, axis),
458 Foam::uniformSet::uniformSet
461 const polyMesh& mesh,
462 meshSearch& searchEngine,
463 const dictionary& dict
466 sampledSet(name, mesh, searchEngine, dict),
467 start_(dict.lookup("start")),
468 end_(dict.lookup("end")),
469 nPoints_(readLabel(dict.lookup("nPoints")))
480 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
482 Foam::uniformSet::~uniformSet()
486 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
489 Foam::point Foam::uniformSet::getRefPoint(const List<point>& pts) const
491 // Use start point as reference for 'distance'
496 // ************************************************************************* //