OGS
MeshLib::NodeSearch Class Referencefinal

Detailed Description

Node search class.

Definition at line 17 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
std::size_t searchNodesConnectedToOnlyGivenElements (const std::vector< std::size_t > &elements)
std::size_t searchUnused ()
 Marks all unused nodes.
std::size_t searchBoundaryNodes ()
 Marks all boundary nodes.

Private Member Functions

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

Private Attributes

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

Constructor & Destructor Documentation

◆ NodeSearch()

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

Definition at line 15 of file NodeSearch.cpp.

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

References _mesh.

Member Function Documentation

◆ getSearchedNodeIDs()

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

return marked node IDs

Definition at line 23 of file NodeSearch.h.

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

References _marked_nodes.

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

◆ searchBoundaryNodes()

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

Marks all boundary nodes.

Definition at line 69 of file NodeSearch.cpp.

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

References _mesh, 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 17 of file NodeSearch.cpp.

19{
20 // Find out by how many elements a node would be removed.
21 //
22 // Note: If there are only few elements to be removed, using a different
23 // algorithm might be more memory efficient.
24 std::vector<std::size_t> node_marked_counts(_mesh.getNumberOfNodes(), 0);
25
26 for (std::size_t eid : elements)
27 {
28 auto* e = _mesh.getElement(eid);
29 for (unsigned i = 0; i < e->getNumberOfNodes(); i++)
30 {
31 node_marked_counts[getNodeIndex(*e, i)]++;
32 }
33 }
34
35 // Push back nodes which counts are equal to number of connected elements to
36 // that node.
37 std::vector<std::size_t> connected_nodes;
38 for (std::size_t i = 0; i < node_marked_counts.size(); i++)
39 {
40 if (node_marked_counts[i] ==
41 _mesh.getElementsConnectedToNode(*_mesh.getNode(i)).size())
42 {
43 connected_nodes.push_back(i);
44 }
45 }
46
47 this->updateUnion(connected_nodes);
48 return connected_nodes.size();
49}
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition Element.cpp:226

References _mesh, MeshLib::getNodeIndex(), and updateUnion().

Referenced by MeshToolsLib::removeElements().

◆ searchUnused()

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

Marks all unused nodes.

Definition at line 51 of file NodeSearch.cpp.

52{
53 const std::size_t nNodes(_mesh.getNumberOfNodes());
54 const std::vector<MeshLib::Node*>& nodes(_mesh.getNodes());
55 std::vector<std::size_t> del_node_idx;
56
57 for (unsigned i = 0; i < nNodes; ++i)
58 {
59 if (_mesh.getElementsConnectedToNode(*nodes[i]).empty())
60 {
61 del_node_idx.push_back(i);
62 }
63 }
64
65 this->updateUnion(del_node_idx);
66 return del_node_idx.size();
67}

References _mesh, and updateUnion().

Referenced by MeshToolsLib::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 147 of file NodeSearch.cpp.

148{
149 std::vector<std::size_t> vec_temp(vec.size() + _marked_nodes.size());
150 auto it = std::set_union(vec.begin(), vec.end(), _marked_nodes.begin(),
151 _marked_nodes.end(), vec_temp.begin());
152 vec_temp.resize(it - vec_temp.begin());
153 _marked_nodes.assign(vec_temp.begin(), vec_temp.end());
154}

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 43 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 41 of file NodeSearch.h.

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


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