FreeFOAM The Cross-Platform CFD Toolkit
surfaceFind.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Application
25  surfaceFind
26 
27 Description
28  Finds nearest triangle and vertex.
29 
30 Usage
31 
32  - surfaceFind [OPTIONS] <Foam surface file>
33 
34  @param <Foam surface file> \n
35  @todo Detailed description of argument.
36 
37  @param -x <X>\n
38  X-coordinate of sample point.
39 
40  @param -y <Y>\n
41  Y-coordinate of sample point.
42 
43  @param -z <Z>\n
44  Z-coordinate of sample point.
45 
46  @param -case <dir>\n
47  Case directory.
48 
49  @param -help \n
50  Display help message.
51 
52  @param -doc \n
53  Display Doxygen API documentation page for this application.
54 
55  @param -srcDoc \n
56  Display Doxygen source documentation page for this application.
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #include <triSurface/triSurface.H>
61 #include <OpenFOAM/argList.H>
62 #include <OpenFOAM/OFstream.H>
63 
64 #ifndef namespaceFoam
65 #define namespaceFoam
66  using namespace Foam;
67 #endif
68 
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 // Main program:
72 
73 int main(int argc, char *argv[])
74 {
77  argList::validOptions.insert("x", "X");
78  argList::validOptions.insert("y", "Y");
79  argList::validOptions.insert("z", "Z");
80 
81  argList::validArgs.append("surface file");
82 
83  argList args(argc, argv);
84 
85  point samplePt
86  (
87  args.optionRead<scalar>("x"),
88  args.optionRead<scalar>("y"),
89  args.optionRead<scalar>("z")
90  );
91  Info<< "Looking for nearest face/vertex to " << samplePt << endl;
92 
93 
94  Info<< "Reading surf1 ..." << endl;
95  triSurface surf1(args.additionalArgs()[0]);
96 
97  //
98  // Nearest vertex
99  //
100 
101  const pointField& localPoints = surf1.localPoints();
102 
103  label minIndex = -1;
104  scalar minDist = GREAT;
105 
106  forAll(localPoints, pointI)
107  {
108  const scalar dist = mag(localPoints[pointI] - samplePt);
109  if (dist < minDist)
110  {
111  minDist = dist;
112  minIndex = pointI;
113  }
114  }
115 
116  Info<< "Nearest vertex:" << endl
117  << " index :" << minIndex << " (in localPoints)" << endl
118  << " index :" << surf1.meshPoints()[minIndex]
119  << " (in points)" << endl
120  << " coordinates:" << localPoints[minIndex] << endl
121  << endl;
122 
123  //
124  // Nearest face
125  //
126 
127  const pointField& points = surf1.points();
128 
129  minIndex = -1;
130  minDist = GREAT;
131 
132  forAll(surf1, faceI)
133  {
134  const labelledTri& f = surf1[faceI];
135  const point centre = f.centre(points);
136 
137  const scalar dist = mag(centre - samplePt);
138  if (dist < minDist)
139  {
140  minDist = dist;
141  minIndex = faceI;
142  }
143  }
144 
145  const labelledTri& f = surf1[minIndex];
146 
147  Info<< "Face with nearest centre:" << endl
148  << " index :" << minIndex << endl
149  << " centre :" << f.centre(points) << endl
150  << " face :" << f << endl
151  << " vertex coords:" << points[f[0]] << " "
152  << points[f[1]] << " " << points[f[2]] << endl
153  << endl;
154 
155 
156  Info << "End\n" << endl;
157 
158  return 0;
159 }
160 
161 
162 // ************************ vim: set sw=4 sts=4 et: ************************ //