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

curveSet.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 "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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00039 
00040 namespace Foam
00041 {
00042     defineTypeNameAndDebug(curveSet, 0);
00043     addToRunTimeSelectionTable(sampledSet, curveSet, word);
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00048 
00049 // Sample till hits boundary.
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     // Alias
00061     const point& trackPt = singleParticle.position();
00062 
00063     while(true)
00064     {
00065         // Local geometry info
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             //Info<< "trackToBoundary : reached boundary"
00085             //    << "  trackPt:" << trackPt << endl;
00086             if
00087             (
00088                 mag(trackPt - sampleCoords_[sampleI+1])
00089               < smallDist
00090             )
00091             {
00092                 // Reached samplePt on boundary
00093                 //Info<< "trackToBoundary : boundary. also sampling."
00094                 //    << "  trackPt:" << trackPt << " sampleI+1:" << sampleI+1
00095                 //    << endl;
00096                 samplingPts.append(trackPt);
00097                 samplingCells.append(singleParticle.cell());
00098                 samplingFaces.append(facei);
00099 
00100                 // trackPt is at sampleI+1
00101                 samplingCurveDist.append(1.0*(sampleI+1));
00102             }
00103             return true;
00104         }
00105 
00106         // Reached samplePt in cell
00107         samplingPts.append(trackPt);
00108         samplingCells.append(singleParticle.cell());
00109         samplingFaces.append(-1);
00110 
00111         // Convert trackPt to fraction inbetween sampleI and sampleI+1
00112         scalar dist =
00113             mag(trackPt - sampleCoords_[sampleI])
00114           / mag(sampleCoords_[sampleI+1] - sampleCoords_[sampleI]);
00115         samplingCurveDist.append(sampleI + dist);
00116 
00117         // go to next samplePt
00118         sampleI++;
00119 
00120         if (sampleI == sampleCoords_.size() - 1)
00121         {
00122             // no more samples.
00123             //Info<< "trackToBoundary : Reached end : sampleI now:" << sampleI
00124             //    << endl;
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     // Check sampling points
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     // current segment number
00164     label segmentI = 0;
00165 
00166     // starting index of current segment in samplePts
00167     label startSegmentI = 0;
00168 
00169     label sampleI = 0;
00170 
00171     point lastSample(GREAT, GREAT, GREAT);
00172     while(true)
00173     {
00174         // Get boundary intersection
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             // Get all boundary intersections
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             // Get tracking point
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                 //Info<< "calcSamples : getTrackingPoint returned valid sample "
00220                 //    << "  trackPt:" << trackPt
00221                 //    << "  trackFaceI:" << trackFaceI
00222                 //    << "  trackCellI:" << trackCellI
00223                 //    << "  sampleI:" << sampleI
00224                 //    << "  dist:" << dist
00225                 //    << endl;
00226 
00227                 samplingPts.append(trackPt);
00228                 samplingCells.append(trackCellI);
00229                 samplingFaces.append(trackFaceI);
00230 
00231                 // Convert sampling position to unique curve parameter. Get
00232                 // fraction of distance between sampleI and sampleI+1.
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                 // No intersection found. Go to next point
00244                 sampleI++;
00245             }
00246         } while((trackCellI == -1) && (sampleI < sampleCoords_.size() - 1));
00247 
00248         if (sampleI == sampleCoords_.size() - 1)
00249         {
00250             //Info<< "calcSamples : Reached end of samples: "
00251             //    << "  sampleI now:" << sampleI
00252             //    << endl;
00253             break;
00254         }
00255 
00256         //
00257         // Segment sampleI .. sampleI+1 intersected by domain
00258         //
00259 
00260         // Initialize tracking starting from sampleI
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         // fill sampleSegments
00281         for(label i = samplingPts.size() - 1; i >= startSegmentI; --i)
00282         {
00283             samplingSegments.append(segmentI);
00284         }
00285 
00286         if (!bReached)
00287         {
00288             //Info<< "calcSamples : Reached end of samples: "
00289             //    << "  sampleI now:" << sampleI
00290             //    << endl;
00291             break;
00292         }
00293         lastSample = singleParticle.position();
00294 
00295 
00296         // Find next boundary.
00297         sampleI++;
00298 
00299         if (sampleI == sampleCoords_.size() - 1)
00300         {
00301             //Info<< "calcSamples : Reached end of samples: "
00302             //    << "  sampleI now:" << sampleI
00303             //    << endl;
00304             break;
00305         }
00306 
00307         segmentI++;
00308 
00309         startSegmentI = samplingPts.size();
00310     }
00311 }
00312 
00313 
00314 void Foam::curveSet::genSamples()
00315 {
00316     // Storage for sample points
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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00393 
00394 Foam::curveSet::~curveSet()
00395 {}
00396 
00397 
00398 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00399 
00400 Foam::point Foam::curveSet::getRefPoint(const List<point>& pts) const
00401 {
00402     if (pts.size())
00403     {
00404         // Use first samplePt as starting point
00405         return pts[0];
00406     }
00407     else
00408     {
00409         return vector::zero;
00410     }
00411 }
00412 
00413 
00414 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd