FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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