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-------------------------------------------------------------------------------
11License
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// ************************************************************************* //
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
void transfer(HashTable< T, Key, Hash > &rhs)
Transfer contents into this table.
Definition: HashTable.C:719
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
label fcIndex(const label i) const noexcept
Definition: UListI.H:60
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
virtual bool checkEdgeLength(const bool report, const scalar minLenSqr, labelHashSet *setPtr=nullptr) const
Check edge length.
virtual const faceList & faces() const =0
Return faces.
label nPoints() const noexcept
Number of mesh points.
virtual const pointField & points() const =0
Return mesh points.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensionedSymmTensor sqr(const dimensionedVector &dv)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensionedScalar sqrt(const dimensionedScalar &ds)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333