1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "faceOnlySet.H"
28 #include "meshSearch.H"
29 #include "DynamicList.H"
33 #include "passiveParticle.H"
36 #include "addToRunTimeSelectionTable.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(faceOnlySet, 0);
43 addToRunTimeSelectionTable(sampledSet, faceOnlySet, word);
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 // Sample singly connected segment. Returns false if end_ reached.
51 bool Foam::faceOnlySet::trackToBoundary
53 Particle<passiveParticle>& singleParticle,
54 DynamicList<point>& samplingPts,
55 DynamicList<label>& samplingCells,
56 DynamicList<label>& samplingFaces,
57 DynamicList<scalar>& samplingCurveDist
60 // distance vector between sampling points
61 const vector offset = end_ - start_;
62 const vector smallVec = tol*offset;
63 const scalar smallDist = mag(smallVec);
66 const point& trackPt = singleParticle.position();
70 point oldPoint = trackPt;
72 singleParticle.trackToFace(end_);
74 if (singleParticle.face() != -1 && mag(oldPoint - trackPt) > smallDist)
76 // Reached face. Sample.
77 samplingPts.append(trackPt);
78 samplingCells.append(singleParticle.cell());
79 samplingFaces.append(singleParticle.face());
80 samplingCurveDist.append(mag(trackPt - start_));
83 if (mag(trackPt - end_) < smallDist)
88 else if (singleParticle.onBoundary())
97 void Foam::faceOnlySet::calcSamples
99 DynamicList<point>& samplingPts,
100 DynamicList<label>& samplingCells,
101 DynamicList<label>& samplingFaces,
102 DynamicList<label>& samplingSegments,
103 DynamicList<scalar>& samplingCurveDist
106 // distance vector between sampling points
107 if (mag(end_ - start_) < SMALL)
109 FatalErrorIn("faceOnlySet::calcSamples()")
110 << "Incorrect sample specification :"
111 << " start equals end point." << endl
112 << " start:" << start_
117 const vector offset = (end_ - start_);
118 const vector normOffset = offset/mag(offset);
119 const vector smallVec = tol*offset;
120 const scalar smallDist = mag(smallVec);
123 // Get all boundary intersections
124 List<pointIndexHit> bHits = searchEngine().intersections
130 point bPoint(GREAT, GREAT, GREAT);
135 bPoint = bHits[0].hitPoint();
136 bFaceI = bHits[0].index();
139 // Get first tracking point. Use bPoint, bFaceI if provided.
142 label trackCellI = -1;
143 label trackFaceI = -1;
145 //Info<< "before getTrackingPoint : bPoint:" << bPoint
146 // << " bFaceI:" << bFaceI << endl;
160 //Info<< "after getTrackingPoint : "
161 // << " trackPt:" << trackPt
162 // << " trackCellI:" << trackCellI
163 // << " trackFaceI:" << trackFaceI
166 if (trackCellI == -1)
168 // Line start_ - end_ does not intersect domain at all.
169 // (or is along edge)
170 // Set points and cell/face labels to empty lists
171 //Info<< "calcSamples : Both start_ and end_ outside domain"
177 if (trackFaceI == -1)
179 // No boundary face. Check for nearish internal face
180 trackFaceI = findNearFace(trackCellI, trackPt, smallDist);
183 //Info<< "calcSamples : got first point to track from :"
184 // << " trackPt:" << trackPt
185 // << " trackCell:" << trackCellI
186 // << " trackFace:" << trackFaceI
190 // Track until hit end of all boundary intersections
193 // current segment number
196 // starting index of current segment in samplePts
197 label startSegmentI = 0;
199 // index in bHits; current boundary intersection
204 if (trackFaceI != -1)
206 //Info<< "trackPt:" << trackPt << " on face so use." << endl;
207 samplingPts.append(trackPt);
208 samplingCells.append(trackCellI);
209 samplingFaces.append(trackFaceI);
210 samplingCurveDist.append(mag(trackPt - start_));
213 // Initialize tracking starting from trackPt
214 Cloud<passiveParticle> particles(mesh(), IDLList<passiveParticle>());
216 passiveParticle singleParticle
223 bool reachedBoundary = trackToBoundary
232 // fill sampleSegments
233 for(label i = samplingPts.size() - 1; i >= startSegmentI; --i)
235 samplingSegments.append(segmentI);
239 if (!reachedBoundary)
241 //Info<< "calcSamples : Reached end of samples: "
242 // << " samplePt now:" << singleParticle.position()
248 // Go past boundary intersection where tracking stopped
249 // Use coordinate comparison instead of face comparison for
252 bool foundValidB = false;
254 while (bHitI < bHits.size())
257 (bHits[bHitI].hitPoint() - singleParticle.position())
260 //Info<< "Finding next boundary : "
261 // << "bPoint:" << bHits[bHitI].hitPoint()
262 // << " tracking:" << singleParticle.position()
263 // << " dist:" << dist
266 if (dist > smallDist)
268 // hitpoint is past tracking position
280 // No valid boundary intersection found beyond tracking position
284 // Update starting point for tracking
285 trackFaceI = bHits[bHitI].index();
286 trackPt = pushIn(bHits[bHitI].hitPoint(), trackFaceI);
287 trackCellI = getBoundaryCell(trackFaceI);
291 startSegmentI = samplingPts.size();
296 void Foam::faceOnlySet::genSamples()
298 // Storage for sample points
299 DynamicList<point> samplingPts;
300 DynamicList<label> samplingCells;
301 DynamicList<label> samplingFaces;
302 DynamicList<label> samplingSegments;
303 DynamicList<scalar> samplingCurveDist;
314 samplingPts.shrink();
315 samplingCells.shrink();
316 samplingFaces.shrink();
317 samplingSegments.shrink();
318 samplingCurveDist.shrink();
332 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
334 Foam::faceOnlySet::faceOnlySet
337 const polyMesh& mesh,
338 meshSearch& searchEngine,
344 sampledSet(name, mesh, searchEngine, axis),
357 Foam::faceOnlySet::faceOnlySet
360 const polyMesh& mesh,
361 meshSearch& searchEngine,
362 const dictionary& dict
365 sampledSet(name, mesh, searchEngine, dict),
366 start_(dict.lookup("start")),
367 end_(dict.lookup("end"))
378 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
380 Foam::faceOnlySet::~faceOnlySet()
384 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
386 Foam::point Foam::faceOnlySet::getRefPoint(const List<point>& pts) const
392 // ************************************************************************* //