From e4139898d21d7501d0641ddfb097e231ae426892 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Nov 2022 17:24:36 +0100 Subject: [PATCH] ENH: face::connected() method - return true if two faces share a common vertex. Same idea as the existing edge::connected() method (previously spelled 'connects()') --- applications/test/edges/Test-edges.C | 2 +- .../meshes/meshShapes/cell/oppositeCellFace.C | 56 ++++++------------- src/OpenFOAM/meshes/meshShapes/edge/edge.H | 9 ++- src/OpenFOAM/meshes/meshShapes/edge/edgeI.H | 2 +- src/OpenFOAM/meshes/meshShapes/face/face.H | 10 +++- src/OpenFOAM/meshes/meshShapes/face/faceI.H | 27 +++++++++ .../edgeMeshTools/edgeMeshFeatureProximity.C | 2 +- .../structuredRenumber/OppositeFaceCellWave.C | 40 +++---------- 8 files changed, 70 insertions(+), 78 deletions(-) diff --git a/applications/test/edges/Test-edges.C b/applications/test/edges/Test-edges.C index fb6e3fd409..43acfbda48 100644 --- a/applications/test/edges/Test-edges.C +++ b/applications/test/edges/Test-edges.C @@ -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); diff --git a/src/OpenFOAM/meshes/meshShapes/cell/oppositeCellFace.C b/src/OpenFOAM/meshes/meshShapes/cell/oppositeCellFace.C index f6aede0250..94044e28b5 100644 --- a/src/OpenFOAM/meshes/meshShapes/cell/oppositeCellFace.C +++ b/src/OpenFOAM/meshes/meshShapes/cell/oppositeCellFace.C @@ -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; } } } diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index b014650ce4..bc653b49c9 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -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 diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index c87dd54285..761948e2d0 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -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())); } diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index b90c8d61e8..3257afc7f6 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -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 + inline bool connected(const FixedList& 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); diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index bc4ca27003..f54203a27e 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -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 +inline bool Foam::face::connected(const FixedList& 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) diff --git a/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C b/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C index 0b6eb51565..a3efb14d93 100644 --- a/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C +++ b/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C @@ -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()); diff --git a/src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C b/src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C index 4ab3daae5d..7b2bb7046d 100644 --- a/src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C +++ b/src/renumber/renumberMethods/structuredRenumber/OppositeFaceCellWave.C @@ -49,44 +49,22 @@ void Foam::OppositeFaceCellWave::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); } } }