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-2026 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",
82  );
83  }
84 
85  writeSets_ = dict.lookupOrDefault("writeSets", false);
86  if (writeSets_)
87  {
88  setFormat_ = dict.lookupOrDefault<word>
89  (
90  "setFormat",
92  );
93  }
94 
95  nonOrthThreshold_ = dict.lookupOrDefault
96  (
97  "nonOrthThreshold",
99  degToRad(70.0)
100  );
101  skewThreshold_ = dict.lookupOrDefault("skewThreshold", 4.0);
102 
103  stopAt_ = Time::stopAtControlNames
104  [
105  dict.lookupOrDefault<word>
106  (
107  "stopAt",
109  )
110  ];
111 
112  return functionObject::read(dict);
113 }
114 
115 
117 {
118  if (mesh_.changing())
119  {
120  autoPtr<surfaceWriter> surfWriter;
121  if (writeSurfaces_)
122  {
123  surfWriter = surfaceWriter::New
124  (
125  surfaceFormat_,
126  mesh_.time().writeFormat(),
127  mesh_.time().writeCompression()
128  );
129  }
130 
132  if (writeSets_)
133  {
135  (
136  setFormat_,
137  mesh_.time().writeFormat(),
138  mesh_.time().writeCompression()
139  );
140  }
141 
142  label nFailedChecks = 0;
143 
144  if (!noTopology_)
145  {
146  nFailedChecks += meshCheck::checkTopology
147  (
148  mesh_,
149  allTopology_,
150  surfWriter,
151  setWriter
152  );
153  }
154 
155  nFailedChecks += meshCheck::checkGeometry
156  (
157  mesh_,
158  allGeometry_,
159  nonOrthThreshold_,
160  skewThreshold_,
161  surfWriter,
162  setWriter
163  );
164 
165  if (nFailedChecks == 0)
166  {
167  Info<< "\n Mesh OK.\n" << endl;
168  }
169  else
170  {
171  Info<< "\n Failed " << nFailedChecks << " mesh checks.\n";
172 
173  if (stopAt_ != Time::stopAtControl::endTime)
174  {
175  Info<< indent
176  << "Stopping at " << Time::stopAtControlNames[stopAt_]
177  << endl;
178 
179  time_.stopAt(stopAt_);
180  }
181 
182  Info<< endl;
183  }
184 
185  return nFailedChecks == 0;
186  }
187  else
188  {
189  return true;
190  }
191 }
192 
193 
195 {
196  return true;
197 }
198 
199 
200 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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:116
virtual bool write()
Do nothing.
Definition: checkMesh.C:194
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:63
Functions for checking mesh topology and geometry.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, 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.
const unitSet degrees
Namespace for OpenFOAM.
scalar degToRad(const scalar deg)
Convert degrees to radians.
Definition: units.C:364
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:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
messageStream Info
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
dictionary dict