OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

faceOnlySet.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "faceOnlySet.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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00039 
00040 namespace Foam
00041 {
00042     defineTypeNameAndDebug(faceOnlySet, 0);
00043     addToRunTimeSelectionTable(sampledSet, faceOnlySet, word);
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00048 
00049 
00050 // Sample singly connected segment. Returns false if end_ reached.
00051 bool Foam::faceOnlySet::trackToBoundary
00052 (
00053     Particle<passiveParticle>& singleParticle,
00054     DynamicList<point>& samplingPts,
00055     DynamicList<label>& samplingCells,
00056     DynamicList<label>& samplingFaces,
00057     DynamicList<scalar>& samplingCurveDist
00058 ) const
00059 {
00060     // distance vector between sampling points
00061     const vector offset = end_ - start_;
00062     const vector smallVec = tol*offset;
00063     const scalar smallDist = mag(smallVec);
00064 
00065     // Alias
00066     const point& trackPt = singleParticle.position();
00067 
00068     while(true)
00069     {
00070         point oldPoint = trackPt;
00071 
00072         singleParticle.trackToFace(end_);
00073 
00074         if (singleParticle.face() != -1 && mag(oldPoint - trackPt) > smallDist)
00075         {
00076             // Reached face. Sample.
00077             samplingPts.append(trackPt);
00078             samplingCells.append(singleParticle.cell());
00079             samplingFaces.append(singleParticle.face());
00080             samplingCurveDist.append(mag(trackPt - start_));
00081         }
00082 
00083         if (mag(trackPt - end_) < smallDist)
00084         {
00085             // end reached
00086             return false;
00087         }
00088         else if (singleParticle.onBoundary())
00089         {
00090             // Boundary reached.
00091             return true;
00092         }
00093     }
00094 }
00095 
00096 
00097 void Foam::faceOnlySet::calcSamples
00098 (
00099     DynamicList<point>& samplingPts,
00100     DynamicList<label>& samplingCells,
00101     DynamicList<label>& samplingFaces,
00102     DynamicList<label>& samplingSegments,
00103     DynamicList<scalar>& samplingCurveDist
00104 ) const
00105 {
00106     // distance vector between sampling points
00107     if (mag(end_ - start_) < SMALL)
00108     {
00109         FatalErrorIn("faceOnlySet::calcSamples()")
00110             << "Incorrect sample specification :"
00111             << " start equals end point." << endl
00112             << "  start:" << start_
00113             << "  end:" << end_
00114             << exit(FatalError);
00115     }
00116 
00117     const vector offset = (end_ - start_);
00118     const vector normOffset = offset/mag(offset);
00119     const vector smallVec = tol*offset;
00120     const scalar smallDist = mag(smallVec);
00121 
00122 
00123     // Get all boundary intersections
00124     List<pointIndexHit> bHits = searchEngine().intersections
00125     (
00126         start_ - smallVec,
00127         end_ + smallVec
00128     );
00129 
00130     point bPoint(GREAT, GREAT, GREAT);
00131     label bFaceI = -1;
00132 
00133     if (bHits.size())
00134     {
00135         bPoint = bHits[0].hitPoint();
00136         bFaceI = bHits[0].index();
00137     }
00138 
00139     // Get first tracking point. Use bPoint, bFaceI if provided.
00140 
00141     point trackPt;
00142     label trackCellI = -1;
00143     label trackFaceI = -1;
00144 
00145     //Info<< "before getTrackingPoint : bPoint:" << bPoint
00146     //    << " bFaceI:" << bFaceI << endl;
00147 
00148     getTrackingPoint
00149     (
00150         offset,
00151         start_,
00152         bPoint,
00153         bFaceI,
00154 
00155         trackPt,
00156         trackCellI,
00157         trackFaceI
00158     );
00159 
00160     //Info<< "after getTrackingPoint : "
00161     //    << " trackPt:" << trackPt
00162     //    << " trackCellI:" << trackCellI
00163     //    << " trackFaceI:" << trackFaceI
00164     //    << endl;
00165 
00166     if (trackCellI == -1)
00167     {
00168         // Line start_ - end_ does not intersect domain at all.
00169         // (or is along edge)
00170         // Set points and cell/face labels to empty lists
00171         //Info<< "calcSamples : Both start_ and end_ outside domain"
00172         //    << endl;
00173 
00174         return;
00175     }
00176 
00177     if (trackFaceI == -1)
00178     {
00179         // No boundary face. Check for nearish internal face
00180         trackFaceI = findNearFace(trackCellI, trackPt, smallDist);
00181     }
00182 
00183     //Info<< "calcSamples : got first point to track from :"
00184     //    << "  trackPt:" << trackPt
00185     //    << "  trackCell:" << trackCellI
00186     //    << "  trackFace:" << trackFaceI
00187     //    << endl;
00188 
00189     //
00190     // Track until hit end of all boundary intersections
00191     //
00192 
00193     // current segment number
00194     label segmentI = 0;
00195 
00196     // starting index of current segment in samplePts
00197     label startSegmentI = 0;
00198 
00199     // index in bHits; current boundary intersection
00200     label bHitI = 1;
00201 
00202     while(true)
00203     {
00204         if (trackFaceI != -1)
00205         {
00206             //Info<< "trackPt:" << trackPt << " on face so use." << endl;
00207             samplingPts.append(trackPt);
00208             samplingCells.append(trackCellI);
00209             samplingFaces.append(trackFaceI);
00210             samplingCurveDist.append(mag(trackPt - start_));
00211         }
00212 
00213         // Initialize tracking starting from trackPt
00214         Cloud<passiveParticle> particles(mesh(), IDLList<passiveParticle>());
00215 
00216         passiveParticle singleParticle
00217         (
00218             particles,
00219             trackPt,
00220             trackCellI
00221         );
00222 
00223         bool reachedBoundary = trackToBoundary
00224         (
00225             singleParticle,
00226             samplingPts,
00227             samplingCells,
00228             samplingFaces,
00229             samplingCurveDist
00230         );
00231 
00232         // fill sampleSegments
00233         for(label i = samplingPts.size() - 1; i >= startSegmentI; --i)
00234         {
00235             samplingSegments.append(segmentI);
00236         }
00237 
00238 
00239         if (!reachedBoundary)
00240         {
00241             //Info<< "calcSamples : Reached end of samples: "
00242             //    << "  samplePt now:" << singleParticle.position()
00243             //    << endl;
00244             break;
00245         }
00246 
00247 
00248         // Go past boundary intersection where tracking stopped
00249         // Use coordinate comparison instead of face comparison for
00250         // accuracy reasons
00251 
00252         bool foundValidB = false;
00253 
00254         while (bHitI < bHits.size())
00255         {
00256             scalar dist =
00257                 (bHits[bHitI].hitPoint() - singleParticle.position())
00258               & normOffset;
00259 
00260             //Info<< "Finding next boundary : "
00261             //    << "bPoint:" << bHits[bHitI].hitPoint()
00262             //    << "  tracking:" << singleParticle.position()
00263             //    << "  dist:" << dist
00264             //    << endl;
00265 
00266             if (dist > smallDist)
00267             {
00268                 // hitpoint is past tracking position
00269                 foundValidB = true;
00270                 break;
00271             }
00272             else
00273             {
00274                 bHitI++;
00275             }
00276         }
00277 
00278         if (!foundValidB)
00279         {
00280             // No valid boundary intersection found beyond tracking position
00281             break;
00282         }
00283 
00284         // Update starting point for tracking
00285         trackFaceI = bHits[bHitI].index();
00286         trackPt = pushIn(bHits[bHitI].hitPoint(), trackFaceI);
00287         trackCellI = getBoundaryCell(trackFaceI);
00288 
00289         segmentI++;
00290 
00291         startSegmentI = samplingPts.size();
00292     }
00293 }
00294 
00295 
00296 void Foam::faceOnlySet::genSamples()
00297 {
00298     // Storage for sample points
00299     DynamicList<point> samplingPts;
00300     DynamicList<label> samplingCells;
00301     DynamicList<label> samplingFaces;
00302     DynamicList<label> samplingSegments;
00303     DynamicList<scalar> samplingCurveDist;
00304 
00305     calcSamples
00306     (
00307         samplingPts,
00308         samplingCells,
00309         samplingFaces,
00310         samplingSegments,
00311         samplingCurveDist
00312     );
00313 
00314     samplingPts.shrink();
00315     samplingCells.shrink();
00316     samplingFaces.shrink();
00317     samplingSegments.shrink();
00318     samplingCurveDist.shrink();
00319 
00320     // Copy into *this
00321     setSamples
00322     (
00323         samplingPts,
00324         samplingCells,
00325         samplingFaces,
00326         samplingSegments,
00327         samplingCurveDist
00328     );
00329 }
00330 
00331 
00332 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00333 
00334 Foam::faceOnlySet::faceOnlySet
00335 (
00336     const word& name,
00337     const polyMesh& mesh,
00338     meshSearch& searchEngine,
00339     const word& axis,
00340     const point& start,
00341     const point& end
00342 )
00343 :
00344     sampledSet(name, mesh, searchEngine, axis),
00345     start_(start),
00346     end_(end)
00347 {
00348     genSamples();
00349 
00350     if (debug)
00351     {
00352         write(Info);
00353     }
00354 }
00355 
00356 
00357 Foam::faceOnlySet::faceOnlySet
00358 (
00359     const word& name,
00360     const polyMesh& mesh,
00361     meshSearch& searchEngine,
00362     const dictionary& dict
00363 )
00364 :
00365     sampledSet(name, mesh, searchEngine, dict),
00366     start_(dict.lookup("start")),
00367     end_(dict.lookup("end"))
00368 {
00369     genSamples();
00370 
00371     if (debug)
00372     {
00373         write(Info);
00374     }
00375 }
00376 
00377 
00378 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00379 
00380 Foam::faceOnlySet::~faceOnlySet()
00381 {}
00382 
00383 
00384 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00385 
00386 Foam::point Foam::faceOnlySet::getRefPoint(const List<point>& pts) const
00387 {
00388     return start_;
00389 }
00390 
00391 
00392 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd