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

primitiveMeshCheckPointNearness.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 "primitiveMesh.H"
00028 #include "SortableList.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 bool Foam::primitiveMesh::checkPointNearness
00033 (
00034     const bool report,
00035     const scalar reportDistSqr,
00036     labelHashSet* setPtr
00037 ) const
00038 {
00039     const pointField& points = this->points();
00040 
00041     // Sort points
00042     SortableList<scalar> sortedMag(magSqr(points));
00043 
00044     label nClose = 0;
00045 
00046     for (label i = 1; i < sortedMag.size(); i++)
00047     {
00048         label pti = sortedMag.indices()[i];
00049 
00050         // Compare pti to any previous points with similar sortedMag
00051         for
00052         (
00053             label j = i-1;
00054             j >= 0 && (sortedMag[j] > sortedMag[i]-reportDistSqr);
00055             --j
00056         )
00057         {
00058             label prevPtI = sortedMag.indices()[j];
00059 
00060             if (magSqr(points[pti] - points[prevPtI]) < reportDistSqr)
00061             {
00063                 //const labelList& pEdges = pointEdges()[pti];
00064                 //
00065                 //bool connected = false;
00066                 //
00067                 //forAll(pEdges, pEdgei)
00068                 //{
00069                 //    if (edges()[pEdges[pEdgei]].otherVertex(prevPtI) != -1)
00070                 //    {
00071                 //        connected = true;
00072                 //        break;
00073                 //    }
00074                 //}
00075                 //
00076                 //if (!connected)
00077                 {
00078                     nClose++;
00079 
00080                     if (setPtr)
00081                     {
00082                         setPtr->insert(pti);
00083                         setPtr->insert(prevPtI);
00084                     }
00085                 }
00086             }
00087         }
00088     }
00089 
00090     reduce(nClose, sumOp<label>());
00091 
00092     if (nClose > 0)
00093     {
00094         if (report)
00095         {
00096             Info<< "  <<Points closer than " << Foam::sqrt(reportDistSqr)
00097                 << " together found, number: " << nClose
00098                 << endl;
00099         }
00100 
00101         return true;
00102     }
00103     else
00104     {
00105         return false;
00106     }
00107 }
00108 
00109 
00110 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd