checkMesh.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-2018 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 Application
25  checkMesh
26 
27 Description
28  Checks validity of a mesh.
29 
30 Usage
31  \b checkMesh [OPTION]
32 
33  Options:
34  - \par -allGeometry
35  Checks all (including non finite-volume specific) geometry
36 
37  - \par -allTopology
38  Checks all (including non finite-volume specific) addressing
39 
40  - \par -meshQuality
41  Checks against user defined (in \a system/meshQualityDict) quality
42  settings
43 
44  - \par -region <name>
45  Specify an alternative mesh region.
46 
47  - \par -writeSets <surfaceFormat>
48  Reconstruct all cellSets and faceSets geometry and write to
49  postProcessing directory according to surfaceFormat
50  (e.g. vtk or ensight). Additionally reconstructs all pointSets and
51  writes as vtk format.
52 
53 \*---------------------------------------------------------------------------*/
54 
55 #include "argList.H"
56 #include "timeSelector.H"
57 #include "Time.H"
58 #include "polyMesh.H"
59 #include "globalMeshData.H"
60 #include "surfaceWriter.H"
61 #include "vtkSetWriter.H"
62 #include "IOdictionary.H"
63 
64 #include "checkTools.H"
65 #include "checkTopology.H"
66 #include "checkGeometry.H"
67 #include "checkMeshQuality.H"
68 
69 using namespace Foam;
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 int main(int argc, char *argv[])
74 {
76  #include "addRegionOption.H"
78  (
79  "noTopology",
80  "skip checking the mesh topology"
81  );
83  (
84  "allGeometry",
85  "include bounding box checks"
86  );
88  (
89  "allTopology",
90  "include extra topology checks"
91  );
93  (
94  "meshQuality",
95  "read user-defined mesh quality criterions from system/meshQualityDict"
96  );
98  (
99  "writeSets",
100  "surfaceFormat",
101  "reconstruct and write all faceSets and cellSets in selected format"
102  );
103 
104  #include "setRootCase.H"
105  #include "createTime.H"
107  #include "createNamedPolyMesh.H"
108 
109  const bool noTopology = args.optionFound("noTopology");
110  const bool allGeometry = args.optionFound("allGeometry");
111  const bool allTopology = args.optionFound("allTopology");
112  const bool meshQuality = args.optionFound("meshQuality");
113 
114  word surfaceFormat;
115  const bool writeSets = args.optionReadIfPresent("writeSets", surfaceFormat);
116 
117  if (noTopology)
118  {
119  Info<< "Disabling all topology checks." << nl << endl;
120  }
121  if (allTopology)
122  {
123  Info<< "Enabling all (cell, face, edge, point) topology checks."
124  << nl << endl;
125  }
126  if (allGeometry)
127  {
128  Info<< "Enabling all geometry checks." << nl << endl;
129  }
130  if (meshQuality)
131  {
132  Info<< "Enabling user-defined geometry checks." << nl << endl;
133  }
134  if (writeSets)
135  {
136  Info<< "Reconstructing and writing " << surfaceFormat
137  << " representation"
138  << " of all faceSets and cellSets." << nl << endl;
139  }
140 
141 
142  autoPtr<IOdictionary> qualDict;
143  if (meshQuality)
144  {
145  qualDict.reset
146  (
147  new IOdictionary
148  (
149  IOobject
150  (
151  "meshQualityDict",
152  mesh.time().system(),
153  mesh,
156  )
157  )
158  );
159  }
160 
161 
162  autoPtr<surfaceWriter> surfWriter;
163  autoPtr<writer<scalar>> setWriter;
164  if (writeSets)
165  {
166  surfWriter = surfaceWriter::New(surfaceFormat);
168  }
169 
170 
171  forAll(timeDirs, timeI)
172  {
173  runTime.setTime(timeDirs[timeI], timeI);
174 
176 
177  if
178  (
179  !timeI
180  || state == polyMesh::TOPO_CHANGE
181  || state == polyMesh::TOPO_PATCH_CHANGE
182  )
183  {
184  Info<< "Time = " << runTime.timeName() << nl << endl;
185 
186  // Reconstruct globalMeshData
187  mesh.globalData();
188 
189  printMeshStats(mesh, allTopology);
190 
191  label nFailedChecks = 0;
192 
193  if (!noTopology)
194  {
195  nFailedChecks += checkTopology
196  (
197  mesh,
198  allTopology,
199  allGeometry,
200  surfWriter,
201  setWriter
202  );
203  }
204 
205  nFailedChecks += checkGeometry
206  (
207  mesh,
208  allGeometry,
209  surfWriter,
210  setWriter
211  );
212 
213  if (meshQuality)
214  {
215  nFailedChecks += checkMeshQuality(mesh, qualDict(), surfWriter);
216  }
217 
218 
219  // Note: no reduction in nFailedChecks necessary since is
220  // counter of checks, not counter of failed cells,faces etc.
221 
222  if (nFailedChecks == 0)
223  {
224  Info<< "\nMesh OK.\n" << endl;
225  }
226  else
227  {
228  Info<< "\nFailed " << nFailedChecks << " mesh checks.\n"
229  << endl;
230  }
231  }
232  else if (state == polyMesh::POINTS_MOVED)
233  {
234  Info<< "Time = " << runTime.timeName() << nl << endl;
235 
236  label nFailedChecks = checkGeometry
237  (
238  mesh,
239  allGeometry,
240  surfWriter,
241  setWriter
242  );
243 
244  if (meshQuality)
245  {
246  nFailedChecks += checkMeshQuality(mesh, qualDict(), surfWriter);
247  }
248 
249 
250  if (nFailedChecks)
251  {
252  Info<< "\nFailed " << nFailedChecks << " mesh checks.\n"
253  << endl;
254  }
255  else
256  {
257  Info<< "\nMesh OK.\n" << endl;
258  }
259  }
260  }
261 
262  Info<< "End\n" << endl;
263 
264  return 0;
265 }
266 
267 
268 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
dynamicFvMesh & mesh
label checkGeometry(const polyMesh &mesh, const bool allGeometry, const autoPtr< surfaceWriter > &, const autoPtr< writer< scalar >> &)
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:489
A class for handling words, derived from string.
Definition: word.H:59
label checkMeshQuality(const polyMesh &, const dictionary &, const autoPtr< surfaceWriter > &)
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:127
label checkTopology(const polyMesh &, const bool, const bool, const autoPtr< surfaceWriter > &, const autoPtr< writer< scalar >> &)
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1394
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
Definition: Time.C:873
const word & system() const
Return system name.
Definition: TimePaths.H:114
static autoPtr< writer > New(const word &writeFormat)
Return a reference to the selected writer.
Definition: writer.C:35
static const char nl
Definition: Ostream.H:265
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:252
void printMeshStats(const polyMesh &mesh, const bool allTopology)
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:117
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
static autoPtr< surfaceWriter > New(const word &writeType)
Return a reference to the selected surfaceWriter.
Definition: surfaceWriter.C:44
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Namespace for OpenFOAM.