/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "extendedEdgeMesh.H"
#include "surfaceFeatures.H"
#include "triSurface.H"
#include "Random.H"
#include "Time.H"
#include "OBJstream.H"
#include "DynamicField.H"
#include "edgeMeshFormatsCore.H"
#include "IOmanip.H"
#include "searchableSurface.H"
#include "triSurfaceMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(extendedEdgeMesh, 0);
}
const Foam::Enum
<
Foam::extendedEdgeMesh::pointStatus
>
Foam::extendedEdgeMesh::pointStatusNames_
({
{ pointStatus::CONVEX, "convex" },
{ pointStatus::CONCAVE, "concave" },
{ pointStatus::MIXED, "mixed" },
{ pointStatus::NONFEATURE, "nonFeature" },
});
const Foam::Enum
<
Foam::extendedEdgeMesh::edgeStatus
>
Foam::extendedEdgeMesh::edgeStatusNames_
({
{ edgeStatus::EXTERNAL, "external" },
{ edgeStatus::INTERNAL, "internal" },
{ edgeStatus::FLAT, "flat" },
{ edgeStatus::OPEN, "open" },
{ edgeStatus::MULTIPLE, "multiple" },
{ edgeStatus::NONE, "none" },
});
const Foam::Enum
<
Foam::extendedEdgeMesh::sideVolumeType
>
Foam::extendedEdgeMesh::sideVolumeTypeNames_
({
{ sideVolumeType::INSIDE, "inside" },
{ sideVolumeType::OUTSIDE, "outside" },
{ sideVolumeType::BOTH, "both" },
{ sideVolumeType::NEITHER, "neither" },
});
Foam::scalar Foam::extendedEdgeMesh::cosNormalAngleTol_ =
Foam::cos(degToRad(0.1));
Foam::label Foam::extendedEdgeMesh::convexStart_ = 0;
Foam::label Foam::extendedEdgeMesh::externalStart_ = 0;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::wordHashSet Foam::extendedEdgeMesh::readTypes()
{
return wordHashSet(*fileExtensionConstructorTablePtr_);
}
Foam::wordHashSet Foam::extendedEdgeMesh::writeTypes()
{
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
}
bool Foam::extendedEdgeMesh::canReadType(const word& fileType, bool verbose)
{
return edgeMeshFormatsCore::checkSupport
(
readTypes(),
fileType,
verbose,
"reading"
);
}
bool Foam::extendedEdgeMesh::canWriteType(const word& fileType, bool verbose)
{
return edgeMeshFormatsCore::checkSupport
(
writeTypes(),
fileType,
verbose,
"writing"
);
}
bool Foam::extendedEdgeMesh::canRead(const fileName& name, bool verbose)
{
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return canReadType(ext, verbose);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::extendedEdgeMesh::pointStatus
Foam::extendedEdgeMesh::classifyFeaturePoint
(
label ptI
) const
{
const labelList& ptEds(pointEdges()[ptI]);
label nPtEds = ptEds.size();
label nExternal = 0;
label nInternal = 0;
if (nPtEds == 0)
{
// There are no edges attached to the point, this is a problem
return NONFEATURE;
}
forAll(ptEds, i)
{
edgeStatus edStat = getEdgeStatus(ptEds[i]);
if (edStat == EXTERNAL)
{
nExternal++;
}
else if (edStat == INTERNAL)
{
nInternal++;
}
}
if (nExternal == nPtEds)
{
return CONVEX;
}
else if (nInternal == nPtEds)
{
return CONCAVE;
}
return MIXED;
}
void Foam::extendedEdgeMesh::cut
(
const searchableSurface& surf,
labelList& pointMap,
labelList& edgeMap,
labelList& pointsFromEdge,
labelList& oldEdge,
labelList& surfTri
)
{
const edgeList& edges = this->edges();
const pointField& points = this->points();
List> edgeHits(edges.size());
{
pointField start(edges.size());
pointField end(edges.size());
forAll(edges, edgeI)
{
const edge& e = edges[edgeI];
start[edgeI] = points[e[0]];
end[edgeI] = points[e[1]];
}
surf.findLineAll(start, end, edgeHits);
}
// Count number of hits
label nHits = 0;
forAll(edgeHits, edgeI)
{
nHits += edgeHits[edgeI].size();
}
DynamicField newPoints(points);
DynamicList