OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceFind.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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Finds nearest triangle and vertex.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "triSurface.H"
00031 #include "argList.H"
00032 #include "OFstream.H"
00033 
00034 #ifndef namespaceFoam
00035 #define namespaceFoam
00036     using namespace Foam;
00037 #endif
00038 
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 // Main program:
00042 
00043 int main(int argc, char *argv[])
00044 {
00045     argList::noParallel();
00046     argList::validArgs.clear();
00047     argList::validOptions.insert("x", "X");
00048     argList::validOptions.insert("y", "Y");
00049     argList::validOptions.insert("z", "Z");
00050 
00051     argList::validArgs.append("surface file");
00052 
00053     argList args(argc, argv);
00054 
00055     point samplePt
00056     (
00057         args.optionRead<scalar>("x"),
00058         args.optionRead<scalar>("y"),
00059         args.optionRead<scalar>("z")
00060     );
00061     Info<< "Looking for nearest face/vertex to " << samplePt << endl;
00062 
00063 
00064     Info<< "Reading surf1 ..." << endl;
00065     triSurface surf1(args.additionalArgs()[0]);
00066 
00067     //
00068     // Nearest vertex
00069     //
00070 
00071     const pointField& localPoints = surf1.localPoints();
00072 
00073     label minIndex = -1;
00074     scalar minDist = GREAT;
00075 
00076     forAll(localPoints, pointI)
00077     {
00078         const scalar dist = mag(localPoints[pointI] - samplePt);
00079         if (dist < minDist)
00080         {
00081             minDist = dist;
00082             minIndex = pointI;
00083         }
00084     }
00085 
00086     Info<< "Nearest vertex:" << endl
00087         << "    index      :" << minIndex << " (in localPoints)" << endl
00088         << "    index      :" << surf1.meshPoints()[minIndex]
00089         << " (in points)" << endl
00090         << "    coordinates:" << localPoints[minIndex] << endl
00091         << endl;
00092 
00093     //
00094     // Nearest face
00095     //
00096 
00097     const pointField& points = surf1.points();
00098 
00099     minIndex = -1;
00100     minDist = GREAT;
00101 
00102     forAll(surf1, faceI)
00103     {
00104         const labelledTri& f = surf1[faceI];
00105         const point centre = f.centre(points);
00106 
00107         const scalar dist = mag(centre - samplePt);
00108         if (dist < minDist)
00109         {
00110             minDist = dist;
00111             minIndex = faceI;
00112         }
00113     }
00114 
00115     const labelledTri& f = surf1[minIndex];
00116 
00117     Info<< "Face with nearest centre:" << endl
00118         << "    index        :" << minIndex << endl
00119         << "    centre       :" << f.centre(points) << endl
00120         << "    face         :" << f << endl
00121         << "    vertex coords:" << points[f[0]] << " "
00122         << points[f[1]] << " " << points[f[2]] << endl
00123         << endl;
00124 
00125 
00126     Info << "End\n" << endl;
00127 
00128     return 0;
00129 }
00130 
00131 
00132 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd