1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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 "primitiveMesh.H"
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 bool Foam::primitiveMesh::pointInCellBB
53 bb.min() - tol*bb.span(),
54 bb.max() + tol*bb.span()
58 return bb.contains(p);
62 bool Foam::primitiveMesh::pointInCell(const point& p, label celli) const
64 const labelList& f = cells()[celli];
65 const labelList& owner = this->faceOwner();
66 const vectorField& cf = faceCentres();
67 const vectorField& Sf = faceAreas();
73 label nFace = f[facei];
74 vector proj = p - cf[nFace];
75 vector normal = Sf[nFace];
76 if (owner[nFace] != celli)
80 inCell = inCell && ((normal & proj) <= 0);
87 Foam::label Foam::primitiveMesh::findNearestCell(const point& location) const
89 const vectorField& centres = cellCentres();
91 label nearestCelli = 0;
92 scalar minProximity = magSqr(centres[0] - location);
94 for (label celli = 1; celli < centres.size(); celli++)
96 scalar proximity = magSqr(centres[celli] - location);
98 if (proximity < minProximity)
100 nearestCelli = celli;
101 minProximity = proximity;
109 Foam::label Foam::primitiveMesh::findCell(const point& location) const
116 // Find the nearest cell centre to this location
117 label celli = findNearestCell(location);
119 // If point is in the nearest cell return
120 if (pointInCell(location, celli))
124 else // point is not in the nearest cell so search all cells
126 bool cellFound = false;
129 while ((!cellFound) && (n < nCells()))
131 if (pointInCell(location, n))
153 // ************************************************************************* //