Newer
Older
#include "checkGeometry.H"
#include "polyMesh.H"
#include "globalMeshData.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry)
{
label noFailedChecks = 0;
Info<< "\nChecking geometry..." << endl;
// Get a small relative length from the bounding box
const boundBox& globalBb = mesh.bounds();
Info<< " Overall domain bounding box "
<< globalBb.min() << " " << globalBb.max() << endl;
// Min length
scalar minDistSqr = magSqr(1e-6*(globalBb.max() - globalBb.min()));
// Non-empty directions
const Vector<label> validDirs = (mesh.directions() + Vector<label>::one)/2;
Info<< " Mesh (non-empty) directions " << validDirs << endl;
scalar nGeomDims = mesh.nGeometricD();
Info<< " Mesh (non-empty, non-wedge) dimensions "
<< nGeomDims << endl;
if (nGeomDims < 3)
{
pointSet nonAlignedPoints(mesh, "nonAlignedEdges", mesh.nPoints()/100);
if (mesh.checkEdgeAlignment(true, validDirs, &nonAlignedPoints))
{
noFailedChecks++;
if (nonAlignedPoints.size() > 0)
{
Pout<< " <<Writing " << nonAlignedPoints.size()
<< " points on non-aligned edges to set "
<< nonAlignedPoints.name() << endl;
nonAlignedPoints.write();
}
}
}
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
if (mesh.checkClosedBoundary(true)) noFailedChecks++;
{
cellSet cells(mesh, "nonClosedCells", mesh.nCells()/100+1);
cellSet aspectCells(mesh, "highAspectRatioCells", mesh.nCells()/100+1);
if (mesh.checkClosedCells(true, &cells, &aspectCells))
{
noFailedChecks++;
if (cells.size() > 0)
{
Pout<< " <<Writing " << cells.size()
<< " non closed cells to set " << cells.name() << endl;
cells.write();
}
}
if (aspectCells.size() > 0)
{
Pout<< " <<Writing " << aspectCells.size()
<< " cells with high aspect ratio to set "
<< aspectCells.name() << endl;
aspectCells.write();
}
}
{
faceSet faces(mesh, "zeroAreaFaces", mesh.nFaces()/100 + 1);
if (mesh.checkFaceAreas(true, &faces))
{
noFailedChecks++;
if (faces.size() > 0)
{
Pout<< " <<Writing " << faces.size()
<< " zero area faces to set " << faces.name() << endl;
faces.write();
}
}
}
{
cellSet cells(mesh, "zeroVolumeCells", mesh.nCells()/100 + 1);
if (mesh.checkCellVolumes(true, &cells))
{
noFailedChecks++;
if (cells.size() > 0)
{
Pout<< " <<Writing " << cells.size()
<< " zero volume cells to set " << cells.name() << endl;
cells.write();
}
}
}
{
faceSet faces(mesh, "nonOrthoFaces", mesh.nFaces()/100 + 1);
if (mesh.checkFaceOrthogonality(true, &faces))
{
noFailedChecks++;
}
if (faces.size() > 0)
{
Pout<< " <<Writing " << faces.size()
<< " non-orthogonal faces to set " << faces.name() << endl;
faces.write();
}
}
{
faceSet faces(mesh, "wrongOrientedFaces", mesh.nFaces()/100 + 1);
if (mesh.checkFacePyramids(true, -SMALL, &faces))
{
noFailedChecks++;
if (faces.size() > 0)
{
Pout<< " <<Writing " << faces.size()
<< " faces with incorrect orientation to set "
<< faces.name() << endl;
faces.write();
}
}
}
{
faceSet faces(mesh, "skewFaces", mesh.nFaces()/100 + 1);
if (mesh.checkFaceSkewness(true, &faces))
{
noFailedChecks++;
if (faces.size() > 0)
{
Pout<< " <<Writing " << faces.size()
<< " skew faces to set " << faces.name() << endl;
faces.write();
}
}
}
if (allGeometry)
{
// Note use of nPoints since don't want edge construction.
pointSet points(mesh, "shortEdges", mesh.nPoints()/1000 + 1);
if (mesh.checkEdgeLength(true, minDistSqr, &points))
{
//noFailedChecks++;
if (points.size() > 0)
{
Pout<< " <<Writing " << points.size()
<< " points on short edges to set " << points.name()
<< endl;
points.write();
}
}
label nEdgeClose = points.size();
if (mesh.checkPointNearness(false, minDistSqr, &points))
{
//noFailedChecks++;
if (points.size() > nEdgeClose)
{
pointSet nearPoints(mesh, "nearPoints", points);
Pout<< " <<Writing " << nearPoints.size()
<< " near (closer than " << Foam::sqrt(minDistSqr)
<< " apart) points to set " << nearPoints.name() << endl;
nearPoints.write();
}
}
}
if (allGeometry)
{
faceSet faces(mesh, "concaveFaces", mesh.nFaces()/100 + 1);
if (mesh.checkFaceAngles(true, 10, &faces))
{
//noFailedChecks++;
if (faces.size() > 0)
{
Pout<< " <<Writing " << faces.size()
<< " faces with concave angles to set " << faces.name()
<< endl;
faces.write();
}
}
}
if (allGeometry)
{
faceSet faces(mesh, "warpedFaces", mesh.nFaces()/100 + 1);
if (mesh.checkFaceFlatness(true, 0.8, &faces))
{
//noFailedChecks++;
if (faces.size() > 0)
{
Pout<< " <<Writing " << faces.size()
<< " warped faces to set " << faces.name() << endl;
faces.write();
}
}
}
if (allGeometry)
{
cellSet cells(mesh, "underdeterminedCells", mesh.nCells()/100);
if (mesh.checkCellDeterminant(true, &cells))
{
noFailedChecks++;
Pout<< " <<Writing " << cells.size()
<< " under-determined cells to set " << cells.name() << endl;
cells.write();
}
}
return noFailedChecks;
}