Skip to content
Snippets Groups Projects
Commit 1ad35ab9 authored by Tom Fischer's avatar Tom Fischer
Browse files

[MeL/Elements] Impl. hasNeighbor as free fct. areNeighbors.

parent 53d69f78
No related branches found
No related tags found
No related merge requests found
...@@ -52,7 +52,7 @@ boost::optional<unsigned> Element::addNeighbor(Element* e) ...@@ -52,7 +52,7 @@ boost::optional<unsigned> Element::addNeighbor(Element* e)
return boost::optional<unsigned>(); return boost::optional<unsigned>();
} }
if (this->hasNeighbor(e)) if (areNeighbors(this, e))
{ {
return boost::optional<unsigned>(); return boost::optional<unsigned>();
} }
...@@ -149,19 +149,6 @@ std::size_t Element::getNodeIndex(unsigned i) const ...@@ -149,19 +149,6 @@ std::size_t Element::getNodeIndex(unsigned i) const
#endif #endif
} }
bool Element::hasNeighbor(Element* elem) const
{
unsigned nNeighbors (this->getNumberOfNeighbors());
for (unsigned i = 0; i < nNeighbors; i++)
{
if (this->_neighbors[i] == elem)
{
return true;
}
}
return false;
}
bool Element::isBoundaryElement() const bool Element::isBoundaryElement() const
{ {
return std::any_of(_neighbors, _neighbors + this->getNumberOfNeighbors(), return std::any_of(_neighbors, _neighbors + this->getNumberOfNeighbors(),
...@@ -188,6 +175,18 @@ std::ostream& operator<<(std::ostream& os, Element const& e) ...@@ -188,6 +175,18 @@ std::ostream& operator<<(std::ostream& os, Element const& e)
} }
#endif // NDEBUG #endif // NDEBUG
bool areNeighbors(Element const* const element, Element const* const other)
{
unsigned nNeighbors(element->getNumberOfNeighbors());
for (unsigned i = 0; i < nNeighbors; i++)
{
if (element->getNeighbor(i) == other)
{
return true;
}
}
return false;
}
bool hasZeroVolume(MeshLib::Element const& element) bool hasZeroVolume(MeshLib::Element const& element)
{ {
......
...@@ -147,9 +147,6 @@ public: ...@@ -147,9 +147,6 @@ public:
*/ */
virtual ElementErrorCode validate() const = 0; virtual ElementErrorCode validate() const = 0;
/// Returns true if elem is a neighbour of this element and false otherwise.
bool hasNeighbor(Element* elem) const;
/// Destructor /// Destructor
virtual ~Element(); virtual ~Element();
......
...@@ -71,14 +71,14 @@ TEST_F(MeshLibLineMesh, ElementNeigbors) ...@@ -71,14 +71,14 @@ TEST_F(MeshLibLineMesh, ElementNeigbors)
// elements. // elements.
ASSERT_EQ(1u, count_neighbors(elements.front())); ASSERT_EQ(1u, count_neighbors(elements.front()));
ASSERT_EQ(1u, count_neighbors(elements.back())); ASSERT_EQ(1u, count_neighbors(elements.back()));
ASSERT_TRUE(elements.front()->hasNeighbor(elements[1])); ASSERT_TRUE(areNeighbors(elements.front(), elements[1]));
ASSERT_TRUE(elements.back()->hasNeighbor(elements[elements.size()-2])); ASSERT_TRUE(areNeighbors(elements.back(), elements[elements.size()-2]));
for (std::size_t i = 1; i < elements.size() - 1; ++i) for (std::size_t i = 1; i < elements.size() - 1; ++i)
{ {
ASSERT_EQ(2u, count_neighbors(elements[i])); ASSERT_EQ(2u, count_neighbors(elements[i]));
ASSERT_TRUE(elements[i]->hasNeighbor(elements[i-1])); ASSERT_TRUE(areNeighbors(elements[i], elements[i-1]));
ASSERT_TRUE(elements[i]->hasNeighbor(elements[i+1])); ASSERT_TRUE(areNeighbors(elements[i], elements[i+1]));
} }
} }
......
...@@ -221,12 +221,12 @@ TEST_F(MeshLibQuadMesh, ElementNeighbors) ...@@ -221,12 +221,12 @@ TEST_F(MeshLibQuadMesh, ElementNeighbors)
std::pair<Indices, Indices> const& neighbors) { std::pair<Indices, Indices> const& neighbors) {
for (auto i_neighbor : neighbors.first) for (auto i_neighbor : neighbors.first)
{ {
ASSERT_TRUE(e->hasNeighbor(getElement(i_neighbor, j))); ASSERT_TRUE(areNeighbors(e, getElement(i_neighbor, j)));
} }
for (auto j_neighbor : neighbors.second) for (auto j_neighbor : neighbors.second)
{ {
ASSERT_TRUE(e->hasNeighbor(getElement(i, j_neighbor))); ASSERT_TRUE(areNeighbors(e, getElement(i, j_neighbor)));
} }
}; };
......
...@@ -107,13 +107,13 @@ TEST_F(MeshLibTriLineMesh, NodeToElementConnectivity) ...@@ -107,13 +107,13 @@ TEST_F(MeshLibTriLineMesh, NodeToElementConnectivity)
TEST_F(MeshLibTriLineMesh, ElementToElementConnectivity) TEST_F(MeshLibTriLineMesh, ElementToElementConnectivity)
{ {
// Triangles have other triangles as neighbors only. // Triangles have other triangles as neighbors only.
EXPECT_TRUE(elements[0]->hasNeighbor(elements[1])); EXPECT_TRUE(areNeighbors(elements[0], elements[1]));
EXPECT_TRUE(elements[1]->hasNeighbor(elements[0])); EXPECT_TRUE(areNeighbors(elements[1], elements[0]));
EXPECT_FALSE(elements[0]->hasNeighbor(elements[2])); EXPECT_FALSE(areNeighbors(elements[0], elements[2]));
EXPECT_FALSE(elements[1]->hasNeighbor(elements[2])); EXPECT_FALSE(areNeighbors(elements[1], elements[2]));
// Line has no neighbors // Line has no neighbors
EXPECT_FALSE(elements[2]->hasNeighbor(elements[0])); EXPECT_FALSE(areNeighbors(elements[2], elements[0]));
EXPECT_FALSE(elements[2]->hasNeighbor(elements[1])); EXPECT_FALSE(areNeighbors(elements[2], elements[1]));
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment