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

[MeL/Mesh] Make setNodesConnectedByElements a free fct.

Rename setNodesConnectedByElements to
calculateNodesConnectedByElements and make it a free
function. This 'out sourcing' makes it possible to
compute the connection information only when it is
required.
parent f5173108
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,6 @@ Mesh::Mesh(std::string name,
}
this->setDimension();
this->setElementsConnectedToNodes();
this->setNodesConnectedByElements();
this->setElementNeighbors();
this->calcEdgeLengthRange();
......@@ -103,7 +102,6 @@ Mesh::Mesh(const Mesh& mesh)
this->setDimension();
}
this->setElementsConnectedToNodes();
// this->setNodesConnectedByElements();
this->setElementNeighbors();
}
......@@ -236,40 +234,6 @@ void Mesh::setElementNeighbors()
}
}
void Mesh::setNodesConnectedByElements()
{
// Allocate temporary space for adjacent nodes.
std::vector<Node*> adjacent_nodes;
for (Node* const node : _nodes)
{
adjacent_nodes.clear();
// Get all elements, to which this node is connected.
std::vector<Element*> const& conn_elems = node->getElements();
// And collect all elements' nodes.
for (Element const* const element : conn_elems)
{
Node* const* const single_elem_nodes = element->getNodes();
std::size_t const nnodes = element->getNumberOfNodes();
for (std::size_t n = 0; n < nnodes; n++)
{
adjacent_nodes.push_back(single_elem_nodes[n]);
}
}
// Make nodes unique and sorted by their ids.
// This relies on the node's id being equivalent to it's address.
std::sort(adjacent_nodes.begin(), adjacent_nodes.end(),
[](Node* a, Node* b) { return a->getID() < b->getID(); });
auto const last =
std::unique(adjacent_nodes.begin(), adjacent_nodes.end());
adjacent_nodes.erase(last, adjacent_nodes.end());
node->setConnectedNodes(adjacent_nodes);
}
}
void Mesh::checkNonlinearNodeIDs() const
{
for (MeshLib::Element const* e : _elements)
......@@ -386,4 +350,41 @@ std::unique_ptr<MeshLib::Mesh> createMeshFromElementSelection(
return mesh;
}
std::vector<std::vector<Node*>> calculateNodesConnectedByElements(
Mesh const& mesh)
{
std::vector<std::vector<Node*>> nodes_connected_by_elements;
auto const& nodes = mesh.getNodes();
nodes_connected_by_elements.resize(nodes.size());
for (std::size_t i = 0; i < nodes.size(); ++i)
{
auto& adjacent_nodes = nodes_connected_by_elements[i];
auto const* node = nodes[i];
// Get all elements, to which this node is connected.
auto const& connected_elements = node->getElements();
// And collect all elements' nodes.
for (Element const* const element : connected_elements)
{
Node* const* const single_elem_nodes = element->getNodes();
std::size_t const nnodes = element->getNumberOfNodes();
for (std::size_t n = 0; n < nnodes; n++)
{
adjacent_nodes.push_back(single_elem_nodes[n]);
}
}
// Make nodes unique and sorted by their ids.
// This relies on the node's id being equivalent to it's address.
std::sort(adjacent_nodes.begin(), adjacent_nodes.end(),
[](Node* a, Node* b) { return a->getID() < b->getID(); });
auto const last =
std::unique(adjacent_nodes.begin(), adjacent_nodes.end());
adjacent_nodes.erase(last, adjacent_nodes.end());
}
return nodes_connected_by_elements;
}
} // namespace MeshLib
......@@ -150,10 +150,6 @@ protected:
/// Note: Using this implementation, an element e can only have neighbors that have the same dimensionality as e.
void setElementNeighbors();
/// Computes the element-connectivity of nodes. Two nodes i and j are
/// connected if they are shared by an element.
void setNodesConnectedByElements();
/// Check if all the nonlinear nodes are stored at the end of the node vector
void checkNonlinearNodeIDs() const;
......@@ -177,6 +173,10 @@ protected:
bool _is_axially_symmetric = false;
}; /* class */
/// Computes the element-connectivity of nodes. Two nodes i and j are
/// connected if they are shared by an element.
std::vector<std::vector<Node*>> calculateNodesConnectedByElements(
Mesh const& mesh);
/// Meshes are equal if their id's are equal.
inline bool operator==(Mesh const& a, Mesh const& b)
......
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