OGS
MeshLib::NodeSearch Class Referencefinal

Detailed Description

Node search class.

Definition at line 24 of file NodeSearch.h.

#include <NodeSearch.h>

Collaboration diagram for MeshLib::NodeSearch:
[legend]

Public Member Functions

 NodeSearch (const MeshLib::Mesh &mesh)
 
const std::vector< std::size_t > & getSearchedNodeIDs () const
 return marked node IDs More...
 
std::size_t searchNodesConnectedToOnlyGivenElements (const std::vector< std::size_t > &elements)
 
std::size_t searchUnused ()
 Marks all unused nodes. More...
 
std::size_t searchBoundaryNodes ()
 Marks all boundary nodes. More...
 

Private Member Functions

void updateUnion (const std::vector< std::size_t > &vec)
 Updates the vector of marked items with values from vec. More...
 

Private Attributes

const MeshLib::Mesh_mesh
 The mesh from which elements should be removed. More...
 
std::vector< std::size_t > _marked_nodes
 The vector of element indices that should be removed. More...
 

Constructor & Destructor Documentation

◆ NodeSearch()

MeshLib::NodeSearch::NodeSearch ( const MeshLib::Mesh mesh)
explicit

Definition at line 22 of file NodeSearch.cpp.

22: _mesh(mesh) {}
const MeshLib::Mesh & _mesh
The mesh from which elements should be removed.
Definition: NodeSearch.h:48

Member Function Documentation

◆ getSearchedNodeIDs()

const std::vector< std::size_t > & MeshLib::NodeSearch::getSearchedNodeIDs ( ) const
inline

return marked node IDs

Definition at line 30 of file NodeSearch.h.

30{return _marked_nodes; }
std::vector< std::size_t > _marked_nodes
The vector of element indices that should be removed.
Definition: NodeSearch.h:50

References _marked_nodes.

Referenced by ProcessLib::LIE::anonymous_namespace{MeshUtils.cpp}::IsCrackTip::IsCrackTip(), MeshLib::MeshValidation::allNodesUsed(), LayeredMeshGenerator::getMesh(), MeshAnalysisDialog::on_startButton_pressed(), and MeshLib::removeElements().

◆ searchBoundaryNodes()

std::size_t MeshLib::NodeSearch::searchBoundaryNodes ( )

Marks all boundary nodes.

Definition at line 76 of file NodeSearch.cpp.

77{
78 std::vector<std::size_t> vec_boundary_nodes;
79 if (_mesh.getDimension() == 1)
80 {
81 for (MeshLib::Node const* n : _mesh.getNodes())
82 {
83 if (_mesh.getElementsConnectedToNode(*n).size() == 1)
84 {
85 vec_boundary_nodes.push_back(n->getID());
86 }
87 }
88 }
89 else if (_mesh.getDimension() == 2)
90 {
91 for (MeshLib::Element const* elem : _mesh.getElements())
92 {
93 if (elem->getDimension() < _mesh.getDimension())
94 {
95 continue;
96 }
97 if (!elem->isBoundaryElement())
98 {
99 continue;
100 }
101
102 std::size_t const n_edges(elem->getNumberOfEdges());
103 for (std::size_t i = 0; i < n_edges; ++i)
104 {
105 if (elem->getNeighbor(i) != nullptr)
106 {
107 continue;
108 }
109 std::unique_ptr<MeshLib::Element const> edge(elem->getEdge(i));
110 for (unsigned j = 0; j < edge->getNumberOfNodes(); j++)
111 {
112 vec_boundary_nodes.push_back(edge->getNode(j)->getID());
113 }
114 }
115 }
116 }
117 else
118 {
119 for (MeshLib::Element const* elem : _mesh.getElements())
120 {
121 if (elem->getDimension() < _mesh.getDimension())
122 {
123 continue;
124 }
125 if (!elem->isBoundaryElement())
126 {
127 continue;
128 }
129
130 std::size_t const n_faces(elem->getNumberOfFaces());
131 for (std::size_t i = 0; i < n_faces; ++i)
132 {
133 if (elem->getNeighbor(i) != nullptr)
134 {
135 continue;
136 }
137 std::unique_ptr<MeshLib::Element const> face(elem->getFace(i));
138 for (unsigned j = 0; j < face->getNumberOfNodes(); j++)
139 {
140 vec_boundary_nodes.push_back(face->getNode(j)->getID());
141 }
142 }
143 }
144 }
145 std::sort(vec_boundary_nodes.begin(), vec_boundary_nodes.end());
146 vec_boundary_nodes.erase(
147 std::unique(vec_boundary_nodes.begin(), vec_boundary_nodes.end()),
148 vec_boundary_nodes.end());
149
150 this->updateUnion(vec_boundary_nodes);
151 return vec_boundary_nodes.size();
152}
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:100
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:103
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:76
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition: Mesh.cpp:238
void updateUnion(const std::vector< std::size_t > &vec)
Updates the vector of marked items with values from vec.
Definition: NodeSearch.cpp:154

References _mesh, MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getElementsConnectedToNode(), MeshLib::Mesh::getNodes(), and updateUnion().

Referenced by ProcessLib::LIE::anonymous_namespace{MeshUtils.cpp}::IsCrackTip::IsCrackTip().

◆ searchNodesConnectedToOnlyGivenElements()

std::size_t MeshLib::NodeSearch::searchNodesConnectedToOnlyGivenElements ( const std::vector< std::size_t > &  elements)

Marks all nodes connected to any of the given elements ids.

Returns
number of connected nodes.

Definition at line 24 of file NodeSearch.cpp.

26{
27 // Find out by how many elements a node would be removed.
28 //
29 // Note: If there are only few elements to be removed, using a different
30 // algorithm might be more memory efficient.
31 std::vector<std::size_t> node_marked_counts(_mesh.getNumberOfNodes(), 0);
32
33 for (std::size_t eid : elements)
34 {
35 auto* e = _mesh.getElement(eid);
36 for (unsigned i = 0; i < e->getNumberOfNodes(); i++)
37 {
38 node_marked_counts[getNodeIndex(*e, i)]++;
39 }
40 }
41
42 // Push back nodes which counts are equal to number of connected elements to
43 // that node.
44 std::vector<std::size_t> connected_nodes;
45 for (std::size_t i = 0; i < node_marked_counts.size(); i++)
46 {
47 if (node_marked_counts[i] ==
49 {
50 connected_nodes.push_back(i);
51 }
52 }
53
54 this->updateUnion(connected_nodes);
55 return connected_nodes.size();
56}
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition: Mesh.h:79
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition: Mesh.h:82
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:94
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition: Element.cpp:219

References _mesh, MeshLib::Mesh::getElement(), MeshLib::Mesh::getElementsConnectedToNode(), MeshLib::Mesh::getNode(), MeshLib::getNodeIndex(), MeshLib::Mesh::getNumberOfNodes(), and updateUnion().

Referenced by MeshLib::removeElements().

◆ searchUnused()

std::size_t MeshLib::NodeSearch::searchUnused ( )

Marks all unused nodes.

Definition at line 58 of file NodeSearch.cpp.

59{
60 const std::size_t nNodes(_mesh.getNumberOfNodes());
61 const std::vector<MeshLib::Node*>& nodes(_mesh.getNodes());
62 std::vector<std::size_t> del_node_idx;
63
64 for (unsigned i = 0; i < nNodes; ++i)
65 {
66 if (_mesh.getElementsConnectedToNode(*nodes[i]).empty())
67 {
68 del_node_idx.push_back(i);
69 }
70 }
71
72 this->updateUnion(del_node_idx);
73 return del_node_idx.size();
74}

References _mesh, MeshLib::Mesh::getElementsConnectedToNode(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfNodes(), and updateUnion().

Referenced by MeshLib::MeshValidation::allNodesUsed(), LayeredMeshGenerator::getMesh(), and MeshAnalysisDialog::on_startButton_pressed().

◆ updateUnion()

void MeshLib::NodeSearch::updateUnion ( const std::vector< std::size_t > &  vec)
private

Updates the vector of marked items with values from vec.

Definition at line 154 of file NodeSearch.cpp.

155{
156 std::vector<std::size_t> vec_temp(vec.size() + _marked_nodes.size());
157 auto it = std::set_union(vec.begin(), vec.end(), _marked_nodes.begin(),
158 _marked_nodes.end(), vec_temp.begin());
159 vec_temp.resize(it - vec_temp.begin());
160 _marked_nodes.assign(vec_temp.begin(), vec_temp.end());
161}

References _marked_nodes.

Referenced by searchBoundaryNodes(), searchNodesConnectedToOnlyGivenElements(), and searchUnused().

Member Data Documentation

◆ _marked_nodes

std::vector<std::size_t> MeshLib::NodeSearch::_marked_nodes
private

The vector of element indices that should be removed.

Definition at line 50 of file NodeSearch.h.

Referenced by getSearchedNodeIDs(), and updateUnion().

◆ _mesh

const MeshLib::Mesh& MeshLib::NodeSearch::_mesh
private

The mesh from which elements should be removed.

Definition at line 48 of file NodeSearch.h.

Referenced by searchBoundaryNodes(), searchNodesConnectedToOnlyGivenElements(), and searchUnused().


The documentation for this class was generated from the following files: