1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "matchPoints.H"
28 #include "SortableList.H"
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 bool Foam::matchPoints
35 const UList<point>& pts0,
36 const UList<point>& pts1,
37 const UList<scalar>& matchDistances,
43 from0To1.setSize(pts0.size());
46 bool fullMatch = true;
48 point compareOrigin = origin;
50 if (origin == point(VGREAT, VGREAT, VGREAT))
54 compareOrigin = sum(pts1)/pts1.size();
58 SortableList<scalar> pts0MagSqr(magSqr(pts0 - compareOrigin));
60 SortableList<scalar> pts1MagSqr(magSqr(pts1 - compareOrigin));
64 scalar dist0 = pts0MagSqr[i];
66 label face0I = pts0MagSqr.indices()[i];
68 scalar matchDist = matchDistances[face0I];
70 label startI = findLower(pts1MagSqr, 0.99999*dist0 - matchDist);
78 // Go through range of equal mag and find nearest vector.
79 scalar minDistSqr = VGREAT;
86 (j < pts1MagSqr.size())
87 && (pts1MagSqr[j] < 1.00001*dist0 + matchDist)
92 label faceI = pts1MagSqr.indices()[j];
93 // Compare actual vectors
94 scalar distSqr = magSqr(pts0[face0I] - pts1[faceI]);
96 if (distSqr <= sqr(matchDist) && distSqr < minDistSqr)
109 Pout<< "Cannot find point in pts1 matching point " << face0I
110 << " coord:" << pts0[face0I]
111 << " in pts0 when using tolerance " << matchDist << endl;
113 // Go through range of equal mag and find equal vector.
114 Pout<< "Searching started from:" << startI << " in pts1"
120 (j < pts1MagSqr.size())
121 && (pts1MagSqr[j] < 1.00001*dist0 + matchDist)
126 label faceI = pts1MagSqr.indices()[j];
128 Pout<< "Compared coord:" << pts1[faceI]
129 << " with difference to point "
130 << mag(pts1[faceI] - pts0[face0I]) << endl;
135 from0To1[face0I] = minFaceI;
141 // ************************************************************************* //