checkMesh.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 | Copyright (C) 2011-2016 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)
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #include "argList.H"
55 #include "timeSelector.H"
56 #include "Time.H"
57 #include "polyMesh.H"
58 #include "globalMeshData.H"
59 #include "vtkSurfaceWriter.H"
60 
61 #include "checkTools.H"
62 #include "checkTopology.H"
63 #include "checkGeometry.H"
64 #include "checkMeshQuality.H"
65 
66 using namespace Foam;
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 int main(int argc, char *argv[])
71 {
73  #include "addRegionOption.H"
75  (
76  "noTopology",
77  "skip checking the mesh topology"
78  );
80  (
81  "allGeometry",
82  "include bounding box checks"
83  );
85  (
86  "allTopology",
87  "include extra topology checks"
88  );
90  (
91  "meshQuality",
92  "read user-defined mesh quality criterions from system/meshQualityDict"
93  );
95  (
96  "writeSets",
97  "<surfaceFormat>"
98  "reconstruct and write all faceSets and cellSets in selected format"
99  );
100 
101  #include "setRootCase.H"
102  #include "createTime.H"
103  instantList timeDirs = timeSelector::select0(runTime, args);
104  #include "createNamedPolyMesh.H"
105 
106  const bool noTopology = args.optionFound("noTopology");
107  const bool allGeometry = args.optionFound("allGeometry");
108  const bool allTopology = args.optionFound("allTopology");
109  const bool meshQuality = args.optionFound("meshQuality");
110 
111  word surfaceFormat;
112  const bool writeSets = args.optionReadIfPresent("writeSets", surfaceFormat);
113 
114  if (noTopology)
115  {
116  Info<< "Disabling all topology checks." << nl << endl;
117  }
118  if (allTopology)
119  {
120  Info<< "Enabling all (cell, face, edge, point) topology checks."
121  << nl << endl;
122  }
123  if (allGeometry)
124  {
125  Info<< "Enabling all geometry checks." << nl << endl;
126  }
127  if (meshQuality)
128  {
129  Info<< "Enabling user-defined geometry checks." << nl << endl;
130  }
131  if (writeSets)
132  {
133  Info<< "Reconstructing and writing " << surfaceFormat
134  << " representation"
135  << " of all faceSets and cellSets." << nl << endl;
136  }
137 
138 
139  autoPtr<IOdictionary> qualDict;
140  if (meshQuality)
141  {
142  qualDict.reset
143  (
144  new IOdictionary
145  (
146  IOobject
147  (
148  "meshQualityDict",
149  mesh.time().system(),
150  mesh,
153  )
154  )
155  );
156  }
157 
158 
159  autoPtr<surfaceWriter> writer;
160  if (writeSets)
161  {
162  writer = surfaceWriter::New(surfaceFormat);
163  }
164 
165 
166  forAll(timeDirs, timeI)
167  {
168  runTime.setTime(timeDirs[timeI], timeI);
169 
171 
172  if
173  (
174  !timeI
175  || state == polyMesh::TOPO_CHANGE
176  || state == polyMesh::TOPO_PATCH_CHANGE
177  )
178  {
179  Info<< "Time = " << runTime.timeName() << nl << endl;
180 
181  // Reconstruct globalMeshData
182  mesh.globalData();
183 
184  printMeshStats(mesh, allTopology);
185 
186  label nFailedChecks = 0;
187 
188  if (!noTopology)
189  {
190  nFailedChecks += checkTopology
191  (
192  mesh,
193  allTopology,
194  allGeometry,
195  writer
196  );
197  }
198 
199  nFailedChecks += checkGeometry(mesh, allGeometry, writer);
200 
201  if (meshQuality)
202  {
203  nFailedChecks += checkMeshQuality(mesh, qualDict(), writer);
204  }
205 
206 
207  // Note: no reduction in nFailedChecks necessary since is
208  // counter of checks, not counter of failed cells,faces etc.
209 
210  if (nFailedChecks == 0)
211  {
212  Info<< "\nMesh OK.\n" << endl;
213  }
214  else
215  {
216  Info<< "\nFailed " << nFailedChecks << " mesh checks.\n"
217  << endl;
218  }
219  }
220  else if (state == polyMesh::POINTS_MOVED)
221  {
222  Info<< "Time = " << runTime.timeName() << nl << endl;
223 
224  label nFailedChecks = checkGeometry(mesh, allGeometry, writer);
225 
226  if (meshQuality)
227  {
228  nFailedChecks += checkMeshQuality(mesh, qualDict(), writer);
229  }
230 
231 
232  if (nFailedChecks)
233  {
234  Info<< "\nFailed " << nFailedChecks << " mesh checks.\n"
235  << endl;
236  }
237  else
238  {
239  Info<< "\nMesh OK.\n" << endl;
240  }
241  }
242  }
243 
244  Info<< "End\n" << endl;
245 
246  return 0;
247 }
248 
249 
250 // ************************************************************************* //
label checkTopology(const polyMesh &, const bool, const bool, const autoPtr< surfaceWriter > &)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
void reset(T *=0)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
dynamicFvMesh & mesh
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:494
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
A class for handling words, derived from string.
Definition: word.H:59
label checkMeshQuality(const polyMesh &, const dictionary &, const autoPtr< surfaceWriter > &)
label checkGeometry(const polyMesh &mesh, const bool allGeometry, 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:93
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1140
static const char nl
Definition: Ostream.H:262
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
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:53
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
const word & system() const
Return system name.
Definition: TimePaths.H:114
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:91
static autoPtr< surfaceWriter > New(const word &writeType)
Return a reference to the selected surfaceWriter.
Definition: surfaceWriter.C:55
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.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243