primitiveMeshCheckEdgeLength.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 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
31 (
32  const primitiveMesh& mesh,
33  const bool report,
34  const scalar reportLenSqr,
35  labelHashSet* setPtr
36 )
37 {
38  const pointField& points = mesh.points();
39  const faceList& faces = mesh.faces();
40 
41  scalar minLenSqr = sqr(great);
42  scalar maxLenSqr = -sqr(great);
43 
44  labelHashSet smallEdgeSet(mesh.nPoints()/100);
45 
46  forAll(faces, facei)
47  {
48  const face& f = faces[facei];
49 
50  forAll(f, fp)
51  {
52  label fp1 = f.fcIndex(fp);
53 
54  scalar magSqrE = magSqr(points[f[fp]] - points[f[fp1]]);
55 
56  if (magSqrE < reportLenSqr)
57  {
58  smallEdgeSet.insert(f[fp]);
59  smallEdgeSet.insert(f[fp1]);
60  }
61 
62  minLenSqr = min(minLenSqr, magSqrE);
63  maxLenSqr = max(maxLenSqr, magSqrE);
64  }
65  }
66 
67  reduce(minLenSqr, minOp<scalar>());
68  reduce(maxLenSqr, maxOp<scalar>());
69 
70  label nSmall = smallEdgeSet.size();
71  reduce(nSmall, sumOp<label>());
72 
73  if (setPtr)
74  {
75  setPtr->transfer(smallEdgeSet);
76  }
77 
78  if (nSmall > 0)
79  {
80  if (report)
81  {
82  Info<< " *Edges too small, min/max edge length = "
83  << sqrt(minLenSqr) << " " << sqrt(maxLenSqr)
84  << ", number too small: " << nSmall << endl;
85  }
86 
87  return true;
88  }
89  else
90  {
91  if (report)
92  {
93  Info<< " Min/max edge length = "
94  << sqrt(minLenSqr) << " " << sqrt(maxLenSqr)
95  << " OK." << endl;
96  }
97 
98  return false;
99  }
100 }
101 
102 
103 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:109
void transfer(HashTable< T, Key, Hash > &)
Transfer the contents of the argument table into this table.
Definition: HashTable.C:587
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
label nPoints() const
virtual const faceList & faces() const =0
Return faces.
virtual const pointField & points() const =0
Return mesh points.
const pointField & points
bool checkEdgeLength(const primitiveMesh &mesh, const bool report, const scalar minLenSqr, labelHashSet *setPtr=nullptr)
Check edge length.
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
dimensionedScalar sqrt(const dimensionedScalar &ds)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
labelList f(nPoints)