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 "faceOnlySet.H"
27 #include "meshSearch.H"
28 #include "DynamicList.H"
32 #include "passiveParticle.H"
35 #include "addToRunTimeSelectionTable.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(faceOnlySet, 0);
42 addToRunTimeSelectionTable(sampledSet, faceOnlySet, word);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 // Sample singly connected segment. Returns false if end_ reached.
50 bool Foam::faceOnlySet::trackToBoundary
52 Particle<passiveParticle>& singleParticle,
53 DynamicList<point>& samplingPts,
54 DynamicList<label>& samplingCells,
55 DynamicList<label>& samplingFaces,
56 DynamicList<scalar>& samplingCurveDist
59 // distance vector between sampling points
60 const vector offset = end_ - start_;
61 const vector smallVec = tol*offset;
62 const scalar smallDist = mag(smallVec);
65 const point& trackPt = singleParticle.position();
69 point oldPoint = trackPt;
71 singleParticle.trackToFace(end_);
73 if (singleParticle.face() != -1 && mag(oldPoint - trackPt) > smallDist)
75 // Reached face. Sample.
76 samplingPts.append(trackPt);
77 samplingCells.append(singleParticle.cell());
78 samplingFaces.append(singleParticle.face());
79 samplingCurveDist.append(mag(trackPt - start_));
82 if (mag(trackPt - end_) < smallDist)
87 else if (singleParticle.onBoundary())
96 void Foam::faceOnlySet::calcSamples
98 DynamicList<point>& samplingPts,
99 DynamicList<label>& samplingCells,
100 DynamicList<label>& samplingFaces,
101 DynamicList<label>& samplingSegments,
102 DynamicList<scalar>& samplingCurveDist
105 // distance vector between sampling points
106 if (mag(end_ - start_) < SMALL)
108 FatalErrorIn("faceOnlySet::calcSamples()")
109 << "Incorrect sample specification :"
110 << " start equals end point." << endl
111 << " start:" << start_
116 const vector offset = (end_ - start_);
117 const vector normOffset = offset/mag(offset);
118 const vector smallVec = tol*offset;
119 const scalar smallDist = mag(smallVec);
122 // Get all boundary intersections
123 List<pointIndexHit> bHits = searchEngine().intersections
129 point bPoint(GREAT, GREAT, GREAT);
134 bPoint = bHits[0].hitPoint();
135 bFaceI = bHits[0].index();
138 // Get first tracking point. Use bPoint, bFaceI if provided.
141 label trackCellI = -1;
142 label trackFaceI = -1;
144 //Info<< "before getTrackingPoint : bPoint:" << bPoint
145 // << " bFaceI:" << bFaceI << endl;
159 //Info<< "after getTrackingPoint : "
160 // << " trackPt:" << trackPt
161 // << " trackCellI:" << trackCellI
162 // << " trackFaceI:" << trackFaceI
165 if (trackCellI == -1)
167 // Line start_ - end_ does not intersect domain at all.
168 // (or is along edge)
169 // Set points and cell/face labels to empty lists
170 //Info<< "calcSamples : Both start_ and end_ outside domain"
176 if (trackFaceI == -1)
178 // No boundary face. Check for nearish internal face
179 trackFaceI = findNearFace(trackCellI, trackPt, smallDist);
182 //Info<< "calcSamples : got first point to track from :"
183 // << " trackPt:" << trackPt
184 // << " trackCell:" << trackCellI
185 // << " trackFace:" << trackFaceI
189 // Track until hit end of all boundary intersections
192 // current segment number
195 // starting index of current segment in samplePts
196 label startSegmentI = 0;
198 // index in bHits; current boundary intersection
203 if (trackFaceI != -1)
205 //Info<< "trackPt:" << trackPt << " on face so use." << endl;
206 samplingPts.append(trackPt);
207 samplingCells.append(trackCellI);
208 samplingFaces.append(trackFaceI);
209 samplingCurveDist.append(mag(trackPt - start_));
212 // Initialize tracking starting from trackPt
213 Cloud<passiveParticle> particles(mesh(), IDLList<passiveParticle>());
215 passiveParticle singleParticle
222 bool reachedBoundary = trackToBoundary
231 // fill sampleSegments
232 for(label i = samplingPts.size() - 1; i >= startSegmentI; --i)
234 samplingSegments.append(segmentI);
238 if (!reachedBoundary)
240 //Info<< "calcSamples : Reached end of samples: "
241 // << " samplePt now:" << singleParticle.position()
247 // Go past boundary intersection where tracking stopped
248 // Use coordinate comparison instead of face comparison for
251 bool foundValidB = false;
253 while (bHitI < bHits.size())
256 (bHits[bHitI].hitPoint() - singleParticle.position())
259 //Info<< "Finding next boundary : "
260 // << "bPoint:" << bHits[bHitI].hitPoint()
261 // << " tracking:" << singleParticle.position()
262 // << " dist:" << dist
265 if (dist > smallDist)
267 // hitpoint is past tracking position
279 // No valid boundary intersection found beyond tracking position
283 // Update starting point for tracking
284 trackFaceI = bHits[bHitI].index();
285 trackPt = pushIn(bHits[bHitI].hitPoint(), trackFaceI);
286 trackCellI = getBoundaryCell(trackFaceI);
290 startSegmentI = samplingPts.size();
295 void Foam::faceOnlySet::genSamples()
297 // Storage for sample points
298 DynamicList<point> samplingPts;
299 DynamicList<label> samplingCells;
300 DynamicList<label> samplingFaces;
301 DynamicList<label> samplingSegments;
302 DynamicList<scalar> samplingCurveDist;
313 samplingPts.shrink();
314 samplingCells.shrink();
315 samplingFaces.shrink();
316 samplingSegments.shrink();
317 samplingCurveDist.shrink();
331 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
333 Foam::faceOnlySet::faceOnlySet
336 const polyMesh& mesh,
337 meshSearch& searchEngine,
343 sampledSet(name, mesh, searchEngine, axis),
356 Foam::faceOnlySet::faceOnlySet
359 const polyMesh& mesh,
360 meshSearch& searchEngine,
361 const dictionary& dict
364 sampledSet(name, mesh, searchEngine, dict),
365 start_(dict.lookup("start")),
366 end_(dict.lookup("end"))
377 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
379 Foam::faceOnlySet::~faceOnlySet()
383 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
385 Foam::point Foam::faceOnlySet::getRefPoint(const List<point>& pts) const
391 // ************************************************************************* //