Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / meshes / primitiveMesh / primitiveMeshCheck / primitiveMeshCheckPointNearness.C
blobb2f40336971b277c07bdb3b0e1de1afe7d462fec
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "primitiveMesh.H"
27 #include "SortableList.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 bool Foam::primitiveMesh::checkPointNearness
33     const bool report,
34     const scalar reportDistSqr,
35     labelHashSet* setPtr
36 ) const
38     const pointField& points = this->points();
40     // Sort points
41     SortableList<scalar> sortedMag(magSqr(points));
43     label nClose = 0;
45     for (label i = 1; i < sortedMag.size(); i++)
46     {
47         label pti = sortedMag.indices()[i];
49         // Compare pti to any previous points with similar sortedMag
50         for
51         (
52             label j = i-1;
53             j >= 0 && (sortedMag[j] > sortedMag[i]-reportDistSqr);
54             --j
55         )
56         {
57             label prevPtI = sortedMag.indices()[j];
59             if (magSqr(points[pti] - points[prevPtI]) < reportDistSqr)
60             {
61                 // Commented out in 1.6.x.  HJ, 17/Aug/2010
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 // ************************************************************************* //