diff --git a/MeshLib/Elements/Element.cpp b/MeshLib/Elements/Element.cpp index 8356657fd483f5c0201d57d3dd0faf80f3585534..b24473e05a79423f5f0872dfd7977750f7c1af19 100644 --- a/MeshLib/Elements/Element.cpp +++ b/MeshLib/Elements/Element.cpp @@ -163,6 +163,11 @@ bool Element::hasNeighbor(Element* elem) const return false; } +bool Element::isBoundaryElement() const +{ + return std::any_of(_neighbors, _neighbors + this->getNNeighbors(), + [](MeshLib::Element* e){ return e == nullptr; }); +} } diff --git a/MeshLib/Elements/Element.h b/MeshLib/Elements/Element.h index 7e10f07e4044f9045a155d193c49e67f58696574..6e2dd8003768da3f312185cd1e853ca5e7041db1 100644 --- a/MeshLib/Elements/Element.h +++ b/MeshLib/Elements/Element.h @@ -148,6 +148,8 @@ public: */ bool hasZeroVolume() const { return this->getContent() < std::numeric_limits<double>::epsilon(); } + /// Returns true if the element is located at a boundary (i.e. has at least one face without neighbour) + virtual bool isBoundaryElement() const; /// Returns true if these two indeces form an edge and false otherwise virtual bool isEdge(unsigned i, unsigned j) const = 0; diff --git a/Tests/MeshLib/TestQuadMesh.cpp b/Tests/MeshLib/TestQuadMesh.cpp index 1d7ed02eac0b5c21d0edea9a31fa8cc7579aa8d6..20cfc94c82fca6d6946b6f3d18aa6a754e958397 100644 --- a/Tests/MeshLib/TestQuadMesh.cpp +++ b/Tests/MeshLib/TestQuadMesh.cpp @@ -209,6 +209,7 @@ TEST_F(MeshLibQuadMesh, ElementNeighbors) // Test the test EXPECT_EQ(1u, ij_neighbors.first.size()); EXPECT_EQ(1u, ij_neighbors.second.size()); + ASSERT_TRUE(e->isBoundaryElement()); testNeighbors(e, i, j, ij_neighbors); }); @@ -222,6 +223,7 @@ TEST_F(MeshLibQuadMesh, ElementNeighbors) std::pair<Indices, Indices> const ij_neighbors = getNeighborIndices(i, j); // Test the test EXPECT_EQ(3u, ij_neighbors.first.size() + ij_neighbors.second.size()); + ASSERT_TRUE(e->isBoundaryElement()); testNeighbors(e, i, j, ij_neighbors); }); @@ -236,6 +238,7 @@ TEST_F(MeshLibQuadMesh, ElementNeighbors) // Test the test EXPECT_EQ(2u, ij_neighbors.first.size()); EXPECT_EQ(2u, ij_neighbors.second.size()); + ASSERT_FALSE(e->isBoundaryElement()); testNeighbors(e, i, j, ij_neighbors); });