initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / meshes / primitiveMesh / primitiveMeshCheck / primitiveMeshCheckPointNearness.C
blob3e0a8a6263cdf829552960f565c3daa81a393066
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "primitiveMesh.H"
28 #include "SortableList.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 bool Foam::primitiveMesh::checkPointNearness
34     const bool report,
35     const scalar reportDistSqr,
36     labelHashSet* setPtr
37 ) const
39     const pointField& points = this->points();
41     // Sort points
42     SortableList<scalar> sortedMag(magSqr(points));
44     label nClose = 0;
46     for (label i = 1; i < sortedMag.size(); i++)
47     {
48         label pti = sortedMag.indices()[i];
50         // Compare pti to any previous points with similar sortedMag
51         for
52         (
53             label j = i-1;
54             j >= 0 && (sortedMag[j] > sortedMag[i]-reportDistSqr);
55             --j
56         )
57         {
58             label prevPtI = sortedMag.indices()[j];
60             if (magSqr(points[pti] - points[prevPtI]) < reportDistSqr)
61             {
62                 //// Check if unconnected.
63                 //const labelList& pEdges = pointEdges()[pti];
64                 //
65                 //bool connected = false;
66                 //
67                 //forAll(pEdges, pEdgei)
68                 //{
69                 //    if (edges()[pEdges[pEdgei]].otherVertex(prevPtI) != -1)
70                 //    {
71                 //        connected = true;
72                 //        break;
73                 //    }
74                 //}
75                 //
76                 //if (!connected)
77                 {
78                     nClose++;
80                     if (setPtr)
81                     {
82                         setPtr->insert(pti);
83                         setPtr->insert(prevPtI);
84                     }
85                 }
86             }
87         }
88     }
90     reduce(nClose, sumOp<label>());
92     if (nClose > 0)
93     {
94         if (report)
95         {
96             Info<< "  <<Points closer than " << Foam::sqrt(reportDistSqr)
97                 << " together found, number: " << nClose
98                 << endl;
99         }
101         return true;
102     }
103     else
104     {
105         return false;
106     }
110 // ************************************************************************* //