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

matchPoints.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "matchPoints.H"
00028 #include "SortableList.H"
00029 #include "ListOps.H"
00030 
00031 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00032 
00033 bool Foam::matchPoints
00034 (
00035     const UList<point>& pts0,
00036     const UList<point>& pts1,
00037     const UList<scalar>& matchDistances,
00038     const bool verbose,
00039     labelList& from0To1,
00040     const point& origin
00041 )
00042 {
00043     from0To1.setSize(pts0.size());
00044     from0To1 = -1;
00045 
00046     bool fullMatch = true;
00047 
00048     point compareOrigin = origin;
00049 
00050     if (origin == point(VGREAT, VGREAT, VGREAT))
00051     {
00052         if (pts1.size())
00053         {
00054             compareOrigin = sum(pts1)/pts1.size();
00055         }
00056     }
00057 
00058     SortableList<scalar> pts0MagSqr(magSqr(pts0 - compareOrigin));
00059 
00060     SortableList<scalar> pts1MagSqr(magSqr(pts1 - compareOrigin));
00061 
00062     forAll(pts0MagSqr, i)
00063     {
00064         scalar dist0 = pts0MagSqr[i];
00065 
00066         label face0I = pts0MagSqr.indices()[i];
00067 
00068         scalar matchDist = matchDistances[face0I];
00069 
00070         label startI = findLower(pts1MagSqr, 0.99999*dist0 - matchDist);
00071 
00072         if (startI == -1)
00073         {
00074             startI = 0;
00075         }
00076 
00077 
00078         // Go through range of equal mag and find nearest vector.
00079         scalar minDistSqr = VGREAT;
00080         label minFaceI = -1;
00081     
00082         for
00083         (
00084             label j = startI;
00085             (
00086                 (j < pts1MagSqr.size())
00087              && (pts1MagSqr[j] < 1.00001*dist0 + matchDist)
00088             );
00089             j++
00090         )
00091         {
00092             label faceI = pts1MagSqr.indices()[j];
00093             // Compare actual vectors
00094             scalar distSqr = magSqr(pts0[face0I] - pts1[faceI]);
00095 
00096             if (distSqr <= sqr(matchDist) && distSqr < minDistSqr)
00097             {
00098                 minDistSqr = distSqr;
00099                 minFaceI = faceI;
00100             }
00101         }
00102 
00103         if (minFaceI == -1)
00104         {
00105             fullMatch = false;
00106 
00107             if (verbose)
00108             {
00109                 Pout<< "Cannot find point in pts1 matching point " << face0I
00110                     << " coord:" << pts0[face0I]
00111                     << " in pts0 when using tolerance " << matchDist << endl;
00112 
00113                 // Go through range of equal mag and find equal vector.
00114                 Pout<< "Searching started from:" << startI << " in pts1"
00115                     << endl;
00116                 for
00117                 (
00118                     label j = startI;
00119                     (
00120                         (j < pts1MagSqr.size())
00121                      && (pts1MagSqr[j] < 1.00001*dist0 + matchDist)
00122                     );
00123                     j++
00124                 )
00125                 {
00126                     label faceI = pts1MagSqr.indices()[j];
00127 
00128                     Pout<< "Compared coord:" << pts1[faceI]
00129                         << " with difference to point "
00130                         << mag(pts1[faceI] - pts0[face0I]) << endl;
00131                 }
00132             }
00133         }
00134 
00135         from0To1[face0I] = minFaceI;
00136     }
00137 
00138     return fullMatch;
00139 }
00140 
00141 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd