primitiveMeshCheckEdgeLength.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-2016 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 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
34 (
35  const bool report,
36  const scalar reportLenSqr,
37  labelHashSet* setPtr
38 ) const
39 {
40  const pointField& points = this->points();
41  const faceList& faces = this->faces();
42 
43  scalar minLenSqr = sqr(GREAT);
44  scalar maxLenSqr = -sqr(GREAT);
45 
46  labelHashSet smallEdgeSet(nPoints()/100);
47 
48  forAll(faces, facei)
49  {
50  const face& f = faces[facei];
51 
52  forAll(f, fp)
53  {
54  label fp1 = f.fcIndex(fp);
55 
56  scalar magSqrE = magSqr(points[f[fp]] - points[f[fp1]]);
57 
58  if (magSqrE < reportLenSqr)
59  {
60  smallEdgeSet.insert(f[fp]);
61  smallEdgeSet.insert(f[fp1]);
62  }
63 
64  minLenSqr = min(minLenSqr, magSqrE);
65  maxLenSqr = max(maxLenSqr, magSqrE);
66  }
67  }
68 
69  reduce(minLenSqr, minOp<scalar>());
70  reduce(maxLenSqr, maxOp<scalar>());
71 
72  label nSmall = smallEdgeSet.size();
73  reduce(nSmall, sumOp<label>());
74 
75  if (setPtr)
76  {
77  setPtr->transfer(smallEdgeSet);
78  }
79 
80  if (nSmall > 0)
81  {
82  if (report)
83  {
84  Info<< " *Edges too small, min/max edge length = "
85  << sqrt(minLenSqr) << " " << sqrt(maxLenSqr)
86  << ", number too small: " << nSmall << endl;
87  }
88 
89  return true;
90  }
91 
92  if (report)
93  {
94  Info<< " Min/max edge length = "
95  << sqrt(minLenSqr) << " " << sqrt(maxLenSqr) << " OK." << endl;
96  }
97 
98  return false;
99 }
100 
101 
102 // ************************************************************************* //
Foam::maxOp
Definition: ops.H:223
Foam::minOp
Definition: ops.H:224
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::HashSet< label, Hash< label > >
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::primitiveMesh::checkEdgeLength
virtual bool checkEdgeLength(const bool report, const scalar minLenSqr, labelHashSet *setPtr=nullptr) const
Check edge length.
Definition: primitiveMeshCheckEdgeLength.C:34
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
reduce
reduce(hasMovingMesh, orOp< bool >())
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
f
labelList f(nPoints)
Foam::List< face >
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::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72