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-2023 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 "primitiveMeshCheck.H"
27 #include "SortableList.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
32 (
33  const primitiveMesh& mesh,
34  const bool report,
35  const scalar reportDistSqr,
36  labelHashSet* setPtr
37 )
38 {
39  const pointField& points = mesh.points();
40 
41  // Sort points
43 
44  label nClose = 0;
45 
46  for (label i = 1; i < sortedMag.size(); i++)
47  {
48  label pti = sortedMag.indices()[i];
49 
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];
59 
60  if (magSqr(points[pti] - points[prevPtI]) < reportDistSqr)
61  {
62  nClose++;
63 
64  if (setPtr)
65  {
66  setPtr->insert(pti);
67  setPtr->insert(prevPtI);
68  }
69  }
70  }
71  }
72 
73  reduce(nClose, sumOp<label>());
74 
75  if (nClose > 0)
76  {
77  if (report)
78  {
79  Info<< " <<Points closer than " << Foam::sqrt(reportDistSqr)
80  << " together found, number: " << nClose
81  << endl;
82  }
83 
84  return true;
85  }
86  else
87  {
88  return false;
89  }
90 }
91 
92 
93 // ************************************************************************* //
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:109
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A list that is sorted upon construction or when explicitly requested with the sort() method.
Definition: SortableList.H:55
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableList.H:96
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
virtual const pointField & points() const =0
Return mesh points.
const pointField & points
bool checkPointNearness(const primitiveMesh &mesh, const bool report, const scalar reportDistSqr, labelHashSet *setPtr=nullptr)
Check for point-point-nearness,.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > magSqr(const dimensioned< Type > &)