ENH: add face/triFace contains(edge) method (#3004)

STYLE: use contains() and reduce reliance on edgeDirection -1/+1 values
This commit is contained in:
Mark Olesen
2023-10-25 21:22:51 +02:00
parent b34793c392
commit 29e2718162
9 changed files with 53 additions and 23 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021-2022 OpenCFD Ltd.
Copyright (C) 2021-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -812,7 +812,7 @@ Foam::edgeList Foam::face::rcEdges() const
int Foam::face::edgeDirection(const Foam::edge& e) const
{
const label idx = find(e.first());
const label idx = labelList::find(e.first());
if (idx != -1)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -365,6 +365,15 @@ public:
// and rcEdge 1 is from [n-1] to [n-2]
edgeList rcEdges() const;
// Searching
//- Regular contains(pointi) tests
using labelList::contains;
//- True if face contains(edge)
inline bool contains(const Foam::edge& e) const;
//- Test the edge direction on the face
// \return
// - 0: edge not found on the face

View File

@ -232,6 +232,12 @@ inline bool Foam::face::connected(const FixedList<label, N>& other) const
}
inline bool Foam::face::contains(const Foam::edge& e) const
{
return (edgeDirection(e) != 0);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline void Foam::face::operator+=(const label vertexOffset)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -319,6 +319,15 @@ public:
// and rcEdge 1 is from [n-1] to [n-2]
inline edgeList rcEdges() const;
// Searching
//- Regular contains(pointi) tests
using FixedList<label, 3>::contains;
//- True if face contains(edge)
inline bool contains(const Foam::edge& e) const;
//- Test the edge direction on the face
// \return
// - +1: forward (counter-clockwise) on the face

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -446,24 +446,30 @@ inline int Foam::triFace::edgeDirection(const Foam::edge& e) const
{
if (e.first() == a())
{
if (e.second() == b()) return 1; // Forward
if (e.second() == c()) return -1; // Reverse
if (e.second() == b()) return 1; // edge 0 - forward
if (e.second() == c()) return -1; // edge 2 - reverse
}
if (e.first() == b())
{
if (e.second() == c()) return 1; // Forward
if (e.second() == a()) return -1; // Reverse
if (e.second() == c()) return 1; // edge 1 - forward
if (e.second() == a()) return -1; // edge 0 - reverse
}
if (e.first() == c())
{
if (e.second() == a()) return 1; // Forward
if (e.second() == b()) return -1; // Reverse
if (e.second() == a()) return 1; // edge 2 - forward
if (e.second() == b()) return -1; // edge 1 - reverse
}
return 0; // Not found
}
inline bool Foam::triFace::contains(const Foam::edge& e) const
{
return (edgeDirection(e) != 0);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline void Foam::triFace::operator+=(const label vertexOffset)

View File

@ -106,7 +106,7 @@ void Foam::wallBoundedParticle::crossEdgeConnectedFace
const Foam::face& otherFace = pFaces[facei];
label edDir = otherFace.edgeDirection(e);
const auto edDir = otherFace.edgeDirection(e);
if (edDir == 0)
{
@ -128,7 +128,7 @@ void Foam::wallBoundedParticle::crossEdgeConnectedFace
label eIndex = -1;
if (edDir == 1)
if (edDir > 0)
{
// Edge is in the forward circulation of this face, so
// work with the start point of the edge
@ -136,7 +136,7 @@ void Foam::wallBoundedParticle::crossEdgeConnectedFace
}
else
{
// edDir == -1, so the edge is in the reverse
// (edge-direction < 0) - edge is in the reverse
// circulation of this face, so work with the end
// point of the edge
eIndex = otherFace.find(e.end());

View File

@ -1026,11 +1026,12 @@ void Foam::refinementSurfaces::setCurvatureMinLevelFields
const auto& f1 = ts[eFaces[1]];
const vector n0 = f0.unitNormal(points);
const int dir0 = f0.edgeDirection(meshE);
const int dir1 = f1.edgeDirection(meshE);
vector n1 = f1.unitNormal(points);
if (dir0 == dir1)
const auto dir0 = f0.edgeDirection(meshE);
const auto dir1 = f1.edgeDirection(meshE);
if (dir0 && ((dir0 > 0) == (dir1 > 0)))
{
// Flip since use edge in same direction
// (should not be the case for 'proper'

View File

@ -587,7 +587,7 @@ Foam::surfaceFeatures::surfaceFeatures::checkFlatRegionEdge
forAll(bin0, i)
{
const labelledTri& t = surf.localFaces()[eFaces[bin0[i]]];
int dir = t.edgeDirection(e);
const auto dir = t.edgeDirection(e);
if (dir > 0)
{
@ -610,7 +610,7 @@ Foam::surfaceFeatures::surfaceFeatures::checkFlatRegionEdge
forAll(bin1, i)
{
const labelledTri& t = surf.localFaces()[eFaces[bin1[i]]];
int dir = t.edgeDirection(e);
const auto dir = t.edgeDirection(e);
label myRegionAndNormal;
if (dir > 0)

View File

@ -1174,8 +1174,7 @@ Foam::label Foam::distributedTriSurfaceMesh::findOtherFace
{
if (facei != nearFacei)
{
int dir = surf[facei].edgeDirection(e);
if (dir != 0)
if (surf[facei].contains(e))
{
return facei;
}
@ -1211,7 +1210,7 @@ void Foam::distributedTriSurfaceMesh::calcFaceFaces
{
if (otherFacei != facei)
{
if (s[otherFacei].edgeDirection(e) != 0)
if (s[otherFacei].contains(e))
{
if (!nbrs.find(otherFacei))
{