/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "primitiveMeshCheck.H"
#include "pyramidPointFaceRef.H"
#include "PackedBoolList.H"
#include "units.H"
#include "SortableList.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::meshCheck::faceSkewness
(
const primitiveMesh& mesh,
const pointField& p,
const vectorField& fCtrs,
const vectorField& fAreas,
const label facei,
const point& ownCc,
const point& neiCc
)
{
const vector Cpf = fCtrs[facei] - ownCc;
const vector d = neiCc - ownCc;
// Skewness vector
const vector sv =
Cpf
- ((fAreas[facei] & Cpf)/((fAreas[facei] & d) + rootVSmall))*d;
const vector svHat = sv/(mag(sv) + rootVSmall);
// Normalisation distance calculated as the approximate distance
// from the face centre to the edge of the face in the direction
// of the skewness
scalar fd = 0.2*mag(d) + rootVSmall;
const face& f = mesh.faces()[facei];
forAll(f, pi)
{
fd = max(fd, mag(svHat & (p[f[pi]] - fCtrs[facei])));
}
// Normalised skewness
return mag(sv)/fd;
}
Foam::scalar Foam::meshCheck::boundaryFaceSkewness
(
const primitiveMesh& mesh,
const pointField& p,
const vectorField& fCtrs,
const vectorField& fAreas,
const label facei,
const point& ownCc
)
{
const vector Cpf = fCtrs[facei] - ownCc;
vector normal = fAreas[facei];
normal /= mag(normal) + rootVSmall;
const vector d = normal*(normal & Cpf);
// Skewness vector
const vector sv =
Cpf
- ((fAreas[facei] & Cpf)/((fAreas[facei] & d) + rootVSmall))*d;
const vector svHat = sv/(mag(sv) + rootVSmall);
// Normalisation distance calculated as the approximate distance
// from the face centre to the edge of the face in the direction
// of the skewness
scalar fd = 0.4*mag(d) + rootVSmall;
const face& f = mesh.faces()[facei];
forAll(f, pi)
{
fd = max(fd, mag(svHat & (p[f[pi]] - fCtrs[facei])));
}
// Normalised skewness
return mag(sv)/fd;
}
Foam::scalar Foam::meshCheck::faceOrthogonality
(
const point& ownCc,
const point& neiCc,
const vector& s
)
{
const vector d = neiCc - ownCc;
return (d & s)/(mag(d)*mag(s) + rootVSmall);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::tmp Foam::meshCheck::faceOrthogonality
(
const primitiveMesh& mesh,
const vectorField& areas,
const vectorField& cc
)
{
const labelList& own = mesh.faceOwner();
const labelList& nei = mesh.faceNeighbour();
tmp tortho(new scalarField(mesh.nInternalFaces()));
scalarField& ortho = tortho.ref();
// Internal faces
forAll(nei, facei)
{
ortho[facei] = faceOrthogonality
(
cc[own[facei]],
cc[nei[facei]],
areas[facei]
);
}
return tortho;
}
Foam::tmp Foam::meshCheck::faceSkewness
(
const primitiveMesh& mesh,
const pointField& p,
const vectorField& fCtrs,
const vectorField& fAreas,
const vectorField& cellCtrs
)
{
const labelList& own = mesh.faceOwner();
const labelList& nei = mesh.faceNeighbour();
tmp tskew(new scalarField(mesh.nFaces()));
scalarField& skew = tskew.ref();
forAll(nei, facei)
{
skew[facei] = faceSkewness
(
mesh,
p,
fCtrs,
fAreas,
facei,
cellCtrs[own[facei]],
cellCtrs[nei[facei]]
);
}
// Boundary faces: consider them to have only skewness error.
// (i.e. treat as if mirror cell on other side)
for (label facei = mesh.nInternalFaces(); facei < mesh.nFaces(); facei++)
{
skew[facei] = boundaryFaceSkewness
(
mesh,
p,
fCtrs,
fAreas,
facei,
cellCtrs[own[facei]]
);
}
return tskew;
}
void Foam::meshCheck::facePyramidVolume
(
const primitiveMesh& mesh,
const pointField& points,
const vectorField& ctrs,
scalarField& ownPyrVol,
scalarField& neiPyrVol
)
{
const labelList& own = mesh.faceOwner();
const labelList& nei = mesh.faceNeighbour();
const faceList& f = mesh.faces();
ownPyrVol.setSize(mesh.nFaces());
neiPyrVol.setSize(mesh.nInternalFaces());
forAll(f, facei)
{
// Create the owner pyramid
ownPyrVol[facei] = -pyramidPointFaceRef
(
f[facei],
ctrs[own[facei]]
).mag(points);
if (mesh.isInternalFace(facei))
{
// Create the neighbour pyramid - it will have positive volume
neiPyrVol[facei] = pyramidPointFaceRef
(
f[facei],
ctrs[nei[facei]]
).mag(points);
}
}
}
void Foam::meshCheck::cellClosedness
(
const primitiveMesh& mesh,
const Vector