FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     surfaceFind
00026 
00027 Description
00028     Finds nearest triangle and vertex.
00029 
00030 Usage
00031 
00032     - surfaceFind [OPTIONS] <Foam surface file>
00033 
00034     @param <Foam surface file> \n
00035     @todo Detailed description of argument.
00036 
00037     @param -x <X>\n
00038     X-coordinate of sample point.
00039 
00040     @param -y <Y>\n
00041     Y-coordinate of sample point.
00042 
00043     @param -z <Z>\n
00044     Z-coordinate of sample point.
00045 
00046     @param -case <dir>\n
00047     Case directory.
00048 
00049     @param -help \n
00050     Display help message.
00051 
00052     @param -doc \n
00053     Display Doxygen API documentation page for this application.
00054 
00055     @param -srcDoc \n
00056     Display Doxygen source documentation page for this application.
00057 
00058 \*---------------------------------------------------------------------------*/
00059 
00060 #include <triSurface/triSurface.H>
00061 #include <OpenFOAM/argList.H>
00062 #include <OpenFOAM/OFstream.H>
00063 
00064 #ifndef namespaceFoam
00065 #define namespaceFoam
00066     using namespace Foam;
00067 #endif
00068 
00069 
00070 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00071 // Main program:
00072 
00073 int main(int argc, char *argv[])
00074 {
00075     argList::noParallel();
00076     argList::validArgs.clear();
00077     argList::validOptions.insert("x", "X");
00078     argList::validOptions.insert("y", "Y");
00079     argList::validOptions.insert("z", "Z");
00080 
00081     argList::validArgs.append("surface file");
00082 
00083     argList args(argc, argv);
00084 
00085     point samplePt
00086     (
00087         args.optionRead<scalar>("x"),
00088         args.optionRead<scalar>("y"),
00089         args.optionRead<scalar>("z")
00090     );
00091     Info<< "Looking for nearest face/vertex to " << samplePt << endl;
00092 
00093 
00094     Info<< "Reading surf1 ..." << endl;
00095     triSurface surf1(args.additionalArgs()[0]);
00096 
00097     //
00098     // Nearest vertex
00099     //
00100 
00101     const pointField& localPoints = surf1.localPoints();
00102 
00103     label minIndex = -1;
00104     scalar minDist = GREAT;
00105 
00106     forAll(localPoints, pointI)
00107     {
00108         const scalar dist = mag(localPoints[pointI] - samplePt);
00109         if (dist < minDist)
00110         {
00111             minDist = dist;
00112             minIndex = pointI;
00113         }
00114     }
00115 
00116     Info<< "Nearest vertex:" << endl
00117         << "    index      :" << minIndex << " (in localPoints)" << endl
00118         << "    index      :" << surf1.meshPoints()[minIndex]
00119         << " (in points)" << endl
00120         << "    coordinates:" << localPoints[minIndex] << endl
00121         << endl;
00122 
00123     //
00124     // Nearest face
00125     //
00126 
00127     const pointField& points = surf1.points();
00128 
00129     minIndex = -1;
00130     minDist = GREAT;
00131 
00132     forAll(surf1, faceI)
00133     {
00134         const labelledTri& f = surf1[faceI];
00135         const point centre = f.centre(points);
00136 
00137         const scalar dist = mag(centre - samplePt);
00138         if (dist < minDist)
00139         {
00140             minDist = dist;
00141             minIndex = faceI;
00142         }
00143     }
00144 
00145     const labelledTri& f = surf1[minIndex];
00146 
00147     Info<< "Face with nearest centre:" << endl
00148         << "    index        :" << minIndex << endl
00149         << "    centre       :" << f.centre(points) << endl
00150         << "    face         :" << f << endl
00151         << "    vertex coords:" << points[f[0]] << " "
00152         << points[f[1]] << " " << points[f[2]] << endl
00153         << endl;
00154 
00155 
00156     Info << "End\n" << endl;
00157 
00158     return 0;
00159 }
00160 
00161 
00162 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines