ENH: face::connected() method

- return true if two faces share a common vertex.

  Same idea as the existing edge::connected() method
  (previously spelled 'connects()')
This commit is contained in:
Mark Olesen 2022-11-01 17:24:36 +01:00 committed by Andrew Heather
parent d3e285b48b
commit e4139898d2
8 changed files with 70 additions and 78 deletions

View File

@ -67,7 +67,7 @@ int main(int argc, char *argv[])
Info<<"collapse? -> " << e4.collapse() << endl;
printInfo(e4);
Info<< e3 << " connects " << e2 << " => " << e2.connects(e3) << endl;
Info<< e3 << " connects " << e2 << " => " << e2.connected(e3) << endl;
labelPair labels(e3);

View File

@ -49,59 +49,35 @@ Foam::label Foam::cell::opposingFaceLabel
const face& masterFace = meshFaces[masterFaceLabel];
const labelList& curFaceLabels = *this;
label oppositeFaceLabel = -1;
forAll(curFaceLabels, facei)
for (const label facei : *this)
{
// Compare the face with the master
const face& curFace = meshFaces[curFaceLabels[facei]];
const face& f = meshFaces[facei];
// Skip the master face
if
(
curFaceLabels[facei] != masterFaceLabel
&& curFace.size() == masterFace.size()
facei != masterFaceLabel
&& f.size() == masterFace.size()
&& !f.connected(masterFace)
)
{
bool sharedPoint = false;
// Compare every vertex of the current face against the
// vertices of the master face
forAll(curFace, pointi)
// Not connected : this is an opposite face
if (oppositeFaceLabel == -1)
{
const label l = curFace[pointi];
forAll(masterFace, masterPointi)
{
if (masterFace[masterPointi] == l)
{
sharedPoint = true;
break;
}
}
if (sharedPoint) break;
// Not previously found
oppositeFaceLabel = facei;
}
// If no points are shared, this is the opposite face
if (!sharedPoint)
else
{
if (oppositeFaceLabel == -1)
{
// Found opposite face
oppositeFaceLabel = curFaceLabels[facei];
}
else
{
// There has already been an opposite face.
// Non-prismatic cell
Info<< "Multiple faces not sharing vertex: "
<< oppositeFaceLabel << " and "
<< curFaceLabels[facei] << endl;
return -1;
}
// There has already been an opposite face.
// Non-prismatic cell
Info<< "Multiple faces not sharing vertex: "
<< oppositeFaceLabel << " and "
<< facei << endl;
return -1;
}
}
}

View File

@ -161,9 +161,8 @@ public:
// Always return -1 for a negative label.
inline label which(const label pointLabel) const;
//- Do the edges share a common vertex index?
// Negative point labels never connect.
inline bool connects(const edge& other) const;
//- True if the edge has at least one vertex in common with other
inline bool connected(const edge& other) const;
//- Return vertex common with other edge or -1 on failure
// Negative point labels are never considered common between edges.
@ -173,6 +172,10 @@ public:
// No special treatment for negative point labels.
inline label otherVertex(const label pointLabel) const;
//- Do the edges share a common vertex index?
// Negative point labels never connect.
bool connects(const edge& other) const { return connected(other); }
// Editing

View File

@ -140,7 +140,7 @@ inline Foam::label Foam::edge::which(const label pointLabel) const
}
inline bool Foam::edge::connects(const edge& other) const
inline bool Foam::edge::connected(const edge& other) const
{
return (other.found(first()) || other.found(second()));
}

View File

@ -427,6 +427,14 @@ public:
faceList& quadFaces
) const;
//- True if the face has at least one vertex in common with other
inline bool connected(const labelUList& other) const;
//- True if the face has at least one vertex in common with other
template<unsigned N>
inline bool connected(const FixedList<label, N>& other) const;
//- Compare faces
// \return
// - 0: different
@ -434,7 +442,7 @@ public:
// - -1: same face, but different orientation
static int compare(const face& a, const face& b);
//- Return true if the faces have the same vertices
//- True if the faces have all the same vertices
static bool sameVertices(const face& a, const face& b);

View File

@ -205,6 +205,33 @@ inline Foam::label Foam::face::nTriangles() const
}
inline bool Foam::face::connected(const labelUList& other) const
{
for (const label pointi : *this)
{
if (other.found(pointi))
{
return true;
}
}
return false;
}
template<unsigned N>
inline bool Foam::face::connected(const FixedList<label, N>& other) const
{
for (const label pointi : *this)
{
if (other.found(pointi))
{
return true;
}
}
return false;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline void Foam::face::operator+=(const label vertexOffset)

View File

@ -117,7 +117,7 @@ scalar calcProximityOfFeatureEdges
const edge& e2 = emesh.edges()[pHit2.index()];
// Don't refine if the edges are connected to each other
if (!e1.connects(e2))
if (!e1.connected(e2))
{
scalar curDist =
mag(pHit1.hitPoint() - pHit2.hitPoint());

View File

@ -49,44 +49,22 @@ void Foam::OppositeFaceCellWave<Type, TrackingData>::opposingFaceLabels
const face& masterFace = this->mesh_.faces()[masterFaceLabel];
const labelList& curFaceLabels = this->mesh_.cells()[celli];
oppositeFaceLabels.clear();
forAll(curFaceLabels, facei)
for (const label facei : this->mesh_.cells()[celli])
{
// Compare the face with the master
const face& curFace = this->mesh_.faces()[curFaceLabels[facei]];
const face& f = this->mesh_.faces()[facei];
// Skip the master face
if (curFaceLabels[facei] != masterFaceLabel)
if
(
facei != masterFaceLabel
&& !f.connected(masterFace)
)
{
bool sharedPoint = false;
// Compare every vertex of the current face against the
// vertices of the master face
forAll(curFace, pointi)
{
const label l = curFace[pointi];
forAll(masterFace, masterPointi)
{
if (masterFace[masterPointi] == l)
{
sharedPoint = true;
break;
}
}
if (sharedPoint) break;
}
// If no points are shared, this is the opposite face
if (!sharedPoint)
{
// Found opposite face
oppositeFaceLabels.append(curFaceLabels[facei]);
}
// Not connected : this is an opposite face
oppositeFaceLabels.push_back(facei);
}
}
}