diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index 6cf57cec18e821e52cd118a3d3f4ecaf3b2e4e08..9e81ba0cee548beb3bfdb5b51a9754ecd02866bb 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -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 diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h index 2056afbe4da47a237df3195a92b3a233c3d26606..0cca934b120ab2bd56cc25e34491163046e219e5 100644 --- a/MeshLib/Mesh.h +++ b/MeshLib/Mesh.h @@ -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)