ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / meshTools / searchableSurface / searchablePlane.C
blob0c08fa234d0053ae7dc08d3a0444517ee1ae3413
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "searchablePlane.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "SortableList.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
35 defineTypeNameAndDebug(searchablePlane, 0);
36 addToRunTimeSelectionTable(searchableSurface, searchablePlane, dict);
41 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
43 Foam::pointIndexHit Foam::searchablePlane::findLine
45     const point& start,
46     const point& end
47 ) const
49     pointIndexHit info(true, vector::zero, 0);
51     linePointRef l(start, end);
53     scalar t = lineIntersect(l);
55     if (t < 0 || t > 1)
56     {
57         info.setMiss();
58         info.setIndex(-1);
59     }
60     else
61     {
62         info.setPoint(start+t*l.vec());
63     }
65     return info;
69 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
71 Foam::searchablePlane::searchablePlane
73     const IOobject& io,
74     const point& basePoint,
75     const vector& normal
78     searchableSurface(io),
79     plane(basePoint, normal)
83 Foam::searchablePlane::searchablePlane
85     const IOobject& io,
86     const dictionary& dict
89     searchableSurface(io),
90     plane(dict)
94 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
96 Foam::searchablePlane::~searchablePlane()
100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
102 const Foam::wordList& Foam::searchablePlane::regions() const
104     if (regions_.empty())
105     {
106         regions_.setSize(1);
107         regions_[0] = "region0";
108     }
109     return regions_;
113 void Foam::searchablePlane::findNearest
115     const pointField& samples,
116     const scalarField& nearestDistSqr,
117     List<pointIndexHit>& info
118 ) const
120     info.setSize(samples.size());
122     forAll(samples, i)
123     {
124         info[i].setPoint(nearestPoint(samples[i]));
126         if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
127         {
128             info[i].setIndex(-1);
129             info[i].setMiss();
130         }
131         else
132         {
133             info[i].setIndex(0);
134             info[i].setHit();
135         }
136     }
140 void Foam::searchablePlane::findLine
142     const pointField& start,
143     const pointField& end,
144     List<pointIndexHit>& info
145 ) const
147     info.setSize(start.size());
149     forAll(start, i)
150     {
151         info[i] = findLine(start[i], end[i]);
152     }
156 void Foam::searchablePlane::findLineAny
158     const pointField& start,
159     const pointField& end,
160     List<pointIndexHit>& info
161 ) const
163     findLine(start, end, info);
167 void Foam::searchablePlane::findLineAll
169     const pointField& start,
170     const pointField& end,
171     List<List<pointIndexHit> >& info
172 ) const
174     List<pointIndexHit> nearestInfo;
175     findLine(start, end, nearestInfo);
177     info.setSize(start.size());
178     forAll(info, pointI)
179     {
180         if (nearestInfo[pointI].hit())
181         {
182             info[pointI].setSize(1);
183             info[pointI][0] = nearestInfo[pointI];
184         }
185         else
186         {
187             info[pointI].clear();
188         }
189     }
193 void Foam::searchablePlane::getRegion
195     const List<pointIndexHit>& info,
196     labelList& region
197 ) const
199     region.setSize(info.size());
200     region = 0;
204 void Foam::searchablePlane::getNormal
206     const List<pointIndexHit>& info,
207     vectorField& n
208 ) const
210     n.setSize(info.size());
211     n = normal();
215 void Foam::searchablePlane::getVolumeType
217     const pointField& points,
218     List<volumeType>& volType
219 ) const
221     FatalErrorIn
222     (
223         "searchableCollection::getVolumeType(const pointField&"
224         ", List<volumeType>&) const"
225     )   << "Volume type not supported for plane."
226         << exit(FatalError);
230 // ************************************************************************* //