FreeFOAM The Cross-Platform CFD Toolkit
primitiveMeshCheckPointNearness.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <OpenFOAM/primitiveMesh.H>
27 #include <OpenFOAM/SortableList.H>
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
32 (
33  const bool report,
34  const scalar reportDistSqr,
35  labelHashSet* setPtr
36 ) const
37 {
38  const pointField& points = this->points();
39 
40  // Sort points
41  SortableList<scalar> sortedMag(magSqr(points));
42 
43  label nClose = 0;
44 
45  for (label i = 1; i < sortedMag.size(); i++)
46  {
47  label pti = sortedMag.indices()[i];
48 
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];
58 
59  if (magSqr(points[pti] - points[prevPtI]) < reportDistSqr)
60  {
62  //const labelList& pEdges = pointEdges()[pti];
63  //
64  //bool connected = false;
65  //
66  //forAll(pEdges, pEdgei)
67  //{
68  // if (edges()[pEdges[pEdgei]].otherVertex(prevPtI) != -1)
69  // {
70  // connected = true;
71  // break;
72  // }
73  //}
74  //
75  //if (!connected)
76  {
77  nClose++;
78 
79  if (setPtr)
80  {
81  setPtr->insert(pti);
82  setPtr->insert(prevPtI);
83  }
84  }
85  }
86  }
87  }
88 
89  reduce(nClose, sumOp<label>());
90 
91  if (nClose > 0)
92  {
93  if (report)
94  {
95  Info<< " <<Points closer than " << Foam::sqrt(reportDistSqr)
96  << " together found, number: " << nClose
97  << endl;
98  }
99 
100  return true;
101  }
102  else
103  {
104  return false;
105  }
106 }
107 
108 
109 // ************************ vim: set sw=4 sts=4 et: ************************ //