initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / searchableSurface / searchablePlane.C
blobcb2a4e2fb9156075acef451843951b1a90793ee6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "searchablePlane.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "SortableList.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
36 defineTypeNameAndDebug(searchablePlane, 0);
37 addToRunTimeSelectionTable(searchableSurface, searchablePlane, dict);
42 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
44 Foam::pointIndexHit Foam::searchablePlane::findLine
46     const point& start,
47     const point& end
48 ) const
50     pointIndexHit info(true, vector::zero, 0);
52     linePointRef l(start, end);
54     scalar t = lineIntersect(l);
56     if (t < 0 || t > 1)
57     {
58         info.setMiss();
59         info.setIndex(-1);
60     }
61     else
62     {
63         info.setPoint(start+t*l.vec());
64     }
66     return info;
70 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
72 Foam::searchablePlane::searchablePlane
74     const IOobject& io,
75     const point& basePoint,
76     const vector& normal
79     searchableSurface(io),
80     plane(basePoint, normal)
84 Foam::searchablePlane::searchablePlane
86     const IOobject& io,
87     const dictionary& dict
90     searchableSurface(io),
91     plane(dict)
95 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
97 Foam::searchablePlane::~searchablePlane()
101 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
103 const Foam::wordList& Foam::searchablePlane::regions() const
105     if (regions_.empty())
106     {
107         regions_.setSize(1);
108         regions_[0] = "region0";
109     }
110     return regions_;
114 void Foam::searchablePlane::findNearest
116     const pointField& samples,
117     const scalarField& nearestDistSqr,
118     List<pointIndexHit>& info
119 ) const
121     info.setSize(samples.size());
123     forAll(samples, i)
124     {
125         info[i].setPoint(nearestPoint(samples[i]));
127         if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
128         {
129             info[i].setIndex(-1);
130             info[i].setMiss();
131         }
132         else
133         {
134             info[i].setIndex(0);
135             info[i].setHit();
136         }
137     }
141 void Foam::searchablePlane::findLine
143     const pointField& start,
144     const pointField& end,
145     List<pointIndexHit>& info
146 ) const
148     info.setSize(start.size());
150     forAll(start, i)
151     {
152         info[i] = findLine(start[i], end[i]);
153     }
157 void Foam::searchablePlane::findLineAny
159     const pointField& start,
160     const pointField& end,
161     List<pointIndexHit>& info
162 ) const
164     findLine(start, end, info);
168 void Foam::searchablePlane::findLineAll
170     const pointField& start,
171     const pointField& end,
172     List<List<pointIndexHit> >& info
173 ) const
175     List<pointIndexHit> nearestInfo;
176     findLine(start, end, nearestInfo);
178     info.setSize(start.size());
179     forAll(info, pointI)
180     {
181         if (nearestInfo[pointI].hit())
182         {
183             info[pointI].setSize(1);
184             info[pointI][0] = nearestInfo[pointI];
185         }
186         else
187         {
188             info[pointI].clear();
189         }
190     }
194 void Foam::searchablePlane::getRegion
196     const List<pointIndexHit>& info,
197     labelList& region
198 ) const
200     region.setSize(info.size());
201     region = 0;
205 void Foam::searchablePlane::getNormal
207     const List<pointIndexHit>& info,
208     vectorField& n
209 ) const
211     n.setSize(info.size());
212     n = normal();
216 void Foam::searchablePlane::getVolumeType
218     const pointField& points,
219     List<volumeType>& volType
220 ) const
222     FatalErrorIn
223     (
224         "searchableCollection::getVolumeType(const pointField&"
225         ", List<volumeType>&) const"
226     )   << "Volume type not supported for plane."
227         << exit(FatalError);
231 // ************************************************************************* //