initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / mesh / manipulation / checkMesh / checkMesh.C
blob62c08b48c50ab0dd7659b00f66c285b27ed114c4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Application
26     checkMesh
28 Description
29     Checks validity of a mesh
31 \*---------------------------------------------------------------------------*/
33 #include "argList.H"
34 #include "Time.H"
35 #include "polyMesh.H"
36 #include "globalMeshData.H"
38 #include "printMeshStats.H"
39 #include "checkTopology.H"
40 #include "checkGeometry.H"
42 using namespace Foam;
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 int main(int argc, char *argv[])
48 #   include "addRegionOption.H"
50 #   include "addTimeOptionsNoConstant.H"
52     argList::validOptions.insert("noTopology", "");
53     argList::validOptions.insert("allGeometry", "");
54     argList::validOptions.insert("allTopology", "");
56 #   include "setRootCase.H"
58     const bool noTopology = args.options().found("noTopology");
59     const bool allGeometry = args.options().found("allGeometry");
60     const bool allTopology = args.options().found("allTopology");
62 #   include "createTime.H"
64     // Get times list
65     instantList Times = runTime.times();
67 #   include "checkTimeOptionsNoConstant.H"
69     runTime.setTime(Times[startTime], startTime);
71 #   include "createNamedPolyMesh.H"
73     bool firstCheck = true;
75     for (label i=startTime; i<endTime; i++)
76     {
77         runTime.setTime(Times[i], i);
79         polyMesh::readUpdateState state = mesh.readUpdate();
81         if
82         (
83             firstCheck
84          || state == polyMesh::TOPO_CHANGE
85          || state == polyMesh::TOPO_PATCH_CHANGE
86         )
87         {
88             firstCheck = false;
90             Info<< "Time = " << runTime.timeName() << nl << endl;
92             // Clear mesh before checking
93             mesh.clearOut();
95             // Reconstruct globalMeshData
96             mesh.globalData();
98             printMeshStats(mesh, allTopology);
100             label noFailedChecks = 0;
102             if (!noTopology)
103             {
104                 noFailedChecks += checkTopology(mesh, allTopology, allGeometry);
105             }
107             noFailedChecks += checkGeometry(mesh, allGeometry);
109             reduce(noFailedChecks, sumOp<label>());
111             if (noFailedChecks == 0)
112             {
113                 Info<< "\nMesh OK."
114                     << nl << endl;
115             }
116             else
117             {
118                 Info<< "\nFailed " << noFailedChecks << " mesh checks."
119                     << nl << endl;
120             }
121         }
122         else if (state == polyMesh::POINTS_MOVED)
123         {
124             Info<< "Time = " << runTime.timeName() << nl << endl;
126             label noFailedChecks = checkGeometry(mesh, allGeometry);
128             reduce(noFailedChecks, sumOp<label>());
130             if (noFailedChecks == 0)
131             {
132                 Info << "\nMesh OK."
133                     << nl << endl;
134             }
135             else
136             {
137                 Info<< "\nFailed " << noFailedChecks << " mesh checks."
138                     << nl << endl;
139             }
140         }
141     }
143     Info<< "End\n" << endl;
145     return(0);
149 // ************************************************************************* //