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

searchablePlane.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 "searchablePlane.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "SortableList.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 defineTypeNameAndDebug(searchablePlane, 0);
00037 addToRunTimeSelectionTable(searchableSurface, searchablePlane, dict);
00038 
00039 }
00040 
00041 
00042 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00043 
00044 Foam::pointIndexHit Foam::searchablePlane::findLine
00045 (
00046     const point& start,
00047     const point& end
00048 ) const
00049 {
00050     pointIndexHit info(true, vector::zero, 0);
00051 
00052     linePointRef l(start, end);
00053 
00054     scalar t = lineIntersect(l);
00055 
00056     if (t < 0 || t > 1)
00057     {
00058         info.setMiss();
00059         info.setIndex(-1);
00060     }
00061     else
00062     {
00063         info.setPoint(start+t*l.vec());
00064     }
00065 
00066     return info;
00067 }
00068 
00069 
00070 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00071 
00072 Foam::searchablePlane::searchablePlane
00073 (
00074     const IOobject& io,
00075     const point& basePoint,
00076     const vector& normal
00077 )
00078 :
00079     searchableSurface(io),
00080     plane(basePoint, normal)
00081 {}
00082 
00083 
00084 Foam::searchablePlane::searchablePlane
00085 (
00086     const IOobject& io,
00087     const dictionary& dict
00088 )
00089 :
00090     searchableSurface(io),
00091     plane(dict)
00092 {}
00093 
00094 
00095 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00096 
00097 Foam::searchablePlane::~searchablePlane()
00098 {}
00099 
00100 
00101 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00102 
00103 const Foam::wordList& Foam::searchablePlane::regions() const
00104 {
00105     if (regions_.empty())
00106     {
00107         regions_.setSize(1);
00108         regions_[0] = "region0";
00109     }
00110     return regions_;
00111 }
00112 
00113 
00114 void Foam::searchablePlane::findNearest
00115 (
00116     const pointField& samples,
00117     const scalarField& nearestDistSqr,
00118     List<pointIndexHit>& info
00119 ) const
00120 {
00121     info.setSize(samples.size());
00122 
00123     forAll(samples, i)
00124     {
00125         info[i].setPoint(nearestPoint(samples[i]));
00126 
00127         if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
00128         {
00129             info[i].setIndex(-1);
00130             info[i].setMiss();
00131         }
00132         else
00133         {
00134             info[i].setIndex(0);
00135             info[i].setHit();
00136         }
00137     }
00138 }
00139 
00140 
00141 void Foam::searchablePlane::findLine
00142 (
00143     const pointField& start,
00144     const pointField& end,
00145     List<pointIndexHit>& info
00146 ) const
00147 {
00148     info.setSize(start.size());
00149 
00150     forAll(start, i)
00151     {
00152         info[i] = findLine(start[i], end[i]);
00153     }
00154 }
00155 
00156 
00157 void Foam::searchablePlane::findLineAny
00158 (
00159     const pointField& start,
00160     const pointField& end,
00161     List<pointIndexHit>& info
00162 ) const
00163 {
00164     findLine(start, end, info);
00165 }
00166 
00167 
00168 void Foam::searchablePlane::findLineAll
00169 (
00170     const pointField& start,
00171     const pointField& end,
00172     List<List<pointIndexHit> >& info
00173 ) const
00174 {
00175     List<pointIndexHit> nearestInfo;
00176     findLine(start, end, nearestInfo);
00177 
00178     info.setSize(start.size());
00179     forAll(info, pointI)
00180     {
00181         if (nearestInfo[pointI].hit())
00182         {
00183             info[pointI].setSize(1);
00184             info[pointI][0] = nearestInfo[pointI];
00185         }
00186         else
00187         {
00188             info[pointI].clear();
00189         }
00190     }
00191 }
00192 
00193 
00194 void Foam::searchablePlane::getRegion
00195 (
00196     const List<pointIndexHit>& info,
00197     labelList& region
00198 ) const
00199 {
00200     region.setSize(info.size());
00201     region = 0;
00202 }
00203 
00204 
00205 void Foam::searchablePlane::getNormal
00206 (
00207     const List<pointIndexHit>& info,
00208     vectorField& n
00209 ) const
00210 {
00211     n.setSize(info.size());
00212     n = normal();
00213 }
00214 
00215 
00216 void Foam::searchablePlane::getVolumeType
00217 (
00218     const pointField& points,
00219     List<volumeType>& volType
00220 ) const
00221 {
00222     FatalErrorIn
00223     (
00224         "searchableCollection::getVolumeType(const pointField&"
00225         ", List<volumeType>&) const"
00226     )   << "Volume type not supported for plane."
00227         << exit(FatalError);
00228 }
00229 
00230 
00231 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd