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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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  - checkMesh [OPTION]
32 
33  \param -allGeometry \n
34  Checks all (including non finite-volume specific) geometry
35 
36  \param -allTopology \n
37  Checks all (including non finite-volume specific) addressing
38 
39  \param -meshQuality \n
40  Checks against user defined (in \a system/meshQualityDict) quality settings
41 
42  \param -region <name> \n
43  Specify an alternative mesh region.
44 
45  \param -writeSets <surfaceFormat> \n
46  Reconstruct all cellSets and faceSets geometry and write to postProcessing/
47  directory according to surfaceFormat (e.g. vtk or ensight)
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #include "argList.H"
52 #include "timeSelector.H"
53 #include "Time.H"
54 #include "polyMesh.H"
55 #include "globalMeshData.H"
56 #include "vtkSurfaceWriter.H"
57 
58 #include "checkTools.H"
59 #include "checkTopology.H"
60 #include "checkGeometry.H"
61 #include "checkMeshQuality.H"
62 
63 using namespace Foam;
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 int main(int argc, char *argv[])
68 {
70  #include "addRegionOption.H"
72  (
73  "noTopology",
74  "skip checking the mesh topology"
75  );
77  (
78  "allGeometry",
79  "include bounding box checks"
80  );
82  (
83  "allTopology",
84  "include extra topology checks"
85  );
87  (
88  "meshQuality",
89  "read user-defined mesh quality criterions from system/meshQualityDict"
90  );
92  (
93  "writeSets",
94  "surfaceFormat"
95  "reconstruct and write all faceSets and cellSets in selected format"
96  );
97 
98  #include "setRootCase.H"
99  #include "createTime.H"
101  #include "createNamedPolyMesh.H"
102 
103  const bool noTopology = args.optionFound("noTopology");
104  const bool allGeometry = args.optionFound("allGeometry");
105  const bool allTopology = args.optionFound("allTopology");
106  const bool meshQuality = args.optionFound("meshQuality");
107 
108  word surfaceFormat;
109  const bool writeSets = args.optionReadIfPresent("writeSets", surfaceFormat);
110 
111  if (noTopology)
112  {
113  Info<< "Disabling all topology checks." << nl << endl;
114  }
115  if (allTopology)
116  {
117  Info<< "Enabling all (cell, face, edge, point) topology checks."
118  << nl << endl;
119  }
120  if (allGeometry)
121  {
122  Info<< "Enabling all geometry checks." << nl << endl;
123  }
124  if (meshQuality)
125  {
126  Info<< "Enabling user-defined geometry checks." << nl << endl;
127  }
128  if (writeSets)
129  {
130  Info<< "Reconstructing and writing " << surfaceFormat
131  << " representation"
132  << " of all faceSets and cellSets." << nl << endl;
133  }
134 
135 
136  autoPtr<IOdictionary> qualDict;
137  if (meshQuality)
138  {
139  qualDict.reset
140  (
141  new IOdictionary
142  (
143  IOobject
144  (
145  "meshQualityDict",
146  mesh.time().system(),
147  mesh,
150  )
151  )
152  );
153  }
154 
155 
157  if (writeSets)
158  {
159  writer = surfaceWriter::New(surfaceFormat);
160  }
161 
162 
163  forAll(timeDirs, timeI)
164  {
165  runTime.setTime(timeDirs[timeI], timeI);
166 
168 
169  if
170  (
171  !timeI
172  || state == polyMesh::TOPO_CHANGE
173  || state == polyMesh::TOPO_PATCH_CHANGE
174  )
175  {
176  Info<< "Time = " << runTime.timeName() << nl << endl;
177 
178  // Clear mesh before checking
179  mesh.clearOut();
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 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
checkTools.H
Foam::polyMesh::POINTS_MOVED
@ POINTS_MOVED
Definition: polyMesh.H:91
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
globalMeshData.H
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::checkGeometry
label checkGeometry(const polyMesh &mesh, const bool allGeometry, const autoPtr< surfaceWriter > &)
Definition: checkGeometry.C:478
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
checkGeometry.H
Foam::printMeshStats
void printMeshStats(const polyMesh &mesh, const bool allTopology)
Definition: checkTools.C:45
polyMesh.H
createNamedPolyMesh.H
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::fvMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:498
Foam::polyMesh::TOPO_PATCH_CHANGE
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:93
Foam::checkMeshQuality
label checkMeshQuality(const polyMesh &, const dictionary &, const autoPtr< surfaceWriter > &)
Definition: checkMeshQuality.C:10
checkTopology.H
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::TimePaths::system
const word & system() const
Return system name.
Definition: TimePaths.H:120
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: checkMesh.C:64
addRegionOption.H
checkMeshQuality.H
Foam::polyMesh::TOPO_CHANGE
@ TOPO_CHANGE
Definition: polyMesh.H:92
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
setRootCase.H
timeDirs
static instantList timeDirs
Definition: globalFoam.H:44
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Foam::surfaceWriter::New
static autoPtr< surfaceWriter > New(const word &writeType)
Return a reference to the selected surfaceWriter.
Definition: surfaceWriter.C:55
vtkSurfaceWriter.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
timeSelector.H
createTime.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::autoPtr::reset
void reset(T *=0)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1143
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
args
Foam::argList args(argc, argv)
Foam::argList::optionReadIfPresent
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
Foam::fvMesh::clearOut
void clearOut()
Clear all geometry and addressing.
Definition: fvMesh.C:231
Foam::checkTopology
label checkTopology(const polyMesh &, const bool, const bool, const autoPtr< surfaceWriter > &)
Definition: checkTopology.C:42