/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "meshCheck.H"
#include "polyMeshCheck.H"
#include "Time.H"
#include "regionSplit.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "IOmanip.H"
#include "emptyPolyPatch.H"
#include "processorPolyPatch.H"
#include "surfaceWriter.H"
#include "mergeAndWrite.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::label Foam::meshCheck::checkTopology
(
const polyMesh& mesh,
const bool allTopology,
const autoPtr& surfWriter,
const autoPtr& setWriter
)
{
label noFailedChecks = 0;
Info<< "Checking topology..." << endl;
// Check if the boundary definition is unique
mesh.boundary().checkDefinition(true);
// Check that empty patches cover all sides of the mesh
{
label nEmpty = 0;
forAll(mesh.boundary(), patchi)
{
if (isA(mesh.boundary()[patchi]))
{
nEmpty += mesh.boundary()[patchi].size();
}
}
reduce(nEmpty, sumOp());
label nTotCells = returnReduce(mesh.cells().size(), sumOp());
// These are actually warnings, not errors.
if (nTotCells && (nEmpty % nTotCells))
{
Info<< " ***Total number of faces on empty patches"
<< " is not divisible by the number of cells in the mesh."
<< " Hence this mesh is not 1D or 2D."
<< endl;
}
}
// Check if the boundary processor patches are correct
mesh.boundary().checkParallelSync(true);
// Check names of zones are equal
mesh.cellZones().checkDefinition(true);
if (mesh.cellZones().checkParallelSync(true))
{
noFailedChecks++;
}
mesh.faceZones().checkDefinition(true);
if (mesh.faceZones().checkParallelSync(true))
{
noFailedChecks++;
}
mesh.pointZones().checkDefinition(true);
if (mesh.pointZones().checkParallelSync(true))
{
noFailedChecks++;
}
{
cellSet cells(mesh, "illegalCells", mesh.nCells()/100);
forAll(mesh.cells(), celli)
{
const cell& cFaces = mesh.cells()[celli];
if (cFaces.size() <= 3)
{
cells.insert(celli);
}
forAll(cFaces, i)
{
if (cFaces[i] < 0 || cFaces[i] >= mesh.nFaces())
{
cells.insert(celli);
break;
}
}
}
label nCells = returnReduce(cells.size(), sumOp());
if (nCells > 0)
{
Info<< " Illegal cells (less than 4 faces or out of range faces)"
<< " found, number of cells: " << nCells << endl;
noFailedChecks++;
if (setWriter.valid())
{
Info<< " < 0)
{
if (setWriter.valid())
{
Info<< " < 0)
{
if (setWriter.valid())
{
Info<< " < 0)
{
if (setWriter.valid())
{
Info<< " < 0)
{
if (setWriter.valid())
{
Info<< " <= 0 : single region
labelList pointToRegion(mesh.nPoints(), -1);
for
(
label faceI = mesh.nInternalFaces();
faceI < mesh.nFaces();
faceI++
)
{
label regionI = rs[mesh.faceOwner()[faceI]];
const face& f = mesh.faces()[faceI];
forAll(f, fp)
{
label& pRegion = pointToRegion[f[fp]];
if (pRegion == -1)
{
pRegion = regionI;
}
else if (pRegion == -2)
{
// Already marked
regionDisconnected[regionI] = false;
}
else if (pRegion != regionI)
{
// Multiple regions
regionDisconnected[regionI] = false;
regionDisconnected[pRegion] = false;
pRegion = -2;
points.insert(f[fp]);
}
}
}
Pstream::listCombineGather
(
regionDisconnected,
andEqOp()
);
Pstream::listCombineScatter(regionDisconnected);
// write cellSet for each region
PtrList cellRegions(rs.nRegions());
for (label i = 0; i < rs.nRegions(); i++)
{
cellRegions.set
(
i,
new cellSet
(
mesh,
"region" + Foam::name(i),
mesh.nCells()/100
)
);
}
forAll(rs, i)
{
cellRegions[rs[i]].insert(i);
}
for (label i = 0; i < rs.nRegions(); i++)
{
Info<< " <(pp))
{
Info<< " "
<< setw(20) << pp.name()
<< setw(9) << returnReduce(pp.size(), sumOp())
<< setw(9) << returnReduce(pp.nPoints(), sumOp());
if (!Pstream::parRun())
{
primitivePatch::surfaceTopo pTyp = pp.surfaceType();
if (pp.empty())
{
Info<< setw(34) << "ok (empty)";
}
else if (pTyp == primitivePatch::MANIFOLD)
{
if (pp.checkPointManifold(true, &points))
{
Info<< setw(34)
<< "multiply connected (shared point)";
}
else
{
Info<< setw(34) << "ok (closed singly connected)";
}
// Add points on non-manifold edges to make set complete
pp.checkTopology(false, &points);
}
else
{
pp.checkTopology(false, &points);
if (pTyp == primitivePatch::OPEN)
{
Info<< setw(34)
<< "ok (non-closed singly connected)";
}
else
{
Info<< setw(34)
<< "multiply connected (shared edge)";
}
}
}
Info<< endl;
}
}
if (points.size() && setWriter.valid())
{
Info<< " <