1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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/>.
25 Finds nearest face and vertex.
27 \*---------------------------------------------------------------------------*/
32 #include "MeshedSurfaces.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 int main(int argc, char *argv[])
42 argList::noParallel();
43 argList::validArgs.append("surfaceFile");
44 argList::addOption("x", "X", "The point x-coordinate (if non-zero)");
45 argList::addOption("y", "Y", "The point y-coordinate (if non-zero)");
46 argList::addOption("z", "Z", "The point y-coordinate (if non-zero)");
48 argList args(argc, argv);
52 args.optionLookupOrDefault<scalar>("x", 0),
53 args.optionLookupOrDefault<scalar>("y", 0),
54 args.optionLookupOrDefault<scalar>("z", 0)
56 Info<< "Looking for nearest face/vertex to " << samplePt << endl;
59 Info<< "Reading surf ..." << endl;
60 meshedSurface surf1(args[1]);
66 const pointField& localPoints = surf1.localPoints();
69 scalar minDist = GREAT;
71 forAll(localPoints, pointI)
73 const scalar dist = mag(localPoints[pointI] - samplePt);
81 Info<< "Nearest vertex:" << nl
82 << " index :" << minIndex << " (in localPoints)" << nl
83 << " index :" << surf1.meshPoints()[minIndex]
84 << " (in points)" << nl
85 << " coordinates:" << localPoints[minIndex] << nl
92 const pointField& points = surf1.points();
99 const point centre = surf1[faceI].centre(points);
101 const scalar dist = mag(centre - samplePt);
109 const face& f = surf1[minIndex];
111 Info<< "Face with nearest centre:" << nl
112 << " index :" << minIndex << nl
113 << " centre :" << f.centre(points) << nl
114 << " face :" << f << nl
115 << " vertex coords:\n";
118 Info<< " " << points[f[fp]] << "\n";
123 Info<< "End\n" << endl;
129 // ************************************************************************* //