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) 2023-2024 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 \*---------------------------------------------------------------------------*/
25 
26 #include "checkMesh.H"
27 #include "fvMesh.H"
28 #include "meshCheck.H"
29 #include "vtkSetWriter.H"
30 #include "vtkSurfaceWriter.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const word& name,
50  const Time& runTime,
51  const dictionary& dict
52 )
53 :
54  fvMeshFunctionObject(name, runTime, dict),
55  stopAt_(Time::stopAtControl::endTime)
56 {
57  read(dict);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 {
71  noTopology_ = dict.lookupOrDefault("noTopology", false);
72  allGeometry_ = dict.lookupOrDefault("allGeometry", false);
73  allTopology_ = dict.lookupOrDefault("allTopology", false);
74 
75  writeSurfaces_ = dict.lookupOrDefault("writeSurfaces", false);
76  if (writeSurfaces_)
77  {
78  surfaceFormat_ = dict.lookupOrDefault<word>
79  (
80  "surfaceFormat",
81  vtkSurfaceWriter::typeName
82  );
83  }
84 
85  writeSets_ = dict.lookupOrDefault("writeSets", false);
86  if (writeSets_)
87  {
88  setFormat_ = dict.lookupOrDefault<word>
89  (
90  "setFormat",
91  vtkSetWriter::typeName
92  );
93  }
94 
95  nonOrthThreshold_ =
96  dict.lookupOrDefault("nonOrthThreshold", unitDegrees, degToRad(70.0));
97  skewThreshold_ = dict.lookupOrDefault("skewThreshold", 4.0);
98 
99  stopAt_ = Time::stopAtControlNames
100  [
101  dict.lookupOrDefault<word>
102  (
103  "stopAt",
105  )
106  ];
107 
108  return functionObject::read(dict);
109 }
110 
111 
113 {
114  if (mesh_.changing())
115  {
116  autoPtr<surfaceWriter> surfWriter;
117  if (writeSurfaces_)
118  {
119  surfWriter = surfaceWriter::New
120  (
121  surfaceFormat_,
122  mesh_.time().writeFormat(),
123  mesh_.time().writeCompression()
124  );
125  }
126 
128  if (writeSets_)
129  {
131  (
132  setFormat_,
133  mesh_.time().writeFormat(),
134  mesh_.time().writeCompression()
135  );
136  }
137 
138  label nFailedChecks = 0;
139 
140  if (!noTopology_)
141  {
142  nFailedChecks += meshCheck::checkTopology
143  (
144  mesh_,
145  allTopology_,
146  surfWriter,
147  setWriter
148  );
149  }
150 
151  nFailedChecks += meshCheck::checkGeometry
152  (
153  mesh_,
154  allGeometry_,
155  nonOrthThreshold_,
156  skewThreshold_,
157  surfWriter,
158  setWriter
159  );
160 
161  if (nFailedChecks == 0)
162  {
163  Info<< "\n Mesh OK.\n" << endl;
164  }
165  else
166  {
167  Info<< "\n Failed " << nFailedChecks << " mesh checks.\n";
168 
169  if (stopAt_ != Time::stopAtControl::endTime)
170  {
171  Info<< " Stopping at " << Time::stopAtControlNames[stopAt_]
172  << endl;
173 
174  time_.stopAt(stopAt_);
175  }
176 
177  Info<< endl;
178  }
179 
180  return nFailedChecks == 0;
181  }
182  else
183  {
184  return true;
185  }
186 }
187 
188 
190 {
191  return true;
192 }
193 
194 
195 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static const NamedEnum< stopAtControl, 4 > stopAtControlNames
Definition: Time.H:117
@ endTime
stop when Time reaches the prescribed endTime
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
Executes primitiveMesh::checkMesh(true) every execute time for which the mesh changed,...
Definition: checkMesh.H:168
virtual ~checkMesh()
Destructor.
Definition: checkMesh.C:63
checkMesh(const word &name, const Time &, const dictionary &)
Construct from Time and dictionary.
Definition: checkMesh.C:48
virtual bool execute()
Execute primitiveMesh::checkMesh(true)
Definition: checkMesh.C:112
virtual bool write()
Do nothing.
Definition: checkMesh.C:189
virtual bool read(const dictionary &)
Read the checkMesh controls.
Definition: checkMesh.C:69
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Base class for writing coordinate sets with data.
Definition: setWriter.H:64
static autoPtr< setWriter > New(const word &writeType, const IOstream::streamFormat writeFormat=IOstream::ASCII, const IOstream::compressionType writeCompression=IOstream::UNCOMPRESSED)
Select given write options.
Definition: setWriter.C:286
static autoPtr< surfaceWriter > New(const word &writeType, const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Select given write options.
Definition: surfaceWriter.C:75
A class for handling words, derived from string.
Definition: word.H:62
Functions for checking mesh topology and geometry.
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
label checkTopology(const polyMesh &mesh, const bool allTopology, const autoPtr< surfaceWriter > &surfWriter, const autoPtr< setWriter > &setWriter)
Check the topology.
Definition: checkTopology.C:42
label checkGeometry(const polyMesh &mesh, const bool allGeometry, const scalar nonOrthThreshold, const scalar skewThreshold, const autoPtr< surfaceWriter > &, const autoPtr< setWriter > &)
Check the geometry.
Namespace for OpenFOAM.
scalar degToRad(const scalar deg)
Convert degrees to radians.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
const unitConversion unitDegrees
dictionary dict