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

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