checkSurfaceMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Reads the specified surface and writes it in the fms format.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "IFstream.H"
31 #include "fileName.H"
32 #include "triSurf.H"
33 #include "triSurfaceChecks.H"
34 #include "boundBox.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // Main program:
38 using namespace Foam;
39 
40 int main(int argc, char *argv[])
41 {
43  argList::validArgs.clear();
44  argList::validArgs.append("input surface file");
45  argList args(argc, argv);
46 
47  const fileName inFileName(args.args()[1]);
48 
49  triSurf surf(inFileName);
50 
51  label nFailed(0);
52 
53  boundBox bb;
55  Info << "\nNumber of points " << surf.nPoints() << endl;
56  Info << "Number of triangles " << surf.size() << endl;
57  Info << "Number of patches " << surf.patches().size() << endl;
58  Info << "Number of feature edges " << surf.nFeatureEdges() << endl;
59  Info << "Bounding box " << bb << nl << nl << endl;
60 
61  const scalar distTol = SMALL * bb.mag();
62 
63  //- calculate manifolds
64  const label nManifolds = triSurfaceChecks::checkSurfaceManifolds(surf);
65  if( nManifolds > 1 )
66  {
67  ++nFailed;
68 
69  Info << "\nSurface mesh consists of " << nManifolds
70  << " manifolds!!" << endl;
71  Info << "You cannot mesh geometries consisting of more than"
72  << " one domain, and it must not contain baffles"
73  << " in the domain which shall be meshed." << endl;
74  }
75  else
76  {
77  Info << "\nSurface mesh consists of a single manifold." << endl;
78  }
79 
80  //- find open boundary edges
82  {
83  ++nFailed;
84 
85  Info << "\nSurface mesh has open boundaries!!" << endl;
86  Info << "This indicates that there may be some holes in the surface"
87  << " mesh. Holes in the mesh must be smaller than the specified"
88  << " cell size at this location. In addition, please avoid"
89  << " using the automatic refinement procedure."
90  << " Please avoid using the minCellSize option." << endl;
91  }
92  else
93  {
94  Info << "No open edges found in the surface mesh." << endl;
95  }
96 
97  //- find non-manifold edges
99  {
100  ++nFailed;
101 
102  Info << "\nSurface mesh has non-manifold edges!!" << endl;
103  Info << "This indicates that the surface mesh consists of multiple"
104  << " domains and/or baffles. Please make sure that they are not"
105  << " in the domain which shall be meshed." << endl;
106  }
107  else
108  {
109  Info << "Surface does not have any non-manifold edges." << endl;
110  }
111 
112  //- check the number of disconnected parts
114  {
115  ++nFailed;
116 
117  Info << "\nSurface mesh consists of disconnected parts!!" << endl;
118  Info << "This is not a problem if there exists a region surrounding"
119  << " all other regions! In other case, the mesher will generate"
120  << " the mesh in the domains with most cells." << endl;
121  }
122  else
123  {
124  Info << "Surface mesh consists of a single region." << endl;
125  }
126 
127  //- find triangles with small angles
128  if( triSurfaceChecks::checkAngles(surf, "smallAngles", 1.0) )
129  {
130  ++nFailed;
131 
132  Info << "\nSurface mesh has some bad-quality triangles with"
133  << " angles smaller than 1.0 deg!!" << endl;
134  Info << "This may cause problems to the automatic refinement"
135  << " procedure. Please avoid using the minCellSize option."
136  << endl;
137  }
138  else
139  {
140  Info << "No sliver triangles found." << endl;
141  }
142 
143  //- find self-intersections in the surface mesh
144  if
145  (
147  (
148  surf,
149  "selfIntersect",
150  distTol
151  )
152  )
153  {
154  ++nFailed;
155 
156  Info << "\nFound self-intersecting parts in the surface mesh!!" << endl;
157  Info << "This causes problems to the automatic refinement procedure"
158  << " Please avoid using the minCellSize option."
159  << " It can also cause problems to the boundary layer"
160  << " generation procedure." << endl;
161  }
162  else
163  {
164  Info << "No self-intersections found." << endl;
165  }
166 
167  //- find overlaps in the surface mesh
168  if
169  (
171  (
172  surf,
173  "overlaps",
174  distTol,
175  5.0
176  )
177  )
178  {
179  ++nFailed;
180 
181  Info << "\nFound overlapping parts in the surface mesh!!" << endl;
182  Info << "This causes problems to the automatic refinement procedure."
183  << " Please avoid using the minCellSize option." << endl;
184  }
185 
186  //- check for existence of collocated points
187  if
188  (
190  (
191  surf,
192  "collocatedPoints",
193  distTol
194  )
195  )
196  {
197  ++nFailed;
198 
199  Info << "\nFound collocated points in the surface mesh!!" << endl;
200  Info << "This causes problems to the automatic refinement procedure."
201  << " Please avoid using the minCellSize option." << endl;
202  }
203 
204  Info << nl << endl;
205 
206  if( nFailed )
207  {
208  Info << "\nFound " << nFailed
209  << " checks indicating potential problems." << endl;
210  Info << "However, it does not mean that you cannot generate"
211  << " a valid mesh.\n" << endl;
212 
213  surf.writeSurface(inFileName);
214  }
215  else
216  {
217  Info << "\nSurface passes all checks.\n" << endl;
218  }
219 
220  Info << "End\n" << endl;
221 
222  return 0;
223 }
224 
225 
226 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
triSurfaceChecks.H
Foam::boundBox::mag
scalar mag() const
The magnitude of the bounding box span.
Definition: boundBoxI.H:90
triSurf.H
Foam::argList::args
const stringList & args() const
Return arguments.
Definition: argListI.H:66
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::triSurfaceChecks::calculateBoundingBox
void calculateBoundingBox(const triSurf &surf, boundBox &bb)
calculate bounding box of the surface mesh
Definition: triSurfaceChecks.C:631
Foam::triSurfPoints::nPoints
label nPoints() const
return the number of points
Definition: triSurfPointsI.H:39
Foam::triSurfFeatureEdges::nFeatureEdges
label nFeatureEdges() const
return the number of feature edges
Definition: triSurfFeatureEdgesI.H:39
Foam::triSurfaceChecks::checkForHoles
label checkForHoles(const triSurf &surf, labelLongList &badTriangles)
check for existence of holes in the surface mesh
Definition: triSurfaceChecks.C:274
Foam::label
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
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::triSurfFacets::patches
const geometricSurfacePatchList & patches() const
access to patches
Definition: triSurfFacetsI.H:49
fileName.H
Foam::triSurfaceChecks::checkCollocatedPoints
label checkCollocatedPoints(const triSurf &surf, labelLongList &collocatedPoints, const scalar distTol)
check existence of collocated points
Definition: triSurfaceChecks.C:638
Foam::triSurfaceChecks::checkSelfIntersections
label checkSelfIntersections(const triSurf &surf, labelLongList &badFaces, const scalar tol)
check if there exist any self-intersections
Definition: triSurfaceChecks.C:727
IFstream.H
Foam::triSurfaceChecks::checkSurfaceManifolds
label checkSurfaceManifolds(const triSurf &surf, labelLongList &triangleInManifold)
check for existence of boudary and non-manifold edges
Definition: triSurfaceChecks.C:225
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::triSurfaceChecks::checkDisconnectedParts
label checkDisconnectedParts(const triSurf &surf, labelLongList &triangleInRegion)
check for disconnected surface parts
Definition: triSurfaceChecks.C:582
boundBox.H
Foam::triSurfFacets::size
label size() const
return the number of triangles
Definition: triSurfFacetsI.H:39
Foam::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::triSurfaceChecks::checkAngles
label checkAngles(const triSurf &surf, labelLongList &badTriangles, const scalar angleTol)
Definition: triSurfaceChecks.C:58
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::triSurfaceChecks::checkOverlaps
label checkOverlaps(const triSurf &surf, labelLongList &badFaces, const scalar tol, const scalar angleTol)
check if there exist any overlaps
Definition: triSurfaceChecks.C:886
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
Foam::triSurfaceChecks::checkForNonManifoldEdges
label checkForNonManifoldEdges(const triSurf &surf, labelLongList &badTriangles)
check for existence of non-manifold edges
Definition: triSurfaceChecks.C:315
args
Foam::argList args(argc, argv)
Foam::triSurf
Definition: triSurf.H:59
main
int main(int argc, char *argv[])
Definition: checkSurfaceMesh.C:40