/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2025 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 "blockDescriptor.H"
#include "blockMesh.H"
#include "blockMeshTools.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::blockDescriptor::check(const Istream& is)
{
forAll(blockShape_, pi)
{
if (blockShape_[pi] < 0)
{
FatalIOErrorInFunction(is)
<< "Negative point label " << blockShape_[pi]
<< " in block " << *this
<< exit(FatalIOError);
}
else if (blockShape_[pi] >= vertices_.size())
{
FatalIOErrorInFunction(is)
<< "Point label " << blockShape_[pi]
<< " out of range 0.." << vertices_.size() - 1
<< " in block " << *this
<< exit(FatalIOError);
}
}
const faceList faces(blockShape_.faces());
// Check each face is outward-pointing with respect to the block centre
label outwardFaceCount = 0;
boolList correctFaces(faces.size(), true);
forAll(faces, i)
{
const point faceCentre(faces[i].centre(vertices_));
const vector faceArea(faces[i].area(vertices_));
if (mag(faceArea) > small)
{
bool outwardFace = false;
forAll(faces, j)
{
if (j != i)
{
if
(
((faceCentre - faces[j].centre(vertices_)) & faceArea)
> 0
)
{
outwardFace = true;
}
}
}
if (outwardFace)
{
outwardFaceCount++;
}
else
{
correctFaces[i] = false;
}
}
else
{
outwardFaceCount++;
}
}
// If all faces are inward-pointing the block is inside-out
if (outwardFaceCount == 0)
{
FatalIOErrorInFunction(is)
<< "Block " << *this << " is inside-out"
<< exit(FatalIOError);
}
else if (outwardFaceCount != faces.size())
{
FatalIOErrorInFunction(is)
<< "Block " << *this << " has inward-pointing faces"
<< nl << " ";
forAll(correctFaces, i)
{
if (!correctFaces[i])
{
FatalIOError<< faces[i] << token::SPACE;
}
}
FatalIOError << exit(FatalIOError);
}
}
void Foam::blockDescriptor::findCurvedFaces()
{
const faceList blockFaces(blockShape().faces());
forAll(blockFaces, blockFacei)
{
forAll(faces_, facei)
{
if
(
face::sameVertices
(
faces_[facei].vertices(),
blockFaces[blockFacei]
)
)
{
curvedFaces_[blockFacei] = facei;
nCurvedFaces_++;
break;
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::blockDescriptor::blockDescriptor
(
const cellShape& bshape,
const pointField& vertices,
const blockEdgeList& edges,
const blockFaceList& faces,
const Vector