primitiveMeshCheckPointNearness.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 "primitiveMesh.H"
27 #include "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 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list that is sorted upon construction or when explicitly requested with the sort() method...
Definition: List.H:73
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
virtual bool checkPointNearness(const bool report, const scalar reportDistSqr, labelHashSet *setPtr=nullptr) const
Check for point-point-nearness,.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
const pointField & points
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableList.H:93
dimensioned< scalar > magSqr(const dimensioned< Type > &)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
messageStream Info