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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "primitiveMesh.H"
30 #include "SortableList.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
35 (
36  const bool report,
37  const scalar reportDistSqr,
38  labelHashSet* setPtr
39 ) const
40 {
41  const pointField& points = this->points();
42 
43  // Sort points
45 
46  label nClose = 0;
47 
48  for (label i = 1; i < sortedMag.size(); i++)
49  {
50  label pti = sortedMag.indices()[i];
51 
52  // Compare pti to any previous points with similar sortedMag
53  for
54  (
55  label j = i-1;
56  j >= 0 && (sortedMag[j] > sortedMag[i]-reportDistSqr);
57  --j
58  )
59  {
60  label prevPtI = sortedMag.indices()[j];
61 
62  if (magSqr(points[pti] - points[prevPtI]) < reportDistSqr)
63  {
65  //const labelList& pEdges = pointEdges()[pti];
66  //
67  //bool connected = false;
68  //
69  //forAll(pEdges, pEdgei)
70  //{
71  // if (edges()[pEdges[pEdgei]].otherVertex(prevPtI) != -1)
72  // {
73  // connected = true;
74  // break;
75  // }
76  //}
77  //
78  //if (!connected)
79  {
80  nClose++;
81 
82  if (setPtr)
83  {
84  setPtr->insert(pti);
85  setPtr->insert(prevPtI);
86  }
87  }
88  }
89  }
90  }
91 
92  reduce(nClose, sumOp<label>());
93 
94  if (nClose > 0)
95  {
96  if (report)
97  {
98  Info<< " <<Points closer than " << Foam::sqrt(reportDistSqr)
99  << " together found, number: " << nClose
100  << endl;
101  }
102 
103  return true;
104  }
105 
106  return false;
107 }
108 
109 
110 // ************************************************************************* //
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::HashSet< label, Hash< label > >
Foam::sumOp
Definition: ops.H:213
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
SortableList.H
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
reduce
reduce(hasMovingMesh, orOp< bool >())
Foam::SortableList
A list that is sorted upon construction or when explicitly requested with the sort() method.
Definition: List.H:60
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
Foam::SortableList::indices
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableList.H:108
Foam::primitiveMesh::checkPointNearness
virtual bool checkPointNearness(const bool report, const scalar reportDistSqr, labelHashSet *setPtr=nullptr) const
Check for point-point-nearness,.
Definition: primitiveMeshCheckPointNearness.C:35